Skip to content

Commit 1f77201

Browse files
committed
Update example
1 parent f04d434 commit 1f77201

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

  • apps/common-app/src/components/flatlist

apps/common-app/src/components/flatlist/index.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import React from 'react';
1+
import React, { useRef, useState } from 'react';
22
import { View, Text, StyleSheet } from 'react-native';
3-
import { FlatList, GestureHandlerRootView } from 'react-native-gesture-handler';
3+
import {
4+
FlatList,
5+
RefreshControl,
6+
GestureHandlerRootView,
7+
GHFlatListRef,
8+
} from 'react-native-gesture-handler';
49

510
const DATA = Array.from({ length: 20 }, (_, i) => ({
611
id: i.toString(),
@@ -14,15 +19,30 @@ const Item = ({ title }: { title: string }) => (
1419
);
1520

1621
export default function FlatListExample() {
22+
const [refreshing, setRefreshing] = useState(false);
23+
24+
const ref = useRef<GHFlatListRef>(null);
25+
26+
const onRefresh = () => {
27+
setRefreshing(true);
28+
console.log(ref.current);
29+
setTimeout(() => {
30+
setRefreshing(false);
31+
}, 1500);
32+
};
33+
1734
return (
1835
<GestureHandlerRootView>
1936
<FlatList
37+
refreshControl={
38+
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
39+
}
40+
ref={ref}
2041
data={DATA}
2142
keyExtractor={(item) => item.id}
2243
renderItem={({ item }) => <Item title={item.title} />}
2344
contentContainerStyle={styles.container}
2445
/>
25-
;
2646
</GestureHandlerRootView>
2747
);
2848
}

0 commit comments

Comments
 (0)