Skip to content

Commit d72c255

Browse files
authored
chore: update refresh control example (#23)
* chore: install react native hooks * feat: update refresh control example
1 parent 38b2a8d commit d72c255

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

Diff for: example/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"web": "expo start --web"
1010
},
1111
"dependencies": {
12+
"@react-native-community/hooks": "^3.0.0",
1213
"@react-navigation/native": "^6.1.1",
1314
"@react-navigation/native-stack": "^6.9.7",
1415
"expo": "~47.0.9",

Diff for: example/src/screens/RefreshControlExample.tsx

+5-9
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,21 @@ import { AnimatedScrollView } from '@kanelloc/react-native-animated-header-scrol
44
import { data, isIOS } from '../utils';
55
import { RefreshControl, StyleSheet } from 'react-native';
66
import { SafeAreaView } from 'react-native-safe-area-context';
7+
import { useRefresh } from '@react-native-community/hooks';
78

8-
const wait = (timeout: any) => {
9-
return new Promise((resolve) => setTimeout(resolve, timeout));
9+
const fetch = () => {
10+
return new Promise((resolve) => setTimeout(resolve, 5000));
1011
};
1112

1213
export const RefreshControlExample = () => {
13-
const [refreshing, setRefreshing] = React.useState(false);
14-
15-
const onRefresh = React.useCallback(() => {
16-
setRefreshing(true);
17-
wait(2000).then(() => setRefreshing(false));
18-
}, []);
14+
const { isRefreshing, onRefresh } = useRefresh(fetch);
1915

2016
return (
2117
<SafeAreaView style={styles.container} edges={['bottom']}>
2218
<AnimatedScrollView
2319
refreshControl={
2420
<RefreshControl
25-
refreshing={refreshing}
21+
refreshing={isRefreshing}
2622
onRefresh={onRefresh}
2723
style={styles.refresh}
2824
progressViewOffset={32} // Add offset to position correctly progressView in iOS

Diff for: example/yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,11 @@
17651765
prompts "^2.4.0"
17661766
semver "^6.3.0"
17671767

1768+
"@react-native-community/hooks@^3.0.0":
1769+
version "3.0.0"
1770+
resolved "https://registry.yarnpkg.com/@react-native-community/hooks/-/hooks-3.0.0.tgz#af5f2ca32eea59b792ce9e3d9a4cf0354f9b195f"
1771+
integrity sha512-g2OyxXHfwIytXUJitBR6Z/ISoOfp0WKx5FOv+NqJ/CrWjRDcTw6zXE5I1C9axfuh30kJqzWchVfCDrkzZYTxqg==
1772+
17681773
"@react-native/[email protected]":
17691774
version "1.0.0"
17701775
resolved "https://registry.yarnpkg.com/@react-native/assets/-/assets-1.0.0.tgz#c6f9bf63d274bafc8e970628de24986b30a55c8e"

0 commit comments

Comments
 (0)