-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
96 lines (84 loc) · 2.23 KB
/
App.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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* Generated with the TypeScript template
* https://github.com/react-native-community/react-native-template-typescript
*
* @format
*/
import React, {useEffect, useState} from 'react';
import {
Button,
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
useColorScheme,
View,
} from 'react-native';
import Animated, {
interpolateColor,
useAnimatedStyle,
useSharedValue,
withTiming,
} from 'react-native-reanimated';
import {Colors, Header} from 'react-native/Libraries/NewAppScreen';
const COUNTER_VALUES = [0, 1, 2, 3, 4, 5, 6];
const App = () => {
const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
const [counter, setCounter] = useState<number>(0);
const counterTransition = useSharedValue(0);
const counterStyle = useAnimatedStyle(() => ({
color: interpolateColor(counterTransition.value, COUNTER_VALUES, [
'#00000000', // #1 can't use 'transparent', 'rgba(0,0,0,0)' or '#00000000' - it has been working in v2.2.0
'#E21414',
'#E21414',
'#FBBA00',
'#FBBA00',
'#1ED25A',
'#1ED25A',
]),
}));
useEffect(() => {
counterTransition.value = withTiming(counter, {
duration: 500,
});
}, [counter]);
return (
<SafeAreaView style={backgroundStyle}>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={backgroundStyle}>
<Header />
<View
style={{
backgroundColor: isDarkMode ? Colors.black : Colors.white,
}}>
<Animated.Text style={[styles.sectionTitle, counterStyle]}>
TEST
</Animated.Text>
<Button
title={`Increment: ${counter}`}
onPress={() =>
setCounter(count =>
count === COUNTER_VALUES.length - 1 ? 0 : count + 1,
)
}
/>
</View>
</ScrollView>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
sectionTitle: {
fontSize: 24,
fontWeight: '600',
},
});
export default App;