-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathGestureCompositionScreen.tsx
More file actions
120 lines (110 loc) · 3.15 KB
/
GestureCompositionScreen.tsx
File metadata and controls
120 lines (110 loc) · 3.15 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
import { COLORS } from './colors';
function RaceDemo() {
const pan = Gesture.Pan()
.onStart(() => console.log('pan onStart'))
.onUpdate(() => console.log('pan onUpdate'))
.onEnd(() => console.log('pan onEnd'));
const longPress = Gesture.LongPress()
.onStart(() => console.log('longPress onStart'))
.onEnd(() => console.log('longPress onEnd'));
return (
<View style={styles.demo}>
<Text style={styles.text}>
Gesture.Race(pan, longPress) - the first gesture that meets its
activation criteria will activate
</Text>
<GestureDetector gesture={Gesture.Race(pan, longPress)}>
<View
style={[styles.largeBox, { backgroundColor: COLORS.KINDA_RED }]}
/>
</GestureDetector>
</View>
);
}
function ExclusiveDemo() {
const singleTap = Gesture.Tap().onStart(() => console.log('single tap!'));
const doubleTap = Gesture.Tap()
.onStart(() => console.log('double tap!'))
.numberOfTaps(2);
return (
<View style={styles.demo}>
<Text style={styles.text}>
Gesture.Exclusive(doubleTap, singleTap) - the second gesture will wait
for the failure of the first one
</Text>
<GestureDetector gesture={Gesture.Exclusive(doubleTap, singleTap)}>
<View
style={[styles.largeBox, { backgroundColor: COLORS.KINDA_GREEN }]}
/>
</GestureDetector>
</View>
);
}
function SimultaneousDemo() {
const pinch = Gesture.Pinch()
.onStart(() => console.log('pinch onStart'))
.onUpdate(() => console.log('pinch onUpdate'))
.onEnd(() => console.log('pinch onEnd'));
const rotation = Gesture.Rotation()
.onStart(() => console.log('rotation onStart'))
.onUpdate(() => console.log('rotation onUpdate'))
.onEnd(() => console.log('rotation onEnd'));
return (
<View style={styles.demo}>
<Text style={styles.text}>
Gesture.Simultaneous(pinch, rotation) - both gestures can activate and
process touches at the same time
</Text>
<GestureDetector gesture={Gesture.Simultaneous(pinch, rotation)}>
<View
style={[styles.largerBox, { backgroundColor: COLORS.KINDA_BLUE }]}
/>
</GestureDetector>
</View>
);
}
export default function ComponentsScreen() {
return (
<View style={styles.container}>
<Text style={styles.bold}>
Gesture Handler provides a simple API for using multiple gestures at
once in different configurations.
</Text>
<RaceDemo />
<ExclusiveDemo />
<SimultaneousDemo />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
bold: {
fontWeight: 'bold',
textAlign: 'center',
marginHorizontal: 20,
},
text: {
marginVertical: 3,
marginHorizontal: 10,
textAlign: 'center',
},
demo: {
marginVertical: 3,
alignItems: 'center',
},
largeBox: {
width: 100,
height: 100,
},
largerBox: {
width: 150,
height: 150,
},
});