Skip to content

Commit b8edb0d

Browse files
committed
chore: add custom refresh control example
1 parent 71b23ed commit b8edb0d

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

Diff for: docs/refreshcontrol.md

+65
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,71 @@ const styles = StyleSheet.create({
5252
export default App;
5353
```
5454

55+
## Example Custom Refresh Control
56+
57+
// You need to pass the props that you received to `RefreshControl`
58+
const CustomRefreshControl = (props) => {
59+
const [refreshing, setRefreshing] = useState(false);
60+
61+
const onRefresh = () => {
62+
setRefreshing(true);
63+
setTimeout(() => {
64+
setRefreshing(false);
65+
}, 2000);
66+
};
67+
68+
return (
69+
<RefreshControl
70+
refreshing={refreshing}
71+
onRefresh={onRefresh}
72+
{...props}
73+
/>
74+
);
75+
};
76+
77+
```SnackPlayer name=RefreshControl&supportedPlatforms=ios,android
78+
import React from 'react';
79+
import {RefreshControl, ScrollView, StyleSheet, Text} from 'react-native';
80+
import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';
81+
82+
const App = () => {
83+
const [refreshing, setRefreshing] = React.useState(false);
84+
85+
const onRefresh = React.useCallback(() => {
86+
setRefreshing(true);
87+
setTimeout(() => {
88+
setRefreshing(false);
89+
}, 2000);
90+
}, []);
91+
92+
return (
93+
<SafeAreaProvider>
94+
<SafeAreaView style={styles.container}>
95+
<ScrollView
96+
contentContainerStyle={styles.scrollView}
97+
refreshControl={<CustomRefreshControl />}>
98+
<Text>Pull down to see RefreshControl indicator</Text>
99+
</ScrollView>
100+
</SafeAreaView>
101+
</SafeAreaProvider>
102+
);
103+
};
104+
105+
const styles = StyleSheet.create({
106+
container: {
107+
flex: 1,
108+
},
109+
scrollView: {
110+
flex: 1,
111+
backgroundColor: 'pink',
112+
alignItems: 'center',
113+
justifyContent: 'center',
114+
},
115+
});
116+
117+
export default App;
118+
```
119+
55120
> Note: `refreshing` is a controlled prop, this is why it needs to be set to `true` in the `onRefresh` function otherwise the refresh indicator will stop immediately.
56121
57122
---

0 commit comments

Comments
 (0)