forked from react-native-oh-library/RNOHDCS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlashListDemo3.tsx
93 lines (85 loc) · 2.22 KB
/
FlashListDemo3.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React, { useEffect, useRef, useState } from "react";
import {
View,
Text,
Pressable,
StyleSheet,
} from "react-native";
import { FlashList } from "@shopify/flash-list";
const generateArray = (size: number) => {
const arr = new Array(size);
for (let i = 0; i < size; i++) {
arr[i] = i;
}
return arr;
};
const List = () => {
const [refreshing, setRefreshing] = useState(false);
const [data, setData] = useState(generateArray(100));
const list = useRef<FlashList<number> | null>(null);
const viewabilityConfigRef = useRef({
itemVisiblePercentThreshold: 50,
waitForInteraction: true,
});
const onViewableItemsChanged = () => {
console.info('flashlist onViewableItemsChanged');
};
const viewabilityConfigCallbackPairs = [
{
viewabilityConfig: viewabilityConfigRef.current,
onViewableItemsChanged,
},
];
const renderItem = ({ item }: { item: number }) => {
const backgroundColor = item % 2 === 0 ? "#00a1f1" : "#ffbb00";
return (
<Pressable
onPress={() => {
console.info('flashlist renderItem refresh');
setRefreshing(!refreshing)
}}
>
<View
style={{
...styles.container,
backgroundColor: item > 97 ? "red" : backgroundColor,
height: item % 2 === 0 ? 100 : 200,
}}
>
<Text>Cell Id: {item}</Text>
</View>
</Pressable>
);
};
useEffect(() => {
console.info('flashlist component render')
}, [refreshing]);
return (
<FlashList
ref={list}
keyExtractor={(item: number) => {
return item.toString();
}}
getItemType={(item: number) => {
return item > 97 ? "even" : "odd";
}}
extraData={refreshing}
renderItem={renderItem}
estimatedItemSize={100}
data={data}
viewabilityConfigCallbackPairs={viewabilityConfigCallbackPairs}
overrideProps={{
contentContainerStyle: { paddingLeft: 10, paddingTop: 10, backgroundColor: 'red' },
}}
/>
);
};
export default List;
const styles = StyleSheet.create({
container: {
justifyContent: "space-around",
alignItems: "center",
height: 120,
backgroundColor: "#00a1f1",
},
});