refreshcontrol

Solutions on MaxInterview for refreshcontrol by the best coders in the world

showing results for - "refreshcontrol"
Paula
28 Sep 2019
1import React from 'react';
2import { RefreshControl, SafeAreaView, ScrollView, StyleSheet, Text } from 'react-native';
3
4const wait = (timeout) => {
5  return new Promise(resolve => setTimeout(resolve, timeout));
6}
7
8const App = () => {
9  const [refreshing, setRefreshing] = React.useState(false);
10
11  const onRefresh = React.useCallback(() => {
12    setRefreshing(true);
13    wait(2000).then(() => setRefreshing(false));
14  }, []);
15
16  return (
17    <SafeAreaView style={styles.container}>
18      <ScrollView
19        contentContainerStyle={styles.scrollView}
20        refreshControl={
21          <RefreshControl
22            refreshing={refreshing}
23            onRefresh={onRefresh}
24          />
25        }
26      >
27        <Text>Pull down to see RefreshControl indicator</Text>
28      </ScrollView>
29    </SafeAreaView>
30  );
31}
32
33const styles = StyleSheet.create({
34  container: {
35    flex: 1,
36  },
37  scrollView: {
38    flex: 1,
39    backgroundColor: 'pink',
40    alignItems: 'center',
41    justifyContent: 'center',
42  },
43});
44
45export default App;