-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basic.js
55 lines (48 loc) · 1.24 KB
/
Basic.js
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
import { StatusBar } from "expo-status-bar";
import { useEffect } from "react";
import { StyleSheet, Text, View } from "react-native";
import Animated, {
useSharedValue,
useAnimatedStyle,
withTiming,
withSpring,
withRepeat,
} from "react-native-reanimated";
const SIZE = 100;
const handleRotation = (progress) => {
'worklet'
return `${progress.value * 2 * Math.PI}rad`;
};
export default function App() {
const progress = useSharedValue(1);
const scale = useSharedValue(2);
const reanimatedStyle = useAnimatedStyle(() => {
return {
opacity: progress.value,
borderRadius: (progress.value * SIZE) / 2,
transform: [{ scale: scale.value }, { rotate: handleRotation(progress) }],
};
}, []);
useEffect(() => {
progress.value = withRepeat(withSpring(0.5), 3, true);
scale.value = withRepeat(withSpring(1), 3, true);
}, []);
return (
<View style={styles.container}>
<Animated.View
style={[
{ height: SIZE, width: SIZE, backgroundColor: "blue" },
reanimatedStyle,
]}
></Animated.View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});