diff --git a/docs/refreshcontrol.md b/docs/refreshcontrol.md index ae1509b660b..f884f13a4ca 100644 --- a/docs/refreshcontrol.md +++ b/docs/refreshcontrol.md @@ -54,6 +54,71 @@ export default App; > 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. +## Example Custom Refresh Control + +```SnackPlayer name=CustomRefreshControl&supportedPlatforms=ios,android +import React from 'react'; +import {RefreshControl, ScrollView, StyleSheet, Text} from 'react-native'; +import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context'; + +// You need to pass the props that you received to `RefreshControl` +const CustomRefreshControl = (props) => { + const [refreshing, setRefreshing] = React.useState(false); + + const onRefresh = () => { + setRefreshing(true); + setTimeout(() => { + setRefreshing(false); + }, 2000); + }; + + return ( + + ); +}; + +const App = () => { + const [refreshing, setRefreshing] = React.useState(false); + + const onRefresh = React.useCallback(() => { + setRefreshing(true); + setTimeout(() => { + setRefreshing(false); + }, 2000); + }, []); + + return ( + + + }> + Pull down to see RefreshControl indicator + + + + ); +}; + +const styles = StyleSheet.create({ + container: { + flex: 1, + }, + scrollView: { + flex: 1, + backgroundColor: 'pink', + alignItems: 'center', + justifyContent: 'center', + }, +}); + +export default App; +``` + --- # Reference