-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathKeyboardTypeExamplePage.tsx
More file actions
274 lines (252 loc) · 8.81 KB
/
KeyboardTypeExamplePage.tsx
File metadata and controls
274 lines (252 loc) · 8.81 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
'use strict';
import {TextInput, Text, View, StyleSheet} from 'react-native';
import React from 'react';
import {Example} from '../components/Example';
import {Page} from '../components/Page';
import {useTheme} from '../Navigation';
import {usePageFocusManagement} from '../hooks/usePageFocusManagement';
export const KeyboardTypeExamplePage: React.FunctionComponent<{navigation?: any}> = ({navigation}) => {
const firstTextInputExampleRef = usePageFocusManagement(navigation);
const {colors} = useTheme();
const [defaultValue, setDefaultValue] = React.useState('');
const [numericValue, setNumericValue] = React.useState('');
const [numberPadValue, setNumberPadValue] = React.useState('');
const [decimalPadValue, setDecimalPadValue] = React.useState('');
const [emailValue, setEmailValue] = React.useState('');
const [phonePadValue, setPhonePadValue] = React.useState('');
const [urlValue, setUrlValue] = React.useState('');
const [webSearchValue, setWebSearchValue] = React.useState('');
const [secureNumericValue, setSecureNumericValue] = React.useState('');
const exampleDefaultJsx = `<TextInput
keyboardType="default"
placeholder="default keyboard"
value={defaultValue}
onChangeText={setDefaultValue}
/>`;
const exampleNumericJsx = `<TextInput
keyboardType="numeric"
placeholder="numeric keyboard"
value={numericValue}
onChangeText={setNumericValue}
/>`;
const exampleNumberPadJsx = `<TextInput
keyboardType="number-pad"
placeholder="number-pad"
value={numberPadValue}
onChangeText={setNumberPadValue}
/>`;
const exampleDecimalPadJsx = `<TextInput
keyboardType="decimal-pad"
placeholder="decimal-pad"
value={decimalPadValue}
onChangeText={setDecimalPadValue}
/>`;
const exampleEmailJsx = `<TextInput
keyboardType="email-address"
placeholder="email-address"
value={emailValue}
onChangeText={setEmailValue}
/>`;
const examplePhonePadJsx = `<TextInput
keyboardType="phone-pad"
placeholder="phone-pad"
value={phonePadValue}
onChangeText={setPhonePadValue}
/>`;
const exampleUrlJsx = `<TextInput
keyboardType="url"
placeholder="url"
value={urlValue}
onChangeText={setUrlValue}
/>`;
const exampleWebSearchJsx = `<TextInput
keyboardType="web-search"
placeholder="web-search"
value={webSearchValue}
onChangeText={setWebSearchValue}
/>`;
const exampleSecureNumericJsx = `<TextInput
keyboardType="numeric"
secureTextEntry={true}
placeholder="numeric password"
value={secureNumericValue}
onChangeText={setSecureNumericValue}
/>`;
return (
<Page
title="Keyboard Type"
description="Test different keyboardType values for TextInput. This uses SetInputScopes on the parent HWND to control the touch keyboard layout."
wrappedNativeControl={{
control: 'TextBox',
url: 'https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.textbox?view=winrt-19041',
}}
componentType="Core"
pageCodeUrl="https://github.com/microsoft/react-native-gallery/blob/main/NewArch/src/examples/KeyboardTypeExamplePage.tsx"
documentation={[
{
label: 'TextInput',
url: 'https://reactnative.dev/docs/textinput#keyboardtype',
},
{
label: 'TextInput Source Code',
url: 'https://github.com/microsoft/react-native-windows/blob/master/vnext/Microsoft.ReactNative/Views/TextInputViewManager.h',
},
]}>
<View style={styles.instructions}>
<Text style={[styles.instructionTitle, {color: colors.text}]}>
Instructions for Testing on Windows:
</Text>
<Text style={[styles.instructionText, {color: colors.text}]}>
1. Right-click taskbar → Show touch keyboard button{'\n'}
2. Click the keyboard icon in system tray{'\n'}
3. Tap/click each TextInput field to focus it{'\n'}
4. Observe the touch keyboard layout changes
</Text>
<Text style={[styles.instructionSubtitle, {color: colors.text}]}>
Expected keyboard layouts:
</Text>
<Text style={[styles.instructionText, {color: colors.text}]}>
• default: Standard QWERTY{'\n'}
• numeric/number-pad: Number keys (IS_NUMBER/IS_DIGITS){'\n'}
• decimal-pad: Numbers with decimal point{'\n'}
• email-address: QWERTY with @ and .com keys{'\n'}
• phone-pad: Phone dial pad layout{'\n'}
• url: QWERTY with .com/.net buttons{'\n'}
• web-search: Search-optimized layout{'\n'}
• secure+numeric: PIN entry layout
</Text>
<Text style={[styles.instructionNote, {color: colors.text}]}>
Note: Physical keyboard allows all input (matches iOS/Android behavior).
</Text>
</View>
<Example title="Default Keyboard" code={exampleDefaultJsx}>
<TextInput
ref={firstTextInputExampleRef}
style={[styles.input, {borderColor: colors.border, color: colors.text}]}
keyboardType="default"
placeholder="default keyboard"
placeholderTextColor={colors.border}
value={defaultValue}
onChangeText={setDefaultValue}
/>
</Example>
<Example title="Numeric Keyboard" code={exampleNumericJsx}>
<TextInput
style={[styles.input, {borderColor: colors.border, color: colors.text}]}
keyboardType="numeric"
placeholder="numeric keyboard"
placeholderTextColor={colors.border}
value={numericValue}
onChangeText={setNumericValue}
/>
</Example>
<Example title="Number Pad" code={exampleNumberPadJsx}>
<TextInput
style={[styles.input, {borderColor: colors.border, color: colors.text}]}
keyboardType="number-pad"
placeholder="number-pad"
placeholderTextColor={colors.border}
value={numberPadValue}
onChangeText={setNumberPadValue}
/>
</Example>
<Example title="Decimal Pad" code={exampleDecimalPadJsx}>
<TextInput
style={[styles.input, {borderColor: colors.border, color: colors.text}]}
keyboardType="decimal-pad"
placeholder="decimal-pad"
placeholderTextColor={colors.border}
value={decimalPadValue}
onChangeText={setDecimalPadValue}
/>
</Example>
<Example title="Email Address" code={exampleEmailJsx}>
<TextInput
style={[styles.input, {borderColor: colors.border, color: colors.text}]}
keyboardType="email-address"
placeholder="email-address"
placeholderTextColor={colors.border}
value={emailValue}
onChangeText={setEmailValue}
/>
</Example>
<Example title="Phone Pad" code={examplePhonePadJsx}>
<TextInput
style={[styles.input, {borderColor: colors.border, color: colors.text}]}
keyboardType="phone-pad"
placeholder="phone-pad"
placeholderTextColor={colors.border}
value={phonePadValue}
onChangeText={setPhonePadValue}
/>
</Example>
<Example title="URL Keyboard" code={exampleUrlJsx}>
<TextInput
style={[styles.input, {borderColor: colors.border, color: colors.text}]}
keyboardType="url"
placeholder="url"
placeholderTextColor={colors.border}
value={urlValue}
onChangeText={setUrlValue}
/>
</Example>
<Example title="Web Search" code={exampleWebSearchJsx}>
<TextInput
style={[styles.input, {borderColor: colors.border, color: colors.text}]}
keyboardType="web-search"
placeholder="web-search"
placeholderTextColor={colors.border}
value={webSearchValue}
onChangeText={setWebSearchValue}
/>
</Example>
<Example title="Secure + Numeric (PIN Entry)" code={exampleSecureNumericJsx}>
<TextInput
style={[styles.input, {borderColor: colors.border, color: colors.text}]}
keyboardType="numeric"
secureTextEntry={true}
placeholder="numeric password"
placeholderTextColor={colors.border}
value={secureNumericValue}
onChangeText={setSecureNumericValue}
/>
</Example>
</Page>
);
};
const styles = StyleSheet.create({
input: {
borderWidth: 1,
borderRadius: 4,
padding: 10,
fontSize: 16,
},
instructions: {
marginBottom: 20,
padding: 15,
backgroundColor: '#e3f2fd',
borderRadius: 8,
borderWidth: 1,
borderColor: '#90caf9',
},
instructionTitle: {
fontSize: 16,
fontWeight: 'bold',
marginBottom: 10,
},
instructionSubtitle: {
fontSize: 14,
fontWeight: '600',
marginTop: 10,
marginBottom: 5,
},
instructionText: {
fontSize: 13,
lineHeight: 20,
},
instructionNote: {
fontSize: 12,
fontStyle: 'italic',
marginTop: 10,
},
});