-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathindex.tsx
More file actions
145 lines (137 loc) · 3.87 KB
/
index.tsx
File metadata and controls
145 lines (137 loc) · 3.87 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
import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {
TextInput,
LegacyTextInput,
Switch,
LegacySwitch,
} from 'react-native-gesture-handler';
export default function SwitchTextInputExample() {
const [switchOn, setSwitchOn] = useState(false);
const [legacySwitchOn, setLegacySwitchOn] = useState(false);
return (
<View style={styles.container}>
<Text style={styles.title}>Components Playground</Text>
<View style={styles.row}>
<View style={styles.card}>
<Text style={styles.cardTitle}>TextInput</Text>
<TextInput
onBegin={() => console.log('[TextInput] onBegin')}
onActivate={() => console.log('[TextInput] onActivate')}
onFinalize={(e) =>
console.log('[TextInput] onFinalize', e.canceled)
}
style={styles.input}
placeholder="Type here..."
/>
</View>
<View style={styles.card}>
<Text style={styles.cardTitle}>LegacyTextInput</Text>
<LegacyTextInput
onBegan={() => console.log('[LegacyTextInput] onBegan')}
onActivated={() => console.log('[LegacyTextInput] onActivated')}
onEnded={(e: any) =>
console.log('[LegacyTextInput] onEnded', e.nativeEvent?.state)
}
style={styles.input}
placeholder="Type here..."
/>
</View>
</View>
<View style={[styles.row, { marginTop: 16 }]}>
<View style={styles.card}>
<Text style={styles.cardTitle}>Switch (new)</Text>
<View style={styles.switchRow}>
<Switch
onBegin={() => console.log('[Switch] onBegin')}
onFinalize={(e) => console.log('[Switch] onFinalize', e.canceled)}
value={switchOn}
onValueChange={(v: boolean) => {
console.log('[Switch] onValueChange', v);
setSwitchOn(v);
}}
/>
<Text style={styles.switchLabel}>{switchOn ? 'On' : 'Off'}</Text>
</View>
</View>
<View style={styles.card}>
<Text style={styles.cardTitle}>LegacySwitch</Text>
<View style={styles.switchRow}>
<LegacySwitch
onBegan={() => console.log('[LegacySwitch] onBegan')}
onEnded={(e: any) =>
console.log('[LegacySwitch] onEnded', e.nativeEvent?.state)
}
value={legacySwitchOn}
onValueChange={(v: boolean) => {
console.log('[LegacySwitch] onValueChange', v);
setLegacySwitchOn(v);
}}
/>
<Text style={styles.switchLabel}>
{legacySwitchOn ? 'On' : 'Off'}
</Text>
</View>
</View>
</View>
<Text style={styles.hint}>
Open console to see gesture callback logs.
</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
padding: 20,
alignItems: 'center',
},
title: {
fontSize: 20,
fontWeight: '600',
marginBottom: 16,
},
row: {
width: '100%',
flexDirection: 'row',
justifyContent: 'space-between',
},
card: {
flex: 1,
backgroundColor: '#fff',
borderRadius: 8,
padding: 12,
marginHorizontal: 8,
shadowColor: '#000',
shadowOpacity: 0.06,
shadowRadius: 6,
elevation: 2,
alignItems: 'center',
},
cardTitle: {
fontSize: 14,
fontWeight: '600',
marginBottom: 8,
},
input: {
height: 40,
width: '100%',
borderColor: '#e1e1e1',
borderWidth: 1,
borderRadius: 6,
paddingHorizontal: 10,
},
switchRow: {
flexDirection: 'row',
alignItems: 'center',
gap: 12,
},
switchLabel: {
marginLeft: 12,
fontSize: 14,
},
hint: {
marginTop: 18,
color: '#666',
fontSize: 12,
},
});