Skip to content

Commit 631380c

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

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

docs/refreshcontrol.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,71 @@ export default App;
5454

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

59124
# Reference

0 commit comments

Comments
 (0)