Skip to content

chore: add custom refresh control example #4545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions docs/refreshcontrol.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<RefreshControl
refreshing={refreshing}
onRefresh={onRefresh}
{...props}
/>
);
};

const App = () => {
const [refreshing, setRefreshing] = React.useState(false);

const onRefresh = React.useCallback(() => {
setRefreshing(true);
setTimeout(() => {
setRefreshing(false);
}, 2000);
}, []);

return (
<SafeAreaProvider>
<SafeAreaView style={styles.container}>
<ScrollView
contentContainerStyle={styles.scrollView}
refreshControl={<CustomRefreshControl />}>
<Text>Pull down to see RefreshControl indicator</Text>
</ScrollView>
</SafeAreaView>
</SafeAreaProvider>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
},
scrollView: {
flex: 1,
backgroundColor: 'pink',
alignItems: 'center',
justifyContent: 'center',
},
});

export default App;
```

---

# Reference
Expand Down