-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
138 lines (129 loc) · 3.2 KB
/
Copy pathApp.tsx
File metadata and controls
138 lines (129 loc) · 3.2 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import React, {useEffect, useState} from 'react';
import {
StyleSheet,
Dimensions,
View,
Text,
FlatList,
Button,
} from 'react-native';
import Animated, {
useSharedValue,
useAnimatedStyle,
withSpring,
withTiming,
Easing,
ReduceMotion,
} from 'react-native-reanimated';
const {width, height} = Dimensions.get('window');
const generateLargeData = (size: number) => {
return Array.from({length: size}, (_, index) => ({
id: index.toString(),
value: Math.random(),
}));
};
const App = () => {
const [time, setTime] = useState(Date.now());
const translateY = useSharedValue(0);
const data = generateLargeData(1000000);
const boxWidth = useSharedValue(20);
const renderItem = ({item}: {item: {id: string; value: number}}) => {
return (
<View style={[styles.item]}>
<Text style={styles.text2}>Item #{item.id}</Text>
<Text style={styles.text2}>Value: {item.value.toFixed(5)}</Text>
</View>
);
};
useEffect(() => {
const interval = setInterval(() => {
setTime(Date.now());
}, 1);
return () => clearInterval(interval);
}, []);
const animatedStyle = useAnimatedStyle(() => ({
transform: [{translateY: translateY.value}],
}));
return (
<View style={[styles.gestureContainer]}>
<Animated.View style={[styles.container, animatedStyle]}>
<FlatList
data={data}
renderItem={renderItem}
keyExtractor={item => item.id}
initialNumToRender={100}
maxToRenderPerBatch={50}
windowSize={50}
/>
<View style={styles.row}>
<Button
title="Down"
onPress={() => {
translateY.value = withSpring(translateY.value + 150, {
duration: 2000,
});
boxWidth.value = withSpring(boxWidth.value - 50, {
duration: 2000,
});
}}
/>
<Button
title="Up"
onPress={() => {
translateY.value = withTiming(translateY.value - 150, {
duration: 1000,
easing: Easing.inOut(Easing.quad),
reduceMotion: ReduceMotion.System,
});
boxWidth.value = withTiming(boxWidth.value + 50, {
duration: 1000,
});
}}
/>
</View>
<Animated.View
style={{
width: boxWidth,
height: 20,
backgroundColor: 'red',
}}></Animated.View>
<Text style={styles.text}>
{global?.nativeFabricUIManager
? 'New Architecture'
: 'Old Architecture'}
</Text>
</Animated.View>
</View>
);
};
const styles = StyleSheet.create({
gestureContainer: {
flex: 1,
},
container: {
width,
height,
backgroundColor: 'lightblue',
justifyContent: 'center',
alignItems: 'center',
},
text: {
fontSize: 24,
fontWeight: 'bold',
color: 'white',
},
item: {
height: 50,
justifyContent: 'center',
alignItems: 'center',
marginVertical: 2,
},
text2: {
color: 'white',
fontSize: 12,
},
row: {
flexDirection: 'row',
},
});
export default App;