-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
109 lines (99 loc) · 2.42 KB
/
App.tsx
File metadata and controls
109 lines (99 loc) · 2.42 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
import {NavigationContainer} from '@react-navigation/native';
import {
createNativeStackNavigator,
NativeStackScreenProps,
} from '@react-navigation/native-stack';
import {useState} from 'react';
import {Button, StyleSheet, Text, View} from 'react-native';
import Animated, {useSharedValue} from 'react-native-reanimated';
export type StackParamList = {
First: undefined;
Second: undefined;
Third: undefined;
};
const Stack = createNativeStackNavigator<StackParamList>();
const Counter = () => {
const [count, setCount] = useState(0);
return (
<View>
<Text>Rerenders: {count}</Text>
<Button
title="Trigger Rerender"
onPress={() => setCount(count + 1)}
color="#aaa"
/>
</View>
);
};
const First = ({navigation}: NativeStackScreenProps<StackParamList>) => {
const animatedValue = useSharedValue(1);
return (
<View style={styles.container}>
<Animated.View
style={[
styles.animatedContainer,
{transform: [{scale: animatedValue}]},
]}>
<Text>Animated.View</Text>
</Animated.View>
<Button
title="Go Next"
onPress={() => {
navigation.navigate('Second');
}}
/>
</View>
);
};
const Second = ({navigation}: NativeStackScreenProps<StackParamList>) => {
return (
<View style={styles.container}>
<Counter />
<Button
title="Go Next"
onPress={() => {
navigation.navigate('Third');
}}
/>
</View>
);
};
const Third = ({navigation}: NativeStackScreenProps<StackParamList>) => {
return (
<View style={styles.container}>
<Counter />
<Button title="Go Back" onPress={navigation.goBack} />
</View>
);
};
const App = () => {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="First" component={First} />
<Stack.Screen name="Second" component={Second} />
<Stack.Screen name="Third" component={Third} />
</Stack.Navigator>
</NavigationContainer>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
gap: 20,
justifyContent: 'center',
alignItems: 'center',
marginVertical: 120,
marginHorizontal: 20,
borderWidth: 1,
borderStyle: 'dashed',
},
animatedContainer: {
width: 150,
height: 150,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#a2d2ff',
},
});