Skip to content

Commit 9e4c666

Browse files
committed
Add example
1 parent 8381df0 commit 9e4c666

2 files changed

Lines changed: 150 additions & 0 deletions

File tree

apps/common-app/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import SimpleFling from './src/simple/fling';
7979
import FlatListExample from './src/components/flatlist';
8080
import ScrollViewExample from './src/components/scrollview';
8181
import ButtonsExample from './src/components/buttons';
82+
import SwitchTextInputExample from './src/components/switchAndInput';
8283

8384
import { Icon } from '@swmansion/icons';
8485

@@ -124,6 +125,7 @@ const EXAMPLES: ExamplesSection[] = [
124125
{ name: 'FlatList example', component: FlatListExample },
125126
{ name: 'ScrollView example', component: ScrollViewExample },
126127
{ name: 'Buttons example', component: ButtonsExample },
128+
{ name: 'Switch & TextInput', component: SwitchTextInputExample },
127129
],
128130
},
129131
{
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import React, { useState } from 'react';
2+
import { StyleSheet, Text, View } from 'react-native';
3+
import type { NativeGestureEvent } from 'react-native-gesture-handler';
4+
import {
5+
TextInput,
6+
LegacyTextInput,
7+
Switch,
8+
LegacySwitch,
9+
} from 'react-native-gesture-handler';
10+
11+
export default function SwitchTextInputExample() {
12+
const [switchOn, setSwitchOn] = useState(false);
13+
const [legacySwitchOn, setLegacySwitchOn] = useState(false);
14+
15+
return (
16+
<View style={styles.container}>
17+
<Text style={styles.title}>Components Playground</Text>
18+
19+
<View style={styles.row}>
20+
<View style={styles.card}>
21+
<Text style={styles.cardTitle}>TextInput</Text>
22+
<TextInput
23+
onBegin={() => console.log('[TextInput] onBegin')}
24+
onActivate={() => console.log('[TextInput] onActivate')}
25+
onFinalize={(_: NativeGestureEvent, s: boolean) =>
26+
console.log('[TextInput] onFinalize', s)
27+
}
28+
style={styles.input}
29+
placeholder="Type here..."
30+
/>
31+
</View>
32+
33+
<View style={styles.card}>
34+
<Text style={styles.cardTitle}>LegacyTextInput</Text>
35+
<LegacyTextInput
36+
onBegan={() => console.log('[LegacyTextInput] onBegan')}
37+
onActivated={() => console.log('[LegacyTextInput] onActivated')}
38+
onEnded={(e: any) =>
39+
console.log('[LegacyTextInput] onEnded', e.nativeEvent?.state)
40+
}
41+
style={styles.input}
42+
placeholder="Type here..."
43+
/>
44+
</View>
45+
</View>
46+
47+
<View style={[styles.row, { marginTop: 16 }]}>
48+
<View style={styles.card}>
49+
<Text style={styles.cardTitle}>Switch (new)</Text>
50+
<View style={styles.switchRow}>
51+
<Switch
52+
onBegin={() => console.log('[Switch] onBegin')}
53+
onFinalize={(_: NativeGestureEvent, s: boolean) =>
54+
console.log('[Switch] onFinalize', s)
55+
}
56+
value={switchOn}
57+
onValueChange={(v: boolean) => {
58+
console.log('[Switch] onValueChange', v);
59+
setSwitchOn(v);
60+
}}
61+
/>
62+
<Text style={styles.switchLabel}>{switchOn ? 'On' : 'Off'}</Text>
63+
</View>
64+
</View>
65+
66+
<View style={styles.card}>
67+
<Text style={styles.cardTitle}>LegacySwitch</Text>
68+
<View style={styles.switchRow}>
69+
<LegacySwitch
70+
onBegan={() => console.log('[LegacySwitch] onBegan')}
71+
onEnded={(e: any) =>
72+
console.log('[LegacySwitch] onEnded', e.nativeEvent?.state)
73+
}
74+
value={legacySwitchOn}
75+
onValueChange={(v: boolean) => {
76+
console.log('[LegacySwitch] onValueChange', v);
77+
setLegacySwitchOn(v);
78+
}}
79+
/>
80+
<Text style={styles.switchLabel}>
81+
{legacySwitchOn ? 'On' : 'Off'}
82+
</Text>
83+
</View>
84+
</View>
85+
</View>
86+
87+
<Text style={styles.hint}>
88+
Open console to see gesture callback logs.
89+
</Text>
90+
</View>
91+
);
92+
}
93+
94+
const styles = StyleSheet.create({
95+
container: {
96+
padding: 20,
97+
alignItems: 'center',
98+
},
99+
title: {
100+
fontSize: 20,
101+
fontWeight: '600',
102+
marginBottom: 16,
103+
},
104+
row: {
105+
width: '100%',
106+
flexDirection: 'row',
107+
justifyContent: 'space-between',
108+
},
109+
card: {
110+
flex: 1,
111+
backgroundColor: '#fff',
112+
borderRadius: 8,
113+
padding: 12,
114+
marginHorizontal: 8,
115+
shadowColor: '#000',
116+
shadowOpacity: 0.06,
117+
shadowRadius: 6,
118+
elevation: 2,
119+
alignItems: 'center',
120+
},
121+
cardTitle: {
122+
fontSize: 14,
123+
fontWeight: '600',
124+
marginBottom: 8,
125+
},
126+
input: {
127+
height: 40,
128+
width: '100%',
129+
borderColor: '#e1e1e1',
130+
borderWidth: 1,
131+
borderRadius: 6,
132+
paddingHorizontal: 10,
133+
},
134+
switchRow: {
135+
flexDirection: 'row',
136+
alignItems: 'center',
137+
gap: 12,
138+
},
139+
switchLabel: {
140+
marginLeft: 12,
141+
fontSize: 14,
142+
},
143+
hint: {
144+
marginTop: 18,
145+
color: '#666',
146+
fontSize: 12,
147+
},
148+
});

0 commit comments

Comments
 (0)