-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCreateGesture.js
99 lines (92 loc) · 2.88 KB
/
CreateGesture.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
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 { SafeAreaView, View, Text, Alert } from "react-native";
import _ from "lodash";
import GestureDetector, {
GesturePath,
Cursor,
GestureRecorder,
} from "react-native-gesture-detector";
const CreateGestureScreen = () => {
const [recorderOffset, setRecorderOffset] = useState(null);
const [detectorOffset, setDetectorOffset] = useState(null);
const [finishedGesture, setFinishedGesture] = useState([]);
return (
<SafeAreaView style={{ flex: 1 }}>
<GestureRecorder
onPanRelease={gesture => {
setFinishedGesture(gesture);
setDetectorOffset(recorderOffset);
}}
>
{({ gesture, offset }) => {
if (!_.isEqual(offset, recorderOffset) && offset !== null) {
setRecorderOffset(offset);
}
return (
<View
style={{
position: "relative",
width: "90%",
height: "50%",
left: "5%",
backgroundColor: "#eee",
}}
>
<View style={{ position: "relative", width: "100%", height: "100%" }}>
<GesturePath
path={gesture.map(coordinate => {
if (recorderOffset) {
return {
x: coordinate.x + recorderOffset.x,
y: coordinate.y + recorderOffset.y,
};
}
return coordinate;
})}
color="green"
slopRadius={30}
center={false}
/>
</View>
</View>
);
}}
</GestureRecorder>
<GestureDetector
onGestureFinish={() => Alert.alert(`Custom User Gesture finished!`)}
gestures={{ CustomUserGesture: finishedGesture }}
>
{({ coordinate }) => (
<View
style={{
position: "relative",
width: "90%",
height: "50%",
left: "5%",
backgroundColor: "red",
}}
>
<View style={{ position: "relative", width: "100%", height: "100%" }}>
<GesturePath
path={finishedGesture.map(coordinate => {
if (detectorOffset) {
return {
x: coordinate.x + detectorOffset.x,
y: coordinate.y + detectorOffset.y,
};
}
return coordinate;
})}
color="green"
slopRadius={30}
center={false}
/>
</View>
{coordinate && <Cursor {...coordinate} />}
</View>
)}
</GestureDetector>
</SafeAreaView>
);
};
export default CreateGestureScreen;