File tree 3 files changed +11
-9
lines changed
3 files changed +11
-9
lines changed Original file line number Diff line number Diff line change 9
9
"web" : " expo start --web"
10
10
},
11
11
"dependencies" : {
12
+ "@react-native-community/hooks" : " ^3.0.0" ,
12
13
"@react-navigation/native" : " ^6.1.1" ,
13
14
"@react-navigation/native-stack" : " ^6.9.7" ,
14
15
"expo" : " ~47.0.9" ,
Original file line number Diff line number Diff line change @@ -4,25 +4,21 @@ import { AnimatedScrollView } from '@kanelloc/react-native-animated-header-scrol
4
4
import { data , isIOS } from '../utils' ;
5
5
import { RefreshControl , StyleSheet } from 'react-native' ;
6
6
import { SafeAreaView } from 'react-native-safe-area-context' ;
7
+ import { useRefresh } from '@react-native-community/hooks' ;
7
8
8
- const wait = ( timeout : any ) => {
9
- return new Promise ( ( resolve ) => setTimeout ( resolve , timeout ) ) ;
9
+ const fetch = ( ) => {
10
+ return new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) ) ;
10
11
} ;
11
12
12
13
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 ) ;
19
15
20
16
return (
21
17
< SafeAreaView style = { styles . container } edges = { [ 'bottom' ] } >
22
18
< AnimatedScrollView
23
19
refreshControl = {
24
20
< RefreshControl
25
- refreshing = { refreshing }
21
+ refreshing = { isRefreshing }
26
22
onRefresh = { onRefresh }
27
23
style = { styles . refresh }
28
24
progressViewOffset = { 32 } // Add offset to position correctly progressView in iOS
Original file line number Diff line number Diff line change 1765
1765
prompts "^2.4.0"
1766
1766
semver "^6.3.0"
1767
1767
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
+
1768
1773
" @react-native/[email protected] " :
1769
1774
version "1.0.0"
1770
1775
resolved "https://registry.yarnpkg.com/@react-native/assets/-/assets-1.0.0.tgz#c6f9bf63d274bafc8e970628de24986b30a55c8e"
You can’t perform that action at this time.
0 commit comments