@onekeyfe/react-native-text-input 0.2.0

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 (101) 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/OneKeyTextInputManagerDelegate.java +25 -0
  5. package/android/generated/android/app/build/generated/source/codegen/java/com/facebook/react/viewmanagers/OneKeyTextInputManagerInterface.java +16 -0
  6. package/android/generated/android/app/build/generated/source/codegen/jni/CMakeLists.txt +49 -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 +67 -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/TextInputView.h +17 -0
  32. package/ios/TextInputView.mm +60 -0
  33. package/ios/TextInputViewManager.mm +23 -0
  34. package/ios/Utils.h +8 -0
  35. package/ios/Utils.m +26 -0
  36. package/ios/generated/build/generated/ios/FBReactNativeSpec/FBReactNativeSpec-generated.mm +1881 -0
  37. package/ios/generated/build/generated/ios/FBReactNativeSpec/FBReactNativeSpec.h +2321 -0
  38. package/ios/generated/build/generated/ios/FBReactNativeSpecJSI-generated.cpp +2785 -0
  39. package/ios/generated/build/generated/ios/FBReactNativeSpecJSI.h +7511 -0
  40. package/ios/generated/build/generated/ios/RCTModulesConformingToProtocolsProvider.h +18 -0
  41. package/ios/generated/build/generated/ios/RCTModulesConformingToProtocolsProvider.mm +33 -0
  42. package/ios/generated/build/generated/ios/RNTextInputViewSpec/RNTextInputViewSpec-generated.mm +16 -0
  43. package/ios/generated/build/generated/ios/RNTextInputViewSpec/RNTextInputViewSpec.h +35 -0
  44. package/ios/generated/build/generated/ios/RNTextInputViewSpecJSI-generated.cpp +17 -0
  45. package/ios/generated/build/generated/ios/RNTextInputViewSpecJSI.h +19 -0
  46. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/ComponentDescriptors.cpp +22 -0
  47. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/ComponentDescriptors.h +24 -0
  48. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/EventEmitters.cpp +24 -0
  49. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/EventEmitters.h +25 -0
  50. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/Props.cpp +25 -0
  51. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/Props.h +27 -0
  52. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/RCTComponentViewHelpers.h +20 -0
  53. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/ShadowNodes.cpp +17 -0
  54. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/ShadowNodes.h +32 -0
  55. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/States.cpp +16 -0
  56. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/States.h +29 -0
  57. package/lib/commonjs/Input.js +670 -0
  58. package/lib/commonjs/Input.js.map +1 -0
  59. package/lib/commonjs/TextInputViewNativeComponent.js +10 -0
  60. package/lib/commonjs/TextInputViewNativeComponent.js.map +1 -0
  61. package/lib/commonjs/enum.js +11 -0
  62. package/lib/commonjs/enum.js.map +1 -0
  63. package/lib/commonjs/index.js +38 -0
  64. package/lib/commonjs/index.js.map +1 -0
  65. package/lib/commonjs/type.js +6 -0
  66. package/lib/commonjs/type.js.map +1 -0
  67. package/lib/module/Input.js +667 -0
  68. package/lib/module/Input.js.map +1 -0
  69. package/lib/module/TextInputViewNativeComponent.js +5 -0
  70. package/lib/module/TextInputViewNativeComponent.js.map +1 -0
  71. package/lib/module/enum.js +7 -0
  72. package/lib/module/enum.js.map +1 -0
  73. package/lib/module/index.js +9 -0
  74. package/lib/module/index.js.map +1 -0
  75. package/lib/module/type.js +4 -0
  76. package/lib/module/type.js.map +1 -0
  77. package/lib/typescript/commonjs/package.json +1 -0
  78. package/lib/typescript/commonjs/src/TextInputViewNativeComponent.d.ts +8 -0
  79. package/lib/typescript/commonjs/src/TextInputViewNativeComponent.d.ts.map +1 -0
  80. package/lib/typescript/commonjs/src/enum.d.ts +4 -0
  81. package/lib/typescript/commonjs/src/enum.d.ts.map +1 -0
  82. package/lib/typescript/commonjs/src/index.d.ts +8 -0
  83. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  84. package/lib/typescript/commonjs/src/type.d.ts +16 -0
  85. package/lib/typescript/commonjs/src/type.d.ts.map +1 -0
  86. package/lib/typescript/module/package.json +1 -0
  87. package/lib/typescript/module/src/TextInputViewNativeComponent.d.ts +8 -0
  88. package/lib/typescript/module/src/TextInputViewNativeComponent.d.ts.map +1 -0
  89. package/lib/typescript/module/src/enum.d.ts +4 -0
  90. package/lib/typescript/module/src/enum.d.ts.map +1 -0
  91. package/lib/typescript/module/src/index.d.ts +8 -0
  92. package/lib/typescript/module/src/index.d.ts.map +1 -0
  93. package/lib/typescript/module/src/type.d.ts +16 -0
  94. package/lib/typescript/module/src/type.d.ts.map +1 -0
  95. package/package.json +200 -0
  96. package/react-native-text-input.podspec +42 -0
  97. package/src/Input.js +1739 -0
  98. package/src/TextInputViewNativeComponent.ts +9 -0
  99. package/src/enum.ts +3 -0
  100. package/src/index.tsx +17 -0
  101. package/src/type.ts +13 -0
