-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathComponentsScreen.tsx
More file actions
193 lines (179 loc) · 4.61 KB
/
ComponentsScreen.tsx
File metadata and controls
193 lines (179 loc) · 4.61 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
182
183
184
185
186
187
188
189
190
191
192
193
import React from 'react';
import {
FlatList,
Gesture,
GestureDetector,
ScrollView,
Switch,
TextInput,
TouchableNativeFeedback,
TouchableOpacity,
} from 'react-native-gesture-handler';
import { StyleSheet, Text, View } from 'react-native';
import { COLORS } from './colors';
function SwitchDemo() {
const [value, setValue] = React.useState(false);
const pan = Gesture.Pan()
.onBegin(() => console.log('onBegin'))
.onUpdate(() => console.log('onUpdate')) // doesn't work on iOS
.onFinalize(() => console.log('onFinalize'));
return (
<View style={styles.demo}>
<Text style={styles.text}>RNGH Switch</Text>
<GestureDetector gesture={pan}>
<Switch value={value} onValueChange={() => setValue(!value)} />
</GestureDetector>
</View>
);
}
function TextInputDemo() {
const [value, setValue] = React.useState('Hello!');
const pan = Gesture.Pan()
.onBegin(() => console.log('onBegin'))
.onUpdate(() => console.log('onUpdate'))
.onFinalize(() => console.log('onFinalize'));
return (
<View style={styles.demo}>
<Text style={styles.text}>RNGH TextInput</Text>
<GestureDetector gesture={pan}>
<TextInput
style={styles.textInput}
value={value}
onChangeText={setValue}
/>
</GestureDetector>
</View>
);
}
function TouchableNativeFeedbackDemo() {
return (
<View style={styles.demo}>
<Text style={styles.text}>RNGH TouchableNativeFeedback</Text>
<TouchableNativeFeedback
onPressIn={() => console.log('onPressIn')}
onPressOut={() => console.log('onPressOut')}
onLongPress={() => console.log('onLongPress')}>
<View
style={[styles.smallBox, { backgroundColor: COLORS.KINDA_BLUE }]}
/>
</TouchableNativeFeedback>
</View>
);
}
function TouchableOpacityDemo() {
return (
<View style={styles.demo}>
<Text style={styles.text}>RNGH TouchableOpacity</Text>
<TouchableOpacity
onPressIn={() => console.log('onPressIn')}
onPressOut={() => console.log('onPressOut')}
onLongPress={() => console.log('onLongPress')}>
<View
style={[styles.smallBox, { backgroundColor: COLORS.KINDA_BLUE }]}
/>
</TouchableOpacity>
</View>
);
}
function ScrollViewDemo() {
const pan = Gesture.Pan().onUpdate((e) => console.log('onUpdate', e.x, e.y));
return (
<View style={styles.demo}>
<Text style={styles.text}>RNGH ScrollView</Text>
<View style={styles.largeBox}>
<ScrollView style={styles.largeBox}>
{Object.values(COLORS).map((color) => (
<View
key={color}
style={[styles.largeBox, { backgroundColor: color }]}
/>
))}
<GestureDetector gesture={pan}>
<View style={styles.panBox}>
<Text style={styles.panText}>
Dragging here should not scroll
</Text>
</View>
</GestureDetector>
</ScrollView>
</View>
</View>
);
}
function FlatListDemo() {
return (
<View style={styles.demo}>
<Text style={styles.text}>RNGH FlatList</Text>
<View style={styles.largeBox}>
<FlatList
data={Object.values(COLORS)}
renderItem={(e) => (
<TouchableOpacity>
<View style={[styles.largeBox, { backgroundColor: e.item }]} />
</TouchableOpacity>
)}
keyExtractor={(e) => e}
/>
</View>
</View>
);
}
export default function ComponentsScreen() {
return (
<View style={styles.container}>
<Text style={styles.bold}>
Gesture Handler also provides a set of components that support gestures.
</Text>
<SwitchDemo />
<TextInputDemo />
<TouchableNativeFeedbackDemo />
<TouchableOpacityDemo />
<ScrollViewDemo />
<FlatListDemo />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
bold: {
fontWeight: 'bold',
textAlign: 'center',
marginHorizontal: 20,
},
textInput: {
borderWidth: 1,
borderStyle: 'solid',
borderColor: 'darkgray',
width: 135,
padding: 10,
},
text: {
marginVertical: 3,
},
demo: {
marginVertical: 3,
alignItems: 'center',
},
smallBox: {
width: 50,
height: 50,
},
largeBox: {
width: 100,
height: 100,
},
panBox: {
width: 100,
height: 75,
backgroundColor: 'lightgray',
alignItems: 'center',
justifyContent: 'center',
},
panText: {
textAlign: 'center',
},
});