@ukeyfe/react-native-text-input 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +33 -0
  3. package/android/build.gradle +126 -0
  4. package/android/generated/android/app/build/generated/source/codegen/java/com/facebook/react/viewmanagers/UKeyTextInputManagerDelegate.java +26 -0
  5. package/android/generated/android/app/build/generated/source/codegen/java/com/facebook/react/viewmanagers/UKeyTextInputManagerInterface.java +17 -0
  6. package/android/generated/android/app/build/generated/source/codegen/jni/CMakeLists.txt +36 -0
  7. package/android/generated/android/app/build/generated/source/codegen/jni/RNTextInputViewSpec-generated.cpp +22 -0
  8. package/android/generated/android/app/build/generated/source/codegen/jni/RNTextInputViewSpec.h +24 -0
  9. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/ComponentDescriptors.cpp +22 -0
  10. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/ComponentDescriptors.h +24 -0
  11. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/EventEmitters.cpp +24 -0
  12. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/EventEmitters.h +25 -0
  13. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/Props.cpp +25 -0
  14. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/Props.h +27 -0
  15. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/RNTextInputViewSpecJSI-generated.cpp +17 -0
  16. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/RNTextInputViewSpecJSI.h +19 -0
  17. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/ShadowNodes.cpp +17 -0
  18. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/ShadowNodes.h +32 -0
  19. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/States.cpp +16 -0
  20. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/States.h +29 -0
  21. package/android/gradle.properties +5 -0
  22. package/android/src/main/AndroidManifest.xml +3 -0
  23. package/android/src/main/AndroidManifestNew.xml +2 -0
  24. package/android/src/main/java/com/textinput/PasteWatcher.kt +10 -0
  25. package/android/src/main/java/com/textinput/TextInputPackage.kt +19 -0
  26. package/android/src/main/java/com/textinput/TextInputPasteEvent.kt +48 -0
  27. package/android/src/main/java/com/textinput/TextInputView.kt +80 -0
  28. package/android/src/main/java/com/textinput/TextInputViewManager.kt +68 -0
  29. package/android/src/newarch/TextInputViewManagerSpec.kt +21 -0
  30. package/android/src/oldarch/TextInputViewManagerSpec.kt +9 -0
  31. package/ios/TextInputViewManager.mm +23 -0
  32. package/ios/Utils.h +8 -0
  33. package/ios/Utils.m +26 -0
  34. package/ios/generated/build/generated/ios/RNTextInputViewSpec/RNTextInputViewSpec-generated.mm +16 -0
  35. package/ios/generated/build/generated/ios/RNTextInputViewSpec/RNTextInputViewSpec.h +38 -0
  36. package/ios/generated/build/generated/ios/RNTextInputViewSpecJSI-generated.cpp +17 -0
  37. package/ios/generated/build/generated/ios/RNTextInputViewSpecJSI.h +19 -0
  38. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/ComponentDescriptors.cpp +22 -0
  39. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/ComponentDescriptors.h +24 -0
  40. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/EventEmitters.cpp +24 -0
  41. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/EventEmitters.h +25 -0
  42. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/Props.cpp +25 -0
  43. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/Props.h +27 -0
  44. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/RCTComponentViewHelpers.h +20 -0
  45. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/ShadowNodes.cpp +17 -0
  46. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/ShadowNodes.h +32 -0
  47. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/States.cpp +16 -0
  48. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/States.h +29 -0
  49. package/lib/commonjs/AndroidTextInputNativeComponent.js +152 -0
  50. package/lib/commonjs/AndroidTextInputNativeComponent.js.map +1 -0
  51. package/lib/commonjs/Input.js +537 -0
  52. package/lib/commonjs/Input.js.map +1 -0
  53. package/lib/commonjs/TextInputViewNativeComponent.ts +9 -0
  54. package/lib/commonjs/enum.js +11 -0
  55. package/lib/commonjs/enum.js.map +1 -0
  56. package/lib/commonjs/index.js +28 -0
  57. package/lib/commonjs/index.js.map +1 -0
  58. package/lib/commonjs/package.json +1 -0
  59. package/lib/commonjs/type.js +6 -0
  60. package/lib/commonjs/type.js.map +1 -0
  61. package/lib/typescript/src/TextInputViewNativeComponent.d.ts +8 -0
  62. package/lib/typescript/src/TextInputViewNativeComponent.d.ts.map +1 -0
  63. package/lib/typescript/src/enum.d.ts +4 -0
  64. package/lib/typescript/src/enum.d.ts.map +1 -0
  65. package/lib/typescript/src/index.d.ts +7 -0
  66. package/lib/typescript/src/index.d.ts.map +1 -0
  67. package/lib/typescript/src/type.d.ts +16 -0
  68. package/lib/typescript/src/type.d.ts.map +1 -0
  69. package/package.json +178 -0
  70. package/src/AndroidTextInputNativeComponent.js +767 -0
  71. package/src/Input.js +1910 -0
  72. package/src/TextInputViewNativeComponent.ts +9 -0
  73. package/src/enum.ts +3 -0
  74. package/src/index.tsx +17 -0
  75. package/src/type.ts +13 -0