@@ -0,0 +1,670 @@
1
+ "use strict";
2
+
3
+ var _usePressability = _interopRequireDefault(require("react-native/Libraries/Pressability/usePressability"));
4
+ var _flattenStyle = _interopRequireDefault(require("react-native/Libraries/StyleSheet/flattenStyle"));
5
+ var _StyleSheet = _interopRequireDefault(require("react-native/Libraries/StyleSheet/StyleSheet"));
6
+ var _Text = _interopRequireDefault(require("react-native/Libraries/Text/Text"));
7
+ var _TextAncestor = _interopRequireDefault(require("react-native/Libraries/Text/TextAncestor"));
8
+ var _Platform = _interopRequireDefault(require("react-native/Libraries/Utilities/Platform"));
9
+ var _useMergeRefs = _interopRequireDefault(require("react-native/Libraries/Utilities/useMergeRefs"));
10
+ var _TextInputState = _interopRequireDefault(require("react-native/Libraries/Components/TextInput/TextInputState"));
11
+ var _invariant = _interopRequireDefault(require("invariant"));
12
+ var _nullthrows = _interopRequireDefault(require("nullthrows"));
13
+ var _react = _interopRequireWildcard(require("react"));
14
+ var React = _react;
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
+ /* eslint-disable prettier/prettier */
20
+
21
+ /**
22
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
23
+ *
24
+ * This source code is licensed under the MIT license found in the
25
+ * LICENSE file in the root directory of this source tree.
26
+ *
27
+ *
28
+ * @format
29
+ */
30
+
31
+ let AndroidTextInput;
32
+ let AndroidTextInputCommands;
33
+ let RCTSinglelineTextInputView;
34
+ let RCTSinglelineTextInputNativeCommands;
35
+ let RCTMultilineTextInputView;
36
+ let RCTMultilineTextInputNativeCommands;
37
+ if (_Platform.default.OS === 'android') {
38
+ AndroidTextInput = require('./TextInputViewNativeComponent').default;
39
+ AndroidTextInputCommands = require('react-native/Libraries/Components/TextInput/AndroidTextInputNativeComponent').Commands;
40
+ } else if (_Platform.default.OS === 'ios') {
41
+ RCTSinglelineTextInputView = require('react-native/Libraries/Components/TextInput/RCTSingelineTextInputNativeComponent').default;
42
+ RCTSinglelineTextInputNativeCommands = require('react-native/Libraries/Components/TextInput/RCTSingelineTextInputNativeComponent').Commands;
43
+ RCTMultilineTextInputView = require('react-native/Libraries/Components/TextInput/RCTMultilineTextInputNativeComponent').default;
44
+ RCTMultilineTextInputNativeCommands = require('react-native/Libraries/Components/TextInput/RCTMultilineTextInputNativeComponent').Commands;
45
+ }
46
+ const emptyFunctionThatReturnsTrue = () => true;
47
+
48
+ /**
49
+ * A foundational component for inputting text into the app via a
50
+ * keyboard. Props provide configurability for several features, such as
51
+ * auto-correction, auto-capitalization, placeholder text, and different keyboard
52
+ * types, such as a numeric keypad.
53
+ *
54
+ * The simplest use case is to plop down a `TextInput` and subscribe to the
55
+ * `onChangeText` events to read the user input. There are also other events,
56
+ * such as `onSubmitEditing` and `onFocus` that can be subscribed to. A simple
57
+ * example:
58
+ *
59
+ * ```ReactNativeWebPlayer
60
+ * import React, { Component } from 'react';
61
+ * import { AppRegistry, TextInput } from 'react-native';
62
+ *
63
+ * export default class UselessTextInput extends Component {
64
+ * constructor(props) {
65
+ * super(props);
66
+ * this.state = { text: 'Useless Placeholder' };
67
+ * }
68
+ *
69
+ * render() {
70
+ * return (
71
+ * <TextInput
72
+ * style={{height: 40, borderColor: 'gray', borderWidth: 1}}
73
+ * onChangeText={(text) => this.setState({text})}
74
+ * value={this.state.text}
75
+ * />
76
+ * );
77
+ * }
78
+ * }
79
+ *
80
+ * // skip this line if using Create React Native App
81
+ * AppRegistry.registerComponent('AwesomeProject', () => UselessTextInput);
82
+ * ```
83
+ *
84
+ * Two methods exposed via the native element are .focus() and .blur() that
85
+ * will focus or blur the TextInput programmatically.
86
+ *
87
+ * Note that some props are only available with `multiline={true/false}`.
88
+ * Additionally, border styles that apply to only one side of the element
89
+ * (e.g., `borderBottomColor`, `borderLeftWidth`, etc.) will not be applied if
90
+ * `multiline=false`. To achieve the same effect, you can wrap your `TextInput`
91
+ * in a `View`:
92
+ *
93
+ * ```ReactNativeWebPlayer
94
+ * import React, { Component } from 'react';
95
+ * import { AppRegistry, View, TextInput } from 'react-native';
96
+ *
97
+ * class UselessTextInput extends Component {
98
+ * render() {
99
+ * return (
100
+ * <TextInput
101
+ * {...this.props} // Inherit any props passed to it; e.g., multiline, numberOfLines below
102
+ * editable={true}
103
+ * maxLength={40}
104
+ * />
105
+ * );
106
+ * }
107
+ * }
108
+ *
109
+ * export default class UselessTextInputMultiline extends Component {
110
+ * constructor(props) {
111
+ * super(props);
112
+ * this.state = {
113
+ * text: 'Useless Multiline Placeholder',
114
+ * };
115
+ * }
116
+ *
117
+ * // If you type something in the text box that is a color, the background will change to that
118
+ * // color.
119
+ * render() {
120
+ * return (
121
+ * <View style={{
122
+ * backgroundColor: this.state.text,
123
+ * borderBottomColor: '#000000',
124
+ * borderBottomWidth: 1 }}
125
+ * >
126
+ * <UselessTextInput
127
+ * multiline={true}
128
+ * numberOfLines={4}
129
+ * onChangeText={(text) => this.setState({text})}
130
+ * value={this.state.text}
131
+ * />
132
+ * </View>
133
+ * );
134
+ * }
135
+ * }
136
+ *
137
+ * // skip these lines if using Create React Native App
138
+ * AppRegistry.registerComponent(
139
+ * 'AwesomeProject',
140
+ * () => UselessTextInputMultiline
141
+ * );
142
+ * ```
143
+ *
144
+ * `TextInput` has by default a border at the bottom of its view. This border
145
+ * has its padding set by the background image provided by the system, and it
146
+ * cannot be changed. Solutions to avoid this is to either not set height
147
+ * explicitly, case in which the system will take care of displaying the border
148
+ * in the correct position, or to not display the border by setting
149
+ * `underlineColorAndroid` to transparent.
150
+ *
151
+ * Note that on Android performing text selection in input can change
152
+ * app's activity `windowSoftInputMode` param to `adjustResize`.
153
+ * This may cause issues with components that have position: 'absolute'
154
+ * while keyboard is active. To avoid this behavior either specify `windowSoftInputMode`
155
+ * in AndroidManifest.xml ( https://developer.android.com/guide/topics/manifest/activity-element.html )
156
+ * or control this param programmatically with native code.
157
+ *
158
+ */
159
+ function InternalTextInput(props) {
160
+ const {
161
+ 'aria-busy': ariaBusy,
162
+ 'aria-checked': ariaChecked,
163
+ 'aria-disabled': ariaDisabled,
164
+ 'aria-expanded': ariaExpanded,
165
+ 'aria-selected': ariaSelected,
166
+ accessibilityState,
167
+ id,
168
+ tabIndex,
169
+ selection: propsSelection,
170
+ selectionColor,
171
+ selectionHandleColor,
172
+ cursorColor,
173
+ ...otherProps
174
+ } = props;
175
+ const inputRef = (0, _react.useRef)(null);
176
+
177
+ // eslint-disable-next-line react-hooks/exhaustive-deps
178
+ const selection = propsSelection == null ? null : {
179
+ start: propsSelection.start,
180
+ end: propsSelection.end ?? propsSelection.start
181
+ };
182
+ const [mostRecentEventCount, setMostRecentEventCount] = (0, _react.useState)(0);
183
+ const [lastNativeText, setLastNativeText] = (0, _react.useState)(props.value);
184
+ const [lastNativeSelectionState, setLastNativeSelection] = (0, _react.useState)({
185
+ selection: {
186
+ start: -1,
187
+ end: -1
188
+ },
189
+ mostRecentEventCount: mostRecentEventCount
190
+ });
191
+ const lastNativeSelection = lastNativeSelectionState.selection;
192
+ let viewCommands;
193
+ if (AndroidTextInputCommands) {
194
+ viewCommands = AndroidTextInputCommands;
195
+ } else {
196
+ viewCommands = props.multiline === true ? RCTMultilineTextInputNativeCommands : RCTSinglelineTextInputNativeCommands;
197
+ }
198
+ const text = typeof props.value === 'string' ? props.value : typeof props.defaultValue === 'string' ? props.defaultValue : '';
199
+
200
+ // This is necessary in case native updates the text and JS decides
201
+ // that the update should be ignored and we should stick with the value
202
+ // that we have in JS.
203
+ (0, _react.useLayoutEffect)(() => {
204
+ const nativeUpdate = {};
205
+ if (lastNativeText !== props.value && typeof props.value === 'string') {
206
+ nativeUpdate.text = props.value;
207
+ setLastNativeText(props.value);
208
+ }
209
+ if (selection && lastNativeSelection && (lastNativeSelection.start !== selection.start || lastNativeSelection.end !== selection.end)) {
210
+ nativeUpdate.selection = selection;
211
+ setLastNativeSelection({
212
+ selection,
213
+ mostRecentEventCount
214
+ });
215
+ }
216
+ if (Object.keys(nativeUpdate).length === 0) {
217
+ return;
218
+ }
219
+ if (inputRef.current != null) {
220
+ viewCommands.setTextAndSelection(inputRef.current, mostRecentEventCount, text, selection?.start ?? -1, selection?.end ?? -1);
221
+ }
222
+ }, [mostRecentEventCount, inputRef, props.value, props.defaultValue, lastNativeText, selection, lastNativeSelection, text, viewCommands]);
223
+ (0, _react.useLayoutEffect)(() => {
224
+ const inputRefValue = inputRef.current;
225
+ if (inputRefValue != null) {
226
+ _TextInputState.default.registerInput(inputRefValue);
227
+ return () => {
228
+ _TextInputState.default.unregisterInput(inputRefValue);
229
+ if (_TextInputState.default.currentlyFocusedInput() === inputRefValue) {
230
+ (0, _nullthrows.default)(inputRefValue).blur();
231
+ }
232
+ };
233
+ }
234
+ }, [inputRef]);
235
+ const setLocalRef = (0, _react.useCallback)(instance => {
236
+ inputRef.current = instance;
237
+
238
+ /*
239
+ Hi reader from the future. I'm sorry for this.
240
+ This is a hack. Ideally we would forwardRef to the underlying
241
+ host component. However, since TextInput has it's own methods that can be
242
+ called as well, if we used the standard forwardRef then these
243
+ methods wouldn't be accessible and thus be a breaking change.
244
+ We have a couple of options of how to handle this:
245
+ - Return a new ref with everything we methods from both. This is problematic
246
+ because we need React to also know it is a host component which requires
247
+ internals of the class implementation of the ref.
248
+ - Break the API and have some other way to call one set of the methods or
249
+ the other. This is our long term approach as we want to eventually
250
+ get the methods on host components off the ref. So instead of calling
251
+ ref.measure() you might call ReactNative.measure(ref). This would hopefully
252
+ let the ref for TextInput then have the methods like `.clear`. Or we do it
253
+ the other way and make it TextInput.clear(textInputRef) which would be fine
254
+ too. Either way though is a breaking change that is longer term.
255
+ - Mutate this ref. :( Gross, but accomplishes what we need in the meantime
256
+ before we can get to the long term breaking change.
257
+ */
258
+ if (instance != null) {
259
+ // $FlowFixMe[incompatible-use] - See the explanation above.
260
+ Object.assign(instance, {
261
+ clear() {
262
+ if (inputRef.current != null) {
263
+ viewCommands.setTextAndSelection(inputRef.current, mostRecentEventCount, '', 0, 0);
264
+ }
265
+ },
266
+ // TODO: Fix this returning true on null === null, when no input is focused
267
+ isFocused() {
268
+ return _TextInputState.default.currentlyFocusedInput() === inputRef.current;
269
+ },
270
+ getNativeRef() {
271
+ return inputRef.current;
272
+ },
273
+ setSelection(start, end) {
274
+ if (inputRef.current != null) {
275
+ viewCommands.setTextAndSelection(inputRef.current, mostRecentEventCount, null, start, end);
276
+ }
277
+ }
278
+ });
279
+ }
280
+ }, [mostRecentEventCount, viewCommands]);
281
+ const ref = (0, _useMergeRefs.default)(setLocalRef, props.forwardedRef);
282
+ const _onChange = event => {
283
+ const currentText = event.nativeEvent.text;
284
+ props.onChange && props.onChange(event);
285
+ props.onChangeText && props.onChangeText(currentText);
286
+ if (inputRef.current == null) {
287
+ // calling `props.onChange` or `props.onChangeText`
288
+ // may clean up the input itself. Exits here.
289
+ return;
290
+ }
291
+ setLastNativeText(currentText);
292
+ // This must happen last, after we call setLastNativeText.
293
+ // Different ordering can cause bugs when editing AndroidTextInputs
294
+ // with multiple Fragments.
295
+ // We must update this so that controlled input updates work.
296
+ setMostRecentEventCount(event.nativeEvent.eventCount);
297
+ };
298
+ const _onSelectionChange = event => {
299
+ props.onSelectionChange && props.onSelectionChange(event);
300
+ if (inputRef.current == null) {
301
+ // calling `props.onSelectionChange`
302
+ // may clean up the input itself. Exits here.
303
+ return;
304
+ }
305
+ setLastNativeSelection({
306
+ selection: event.nativeEvent.selection,
307
+ mostRecentEventCount
308
+ });
309
+ };
310
+ const _onFocus = event => {
311
+ _TextInputState.default.focusInput(inputRef.current);
312
+ if (props.onFocus) {
313
+ props.onFocus(event);
314
+ }
315
+ };
316
+ const _onBlur = event => {
317
+ _TextInputState.default.blurInput(inputRef.current);
318
+ if (props.onBlur) {
319
+ props.onBlur(event);
320
+ }
321
+ };
322
+ const _onScroll = event => {
323
+ props.onScroll && props.onScroll(event);
324
+ };
325
+ let textInput = null;
326
+ const multiline = props.multiline ?? false;
327
+ let submitBehavior;
328
+ if (props.submitBehavior != null) {
329
+ // `submitBehavior` is set explicitly
330
+ if (!multiline && props.submitBehavior === 'newline') {
331
+ // For single line text inputs, `'newline'` is not a valid option
332
+ submitBehavior = 'blurAndSubmit';
333
+ } else {
334
+ submitBehavior = props.submitBehavior;
335
+ }
336
+ } else if (multiline) {
337
+ if (props.blurOnSubmit === true) {
338
+ submitBehavior = 'blurAndSubmit';
339
+ } else {
340
+ submitBehavior = 'newline';
341
+ }
342
+ } else {
343
+ // Single line
344
+ if (props.blurOnSubmit !== false) {
345
+ submitBehavior = 'blurAndSubmit';
346
+ } else {
347
+ submitBehavior = 'submit';
348
+ }
349
+ }
350
+ const accessible = props.accessible !== false;
351
+ const focusable = props.focusable !== false;
352
+ const {
353
+ editable,
354
+ hitSlop,
355
+ onPress,
356
+ onPressIn,
357
+ onPressOut,
358
+ rejectResponderTermination
359
+ } = props;
360
+ const config = React.useMemo(() => ({
361
+ hitSlop,
362
+ onPress: event => {
363
+ onPress?.(event);
364
+ if (editable !== false) {
365
+ if (inputRef.current != null) {
366
+ inputRef.current.focus();
367
+ }
368
+ }
369
+ },
370
+ onPressIn: onPressIn,
371
+ onPressOut: onPressOut,
372
+ cancelable: _Platform.default.OS === 'ios' ? !rejectResponderTermination : null
373
+ }), [editable, hitSlop, onPress, onPressIn, onPressOut, rejectResponderTermination]);
374
+
375
+ // Hide caret during test runs due to a flashing caret
376
+ // makes screenshot tests flakey
377
+ let caretHidden = props.caretHidden;
378
+ if (_Platform.default.isTesting) {
379
+ caretHidden = true;
380
+ }
381
+
382
+ // TextInput handles onBlur and onFocus events
383
+ // so omitting onBlur and onFocus pressability handlers here.
384
+ const {
385
+ onBlur,
386
+ onFocus,
387
+ ...eventHandlers
388
+ } = (0, _usePressability.default)(config) || {};
389
+ let _accessibilityState;
390
+ if (accessibilityState != null || ariaBusy != null || ariaChecked != null || ariaDisabled != null || ariaExpanded != null || ariaSelected != null) {
391
+ _accessibilityState = {
392
+ busy: ariaBusy ?? accessibilityState?.busy,
393
+ checked: ariaChecked ?? accessibilityState?.checked,
394
+ disabled: ariaDisabled ?? accessibilityState?.disabled,
395
+ expanded: ariaExpanded ?? accessibilityState?.expanded,
396
+ selected: ariaSelected ?? accessibilityState?.selected
397
+ };
398
+ }
399
+ const style = (0, _flattenStyle.default)(props.style);
400
+ if (typeof style?.fontWeight === 'number') {
401
+ // $FlowFixMe[prop-missing]
402
+ // $FlowFixMe[cannot-write]
403
+ style.fontWeight = style?.fontWeight.toString();
404
+ }
405
+ if (_Platform.default.OS === 'ios') {
406
+ const RCTTextInputView = props.multiline === true ? RCTMultilineTextInputView : RCTSinglelineTextInputView;
407
+ const useMultilineDefaultStyle = props.multiline === true && (style == null || style.padding == null && style.paddingVertical == null && style.paddingTop == null);
408
+ textInput = /*#__PURE__*/(0, _jsxRuntime.jsx)(RCTTextInputView
409
+ // $FlowFixMe[incompatible-type] - Figure out imperative + forward refs.
410
+ , {
411
+ ref: ref,
412
+ ...otherProps,
413
+ ...eventHandlers,
414
+ accessibilityState: _accessibilityState,
415
+ accessible: accessible,
416
+ submitBehavior: submitBehavior,
417
+ caretHidden: caretHidden,
418
+ dataDetectorTypes: props.dataDetectorTypes,
419
+ focusable: tabIndex !== undefined ? !tabIndex : focusable,
420
+ mostRecentEventCount: mostRecentEventCount,
421
+ nativeID: id ?? props.nativeID,
422
+ onBlur: _onBlur,
423
+ onChange: _onChange,
424
+ onContentSizeChange: props.onContentSizeChange,
425
+ onFocus: _onFocus,
426
+ onScroll: _onScroll,
427
+ onSelectionChange: _onSelectionChange,
428
+ onSelectionChangeShouldSetResponder: emptyFunctionThatReturnsTrue,
429
+ selection: selection,
430
+ selectionColor: selectionColor,
431
+ style: _StyleSheet.default.compose(useMultilineDefaultStyle ? styles.multilineDefault : null, style),
432
+ text: text
433
+ });
434
+ } else if (_Platform.default.OS === 'android') {
435
+ const autoCapitalize = props.autoCapitalize || 'sentences';
436
+ const _accessibilityLabelledBy = props?.['aria-labelledby'] ?? props?.accessibilityLabelledBy;
437
+ const placeholder = props.placeholder ?? '';
438
+ let children = props.children;
439
+ const childCount = React.Children.count(children);
440
+ (0, _invariant.default)(!(props.value != null && childCount), 'Cannot specify both value and children.');
441
+ if (childCount > 1) {
442
+ children = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.default, {
443
+ children: children
444
+ });
445
+ }
446
+ // For consistency with iOS set cursor/selectionHandle color as selectionColor
447
+ const colorProps = {
448
+ selectionColor,
449
+ selectionHandleColor: selectionHandleColor === undefined ? selectionColor : selectionHandleColor,
450
+ cursorColor: cursorColor === undefined ? selectionColor : cursorColor
451
+ };
452
+ textInput =
453
+ /*#__PURE__*/
454
+ /* $FlowFixMe[prop-missing] the types for AndroidTextInput don't match up
455
+ * exactly with the props for TextInput. This will need to get fixed */
456
+ /* $FlowFixMe[incompatible-type] the types for AndroidTextInput don't
457
+ * match up exactly with the props for TextInput. This will need to get
458
+ * fixed */
459
+ /* $FlowFixMe[incompatible-type-arg] the types for AndroidTextInput don't
460
+ * match up exactly with the props for TextInput. This will need to get
461
+ * fixed */
462
+ (0, _jsxRuntime.jsx)(AndroidTextInput
463
+ // $FlowFixMe[incompatible-type] - Figure out imperative + forward refs.
464
+ , {
465
+ ref: ref,
466
+ ...otherProps,
467
+ ...colorProps,
468
+ ...eventHandlers,
469
+ accessibilityState: _accessibilityState,
470
+ accessibilityLabelledBy: _accessibilityLabelledBy,
471
+ accessible: accessible,
472
+ autoCapitalize: autoCapitalize,
473
+ submitBehavior: submitBehavior,
474
+ caretHidden: caretHidden,
475
+ children: children,
476
+ disableFullscreenUI: props.disableFullscreenUI,
477
+ focusable: tabIndex !== undefined ? !tabIndex : focusable,
478
+ mostRecentEventCount: mostRecentEventCount,
479
+ nativeID: id ?? props.nativeID,
480
+ numberOfLines: props.rows ?? props.numberOfLines,
481
+ onBlur: _onBlur,
482
+ onChange: _onChange,
483
+ onFocus: _onFocus
484
+ /* $FlowFixMe[prop-missing] the types for AndroidTextInput don't match
485
+ * up exactly with the props for TextInput. This will need to get fixed
486
+ */
487
+ /* $FlowFixMe[incompatible-type-arg] the types for AndroidTextInput
488
+ * don't match up exactly with the props for TextInput. This will need
489
+ * to get fixed */,
490
+ onScroll: _onScroll,
491
+ onSelectionChange: _onSelectionChange,
492
+ placeholder: placeholder,
493
+ style: style,
494
+ text: text,
495
+ textBreakStrategy: props.textBreakStrategy
496
+ });
497
+ }
498
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextAncestor.default.Provider, {
499
+ value: true,
500
+ children: textInput
501
+ });
502
+ }
503
+ const enterKeyHintToReturnTypeMap = {
504
+ enter: 'default',
505
+ done: 'done',
506
+ go: 'go',
507
+ next: 'next',
508
+ previous: 'previous',
509
+ search: 'search',
510
+ send: 'send'
511
+ };
512
+ const inputModeToKeyboardTypeMap = {
513
+ none: 'default',
514
+ text: 'default',
515
+ decimal: 'decimal-pad',
516
+ numeric: 'number-pad',
517
+ tel: 'phone-pad',
518
+ search: _Platform.default.OS === 'ios' ? 'web-search' : 'default',
519
+ email: 'email-address',
520
+ url: 'url'
521
+ };
522
+
523
+ // Map HTML autocomplete values to Android autoComplete values
524
+ const autoCompleteWebToAutoCompleteAndroidMap = {
525
+ 'address-line1': 'postal-address-region',
526
+ 'address-line2': 'postal-address-locality',
527
+ bday: 'birthdate-full',
528
+ 'bday-day': 'birthdate-day',
529
+ 'bday-month': 'birthdate-month',
530
+ 'bday-year': 'birthdate-year',
531
+ 'cc-csc': 'cc-csc',
532
+ 'cc-exp': 'cc-exp',
533
+ 'cc-exp-month': 'cc-exp-month',
534
+ 'cc-exp-year': 'cc-exp-year',
535
+ 'cc-number': 'cc-number',
536
+ country: 'postal-address-country',
537
+ 'current-password': 'password',
538
+ email: 'email',
539
+ 'honorific-prefix': 'name-prefix',
540
+ 'honorific-suffix': 'name-suffix',
541
+ name: 'name',
542
+ 'additional-name': 'name-middle',
543
+ 'family-name': 'name-family',
544
+ 'given-name': 'name-given',
545
+ 'new-password': 'password-new',
546
+ off: 'off',
547
+ 'one-time-code': 'sms-otp',
548
+ 'postal-code': 'postal-code',
549
+ sex: 'gender',
550
+ 'street-address': 'street-address',
551
+ tel: 'tel',
552
+ 'tel-country-code': 'tel-country-code',
553
+ 'tel-national': 'tel-national',
554
+ username: 'username'
555
+ };
556
+
557
+ // Map HTML autocomplete values to iOS textContentType values
558
+ const autoCompleteWebToTextContentTypeMap = {
559
+ 'address-line1': 'streetAddressLine1',
560
+ 'address-line2': 'streetAddressLine2',
561
+ bday: 'birthdate',
562
+ 'bday-day': 'birthdateDay',
563
+ 'bday-month': 'birthdateMonth',
564
+ 'bday-year': 'birthdateYear',
565
+ 'cc-csc': 'creditCardSecurityCode',
566
+ 'cc-exp-month': 'creditCardExpirationMonth',
567
+ 'cc-exp-year': 'creditCardExpirationYear',
568
+ 'cc-exp': 'creditCardExpiration',
569
+ 'cc-given-name': 'creditCardGivenName',
570
+ 'cc-additional-name': 'creditCardMiddleName',
571
+ 'cc-family-name': 'creditCardFamilyName',
572
+ 'cc-name': 'creditCardName',
573
+ 'cc-number': 'creditCardNumber',
574
+ 'cc-type': 'creditCardType',
575
+ 'current-password': 'password',
576
+ country: 'countryName',
577
+ email: 'emailAddress',
578
+ name: 'name',
579
+ 'additional-name': 'middleName',
580
+ 'family-name': 'familyName',
581
+ 'given-name': 'givenName',
582
+ nickname: 'nickname',
583
+ 'honorific-prefix': 'namePrefix',
584
+ 'honorific-suffix': 'nameSuffix',
585
+ 'new-password': 'newPassword',
586
+ off: 'none',
587
+ 'one-time-code': 'oneTimeCode',
588
+ organization: 'organizationName',
589
+ 'organization-title': 'jobTitle',
590
+ 'postal-code': 'postalCode',
591
+ 'street-address': 'fullStreetAddress',
592
+ tel: 'telephoneNumber',
593
+ url: 'URL',
594
+ username: 'username'
595
+ };
596
+ const ExportedForwardRef = /*#__PURE__*/React.forwardRef(function TextInput({
597
+ allowFontScaling = true,
598
+ rejectResponderTermination = true,
599
+ underlineColorAndroid = 'transparent',
600
+ autoComplete,
601
+ textContentType,
602
+ readOnly,
603
+ editable,
604
+ enterKeyHint,
605
+ returnKeyType,
606
+ inputMode,
607
+ showSoftInputOnFocus,
608
+ keyboardType,
609
+ ...restProps
610
+ }, forwardedRef) {
611
+ // $FlowFixMe[underconstrained-implicit-instantiation]
612
+ let style = (0, _flattenStyle.default)(restProps.style);
613
+ if (style?.verticalAlign != null) {
614
+ // $FlowFixMe[prop-missing]
615
+ // $FlowFixMe[cannot-write]
616
+ style.textAlignVertical =
617
+ // $FlowFixMe[invalid-computed-prop]
618
+ verticalAlignToTextAlignVerticalMap[style.verticalAlign];
619
+ // $FlowFixMe[prop-missing]
620
+ // $FlowFixMe[cannot-write]
621
+ delete style.verticalAlign;
622
+ }
623
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(InternalTextInput, {
624
+ allowFontScaling: allowFontScaling,
625
+ rejectResponderTermination: rejectResponderTermination,
626
+ underlineColorAndroid: underlineColorAndroid,
627
+ editable: readOnly !== undefined ? !readOnly : editable,
628
+ returnKeyType: enterKeyHint ? enterKeyHintToReturnTypeMap[enterKeyHint] : returnKeyType,
629
+ keyboardType: inputMode ? inputModeToKeyboardTypeMap[inputMode] : keyboardType,
630
+ showSoftInputOnFocus: inputMode == null ? showSoftInputOnFocus : inputMode !== 'none',
631
+ autoComplete: _Platform.default.OS === 'android' ?
632
+ // $FlowFixMe[invalid-computed-prop]
633
+ // $FlowFixMe[prop-missing]
634
+ autoCompleteWebToAutoCompleteAndroidMap[autoComplete] ?? autoComplete : undefined,
635
+ textContentType: textContentType != null ? textContentType : _Platform.default.OS === 'ios' && autoComplete && autoComplete in autoCompleteWebToTextContentTypeMap ?
636
+ // $FlowFixMe[invalid-computed-prop]
637
+ // $FlowFixMe[prop-missing]
638
+ autoCompleteWebToTextContentTypeMap[autoComplete] : textContentType,
639
+ ...restProps,
640
+ forwardedRef: forwardedRef,
641
+ style: style
642
+ });
643
+ });
644
+ ExportedForwardRef.displayName = 'TextInput';
645
+
646
+ // $FlowFixMe[prop-missing]
647
+ ExportedForwardRef.State = {
648
+ currentlyFocusedInput: _TextInputState.default.currentlyFocusedInput,
649
+ currentlyFocusedField: _TextInputState.default.currentlyFocusedField,
650
+ focusTextInput: _TextInputState.default.focusTextInput,
651
+ blurTextInput: _TextInputState.default.blurTextInput
652
+ };
653
+ const styles = _StyleSheet.default.create({
654
+ multilineDefault: {
655
+ // This default top inset makes RCTMultilineTextInputView seem as close as possible
656
+ // to single-line RCTSinglelineTextInputView defaults, using the system defaults
657
+ // of font size 17 and a height of 31 points.
658
+ paddingTop: 5
659
+ }
660
+ });
661
+ const verticalAlignToTextAlignVerticalMap = {
662
+ auto: 'auto',
663
+ top: 'top',
664
+ bottom: 'bottom',
665
+ middle: 'center'
666
+ };
667
+
668
+ // $FlowFixMe[unclear-type] Unclear type. Using `any` type is not safe.
669
+ module.exports = ExportedForwardRef;
670
+ //# sourceMappingURL=Input.js.map