forked from react-native-oh-library/RNOHDCS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlashListDemo4.tsx
102 lines (92 loc) · 2.13 KB
/
FlashListDemo4.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
94
95
96
97
98
99
100
101
102
import React, { useEffect, useRef } from "react";
import {
Animated,
View,
RefreshControl,
Text,
} from 'react-native';
import { FlashList, CellContainer } from '@shopify/flash-list';
const AnimatedCellContainer = Animated.createAnimatedComponent(CellContainer);
const CustomCellRendererComponent = React.forwardRef((props: any, _) => {
const offset = useRef(new Animated.Value(400)).current;
const cellContainerRef = useRef<View>(null);
useEffect(() => {
Animated.sequence([
Animated.delay(props.index * 50),
Animated.spring(offset, {
toValue: 0,
useNativeDriver: true,
}),
]).start();
}, [props.index]);
useEffect(() => {
cellContainerRef.current?.setNativeProps({ opacity: 1 });
});
return (
<AnimatedCellContainer
ref={cellContainerRef}
{...props}
style={[
{ opacity: 0 },
{
transform: [
{
translateY: offset.interpolate({
inputRange: [0, 1],
outputRange: [0, -400],
}),
},
],
},
props.style]}
/>
);
});
CustomCellRendererComponent.displayName = "CustomCellRendererComponent";
interface ItemData {
title: string;
id: string;
}
const List = () => {
const DATA: ItemData[] = [
{
id: 'gd5jc6gnbb2sbrz9w8z2',
title: 'First Item',
},
{
id: 'jb95igwbswt13etu073o',
title: 'Second Item',
},
{
id: 'zcp3zsdkkjmc7cx66hjl',
title: 'Third Item',
},
{
id: 'fx72rfguehrydmd4n21l',
title: 'Fourth Item',
},
{
id: '8kadvdlhtr7m3yv3fp4v',
title: 'Fifth Item',
},
];
const renderItem = ({ item }: { item: ItemData }) => (
<View
style={{
padding: 20,
borderBottomWidth: 1,
borderBottomColor: '#ccc',
}}>
<Text style={{ fontSize: 16 }}>{item.title}</Text>
</View>
);
return (
<FlashList
data={DATA}
renderItem={renderItem}
refreshControl={<RefreshControl refreshing={true} />}
CellRendererComponent={CustomCellRendererComponent}
/>
);
}
export default List;