package/src/Input.js ADDED
@@ -0,0 +1,1910 @@
1
+ /* eslint-disable prettier/prettier */
2
+
3
+ /**
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ *
9
+ * @flow strict-local
10
+ * @format
11
+ */
12
+
13
+ import type {HostInstance} from 'react-native/src/private/types/HostInstance';
14
+ import type {____TextStyle_Internal as TextStyleInternal} from 'react-native/Libraries/StyleSheet/StyleSheetTypes';
15
+ import type {
16
+ GestureResponderEvent,
17
+ NativeSyntheticEvent,
18
+ ScrollEvent,
19
+ } from 'react-native/Libraries/Types/CoreEventTypes';
20
+ import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes';
21
+ import type {TextInputInstance, TextInputType} from 'react-native/Libraries/Components/TextInput/TextInput.flow';
22
+
23
+ import * as ReactNativeFeatureFlags from 'react-native/src/private/featureflags/ReactNativeFeatureFlags.js';
24
+ import usePressability from 'react-native/Libraries/Pressability/usePressability.js';
25
+ import flattenStyle from 'react-native/Libraries/StyleSheet/flattenStyle.js';
26
+ import StyleSheet, {
27
+ type ColorValue,
28
+ type TextStyleProp,
29
+ type ViewStyleProp,
30
+ } from 'react-native/Libraries/StyleSheet/StyleSheet';
31
+ import Text from 'react-native/Libraries/Text/Text';
32
+ import TextAncestor from 'react-native/Libraries/Text/TextAncestor';
33
+ import Platform from 'react-native/Libraries/Utilities/Platform';
34
+ import useMergeRefs from 'react-native/Libraries/Utilities/useMergeRefs';
35
+ import TextInputState from 'react-native/Libraries/Components/TextInput/TextInputState';
36
+ import invariant from 'invariant';
37
+ import nullthrows from 'nullthrows';
38
+ import * as React from 'react';
39
+ import {useCallback, useLayoutEffect, useRef, useState} from 'react';
40
+
41
+ let AndroidTextInput;
42
+ let AndroidTextInputCommands;
43
+ let RCTSinglelineTextInputView;
44
+ let RCTSinglelineTextInputNativeCommands;
45
+ let RCTMultilineTextInputView;
46
+ let RCTMultilineTextInputNativeCommands;
47
+
48
+ if (Platform.OS === 'android') {
49
+ AndroidTextInput = require('./AndroidTextInputNativeComponent').default;
50
+ AndroidTextInputCommands =
51
+ require('./AndroidTextInputNativeComponent').Commands;
52
+ } else if (Platform.OS === 'ios') {
53
+ RCTSinglelineTextInputView =
54
+ require('react-native/Libraries/Components/TextInput/RCTSingelineTextInputNativeComponent').default;
55
+ RCTSinglelineTextInputNativeCommands =
56
+ require('react-native/Libraries/Components/TextInput/RCTSingelineTextInputNativeComponent').Commands;
57
+ RCTMultilineTextInputView =
58
+ require('react-native/Libraries/Components/TextInput/RCTMultilineTextInputNativeComponent').default;
59
+ RCTMultilineTextInputNativeCommands =
60
+ require('react-native/Libraries/Components/TextInput/RCTMultilineTextInputNativeComponent').Commands;
61
+ }
62
+
63
+ export type TextInputChangeEventData = $ReadOnly<{
64
+ eventCount: number,
65
+ target: number,
66
+ text: string,
67
+ }>;
68
+
69
+ export type TextInputChangeEvent =
70
+ NativeSyntheticEvent<TextInputChangeEventData>;
71
+
72
+ export type TextInputEvent = NativeSyntheticEvent<
73
+ $ReadOnly<{
74
+ eventCount: number,
75
+ previousText: string,
76
+ range: $ReadOnly<{
77
+ start: number,
78
+ end: number,
79
+ }>,
80
+ target: number,
81
+ text: string,
82
+ }>,
83
+ >;
84
+
85
+ export type TextInputContentSizeChangeEventData = $ReadOnly<{
86
+ target: number,
87
+ contentSize: $ReadOnly<{
88
+ width: number,
89
+ height: number,
90
+ }>,
91
+ }>;
92
+
93
+ export type TextInputContentSizeChangeEvent =
94
+ NativeSyntheticEvent<TextInputContentSizeChangeEventData>;
95
+
96
+ export type TargetEvent = $ReadOnly<{
97
+ target: number,
98
+ }>;
99
+
100
+ export type TextInputFocusEventData = TargetEvent;
101
+
102
+ export type TextInputBlurEvent = NativeSyntheticEvent<TextInputFocusEventData>;
103
+ export type TextInputFocusEvent = NativeSyntheticEvent<TextInputFocusEventData>;
104
+
105
+ type Selection = $ReadOnly<{
106
+ start: number,
107
+ end: number,
108
+ }>;
109
+
110
+ export type TextInputSelectionChangeEventData = $ReadOnly<{
111
+ ...TargetEvent,
112
+ selection: Selection,
113
+ }>;
114
+
115
+ export type TextInputSelectionChangeEvent =
116
+ NativeSyntheticEvent<TextInputSelectionChangeEventData>;
117
+
118
+ type TextInputKeyPressEventData = $ReadOnly<{
119
+ ...TargetEvent,
120
+ key: string,
121
+ target?: ?number,
122
+ eventCount?: ?number,
123
+ }>;
124
+
125
+ export type TextInputKeyPressEvent =
126
+ NativeSyntheticEvent<TextInputKeyPressEventData>;
127
+
128
+ export type TextInputEndEditingEventData = $ReadOnly<{
129
+ ...TargetEvent,
130
+ eventCount: number,
131
+ text: string,
132
+ }>;
133
+
134
+ export type TextInputEditingEvent =
135
+ NativeSyntheticEvent<TextInputEndEditingEventData>;
136
+
137
+ type DataDetectorTypesType =
138
+ | 'phoneNumber'
139
+ | 'link'
140
+ | 'address'
141
+ | 'calendarEvent'
142
+ | 'trackingNumber'
143
+ | 'flightNumber'
144
+ | 'lookupSuggestion'
145
+ | 'none'
146
+ | 'all';
147
+
148
+ export type KeyboardType =
149
+ | 'default'
150
+ | 'email-address'
151
+ | 'numeric'
152
+ | 'phone-pad'
153
+ | 'number-pad'
154
+ | 'decimal-pad'
155
+ | 'url';
156
+
157
+ export type KeyboardTypeIOS =
158
+ | 'ascii-capable'
159
+ | 'numbers-and-punctuation'
160
+ | 'name-phone-pad'
161
+ | 'twitter'
162
+ | 'web-search'
163
+ // iOS 10+ only
164
+ | 'ascii-capable-number-pad';
165
+
166
+ export type KeyboardTypeAndroid = 'visible-password';
167
+
168
+ export type KeyboardTypeOptions =
169
+ | KeyboardType
170
+ | KeyboardTypeIOS
171
+ | KeyboardTypeAndroid;
172
+
173
+ export type InputModeOptions =
174
+ | 'none'
175
+ | 'text'
176
+ | 'decimal'
177
+ | 'numeric'
178
+ | 'tel'
179
+ | 'search'
180
+ | 'email'
181
+ | 'url';
182
+
183
+ export type ReturnKeyType = 'done' | 'go' | 'next' | 'search' | 'send';
184
+
185
+ export type ReturnKeyTypeIOS =
186
+ | 'default'
187
+ | 'emergency-call'
188
+ | 'google'
189
+ | 'join'
190
+ | 'route'
191
+ | 'yahoo';
192
+
193
+ export type ReturnKeyTypeAndroid = 'none' | 'previous';
194
+
195
+ export type ReturnKeyTypeOptions =
196
+ | ReturnKeyType
197
+ | ReturnKeyTypeIOS
198
+ | ReturnKeyTypeAndroid;
199
+
200
+ export type SubmitBehavior = 'submit' | 'blurAndSubmit' | 'newline';
201
+
202
+ export type AutoCapitalize = 'none' | 'sentences' | 'words' | 'characters';
203
+
204
+ export type TextContentType =
205
+ | 'none'
206
+ | 'URL'
207
+ | 'addressCity'
208
+ | 'addressCityAndState'
209
+ | 'addressState'
210
+ | 'countryName'
211
+ | 'creditCardNumber'
212
+ | 'creditCardExpiration'
213
+ | 'creditCardExpirationMonth'
214
+ | 'creditCardExpirationYear'
215
+ | 'creditCardSecurityCode'
216
+ | 'creditCardType'
217
+ | 'creditCardName'
218
+ | 'creditCardGivenName'
219
+ | 'creditCardMiddleName'
220
+ | 'creditCardFamilyName'
221
+ | 'emailAddress'
222
+ | 'familyName'
223
+ | 'fullStreetAddress'
224
+ | 'givenName'
225
+ | 'jobTitle'
226
+ | 'location'
227
+ | 'middleName'
228
+ | 'name'
229
+ | 'namePrefix'
230
+ | 'nameSuffix'
231
+ | 'nickname'
232
+ | 'organizationName'
233
+ | 'postalCode'
234
+ | 'streetAddressLine1'
235
+ | 'streetAddressLine2'
236
+ | 'sublocality'
237
+ | 'telephoneNumber'
238
+ | 'username'
239
+ | 'password'
240
+ | 'newPassword'
241
+ | 'oneTimeCode'
242
+ | 'birthdate'
243
+ | 'birthdateDay'
244
+ | 'birthdateMonth'
245
+ | 'birthdateYear'
246
+ | 'cellularEID'
247
+ | 'cellularIMEI'
248
+ | 'dateTime'
249
+ | 'flightNumber'
250
+ | 'shipmentTrackingNumber';
251
+
252
+ export type EnterKeyHintTypeAndroid = 'previous';
253
+
254
+ export type EnterKeyHintTypeIOS = 'enter';
255
+
256
+ export type EnterKeyHintType = 'done' | 'go' | 'next' | 'search' | 'send';
257
+
258
+ export type EnterKeyHintTypeOptions =
259
+ | EnterKeyHintType
260
+ | EnterKeyHintTypeAndroid
261
+ | EnterKeyHintTypeIOS;
262
+
263
+ type PasswordRules = string;
264
+
265
+ export type TextInputIOSProps = $ReadOnly<{
266
+ /**
267
+ * If true, the keyboard shortcuts (undo/redo and copy buttons) are disabled. The default value is false.
268
+ * @platform ios
269
+ */
270
+ disableKeyboardShortcuts?: ?boolean,
271
+
272
+ /**
273
+ * When the clear button should appear on the right side of the text view.
274
+ * This property is supported only for single-line TextInput component.
275
+ * @platform ios
276
+ */
277
+ clearButtonMode?: ?('never' | 'while-editing' | 'unless-editing' | 'always'),
278
+
279
+ /**
280
+ * If `true`, clears the text field automatically when editing begins.
281
+ * @platform ios
282
+ */
283
+ clearTextOnFocus?: ?boolean,
284
+
285
+ /**
286
+ * Determines the types of data converted to clickable URLs in the text input.
287
+ * Only valid if `multiline={true}` and `editable={false}`.
288
+ * By default no data types are detected.
289
+ *
290
+ * You can provide one type or an array of many types.
291
+ *
292
+ * Possible values for `dataDetectorTypes` are:
293
+ *
294
+ * - `'phoneNumber'`
295
+ * - `'link'`
296
+ * - `'address'`
297
+ * - `'calendarEvent'`
298
+ * - `'none'`
299
+ * - `'all'`
300
+ *
301
+ * @platform ios
302
+ */
303
+ dataDetectorTypes?:
304
+ | ?DataDetectorTypesType
305
+ | $ReadOnlyArray<DataDetectorTypesType>,
306
+
307
+ /**
308
+ * If `true`, the keyboard disables the return key when there is no text and
309
+ * automatically enables it when there is text. The default value is `false`.
310
+ * @platform ios
311
+ */
312
+ enablesReturnKeyAutomatically?: ?boolean,
313
+
314
+ /**
315
+ * An optional identifier which links a custom InputAccessoryView to
316
+ * this text input. The InputAccessoryView is rendered above the
317
+ * keyboard when this text input is focused.
318
+ * @platform ios
319
+ */
320
+ inputAccessoryViewID?: ?string,
321
+
322
+ /**
323
+ * An optional label that overrides the default input accessory view button label.
324
+ * @platform ios
325
+ */
326
+ inputAccessoryViewButtonLabel?: ?string,
327
+
328
+ /**
329
+ * Determines the color of the keyboard.
330
+ * @platform ios
331
+ */
332
+ keyboardAppearance?: ?('default' | 'light' | 'dark'),
333
+
334
+ /**
335
+ * Provide rules for your password.
336
+ * For example, say you want to require a password with at least eight characters consisting of a mix of uppercase and lowercase letters, at least one number, and at most two consecutive characters.
337
+ * "required: upper; required: lower; required: digit; max-consecutive: 2; minlength: 8;"
338
+ * @platform ios
339
+ */
340
+ passwordRules?: ?PasswordRules,
341
+
342
+ /*
343
+ * If `true`, allows TextInput to pass touch events to the parent component.
344
+ * This allows components to be swipeable from the TextInput on iOS,
345
+ * as is the case on Android by default.
346
+ * If `false`, TextInput always asks to handle the input (except when disabled).
347
+ * @platform ios
348
+ */
349
+ rejectResponderTermination?: ?boolean,
350
+
351
+ /**
352
+ * If `false`, scrolling of the text view will be disabled.
353
+ * The default value is `true`. Does only work with 'multiline={true}'.
354
+ * @platform ios
355
+ */
356
+ scrollEnabled?: ?boolean,
357
+
358
+ /**
359
+ * If `false`, disables spell-check style (i.e. red underlines).
360
+ * The default value is inherited from `autoCorrect`.
361
+ * @platform ios
362
+ */
363
+ spellCheck?: ?boolean,
364
+
365
+ /**
366
+ * Give the keyboard and the system information about the
367
+ * expected semantic meaning for the content that users enter.
368
+ * `autoComplete` property accomplishes same behavior and is recommended as its supported by both platforms.
369
+ * Avoid using both `autoComplete` and `textContentType`, you can use `Platform.select` for differing platform behaviors.
370
+ * For backwards compatibility, when both set, `textContentType` takes precedence on iOS.
371
+ * @platform ios
372
+ */
373
+ textContentType?: ?TextContentType,
374
+
375
+ /**
376
+ * Set line break strategy on iOS.
377
+ * @platform ios
378
+ */
379
+ lineBreakStrategyIOS?: ?('none' | 'standard' | 'hangul-word' | 'push-out'),
380
+
381
+ /**
382
+ * Set line break mode on iOS.
383
+ * @platform ios
384
+ */
385
+ lineBreakModeIOS?: ?(
386
+ | 'wordWrapping'
387
+ | 'char'
388
+ | 'clip'
389
+ | 'head'
390
+ | 'middle'
391
+ | 'tail'
392
+ ),
393
+
394
+ /**
395
+ * If `false`, the iOS system will not insert an extra space after a paste operation
396
+ * neither delete one or two spaces after a cut or delete operation.
397
+ *
398
+ * The default value is `true`.
399
+ *
400
+ * @platform ios
401
+ */
402
+ smartInsertDelete?: ?boolean,
403
+ }>;
404
+
405
+ export type TextInputAndroidProps = $ReadOnly<{
406
+ /**
407
+ * When provided it will set the color of the cursor (or "caret") in the component.
408
+ * Unlike the behavior of `selectionColor` the cursor color will be set independently
409
+ * from the color of the text selection box.
410
+ * @platform android
411
+ */
412
+ cursorColor?: ?ColorValue,
413
+
414
+ /**
415
+ * When `false`, if there is a small amount of space available around a text input
416
+ * (e.g. landscape orientation on a phone), the OS may choose to have the user edit
417
+ * the text inside of a full screen text input mode. When `true`, this feature is
418
+ * disabled and users will always edit the text directly inside of the text input.
419
+ * Defaults to `false`.
420
+ * @platform android
421
+ */
422
+ disableFullscreenUI?: ?boolean,
423
+
424
+ importantForAutofill?: ?(
425
+ | 'auto'
426
+ | 'no'
427
+ | 'noExcludeDescendants'
428
+ | 'yes'
429
+ | 'yesExcludeDescendants'
430
+ ),
431
+
432
+ /**
433
+ * If defined, the provided image resource will be rendered on the left.
434
+ * The image resource must be inside `/android/app/src/main/res/drawable` and referenced
435
+ * like
436
+ * ```
437
+ * <TextInput
438
+ * inlineImageLeft='search_icon'
439
+ * />
440
+ * ```
441
+ * @platform android
442
+ */
443
+ inlineImageLeft?: ?string,
444
+
445
+ /**
446
+ * Padding between the inline image, if any, and the text input itself.
447
+ * @platform android
448
+ */
449
+ inlineImagePadding?: ?number,
450
+
451
+ /**
452
+ * Sets the number of lines for a `TextInput`. Use it with multiline set to
453
+ * `true` to be able to fill the lines.
454
+ * @platform android
455
+ */
456
+ numberOfLines?: ?number,
457
+
458
+ /**
459
+ * Sets the return key to the label. Use it instead of `returnKeyType`.
460
+ * @platform android
461
+ */
462
+ returnKeyLabel?: ?string,
463
+
464
+ /**
465
+ * Sets the number of rows for a `TextInput`. Use it with multiline set to
466
+ * `true` to be able to fill the lines.
467
+ * @platform android
468
+ */
469
+ rows?: ?number,
470
+
471
+ /**
472
+ * When `false`, it will prevent the soft keyboard from showing when the field is focused.
473
+ * Defaults to `true`.
474
+ */
475
+ showSoftInputOnFocus?: ?boolean,
476
+
477
+ /**
478
+ * Set text break strategy on Android API Level 23+, possible values are `simple`, `highQuality`, `balanced`
479
+ * The default value is `simple`.
480
+ * @platform android
481
+ */
482
+ textBreakStrategy?: ?('simple' | 'highQuality' | 'balanced'),
483
+
484
+ /**
485
+ * The color of the `TextInput` underline.
486
+ * @platform android
487
+ */
488
+ underlineColorAndroid?: ?ColorValue,
489
+ }>;
490
+
491
+ export type TextInputProps = $ReadOnly<{
492
+ ...$Diff<ViewProps, $ReadOnly<{style: ?ViewStyleProp}>>,
493
+ ...TextInputIOSProps,
494
+ ...TextInputAndroidProps,
495
+
496
+ /**
497
+ * Can tell `TextInput` to automatically capitalize certain characters.
498
+ *
499
+ * - `characters`: all characters.
500
+ * - `words`: first letter of each word.
501
+ * - `sentences`: first letter of each sentence (*default*).
502
+ * - `none`: don't auto capitalize anything.
503
+ */
504
+ autoCapitalize?: ?AutoCapitalize,
505
+
506
+ /**
507
+ * Specifies autocomplete hints for the system, so it can provide autofill.
508
+ * On Android, the system will always attempt to offer autofill by using heuristics to identify the type of content.
509
+ * To disable autocomplete, set autoComplete to off.
510
+ *
511
+ * The following values work across platforms:
512
+ *
513
+ * - `additional-name`
514
+ * - `address-line1`
515
+ * - `address-line2`
516
+ * - `birthdate-day` (iOS 17+)
517
+ * - `birthdate-full` (iOS 17+)
518
+ * - `birthdate-month` (iOS 17+)
519
+ * - `birthdate-year` (iOS 17+)
520
+ * - `cc-number`
521
+ * - `cc-csc` (iOS 17+)
522
+ * - `cc-exp` (iOS 17+)
523
+ * - `cc-exp-day` (iOS 17+)
524
+ * - `cc-exp-month` (iOS 17+)
525
+ * - `cc-exp-year` (iOS 17+)
526
+ * - `country`
527
+ * - `current-password`
528
+ * - `email`
529
+ * - `family-name`
530
+ * - `given-name`
531
+ * - `honorific-prefix`
532
+ * - `honorific-suffix`
533
+ * - `name`
534
+ * - `new-password`
535
+ * - `off`
536
+ * - `one-time-code`
537
+ * - `postal-code`
538
+ * - `street-address`
539
+ * - `tel`
540
+ * - `username`
541
+ *
542
+ * The following values work on iOS only:
543
+ *
544
+ * - `cc-name` (iOS 17+)
545
+ * - `cc-given-name` (iOS 17+)
546
+ * - `cc-middle-name` (iOS 17+)
547
+ * - `cc-family-name` (iOS 17+)
548
+ * - `cc-type` (iOS 17+)
549
+ * - `nickname`
550
+ * - `organization`
551
+ * - `organization-title`
552
+ * - `url`
553
+ *
554
+ * The following values work on Android only:
555
+ *
556
+ * - `gender`
557
+ * - `name-family`
558
+ * - `name-given`
559
+ * - `name-middle`
560
+ * - `name-middle-initial`
561
+ * - `name-prefix`
562
+ * - `name-suffix`
563
+ * - `password`
564
+ * - `password-new`
565
+ * - `postal-address`
566
+ * - `postal-address-country`
567
+ * - `postal-address-extended`
568
+ * - `postal-address-extended-postal-code`
569
+ * - `postal-address-locality`
570
+ * - `postal-address-region`
571
+ * - `sms-otp`
572
+ * - `tel-country-code`
573
+ * - `tel-national`
574
+ * - `tel-device`
575
+ * - `username-new`
576
+ */
577
+ autoComplete?: ?(
578
+ | 'additional-name'
579
+ | 'address-line1'
580
+ | 'address-line2'
581
+ | 'birthdate-day'
582
+ | 'birthdate-full'
583
+ | 'birthdate-month'
584
+ | 'birthdate-year'
585
+ | 'cc-csc'
586
+ | 'cc-exp'
587
+ | 'cc-exp-day'
588
+ | 'cc-exp-month'
589
+ | 'cc-exp-year'
590
+ | 'cc-number'
591
+ | 'cc-name'
592
+ | 'cc-given-name'
593
+ | 'cc-middle-name'
594
+ | 'cc-family-name'
595
+ | 'cc-type'
596
+ | 'country'
597
+ | 'current-password'
598
+ | 'email'
599
+ | 'family-name'
600
+ | 'gender'
601
+ | 'given-name'
602
+ | 'honorific-prefix'
603
+ | 'honorific-suffix'
604
+ | 'name'
605
+ | 'name-family'
606
+ | 'name-given'
607
+ | 'name-middle'
608
+ | 'name-middle-initial'
609
+ | 'name-prefix'
610
+ | 'name-suffix'
611
+ | 'new-password'
612
+ | 'nickname'
613
+ | 'one-time-code'
614
+ | 'organization'
615
+ | 'organization-title'
616
+ | 'password'
617
+ | 'password-new'
618
+ | 'postal-address'
619
+ | 'postal-address-country'
620
+ | 'postal-address-extended'
621
+ | 'postal-address-extended-postal-code'
622
+ | 'postal-address-locality'
623
+ | 'postal-address-region'
624
+ | 'postal-code'
625
+ | 'street-address'
626
+ | 'sms-otp'
627
+ | 'tel'
628
+ | 'tel-country-code'
629
+ | 'tel-national'
630
+ | 'tel-device'
631
+ | 'url'
632
+ | 'username'
633
+ | 'username-new'
634
+ | 'off'
635
+ ),
636
+
637
+ /**
638
+ * If `false`, disables auto-correct. The default value is `true`.
639
+ */
640
+ autoCorrect?: ?boolean,
641
+
642
+ /**
643
+ * If `true`, focuses the input on `componentDidMount`.
644
+ * The default value is `false`.
645
+ */
646
+ autoFocus?: ?boolean,
647
+
648
+ /**
649
+ * Specifies whether fonts should scale to respect Text Size accessibility settings. The
650
+ * default is `true`.
651
+ */
652
+ allowFontScaling?: ?boolean,
653
+
654
+ /**
655
+ * If `true`, caret is hidden. The default value is `false`.
656
+ *
657
+ * On Android devices manufactured by Xiaomi with Android Q,
658
+ * when keyboardType equals 'email-address'this will be set
659
+ * in native to 'true' to prevent a system related crash. This
660
+ * will cause cursor to be disabled as a side-effect.
661
+ *
662
+ */
663
+ caretHidden?: ?boolean,
664
+
665
+ /*
666
+ * If `true`, contextMenuHidden is hidden. The default value is `false`.
667
+ */
668
+ contextMenuHidden?: ?boolean,
669
+
670
+ /**
671
+ * Provides an initial value that will change when the user starts typing.
672
+ * Useful for simple use-cases where you do not want to deal with listening
673
+ * to events and updating the value prop to keep the controlled state in sync.
674
+ */
675
+ defaultValue?: ?Stringish,
676
+
677
+ /**
678
+ * If `false`, text is not editable. The default value is `true`.
679
+ */
680
+ editable?: ?boolean,
681
+
682
+ forwardedRef?: ?React.RefSetter<TextInputInstance>,
683
+
684
+ /**
685
+ * `enterKeyHint` defines what action label (or icon) to present for the enter key on virtual keyboards.
686
+ *
687
+ * The following values is supported:
688
+ *
689
+ * - `enter`
690
+ * - `done`
691
+ * - `go`
692
+ * - `next`
693
+ * - `previous`
694
+ * - `search`
695
+ * - `send`
696
+ */
697
+ enterKeyHint?: ?EnterKeyHintTypeOptions,
698
+
699
+ /**
700
+ * `inputMode` works like the `inputmode` attribute in HTML, it determines which
701
+ * keyboard to open, e.g.`numeric` and has precedence over keyboardType
702
+ *
703
+ * Support the following values:
704
+ *
705
+ * - `none`
706
+ * - `text`
707
+ * - `decimal`
708
+ * - `numeric`
709
+ * - `tel`
710
+ * - `search`
711
+ * - `email`
712
+ * - `url`
713
+ */
714
+ inputMode?: ?InputModeOptions,
715
+
716
+ /**
717
+ * Determines which keyboard to open, e.g.`numeric`.
718
+ *
719
+ * The following values work across platforms:
720
+ *
721
+ * - `default`
722
+ * - `numeric`
723
+ * - `number-pad`
724
+ * - `decimal-pad`
725
+ * - `email-address`
726
+ * - `phone-pad`
727
+ * - `url`
728
+ *
729
+ * *iOS Only*
730
+ *
731
+ * The following values work on iOS only:
732
+ *
733
+ * - `ascii-capable`
734
+ * - `numbers-and-punctuation`
735
+ * - `name-phone-pad`
736
+ * - `twitter`
737
+ * - `web-search`
738
+ *
739
+ * *Android Only*
740
+ *
741
+ * The following values work on Android only:
742
+ *
743
+ * - `visible-password`
744
+ *
745
+ */
746
+ keyboardType?: ?KeyboardTypeOptions,
747
+
748
+ /**
749
+ * Specifies largest possible scale a font can reach when `allowFontScaling` is enabled.
750
+ * Possible values:
751
+ * `null/undefined` (default): inherit from the parent node or the global default (0)
752
+ * `0`: no max, ignore parent/global default
753
+ * `>= 1`: sets the maxFontSizeMultiplier of this node to this value
754
+ */
755
+ maxFontSizeMultiplier?: ?number,
756
+
757
+ /**
758
+ * Limits the maximum number of characters that can be entered. Use this
759
+ * instead of implementing the logic in JS to avoid flicker.
760
+ */
761
+ maxLength?: ?number,
762
+
763
+ /**
764
+ * If `true`, the text input can be multiple lines.
765
+ * The default value is `false`.
766
+ */
767
+ multiline?: ?boolean,
768
+
769
+ /**
770
+ * Callback that is called when the text input is blurred.
771
+ */
772
+ onBlur?: ?(e: TextInputBlurEvent) => mixed,
773
+
774
+ /**
775
+ * Callback that is called when the text input's text changes.
776
+ */
777
+ onChange?: ?(e: TextInputChangeEvent) => mixed,
778
+
779
+ /**
780
+ * Callback that is called when the text input's text changes.
781
+ * Changed text is passed as an argument to the callback handler.
782
+ */
783
+ onChangeText?: ?(text: string) => mixed,
784
+
785
+ /**
786
+ * Callback that is called when the text input's content size changes.
787
+ * This will be called with
788
+ * `{ nativeEvent: { contentSize: { width, height } } }`.
789
+ *
790
+ * Only called for multiline text inputs.
791
+ */
792
+ onContentSizeChange?: ?(e: TextInputContentSizeChangeEvent) => mixed,
793
+
794
+ /**
795
+ * Callback that is called when text input ends.
796
+ */
797
+ onEndEditing?: ?(e: TextInputEditingEvent) => mixed,
798
+
799
+ /**
800
+ * Callback that is called when the text input is focused.
801
+ */
802
+ onFocus?: ?(e: TextInputFocusEvent) => mixed,
803
+
804
+ /**
805
+ * Callback that is called when a key is pressed.
806
+ * This will be called with `{ nativeEvent: { key: keyValue } }`
807
+ * where `keyValue` is `'Enter'` or `'Backspace'` for respective keys and
808
+ * the typed-in character otherwise including `' '` for space.
809
+ * Fires before `onChange` callbacks.
810
+ */
811
+ onKeyPress?: ?(e: TextInputKeyPressEvent) => mixed,
812
+
813
+ /**
814
+ * Called when a single tap gesture is detected.
815
+ */
816
+ onPress?: ?(event: GestureResponderEvent) => mixed,
817
+
818
+ /**
819
+ * Called when a touch is engaged.
820
+ */
821
+ onPressIn?: ?(event: GestureResponderEvent) => mixed,
822
+
823
+ /**
824
+ * Called when a touch is released.
825
+ */
826
+ onPressOut?: ?(event: GestureResponderEvent) => mixed,
827
+
828
+ /**
829
+ * Callback that is called when the text input selection is changed.
830
+ * This will be called with
831
+ * `{ nativeEvent: { selection: { start, end } } }`.
832
+ */
833
+ onSelectionChange?: ?(e: TextInputSelectionChangeEvent) => mixed,
834
+
835
+ /**
836
+ * Callback that is called when the text input's submit button is pressed.
837
+ * Invalid if `multiline={true}` is specified.
838
+ */
839
+ onSubmitEditing?: ?(e: TextInputEditingEvent) => mixed,
840
+
841
+ /**
842
+ * Invoked on content scroll with `{ nativeEvent: { contentOffset: { x, y } } }`.
843
+ * May also contain other properties from ScrollEvent but on Android contentSize
844
+ * is not provided for performance reasons.
845
+ */
846
+ onScroll?: ?(e: ScrollEvent) => mixed,
847
+
848
+ /**
849
+ * The string that will be rendered before text input has been entered.
850
+ */
851
+ placeholder?: ?Stringish,
852
+
853
+ /**
854
+ * The text color of the placeholder string.
855
+ */
856
+ placeholderTextColor?: ?ColorValue,
857
+
858
+ /** `readOnly` works like the `readonly` attribute in HTML.
859
+ * If `true`, text is not editable. The default value is `false`.
860
+ * See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly
861
+ * for more details.
862
+ */
863
+ readOnly?: ?boolean,
864
+
865
+ /**
866
+ * Determines how the return key should look. On Android you can also use
867
+ * `returnKeyLabel`.
868
+ *
869
+ * *Cross platform*
870
+ *
871
+ * The following values work across platforms:
872
+ *
873
+ * - `done`
874
+ * - `go`
875
+ * - `next`
876
+ * - `search`
877
+ * - `send`
878
+ *
879
+ * *Android Only*
880
+ *
881
+ * The following values work on Android only:
882
+ *
883
+ * - `none`
884
+ * - `previous`
885
+ *
886
+ * *iOS Only*
887
+ *
888
+ * The following values work on iOS only:
889
+ *
890
+ * - `default`
891
+ * - `emergency-call`
892
+ * - `google`
893
+ * - `join`
894
+ * - `route`
895
+ * - `yahoo`
896
+ */
897
+ returnKeyType?: ?ReturnKeyTypeOptions,
898
+
899
+ /**
900
+ * If `true`, the text input obscures the text entered so that sensitive text
901
+ * like passwords stay secure. The default value is `false`. Does not work with 'multiline={true}'.
902
+ */
903
+ secureTextEntry?: ?boolean,
904
+
905
+ /**
906
+ * The start and end of the text input's selection. Set start and end to
907
+ * the same value to position the cursor.
908
+ */
909
+ selection?: ?$ReadOnly<{
910
+ start: number,
911
+ end?: ?number,
912
+ }>,
913
+
914
+ /**
915
+ * The highlight and cursor color of the text input.
916
+ */
917
+ selectionColor?: ?ColorValue,
918
+
919
+ /**
920
+ * The text selection handle color.
921
+ * @platform android
922
+ */
923
+ selectionHandleColor?: ?ColorValue,
924
+
925
+ /**
926
+ * If `true`, all text will automatically be selected on focus.
927
+ */
928
+ selectTextOnFocus?: ?boolean,
929
+
930
+ /**
931
+ * If `true`, the text field will blur when submitted.
932
+ * The default value is true for single-line fields and false for
933
+ * multiline fields. Note that for multiline fields, setting `blurOnSubmit`
934
+ * to `true` means that pressing return will blur the field and trigger the
935
+ * `onSubmitEditing` event instead of inserting a newline into the field.
936
+ *
937
+ * @deprecated
938
+ * Note that `submitBehavior` now takes the place of `blurOnSubmit` and will
939
+ * override any behavior defined by `blurOnSubmit`.
940
+ * @see submitBehavior
941
+ */
942
+ blurOnSubmit?: ?boolean,
943
+
944
+ /**
945
+ * When the return key is pressed,
946
+ *
947
+ * For single line inputs:
948
+ *
949
+ * - `'newline`' defaults to `'blurAndSubmit'`
950
+ * - `undefined` defaults to `'blurAndSubmit'`
951
+ *
952
+ * For multiline inputs:
953
+ *
954
+ * - `'newline'` adds a newline
955
+ * - `undefined` defaults to `'newline'`
956
+ *
957
+ * For both single line and multiline inputs:
958
+ *
959
+ * - `'submit'` will only send a submit event and not blur the input
960
+ * - `'blurAndSubmit`' will both blur the input and send a submit event
961
+ */
962
+ submitBehavior?: ?SubmitBehavior,
963
+
964
+ /**
965
+ * Note that not all Text styles are supported, an incomplete list of what is not supported includes:
966
+ *
967
+ * - `borderLeftWidth`
968
+ * - `borderTopWidth`
969
+ * - `borderRightWidth`
970
+ * - `borderBottomWidth`
971
+ * - `borderTopLeftRadius`
972
+ * - `borderTopRightRadius`
973
+ * - `borderBottomRightRadius`
974
+ * - `borderBottomLeftRadius`
975
+ *
976
+ * see [Issue#7070](https://github.com/facebook/react-native/issues/7070)
977
+ * for more detail.
978
+ *
979
+ * [Styles](docs/style.html)
980
+ */
981
+ style?: ?TextStyleProp,
982
+
983
+ /**
984
+ * The value to show for the text input. `TextInput` is a controlled
985
+ * component, which means the native value will be forced to match this
986
+ * value prop if provided. For most uses, this works great, but in some
987
+ * cases this may cause flickering - one common cause is preventing edits
988
+ * by keeping value the same. In addition to simply setting the same value,
989
+ * either set `editable={false}`, or set/update `maxLength` to prevent
990
+ * unwanted edits without flicker.
991
+ */
992
+ value?: ?Stringish,
993
+ }>;
994
+
995
+ type ViewCommands = $NonMaybeType<
996
+ | typeof AndroidTextInputCommands
997
+ | typeof RCTMultilineTextInputNativeCommands
998
+ | typeof RCTSinglelineTextInputNativeCommands,
999
+ >;
1000
+
1001
+ type LastNativeSelection = {
1002
+ selection: Selection,
1003
+ mostRecentEventCount: number,
1004
+ };
1005
+
1006
+ const emptyFunctionThatReturnsTrue = () => true;
1007
+
1008
+ /**
1009
+ * This hook handles the synchronization between the state of the text input
1010
+ * in native and in JavaScript. This is necessary due to the asynchronous nature
1011
+ * of text input events.
1012
+ */
1013
+ function useTextInputStateSynchronization_STATE({
1014
+ props,
1015
+ mostRecentEventCount,
1016
+ selection,
1017
+ inputRef,
1018
+ text,
1019
+ viewCommands,
1020
+ }: {
1021
+ props: TextInputProps,
1022
+ mostRecentEventCount: number,
1023
+ selection: ?Selection,
1024
+ inputRef: React.RefObject<null | TextInputInstance>,
1025
+ text?: string,
1026
+ viewCommands: ViewCommands,
1027
+ }): {
1028
+ setLastNativeText: string => void,
1029
+ setLastNativeSelection: LastNativeSelection => void,
1030
+ } {
1031
+ const [lastNativeText, setLastNativeText] = useState<?Stringish>(props.value);
1032
+ const [lastNativeSelectionState, setLastNativeSelection] =
1033
+ useState<LastNativeSelection>({
1034
+ selection: {start: -1, end: -1},
1035
+ mostRecentEventCount: mostRecentEventCount,
1036
+ });
1037
+
1038
+ const lastNativeSelection = lastNativeSelectionState.selection;
1039
+
1040
+ // This is necessary in case native updates the text and JS decides
1041
+ // that the update should be ignored and we should stick with the value
1042
+ // that we have in JS.
1043
+ useLayoutEffect(() => {
1044
+ const nativeUpdate: {text?: string, selection?: Selection} = {};
1045
+
1046
+ if (lastNativeText !== props.value && typeof props.value === 'string') {
1047
+ nativeUpdate.text = props.value;
1048
+ setLastNativeText(props.value);
1049
+ }
1050
+
1051
+ if (
1052
+ selection &&
1053
+ lastNativeSelection &&
1054
+ (lastNativeSelection.start !== selection.start ||
1055
+ lastNativeSelection.end !== selection.end)
1056
+ ) {
1057
+ nativeUpdate.selection = selection;
1058
+ setLastNativeSelection({selection, mostRecentEventCount});
1059
+ }
1060
+
1061
+ if (Object.keys(nativeUpdate).length === 0) {
1062
+ return;
1063
+ }
1064
+
1065
+ if (inputRef.current != null) {
1066
+ viewCommands.setTextAndSelection(
1067
+ inputRef.current,
1068
+ mostRecentEventCount,
1069
+ text,
1070
+ selection?.start ?? -1,
1071
+ selection?.end ?? -1,
1072
+ );
1073
+ }
1074
+ }, [
1075
+ mostRecentEventCount,
1076
+ inputRef,
1077
+ props.value,
1078
+ props.defaultValue,
1079
+ lastNativeText,
1080
+ selection,
1081
+ lastNativeSelection,
1082
+ text,
1083
+ viewCommands,
1084
+ ]);
1085
+
1086
+ return {setLastNativeText, setLastNativeSelection};
1087
+ }
1088
+
1089
+ /**
1090
+ * This hook handles the synchronization between the state of the text input
1091
+ * in native and in JavaScript. This is necessary due to the asynchronous nature
1092
+ * of text input events.
1093
+ */
1094
+ function useTextInputStateSynchronization_REFS({
1095
+ props,
1096
+ mostRecentEventCount,
1097
+ selection,
1098
+ inputRef,
1099
+ text,
1100
+ viewCommands,
1101
+ }: {
1102
+ props: TextInputProps,
1103
+ mostRecentEventCount: number,
1104
+ selection: ?Selection,
1105
+ inputRef: React.RefObject<null | TextInputInstance>,
1106
+ text?: string,
1107
+ viewCommands: ViewCommands,
1108
+ }): {
1109
+ setLastNativeText: string => void,
1110
+ setLastNativeSelection: LastNativeSelection => void,
1111
+ } {
1112
+ const lastNativeTextRef = useRef<?Stringish>(props.value);
1113
+ const lastNativeSelectionRef = useRef<LastNativeSelection>({
1114
+ selection: {start: -1, end: -1},
1115
+ mostRecentEventCount: mostRecentEventCount,
1116
+ });
1117
+
1118
+ // This is necessary in case native updates the text and JS decides
1119
+ // that the update should be ignored and we should stick with the value
1120
+ // that we have in JS.
1121
+ useLayoutEffect(() => {
1122
+ const nativeUpdate: {text?: string, selection?: Selection} = {};
1123
+
1124
+ const lastNativeSelection = lastNativeSelectionRef.current.selection;
1125
+
1126
+ if (
1127
+ lastNativeTextRef.current !== props.value &&
1128
+ typeof props.value === 'string'
1129
+ ) {
1130
+ nativeUpdate.text = props.value;
1131
+ lastNativeTextRef.current = props.value;
1132
+ }
1133
+
1134
+ if (
1135
+ selection &&
1136
+ lastNativeSelection &&
1137
+ (lastNativeSelection.start !== selection.start ||
1138
+ lastNativeSelection.end !== selection.end)
1139
+ ) {
1140
+ nativeUpdate.selection = selection;
1141
+ lastNativeSelectionRef.current = {selection, mostRecentEventCount};
1142
+ }
1143
+
1144
+ if (Object.keys(nativeUpdate).length === 0) {
1145
+ return;
1146
+ }
1147
+
1148
+ if (inputRef.current != null) {
1149
+ viewCommands.setTextAndSelection(
1150
+ inputRef.current,
1151
+ mostRecentEventCount,
1152
+ text,
1153
+ selection?.start ?? -1,
1154
+ selection?.end ?? -1,
1155
+ );
1156
+ }
1157
+ }, [
1158
+ mostRecentEventCount,
1159
+ inputRef,
1160
+ props.value,
1161
+ props.defaultValue,
1162
+ selection,
1163
+ text,
1164
+ viewCommands,
1165
+ ]);
1166
+
1167
+ return {
1168
+ setLastNativeText: lastNativeText => {
1169
+ lastNativeTextRef.current = lastNativeText;
1170
+ },
1171
+ setLastNativeSelection: lastNativeSelection => {
1172
+ lastNativeSelectionRef.current = lastNativeSelection;
1173
+ },
1174
+ };
1175
+ }
1176
+
1177
+ /**
1178
+ * A foundational component for inputting text into the app via a
1179
+ * keyboard. Props provide configurability for several features, such as
1180
+ * auto-correction, auto-capitalization, placeholder text, and different keyboard
1181
+ * types, such as a numeric keypad.
1182
+ *
1183
+ * The simplest use case is to plop down a `TextInput` and subscribe to the
1184
+ * `onChangeText` events to read the user input. There are also other events,
1185
+ * such as `onSubmitEditing` and `onFocus` that can be subscribed to. A simple
1186
+ * example:
1187
+ *
1188
+ * ```ReactNativeWebPlayer
1189
+ * import React, { Component } from 'react';
1190
+ * import { AppRegistry, TextInput } from 'react-native';
1191
+ *
1192
+ * export default class UselessTextInput extends Component {
1193
+ * constructor(props) {
1194
+ * super(props);
1195
+ * this.state = { text: 'Useless Placeholder' };
1196
+ * }
1197
+ *
1198
+ * render() {
1199
+ * return (
1200
+ * <TextInput
1201
+ * style={{height: 40, borderColor: 'gray', borderWidth: 1}}
1202
+ * onChangeText={(text) => this.setState({text})}
1203
+ * value={this.state.text}
1204
+ * />
1205
+ * );
1206
+ * }
1207
+ * }
1208
+ *
1209
+ * // skip this line if using Create React Native App
1210
+ * AppRegistry.registerComponent('AwesomeProject', () => UselessTextInput);
1211
+ * ```
1212
+ *
1213
+ * Two methods exposed via the native element are .focus() and .blur() that
1214
+ * will focus or blur the TextInput programmatically.
1215
+ *
1216
+ * Note that some props are only available with `multiline={true/false}`.
1217
+ * Additionally, border styles that apply to only one side of the element
1218
+ * (e.g., `borderBottomColor`, `borderLeftWidth`, etc.) will not be applied if
1219
+ * `multiline=false`. To achieve the same effect, you can wrap your `TextInput`
1220
+ * in a `View`:
1221
+ *
1222
+ * ```ReactNativeWebPlayer
1223
+ * import React, { Component } from 'react';
1224
+ * import { AppRegistry, View, TextInput } from 'react-native';
1225
+ *
1226
+ * class UselessTextInput extends Component {
1227
+ * render() {
1228
+ * return (
1229
+ * <TextInput
1230
+ * {...this.props} // Inherit any props passed to it; e.g., multiline, numberOfLines below
1231
+ * editable={true}
1232
+ * maxLength={40}
1233
+ * />
1234
+ * );
1235
+ * }
1236
+ * }
1237
+ *
1238
+ * export default class UselessTextInputMultiline extends Component {
1239
+ * constructor(props) {
1240
+ * super(props);
1241
+ * this.state = {
1242
+ * text: 'Useless Multiline Placeholder',
1243
+ * };
1244
+ * }
1245
+ *
1246
+ * // If you type something in the text box that is a color, the background will change to that
1247
+ * // color.
1248
+ * render() {
1249
+ * return (
1250
+ * <View style={{
1251
+ * backgroundColor: this.state.text,
1252
+ * borderBottomColor: '#000000',
1253
+ * borderBottomWidth: 1 }}
1254
+ * >
1255
+ * <UselessTextInput
1256
+ * multiline={true}
1257
+ * numberOfLines={4}
1258
+ * onChangeText={(text) => this.setState({text})}
1259
+ * value={this.state.text}
1260
+ * />
1261
+ * </View>
1262
+ * );
1263
+ * }
1264
+ * }
1265
+ *
1266
+ * // skip these lines if using Create React Native App
1267
+ * AppRegistry.registerComponent(
1268
+ * 'AwesomeProject',
1269
+ * () => UselessTextInputMultiline
1270
+ * );
1271
+ * ```
1272
+ *
1273
+ * `TextInput` has by default a border at the bottom of its view. This border
1274
+ * has its padding set by the background image provided by the system, and it
1275
+ * cannot be changed. Solutions to avoid this is to either not set height
1276
+ * explicitly, case in which the system will take care of displaying the border
1277
+ * in the correct position, or to not display the border by setting
1278
+ * `underlineColorAndroid` to transparent.
1279
+ *
1280
+ * Note that on Android performing text selection in input can change
1281
+ * app's activity `windowSoftInputMode` param to `adjustResize`.
1282
+ * This may cause issues with components that have position: 'absolute'
1283
+ * while keyboard is active. To avoid this behavior either specify `windowSoftInputMode`
1284
+ * in AndroidManifest.xml ( https://developer.android.com/guide/topics/manifest/activity-element.html )
1285
+ * or control this param programmatically with native code.
1286
+ *
1287
+ */
1288
+ function InternalTextInput(props: TextInputProps): React.Node {
1289
+ const {
1290
+ 'aria-busy': ariaBusy,
1291
+ 'aria-checked': ariaChecked,
1292
+ 'aria-disabled': ariaDisabled,
1293
+ 'aria-expanded': ariaExpanded,
1294
+ 'aria-selected': ariaSelected,
1295
+ accessibilityState,
1296
+ id,
1297
+ tabIndex,
1298
+ selection: propsSelection,
1299
+ selectionColor,
1300
+ selectionHandleColor,
1301
+ cursorColor,
1302
+ ...otherProps
1303
+ } = props;
1304
+
1305
+ const inputRef = useRef<null | TextInputInstance>(null);
1306
+
1307
+ const selection: ?Selection =
1308
+ propsSelection == null
1309
+ ? null
1310
+ : {
1311
+ start: propsSelection.start,
1312
+ end: propsSelection.end ?? propsSelection.start,
1313
+ };
1314
+
1315
+ const text =
1316
+ typeof props.value === 'string'
1317
+ ? props.value
1318
+ : typeof props.defaultValue === 'string'
1319
+ ? props.defaultValue
1320
+ : undefined;
1321
+
1322
+ const viewCommands =
1323
+ AndroidTextInputCommands ||
1324
+ (props.multiline === true
1325
+ ? RCTMultilineTextInputNativeCommands
1326
+ : RCTSinglelineTextInputNativeCommands);
1327
+
1328
+ const [mostRecentEventCount, setMostRecentEventCount] = useState<number>(0);
1329
+ const useTextInputStateSynchronization =
1330
+ ReactNativeFeatureFlags.useRefsForTextInputState()
1331
+ ? useTextInputStateSynchronization_REFS
1332
+ : useTextInputStateSynchronization_STATE;
1333
+ const {setLastNativeText, setLastNativeSelection} =
1334
+ useTextInputStateSynchronization({
1335
+ props,
1336
+ inputRef,
1337
+ mostRecentEventCount,
1338
+ selection,
1339
+ text,
1340
+ viewCommands,
1341
+ });
1342
+
1343
+ useLayoutEffect(() => {
1344
+ const inputRefValue = inputRef.current;
1345
+
1346
+ if (inputRefValue != null) {
1347
+ TextInputState.registerInput(inputRefValue);
1348
+
1349
+ return () => {
1350
+ TextInputState.unregisterInput(inputRefValue);
1351
+
1352
+ if (TextInputState.currentlyFocusedInput() === inputRefValue) {
1353
+ nullthrows(inputRefValue).blur();
1354
+ }
1355
+ };
1356
+ }
1357
+ }, []);
1358
+
1359
+ const setLocalRef = useCallback(
1360
+ (instance: HostInstance | null) => {
1361
+ // $FlowExpectedError[incompatible-type]
1362
+ inputRef.current = instance;
1363
+
1364
+ /*
1365
+ Hi reader from the future. I'm sorry for this.
1366
+
1367
+ This is a hack. Ideally we would forwardRef to the underlying
1368
+ host component. However, since TextInput has it's own methods that can be
1369
+ called as well, if we used the standard forwardRef then these
1370
+ methods wouldn't be accessible and thus be a breaking change.
1371
+
1372
+ We have a couple of options of how to handle this:
1373
+ - Return a new ref with everything we methods from both. This is problematic
1374
+ because we need React to also know it is a host component which requires
1375
+ internals of the class implementation of the ref.
1376
+ - Break the API and have some other way to call one set of the methods or
1377
+ the other. This is our long term approach as we want to eventually
1378
+ get the methods on host components off the ref. So instead of calling
1379
+ ref.measure() you might call ReactNative.measure(ref). This would hopefully
1380
+ let the ref for TextInput then have the methods like `.clear`. Or we do it
1381
+ the other way and make it TextInput.clear(textInputRef) which would be fine
1382
+ too. Either way though is a breaking change that is longer term.
1383
+ - Mutate this ref. :( Gross, but accomplishes what we need in the meantime
1384
+ before we can get to the long term breaking change.
1385
+ */
1386
+ if (instance != null) {
1387
+ // $FlowFixMe[prop-missing] - See the explanation above.
1388
+ Object.assign(instance, {
1389
+ clear(): void {
1390
+ if (inputRef.current != null) {
1391
+ viewCommands.setTextAndSelection(
1392
+ inputRef.current,
1393
+ mostRecentEventCount,
1394
+ '',
1395
+ 0,
1396
+ 0,
1397
+ );
1398
+ }
1399
+ },
1400
+ // TODO: Fix this returning true on null === null, when no input is focused
1401
+ isFocused(): boolean {
1402
+ return TextInputState.currentlyFocusedInput() === inputRef.current;
1403
+ },
1404
+ getNativeRef(): ?TextInputInstance {
1405
+ return inputRef.current;
1406
+ },
1407
+ setSelection(start: number, end: number): void {
1408
+ if (inputRef.current != null) {
1409
+ viewCommands.setTextAndSelection(
1410
+ inputRef.current,
1411
+ mostRecentEventCount,
1412
+ null,
1413
+ start,
1414
+ end,
1415
+ );
1416
+ }
1417
+ },
1418
+ });
1419
+ }
1420
+ },
1421
+ [mostRecentEventCount, viewCommands],
1422
+ );
1423
+
1424
+ // $FlowExpectedError[incompatible-call]
1425
+ const ref = useMergeRefs<HostInstance>(setLocalRef, props.forwardedRef);
1426
+
1427
+ const _onChange = (event: TextInputChangeEvent) => {
1428
+ const currentText = event.nativeEvent.text;
1429
+ props.onChange && props.onChange(event);
1430
+ props.onChangeText && props.onChangeText(currentText);
1431
+
1432
+ if (inputRef.current == null) {
1433
+ // calling `props.onChange` or `props.onChangeText`
1434
+ // may clean up the input itself. Exits here.
1435
+ return;
1436
+ }
1437
+
1438
+ setLastNativeText(currentText);
1439
+ // This must happen last, after we call setLastNativeText.
1440
+ // Different ordering can cause bugs when editing AndroidTextInputs
1441
+ // with multiple Fragments.
1442
+ // We must update this so that controlled input updates work.
1443
+ setMostRecentEventCount(event.nativeEvent.eventCount);
1444
+ };
1445
+
1446
+ const _onSelectionChange = (event: TextInputSelectionChangeEvent) => {
1447
+ props.onSelectionChange && props.onSelectionChange(event);
1448
+
1449
+ if (inputRef.current == null) {
1450
+ // calling `props.onSelectionChange`
1451
+ // may clean up the input itself. Exits here.
1452
+ return;
1453
+ }
1454
+
1455
+ setLastNativeSelection({
1456
+ selection: event.nativeEvent.selection,
1457
+ mostRecentEventCount,
1458
+ });
1459
+ };
1460
+
1461
+ const _onFocus = (event: TextInputFocusEvent) => {
1462
+ TextInputState.focusInput(inputRef.current);
1463
+ if (props.onFocus) {
1464
+ props.onFocus(event);
1465
+ }
1466
+ };
1467
+
1468
+ const _onBlur = (event: TextInputBlurEvent) => {
1469
+ TextInputState.blurInput(inputRef.current);
1470
+ if (props.onBlur) {
1471
+ props.onBlur(event);
1472
+ }
1473
+ };
1474
+
1475
+ const _onScroll = (event: ScrollEvent) => {
1476
+ props.onScroll && props.onScroll(event);
1477
+ };
1478
+
1479
+ let textInput = null;
1480
+
1481
+ const multiline = props.multiline ?? false;
1482
+
1483
+ let submitBehavior: SubmitBehavior;
1484
+ if (props.submitBehavior != null) {
1485
+ // `submitBehavior` is set explicitly
1486
+ if (!multiline && props.submitBehavior === 'newline') {
1487
+ // For single line text inputs, `'newline'` is not a valid option
1488
+ submitBehavior = 'blurAndSubmit';
1489
+ } else {
1490
+ submitBehavior = props.submitBehavior;
1491
+ }
1492
+ } else if (multiline) {
1493
+ if (props.blurOnSubmit === true) {
1494
+ submitBehavior = 'blurAndSubmit';
1495
+ } else {
1496
+ submitBehavior = 'newline';
1497
+ }
1498
+ } else {
1499
+ // Single line
1500
+ if (props.blurOnSubmit !== false) {
1501
+ submitBehavior = 'blurAndSubmit';
1502
+ } else {
1503
+ submitBehavior = 'submit';
1504
+ }
1505
+ }
1506
+
1507
+ const accessible = props.accessible !== false;
1508
+ const focusable = props.focusable !== false;
1509
+
1510
+ const {
1511
+ editable,
1512
+ hitSlop,
1513
+ onPress,
1514
+ onPressIn,
1515
+ onPressOut,
1516
+ rejectResponderTermination,
1517
+ } = props;
1518
+
1519
+ const config = React.useMemo(
1520
+ () => ({
1521
+ hitSlop,
1522
+ onPress: (event: GestureResponderEvent) => {
1523
+ onPress?.(event);
1524
+ if (editable !== false) {
1525
+ if (inputRef.current != null) {
1526
+ inputRef.current.focus();
1527
+ }
1528
+ }
1529
+ },
1530
+ onPressIn: onPressIn,
1531
+ onPressOut: onPressOut,
1532
+ cancelable: Platform.OS === 'ios' ? !rejectResponderTermination : null,
1533
+ }),
1534
+ [
1535
+ editable,
1536
+ hitSlop,
1537
+ onPress,
1538
+ onPressIn,
1539
+ onPressOut,
1540
+ rejectResponderTermination,
1541
+ ],
1542
+ );
1543
+
1544
+ // Hide caret during test runs due to a flashing caret
1545
+ // makes screenshot tests flakey
1546
+ let caretHidden = props.caretHidden;
1547
+ if (Platform.isTesting) {
1548
+ caretHidden = true;
1549
+ }
1550
+
1551
+ // TextInput handles onBlur and onFocus events
1552
+ // so omitting onBlur and onFocus pressability handlers here.
1553
+ const {onBlur, onFocus, ...eventHandlers} = usePressability(config);
1554
+
1555
+ let _accessibilityState;
1556
+ if (
1557
+ accessibilityState != null ||
1558
+ ariaBusy != null ||
1559
+ ariaChecked != null ||
1560
+ ariaDisabled != null ||
1561
+ ariaExpanded != null ||
1562
+ ariaSelected != null
1563
+ ) {
1564
+ _accessibilityState = {
1565
+ busy: ariaBusy ?? accessibilityState?.busy,
1566
+ checked: ariaChecked ?? accessibilityState?.checked,
1567
+ disabled: ariaDisabled ?? accessibilityState?.disabled,
1568
+ expanded: ariaExpanded ?? accessibilityState?.expanded,
1569
+ selected: ariaSelected ?? accessibilityState?.selected,
1570
+ };
1571
+ }
1572
+
1573
+ // Keep the original (potentially nested) style when possible, as React can diff these more efficiently
1574
+ let _style = props.style;
1575
+ const flattenedStyle = flattenStyle<TextStyleProp>(props.style);
1576
+ if (flattenedStyle != null) {
1577
+ let overrides: ?{...TextStyleInternal} = null;
1578
+ if (typeof flattenedStyle?.fontWeight === 'number') {
1579
+ overrides = overrides || ({}: {...TextStyleInternal});
1580
+ overrides.fontWeight =
1581
+ // $FlowFixMe[incompatible-cast]
1582
+ (flattenedStyle.fontWeight.toString(): TextStyleInternal['fontWeight']);
1583
+ }
1584
+
1585
+ if (flattenedStyle.verticalAlign != null) {
1586
+ overrides = overrides || ({}: {...TextStyleInternal});
1587
+ overrides.textAlignVertical =
1588
+ verticalAlignToTextAlignVerticalMap[flattenedStyle.verticalAlign];
1589
+ overrides.verticalAlign = undefined;
1590
+ }
1591
+
1592
+ if (overrides != null) {
1593
+ // $FlowFixMe[incompatible-type]
1594
+ _style = [_style, overrides];
1595
+ }
1596
+ }
1597
+
1598
+ if (Platform.OS === 'ios') {
1599
+ const RCTTextInputView =
1600
+ props.multiline === true
1601
+ ? RCTMultilineTextInputView
1602
+ : RCTSinglelineTextInputView;
1603
+
1604
+ const useMultilineDefaultStyle =
1605
+ props.multiline === true &&
1606
+ (flattenedStyle == null ||
1607
+ (flattenedStyle.padding == null &&
1608
+ flattenedStyle.paddingVertical == null &&
1609
+ flattenedStyle.paddingTop == null));
1610
+
1611
+ textInput = (
1612
+ <RCTTextInputView
1613
+ // Figure out imperative + forward refs.
1614
+ ref={(ref: $FlowFixMe)}
1615
+ {...otherProps}
1616
+ {...eventHandlers}
1617
+ accessibilityState={_accessibilityState}
1618
+ accessible={accessible}
1619
+ submitBehavior={submitBehavior}
1620
+ caretHidden={caretHidden}
1621
+ dataDetectorTypes={props.dataDetectorTypes}
1622
+ focusable={tabIndex !== undefined ? !tabIndex : focusable}
1623
+ mostRecentEventCount={mostRecentEventCount}
1624
+ nativeID={id ?? props.nativeID}
1625
+ numberOfLines={props.rows ?? props.numberOfLines}
1626
+ onBlur={_onBlur}
1627
+ onChange={_onChange}
1628
+ onContentSizeChange={props.onContentSizeChange}
1629
+ onFocus={_onFocus}
1630
+ onScroll={_onScroll}
1631
+ onSelectionChange={_onSelectionChange}
1632
+ onSelectionChangeShouldSetResponder={emptyFunctionThatReturnsTrue}
1633
+ selection={selection}
1634
+ selectionColor={selectionColor}
1635
+ style={StyleSheet.compose(
1636
+ useMultilineDefaultStyle ? styles.multilineDefault : null,
1637
+ _style,
1638
+ )}
1639
+ text={text}
1640
+ />
1641
+ );
1642
+ } else if (Platform.OS === 'android') {
1643
+ const autoCapitalize = props.autoCapitalize || 'sentences';
1644
+ const _accessibilityLabelledBy =
1645
+ props?.['aria-labelledby'] ?? props?.accessibilityLabelledBy;
1646
+ const placeholder = props.placeholder ?? '';
1647
+ let children = props.children;
1648
+ const childCount = React.Children.count(children);
1649
+ invariant(
1650
+ !(props.value != null && childCount),
1651
+ 'Cannot specify both value and children.',
1652
+ );
1653
+ if (childCount > 1) {
1654
+ children = <Text>{children}</Text>;
1655
+ }
1656
+ // For consistency with iOS set cursor/selectionHandle color as selectionColor
1657
+ const colorProps = {
1658
+ selectionColor,
1659
+ selectionHandleColor:
1660
+ selectionHandleColor === undefined
1661
+ ? selectionColor
1662
+ : selectionHandleColor,
1663
+ cursorColor: cursorColor === undefined ? selectionColor : cursorColor,
1664
+ };
1665
+ const { onPaste, ...rest } = otherProps;
1666
+ textInput = (
1667
+ /* $FlowFixMe[prop-missing] the types for AndroidTextInput don't match up
1668
+ * exactly with the props for TextInput. This will need to get fixed */
1669
+ /* $FlowFixMe[incompatible-type] the types for AndroidTextInput don't
1670
+ * match up exactly with the props for TextInput. This will need to get
1671
+ * fixed */
1672
+ /* $FlowFixMe[incompatible-type-arg] the types for AndroidTextInput don't
1673
+ * match up exactly with the props for TextInput. This will need to get
1674
+ * fixed */
1675
+ <AndroidTextInput
1676
+ // Figure out imperative + forward refs.
1677
+ ref={(ref: $FlowFixMe)}
1678
+ {...rest}
1679
+ {...colorProps}
1680
+ {...eventHandlers}
1681
+ onPaste={onPaste}
1682
+ accessibilityState={_accessibilityState}
1683
+ accessibilityLabelledBy={_accessibilityLabelledBy}
1684
+ accessible={accessible}
1685
+ autoCapitalize={autoCapitalize}
1686
+ submitBehavior={submitBehavior}
1687
+ caretHidden={caretHidden}
1688
+ children={children}
1689
+ disableFullscreenUI={props.disableFullscreenUI}
1690
+ focusable={tabIndex !== undefined ? !tabIndex : focusable}
1691
+ mostRecentEventCount={mostRecentEventCount}
1692
+ nativeID={id ?? props.nativeID}
1693
+ numberOfLines={props.rows ?? props.numberOfLines}
1694
+ onBlur={_onBlur}
1695
+ onChange={_onChange}
1696
+ onFocus={_onFocus}
1697
+ /* $FlowFixMe[prop-missing] the types for AndroidTextInput don't match
1698
+ * up exactly with the props for TextInput. This will need to get fixed
1699
+ */
1700
+ /* $FlowFixMe[incompatible-type-arg] the types for AndroidTextInput
1701
+ * don't match up exactly with the props for TextInput. This will need
1702
+ * to get fixed */
1703
+ onScroll={_onScroll}
1704
+ onSelectionChange={_onSelectionChange}
1705
+ placeholder={placeholder}
1706
+ style={_style}
1707
+ text={text}
1708
+ textBreakStrategy={props.textBreakStrategy}
1709
+ />
1710
+ );
1711
+ }
1712
+ return (
1713
+ <TextAncestor.Provider value={true}>{textInput}</TextAncestor.Provider>
1714
+ );
1715
+ }
1716
+
1717
+ const enterKeyHintToReturnTypeMap = {
1718
+ enter: 'default',
1719
+ done: 'done',
1720
+ go: 'go',
1721
+ next: 'next',
1722
+ previous: 'previous',
1723
+ search: 'search',
1724
+ send: 'send',
1725
+ };
1726
+
1727
+ const inputModeToKeyboardTypeMap = {
1728
+ none: 'default',
1729
+ text: 'default',
1730
+ decimal: 'decimal-pad',
1731
+ numeric: 'number-pad',
1732
+ tel: 'phone-pad',
1733
+ search: Platform.OS === 'ios' ? 'web-search' : 'default',
1734
+ email: 'email-address',
1735
+ url: 'url',
1736
+ };
1737
+
1738
+ // Map HTML autocomplete values to Android autoComplete values
1739
+ const autoCompleteWebToAutoCompleteAndroidMap = {
1740
+ 'address-line1': 'postal-address-region',
1741
+ 'address-line2': 'postal-address-locality',
1742
+ bday: 'birthdate-full',
1743
+ 'bday-day': 'birthdate-day',
1744
+ 'bday-month': 'birthdate-month',
1745
+ 'bday-year': 'birthdate-year',
1746
+ 'cc-csc': 'cc-csc',
1747
+ 'cc-exp': 'cc-exp',
1748
+ 'cc-exp-month': 'cc-exp-month',
1749
+ 'cc-exp-year': 'cc-exp-year',
1750
+ 'cc-number': 'cc-number',
1751
+ country: 'postal-address-country',
1752
+ 'current-password': 'password',
1753
+ email: 'email',
1754
+ 'honorific-prefix': 'name-prefix',
1755
+ 'honorific-suffix': 'name-suffix',
1756
+ name: 'name',
1757
+ 'additional-name': 'name-middle',
1758
+ 'family-name': 'name-family',
1759
+ 'given-name': 'name-given',
1760
+ 'new-password': 'password-new',
1761
+ off: 'off',
1762
+ 'one-time-code': 'sms-otp',
1763
+ 'postal-code': 'postal-code',
1764
+ sex: 'gender',
1765
+ 'street-address': 'street-address',
1766
+ tel: 'tel',
1767
+ 'tel-country-code': 'tel-country-code',
1768
+ 'tel-national': 'tel-national',
1769
+ username: 'username',
1770
+ };
1771
+
1772
+ // Map HTML autocomplete values to iOS textContentType values
1773
+ const autoCompleteWebToTextContentTypeMap = {
1774
+ 'address-line1': 'streetAddressLine1',
1775
+ 'address-line2': 'streetAddressLine2',
1776
+ bday: 'birthdate',
1777
+ 'bday-day': 'birthdateDay',
1778
+ 'bday-month': 'birthdateMonth',
1779
+ 'bday-year': 'birthdateYear',
1780
+ 'cc-csc': 'creditCardSecurityCode',
1781
+ 'cc-exp-month': 'creditCardExpirationMonth',
1782
+ 'cc-exp-year': 'creditCardExpirationYear',
1783
+ 'cc-exp': 'creditCardExpiration',
1784
+ 'cc-given-name': 'creditCardGivenName',
1785
+ 'cc-additional-name': 'creditCardMiddleName',
1786
+ 'cc-family-name': 'creditCardFamilyName',
1787
+ 'cc-name': 'creditCardName',
1788
+ 'cc-number': 'creditCardNumber',
1789
+ 'cc-type': 'creditCardType',
1790
+ 'current-password': 'password',
1791
+ country: 'countryName',
1792
+ email: 'emailAddress',
1793
+ name: 'name',
1794
+ 'additional-name': 'middleName',
1795
+ 'family-name': 'familyName',
1796
+ 'given-name': 'givenName',
1797
+ nickname: 'nickname',
1798
+ 'honorific-prefix': 'namePrefix',
1799
+ 'honorific-suffix': 'nameSuffix',
1800
+ 'new-password': 'newPassword',
1801
+ off: 'none',
1802
+ 'one-time-code': 'oneTimeCode',
1803
+ organization: 'organizationName',
1804
+ 'organization-title': 'jobTitle',
1805
+ 'postal-code': 'postalCode',
1806
+ 'street-address': 'fullStreetAddress',
1807
+ tel: 'telephoneNumber',
1808
+ url: 'URL',
1809
+ username: 'username',
1810
+ };
1811
+
1812
+ const ExportedForwardRef: component(
1813
+ ref: React.RefSetter<TextInputInstance>,
1814
+ ...props: React.ElementConfig<typeof InternalTextInput>
1815
+ ) = React.forwardRef(function TextInput(
1816
+ {
1817
+ allowFontScaling = true,
1818
+ rejectResponderTermination = true,
1819
+ underlineColorAndroid = 'transparent',
1820
+ autoComplete,
1821
+ textContentType,
1822
+ readOnly,
1823
+ editable,
1824
+ enterKeyHint,
1825
+ returnKeyType,
1826
+ inputMode,
1827
+ showSoftInputOnFocus,
1828
+ keyboardType,
1829
+ ...restProps
1830
+ },
1831
+ forwardedRef: React.RefSetter<TextInputInstance>,
1832
+ ) {
1833
+ return (
1834
+ <InternalTextInput
1835
+ allowFontScaling={allowFontScaling}
1836
+ rejectResponderTermination={rejectResponderTermination}
1837
+ underlineColorAndroid={underlineColorAndroid}
1838
+ editable={readOnly !== undefined ? !readOnly : editable}
1839
+ returnKeyType={
1840
+ enterKeyHint ? enterKeyHintToReturnTypeMap[enterKeyHint] : returnKeyType
1841
+ }
1842
+ keyboardType={
1843
+ inputMode ? inputModeToKeyboardTypeMap[inputMode] : keyboardType
1844
+ }
1845
+ showSoftInputOnFocus={
1846
+ inputMode == null ? showSoftInputOnFocus : inputMode !== 'none'
1847
+ }
1848
+ autoComplete={
1849
+ Platform.OS === 'android'
1850
+ ? // $FlowFixMe[invalid-computed-prop]
1851
+ // $FlowFixMe[prop-missing]
1852
+ autoCompleteWebToAutoCompleteAndroidMap[autoComplete] ??
1853
+ autoComplete
1854
+ : undefined
1855
+ }
1856
+ textContentType={
1857
+ textContentType != null
1858
+ ? textContentType
1859
+ : Platform.OS === 'ios' &&
1860
+ autoComplete &&
1861
+ autoComplete in autoCompleteWebToTextContentTypeMap
1862
+ ? // $FlowFixMe[invalid-computed-prop]
1863
+ // $FlowFixMe[prop-missing]
1864
+ autoCompleteWebToTextContentTypeMap[autoComplete]
1865
+ : textContentType
1866
+ }
1867
+ {...restProps}
1868
+ forwardedRef={forwardedRef}
1869
+ />
1870
+ );
1871
+ });
1872
+
1873
+ ExportedForwardRef.displayName = 'TextInput';
1874
+
1875
+ // $FlowFixMe[prop-missing]
1876
+ ExportedForwardRef.State = {
1877
+ currentlyFocusedInput: TextInputState.currentlyFocusedInput,
1878
+
1879
+ currentlyFocusedField: TextInputState.currentlyFocusedField,
1880
+ focusTextInput: TextInputState.focusTextInput,
1881
+ blurTextInput: TextInputState.blurTextInput,
1882
+ };
1883
+
1884
+ export type TextInputComponentStatics = $ReadOnly<{
1885
+ State: $ReadOnly<{
1886
+ currentlyFocusedInput: typeof TextInputState.currentlyFocusedInput,
1887
+ currentlyFocusedField: typeof TextInputState.currentlyFocusedField,
1888
+ focusTextInput: typeof TextInputState.focusTextInput,
1889
+ blurTextInput: typeof TextInputState.blurTextInput,
1890
+ }>,
1891
+ }>;
1892
+
1893
+ const styles = StyleSheet.create({
1894
+ multilineDefault: {
1895
+ // This default top inset makes RCTMultilineTextInputView seem as close as possible
1896
+ // to single-line RCTSinglelineTextInputView defaults, using the system defaults
1897
+ // of font size 17 and a height of 31 points.
1898
+ paddingTop: 5,
1899
+ },
1900
+ });
1901
+
1902
+ const verticalAlignToTextAlignVerticalMap = {
1903
+ auto: 'auto',
1904
+ top: 'top',
1905
+ bottom: 'bottom',
1906
+ middle: 'center',
1907
+ };
1908
+
1909
+ // $FlowFixMe[unclear-type] Unclear type. Using `any` type is not safe.
1910
+ export default ExportedForwardRef as any as TextInputType;