Skip to content

Commit b700e0c

Browse files
authored
feat: add new refresh control example (#6)
1 parent 3c65f02 commit b700e0c

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

example/src/App.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SafeAreaProvider } from 'react-native-safe-area-context';
88
import type { RootStackParamList } from './types';
99
import { ImageForegroundExample } from './screens/ImageForegroundExample';
1010
import { OnlyForegroundExample } from './screens/OnlyForegroundExample';
11+
import { RefreshControlExample } from './screens/RefreshControlExample';
1112

1213
const App = () => {
1314
const Stack = createNativeStackNavigator<RootStackParamList>();
@@ -36,6 +37,10 @@ const App = () => {
3637
name="OnlyForegroundExample"
3738
component={OnlyForegroundExample}
3839
/>
40+
<Stack.Screen
41+
name="RefreshControlExample"
42+
component={RefreshControlExample}
43+
/>
3944
</Stack.Navigator>
4045
</NavigationContainer>
4146
</SafeAreaProvider>

example/src/screens/ExamplesDirectory.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const ExamplesDirectory = ({ navigation }: Props) => {
1515
{ screen: SCREENS.SAFE_AREA_VIEW_EXAMPLE },
1616
{ screen: SCREENS.IMAGE_FOREGROUND_EXAMPLE },
1717
{ screen: SCREENS.ONLY_FOREGROUND_EXAMPLE },
18+
{ screen: SCREENS.REFRESH_CONTROL_EXAMPLE },
1819
];
1920

2021
return (
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { Card, TopNavBar, HeaderNavBar } from '../components';
2+
import * as React from 'react';
3+
import { AnimatedScrollView } from '@kanelloc/react-native-animated-header-scroll-view';
4+
import { data, isIOS } from '../utils';
5+
import { RefreshControl, StyleSheet } from 'react-native';
6+
import { SafeAreaView } from 'react-native-safe-area-context';
7+
8+
const wait = (timeout: any) => {
9+
return new Promise((resolve) => setTimeout(resolve, timeout));
10+
};
11+
12+
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+
}, []);
19+
20+
return (
21+
<SafeAreaView style={styles.container} edges={['bottom']}>
22+
<AnimatedScrollView
23+
refreshControl={
24+
<RefreshControl
25+
refreshing={refreshing}
26+
onRefresh={onRefresh}
27+
style={styles.refresh}
28+
progressViewOffset={32} // Add offset to position correctly progressView in iOS
29+
tintColor="black"
30+
/>
31+
}
32+
headerMaxHeight={400}
33+
topBarHeight={isIOS ? 90 : 70}
34+
HeaderNavbarComponent={<HeaderNavBar />}
35+
TopNavBarComponent={<TopNavBar />}
36+
headerImage={require('../../assets/cabin.jpg')}
37+
>
38+
{data.map((e) => {
39+
return <Card item={e} key={e} />;
40+
})}
41+
</AnimatedScrollView>
42+
</SafeAreaView>
43+
);
44+
};
45+
46+
const styles = StyleSheet.create({
47+
container: {
48+
flex: 1,
49+
},
50+
refresh: {
51+
zIndex: 10,
52+
},
53+
});

example/src/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export type RootStackParamList = {
55
SimpleExample: undefined;
66
ImageForegroundExample: undefined;
77
OnlyForegroundExample: undefined;
8+
RefreshControlExample: undefined;
89
};

example/src/utils/enums.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export enum SCREENS {
44
SAFE_AREA_VIEW_EXAMPLE = 'SafeAreaViewExample',
55
IMAGE_FOREGROUND_EXAMPLE = 'ImageForegroundExample',
66
ONLY_FOREGROUND_EXAMPLE = 'OnlyForegroundExample',
7+
REFRESH_CONTROL_EXAMPLE = 'RefreshControlExample',
78
}

0 commit comments

Comments
 (0)