-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathindex.tsx
More file actions
99 lines (84 loc) · 2.09 KB
/
index.tsx
File metadata and controls
99 lines (84 loc) · 2.09 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
import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {
Gesture,
GestureDetector,
Pressable,
} from 'react-native-gesture-handler';
import Animated, {
interpolateColor,
useAnimatedStyle,
useSharedValue,
withTiming,
} from 'react-native-reanimated';
const Colors = {
enabled: '#32a852',
disabled: '#b02525',
};
const AnimationDuration = 250;
export default function WebStylesResetExample() {
const [enabled, setEnabled] = useState(true);
const [x, setX] = useState(0);
const [y, setY] = useState(0);
const colorProgress = useSharedValue(0);
const animatedStyles = useAnimatedStyle(() => {
const backgroundColor = interpolateColor(
colorProgress.value,
[0, 1],
[Colors.enabled, Colors.disabled]
);
return { backgroundColor };
});
const g = Gesture.Pan()
.onUpdate((e) => {
setX(e.x);
setY(e.y);
})
.enabled(enabled);
return (
<View style={[styles.container, styles.centered]}>
<GestureDetector gesture={g} enableContextMenu={false}>
<Animated.View style={[styles.box, styles.centered, animatedStyles]}>
<Text style={{ fontSize: 32 }}> Lorem Ipsum </Text>
</Animated.View>
</GestureDetector>
<Pressable
style={[styles.button, styles.centered]}
onPress={() => {
setEnabled((prev) => !prev);
colorProgress.value = withTiming(enabled ? 1 : 0, {
duration: AnimationDuration,
});
}}>
<Text style={{ fontSize: 16 }}>{enabled ? 'Disable' : 'Enable'}</Text>
</Pressable>
<Text style={{ fontSize: 16 }}>
{' '}
x: {x}, y: {y}{' '}
</Text>
</View>
);
}
const styles = StyleSheet.create({
centered: {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
},
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
button: {
width: 250,
height: 35,
backgroundColor: 'plum',
borderRadius: 10,
margin: 25,
},
box: {
width: 250,
height: 250,
borderRadius: 25,
},
});