-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathindex.tsx
More file actions
181 lines (148 loc) · 4.89 KB
/
index.tsx
File metadata and controls
181 lines (148 loc) · 4.89 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import React from 'react';
import {
Gesture,
GestureDetector,
GestureType,
MouseButton,
Directions,
ScrollView,
} from 'react-native-gesture-handler';
import { StyleSheet, View, Text } from 'react-native';
const COLORS = ['darkmagenta', 'darkgreen', 'darkblue', 'crimson', 'pink'];
type TestProps = {
name: string;
gestureHandlers: GestureType[];
};
function Test({ name, gestureHandlers }: TestProps) {
return (
<View style={styles.center}>
<Text>{name}</Text>
<View
style={[
{ margin: 10, width: '100%', flexDirection: 'row' },
styles.center,
]}>
{gestureHandlers.map((handler, index) => {
return (
<GestureDetector gesture={handler} key={index}>
<View style={[styles.box, { backgroundColor: COLORS[index] }]} />
</GestureDetector>
);
})}
</View>
</View>
);
}
function TapTests() {
const leftTap = Gesture.Tap()
.mouseButton(MouseButton.LEFT)
.onEnd(() => console.log('Tap with left'));
const middleTap = Gesture.Tap()
.mouseButton(MouseButton.MIDDLE)
.onEnd(() => console.log('Tap with middle'));
const rightTap = Gesture.Tap()
.mouseButton(MouseButton.RIGHT)
.onEnd(() => console.log('Tap with right'));
const leftRightTap = Gesture.Tap()
.mouseButton(MouseButton.LEFT | MouseButton.RIGHT)
.onEnd(() => console.log('Tap with left | right'));
const allTap = Gesture.Tap()
.mouseButton(MouseButton.ALL)
.onEnd(() => console.log('Tap with any button'));
const gestureHandlers = [leftTap, middleTap, rightTap, leftRightTap, allTap];
return <Test name={'Tap'} gestureHandlers={gestureHandlers} />;
}
function PanTests() {
const leftPan = Gesture.Pan()
.mouseButton(MouseButton.LEFT)
.onChange(() => console.log('Panning with left'));
const middlePan = Gesture.Pan()
.mouseButton(MouseButton.MIDDLE)
.onChange(() => console.log('Panning with middle'));
const rightPan = Gesture.Pan()
.mouseButton(MouseButton.RIGHT)
.onChange(() => console.log('Panning with right'));
const leftRightPan = Gesture.Pan()
.mouseButton(MouseButton.LEFT | MouseButton.RIGHT)
.onChange(() => console.log('Panning with left | right'));
const allPan = Gesture.Pan()
.mouseButton(MouseButton.ALL)
.onChange(() => console.log('Panning with any button'));
const gestureHandlers = [leftPan, middlePan, rightPan, leftRightPan, allPan];
return <Test name={'Pan'} gestureHandlers={gestureHandlers} />;
}
function LongPressTests() {
const leftLongPress = Gesture.LongPress()
.mouseButton(MouseButton.LEFT)
.onStart(() => console.log('LongPress with left'));
const middleLongPress = Gesture.LongPress()
.mouseButton(MouseButton.MIDDLE)
.onStart(() => console.log('LongPress with middle'));
const rightLongPress = Gesture.LongPress()
.mouseButton(MouseButton.RIGHT)
.onStart(() => console.log('LongPress with right'));
const leftRightLongPress = Gesture.LongPress()
.mouseButton(MouseButton.LEFT | MouseButton.RIGHT)
.onStart(() => console.log('LongPress with left | right'));
const allLongPress = Gesture.LongPress()
.mouseButton(MouseButton.ALL)
.onStart(() => console.log('LongPress with any button'));
const gestureHandlers = [
leftLongPress,
middleLongPress,
rightLongPress,
leftRightLongPress,
allLongPress,
];
return <Test name={'LongPress'} gestureHandlers={gestureHandlers} />;
}
function FlingTests() {
const leftFling = Gesture.Fling()
.direction(Directions.LEFT | Directions.RIGHT)
.mouseButton(MouseButton.LEFT)
.onStart(() => console.log('Fling with left'));
const middleFling = Gesture.Fling()
.direction(Directions.LEFT | Directions.RIGHT)
.mouseButton(MouseButton.MIDDLE)
.onStart(() => console.log('Fling with middle'));
const rightFling = Gesture.Fling()
.direction(Directions.LEFT | Directions.RIGHT)
.mouseButton(MouseButton.RIGHT)
.onStart(() => console.log('Fling with right'));
const leftRightFling = Gesture.Fling()
.direction(Directions.LEFT | Directions.RIGHT)
.mouseButton(MouseButton.LEFT | MouseButton.RIGHT)
.onStart(() => console.log('Fling with left | right'));
const allFling = Gesture.Fling()
.direction(Directions.LEFT | Directions.RIGHT)
.mouseButton(MouseButton.ALL)
.onStart(() => console.log('Fling with any button'));
const gestureHandlers = [
leftFling,
middleFling,
rightFling,
leftRightFling,
allFling,
];
return <Test name={'Fling'} gestureHandlers={gestureHandlers} />;
}
export default function Buttons() {
return (
<ScrollView style={{ flex: 1 }}>
<TapTests />
<PanTests />
<LongPressTests />
<FlingTests />
</ScrollView>
);
}
const styles = StyleSheet.create({
center: {
alignItems: 'center',
justifyContent: 'space-around',
},
box: {
width: 75,
height: 75,
},
});