@react-native-oh/react-native-harmony 0.72.82 → 0.77.18

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