-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnim1.js
58 lines (51 loc) · 1.37 KB
/
Anim1.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
56
57
58
import { Button, StyleSheet, View, Text } from "react-native";
import React from "react";
import Animated, {
useSharedValue,
useAnimatedStyle,
withSpring,
} from "react-native-reanimated";
const Anim1 = () => {
const offset = useSharedValue(0);
const animatedStyles = useAnimatedStyle(() => {
return {
transform: [{ translateX: offset.value * 255 }],
};
});
return (
<>
<Animated.View style={[styles.box, animatedStyles]} />
<Button
onPress={() => (offset.value = withSpring(Math.random()))}
title="Move"
style={styles.btnstyle}
/>
<Button
onPress={() => (offset.value = withSpring(0))}
title="Move2"
style={styles.btnstyle}
/>
<Button
onPress={() => (offset.value = withSpring(0.9))}
title="Move3"
style={styles.btnstyle}
/>
<Button
onPress={() => (offset.value = 0.5)}
title="Move4"
style={styles.btnstyle}
/>
</>
);
};
const styles = StyleSheet.create({
box: {
height: 50,
width: 50,
backgroundColor: "blue",
},
btnstyle: {
width: 100,
},
});
export default Anim1;