-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathWobbleExample.tsx
67 lines (61 loc) · 1.46 KB
/
WobbleExample.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
import Animated, {
useSharedValue,
withTiming,
Easing,
useAnimatedStyle,
withRepeat,
withSequence,
} from 'react-native-reanimated';
import { View, Button, StyleSheet } from 'react-native';
import React from 'react';
const ANGLE = 9;
const TIME = 100;
const EASING = Easing.elastic(1.5);
function WobbleExample(): React.ReactElement {
const rotation = useSharedValue(1);
const style = useAnimatedStyle(() => {
return {
transform: [{ rotateZ: `${rotation.value}deg` }],
};
});
return (
<View
style={{
flex: 1,
flexDirection: 'column',
}}>
<Animated.View style={[styles.box, style]} />
<Button
title="start"
onPress={() => {
rotation.value = withSequence(
// deviate left to start from -ANGLE
withTiming(-ANGLE, { duration: TIME / 2, easing: EASING }),
// wobble between -ANGLE and ANGLE 7 times
withRepeat(
withTiming(ANGLE, {
duration: TIME,
easing: EASING,
}),
7,
true
),
// go back to 0 at the end
withTiming(0, { duration: TIME / 2, easing: EASING })
);
}}
/>
</View>
);
}
const styles = StyleSheet.create({
box: {
width: 80,
height: 80,
alignSelf: 'center',
margin: 50,
borderRadius: 15,
backgroundColor: '#001a72',
},
});
export default WobbleExample;