react-native-nitro-input 0.3.2 → 0.3.3

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 (30) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +45 -0
  3. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +25 -4
  4. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +170 -2
  5. package/android/src/main/java/com/margelo/nitro/nitroinput/UnmountHandoffs.kt +57 -0
  6. package/ios/HybridNitroInputView.swift +19 -4
  7. package/ios/NitroInputCommands.mm +10 -0
  8. package/ios/NitroInputView.swift +349 -13
  9. package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +2 -0
  10. package/lib/commonjs/src/NitroInput.js +103 -15
  11. package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +2 -0
  12. package/lib/module/src/NitroInput.js +104 -16
  13. package/lib/typescript/src/NitroInput.d.ts +16 -0
  14. package/lib/typescript/src/specs/NitroInput.nitro.d.ts +22 -0
  15. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +22 -0
  16. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +5 -0
  17. package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +10 -0
  18. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +16 -0
  19. package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +18 -0
  20. package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +12 -0
  21. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +3 -0
  22. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +33 -0
  23. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +5 -0
  24. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +5 -0
  25. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +4 -0
  26. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +6 -0
  27. package/nitrogen/generated/shared/json/NitroInputViewConfig.json +2 -0
  28. package/package.json +1 -1
  29. package/src/NitroInput.tsx +117 -11
  30. package/src/specs/NitroInput.nitro.ts +22 -0
@@ -107,6 +107,20 @@ const EMPTY_STRINGS = [];
107
107
  const EMPTY_MAPPINGS = [];
108
108
  /** Mounted fields, by the host instance React Native's registry stores. */
109
109
  const mountedFields = new WeakMap();
110
+ /** The same fields, iterable: `Keyboard.dismiss()` with nothing focused reaches one through it. */
111
+ const liveFields = new Set();
112
+ /**
113
+ * The last field that handed the keyboard off as it unmounted, kept until its
114
+ * hold is over: a screen may have no field left (a tap-only question) when it
115
+ * calls `Keyboard.dismiss()`, and the hold is released through a native blur.
116
+ */
117
+ let lastHandoff = null;
118
+ /**
119
+ * Which field a native view currently belongs to. A view can change hands:
120
+ * on iOS a hidden <Activity>'s views go back to the pool and another field
121
+ * may be given one; on Android they are kept for the same field.
122
+ */
123
+ const viewOwner = new WeakMap();
110
124
  let patchedRegistry = false;
111
125
  /**
112
126
  * `TextInputState.focusTextInput` / `blurTextInput` — which is how
@@ -144,7 +158,13 @@ function patchRegistryOnce() {
144
158
  const field = input != null ? mountedFields.get(input) : undefined;
145
159
  if (field)
146
160
  return field.blur();
147
- return originalBlur.call(registry, input);
161
+ const result = originalBlur.call(registry, input);
162
+ // `Keyboard.dismiss()` with no input focused: a field that just left the
163
+ // screen may still be holding the keyboard for the next one
164
+ // (`keyboardHandoffMs`). A native blur on any field lets that go.
165
+ if (input == null)
166
+ (liveFields.values().next().value ?? lastHandoff)?.blur();
167
+ return result;
148
168
  };
149
169
  }
150
170
  }
@@ -178,8 +198,28 @@ function warnIncompatible(what) {
178
198
  * Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
179
199
  * it to its content instead, and is on by default when the text reflows.
180
200
  */
181
- exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, format, placeholder, placeholderTextColor, duration, easing, bounce, effect, fontSize, lineHeight, fontWeight, fontFamily, color, textAlign, cursorColor, selectionColor, caretHidden, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, variant, label, labelBehavior, labelColor, labelFocusedColor, labelFontSize, strokeColor, focusedStrokeColor, strokeWidth, cornerRadius, fillColor, keyboardType, inputMode, enterKeyHint, mask, maskNotations, maskAutocomplete, maskAutoSkip, maskAffinityFormats, maskAffinityStrategy, maskTextCase, maskCharacterMap, maskSlotPlaceholder, keepPlaceholder, returnKeyType, autoCapitalize, autoCorrect, editable, multiline, numberOfLines, rows, textAlignVertical, scrollEnabled, autoFocus, transition, autoWidth: autoWidthProp, submitBehavior, blurOnSubmit, secureTextEntry, keyboardAppearance, textContentType, autoComplete, enablesReturnKeyAutomatically, showSoftInputOnFocus, selectTextOnFocus, clearTextOnFocus, contextMenuHidden, spellCheck, readOnly, selection, onEndEditing, onSelectionChange, onKeyPress, maxLength, transform, onChangeText, onChange, onChangeValue, onChangeMask, onFocus, onBlur, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
201
+ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, format, placeholder, placeholderTextColor, duration, easing, bounce, effect, fontSize, lineHeight, fontWeight, fontFamily, color, textAlign, cursorColor, selectionColor, caretHidden, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, variant, label, labelBehavior, labelColor, labelFocusedColor, labelFontSize, strokeColor, focusedStrokeColor, strokeWidth, cornerRadius, fillColor, keyboardType, inputMode, enterKeyHint, mask, maskNotations, maskAutocomplete, maskAutoSkip, maskAffinityFormats, maskAffinityStrategy, maskTextCase, maskCharacterMap, maskSlotPlaceholder, keepPlaceholder, returnKeyType, autoCapitalize, autoCorrect, editable, multiline, numberOfLines, rows, textAlignVertical, scrollEnabled, autoFocus, transition, autoWidth: autoWidthProp, submitBehavior, blurOnSubmit, secureTextEntry, keyboardAppearance, textContentType, autoComplete, enablesReturnKeyAutomatically, showSoftInputOnFocus, selectTextOnFocus, clearTextOnFocus, keyboardHandoffMs, returnKeyBar, contextMenuHidden, spellCheck, readOnly, selection, onEndEditing, onSelectionChange, onKeyPress, maxLength, transform, onChangeText, onChange, onChangeValue, onChangeMask, onFocus, onBlur, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
182
202
  const nativeRef = (0, react_1.useRef)(null);
203
+ // `keyboardHandoffMs`: hand the keyboard off while this field still has it.
204
+ // A layout-effect cleanup runs in React's commit, so the native call is
205
+ // queued on the main thread before Fabric's removal of the view - by then
206
+ // UIKit would already have taken first responder away.
207
+ const handoffRef = (0, react_1.useRef)(keyboardHandoffMs ?? 0);
208
+ handoffRef.current = keyboardHandoffMs ?? 0;
209
+ (0, react_1.useLayoutEffect)(() => () => {
210
+ if (handoffRef.current > 0) {
211
+ const native = nativeRef.current;
212
+ native?.prepareForUnmount();
213
+ if (native) {
214
+ const handoff = { blur: () => native.blur() };
215
+ lastHandoff = handoff;
216
+ setTimeout(() => {
217
+ if (lastHandoff === handoff)
218
+ lastHandoff = null;
219
+ }, handoffRef.current + 100);
220
+ }
221
+ }
222
+ }, []);
183
223
  // What React Native's registry stores for this field. The React host
184
224
  // instance when there is one (iOS), otherwise a stable per-instance token:
185
225
  // on Android the Nitro host component hands out no instance, and the
@@ -245,9 +285,9 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
245
285
  const [, setEventCountState] = (0, react_1.useState)(0);
246
286
  const controlledRef = (0, react_1.useRef)(value != null);
247
287
  controlledRef.current = value != null;
248
- // The initial text of an uncontrolled field never changes afterwards, so
249
- // native applies it exactly once.
250
- const [initialText] = (0, react_1.useState)(() => defaultValue ?? '');
288
+ // An uncontrolled field's text for its native view: its initial text, and
289
+ // what it held when <Activity> last hid it (see the layout effect below).
290
+ const [uncontrolledText, setUncontrolledText] = (0, react_1.useState)(() => defaultValue ?? '');
251
291
  // Nitro callbacks must be wrapped with `callback()` and the wrapper object
252
292
  // has to be referentially stable, otherwise every render re-sets the prop.
253
293
  // Handlers are read through a ref so inline arrows don't re-set them either.
@@ -256,30 +296,70 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
256
296
  // does, as React Native queues a `TextInput`'s view commands. Without this
257
297
  // the common `useEffect(() => ref.current?.focus(), [])` was a silent no-op.
258
298
  const pendingCommands = (0, react_1.useRef)([]);
299
+ const [owner] = (0, react_1.useState)(() => ({}));
259
300
  const hybridRef = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((instance) => {
260
301
  nativeRef.current = instance;
302
+ viewOwner.set(instance, owner);
261
303
  const queued = pendingCommands.current;
262
304
  pendingCommands.current = [];
263
305
  for (const command of queued)
264
306
  command(instance);
265
307
  latest.current.onNativeRef?.(instance);
266
308
  }), []);
309
+ // React's <Activity> hides a subtree by deleting its native views (they go
310
+ // back to the view pool, and another field may be given one) and creates
311
+ // new ones when it is shown again, running layout-effect cleanups on hide
312
+ // and the effects again on show. So on hide: keep the text for the view the
313
+ // field gets back (an uncontrolled field's text lives only natively), and
314
+ // let go of the old view, or a handle kept from before would read and
315
+ // focus whichever field is given it next. While hidden, focus() and blur()
316
+ // do nothing and text changes wait for the field to be shown.
317
+ const hiddenRef = (0, react_1.useRef)(false);
318
+ const hiddenViewRef = (0, react_1.useRef)(null);
319
+ (0, react_1.useLayoutEffect)(() => {
320
+ hiddenRef.current = false;
321
+ // Shown again. Android keeps a hidden field's view, and calls no
322
+ // `hybridRef` for it again: take it back, unless another field has been
323
+ // given it (iOS), in which case this field's new view calls `hybridRef`.
324
+ const previous = hiddenViewRef.current;
325
+ hiddenViewRef.current = null;
326
+ if (nativeRef.current == null && previous != null && viewOwner.get(previous) === owner) {
327
+ nativeRef.current = previous;
328
+ const queued = pendingCommands.current;
329
+ pendingCommands.current = [];
330
+ for (const command of queued)
331
+ command(previous);
332
+ }
333
+ return () => {
334
+ const native = nativeRef.current;
335
+ if (native != null)
336
+ textRef.current = native.currentText();
337
+ hiddenViewRef.current = native;
338
+ nativeRef.current = null;
339
+ hiddenRef.current = true;
340
+ if (!controlledRef.current)
341
+ setUncontrolledText(textRef.current);
342
+ };
343
+ }, []);
267
344
  (0, react_1.useEffect)(() => {
268
345
  if (textInputRegistry == null)
269
346
  return;
270
347
  const key = hostRef.current ?? { nitroInput: true };
271
348
  registryKeyRef.current = key;
272
349
  patchRegistryOnce();
273
- mountedFields.set(key, {
350
+ const field = {
274
351
  focus: () => nativeRef.current?.focus(),
275
352
  blur: () => nativeRef.current?.blur(),
276
- });
353
+ };
354
+ mountedFields.set(key, field);
355
+ liveFields.add(field);
277
356
  textInputRegistry.registerInput(key);
278
357
  return () => {
279
358
  if (textInputRegistry.currentlyFocusedInput() === key)
280
359
  textInputRegistry.blurInput(key);
281
360
  textInputRegistry.unregisterInput(key);
282
361
  mountedFields.delete(key);
362
+ liveFields.delete(field);
283
363
  registryKeyRef.current = null;
284
364
  };
285
365
  }, []);
@@ -412,9 +492,13 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
412
492
  else
413
493
  pendingCommands.current.push(command);
414
494
  };
495
+ const unlessHidden = (command) => {
496
+ if (!hiddenRef.current)
497
+ send(command);
498
+ };
415
499
  return {
416
- focus: () => send((native) => native.focus()),
417
- blur: () => send((native) => native.blur()),
500
+ focus: () => unlessHidden((native) => native.focus()),
501
+ blur: () => unlessHidden((native) => native.blur()),
418
502
  clear: () => send((native) => native.clear()),
419
503
  setText: (text) => send((native) => native.replaceText(text)),
420
504
  setValue: (next) => send((native) => native.setValue(next)),
@@ -426,10 +510,11 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
426
510
  // actually holds first responder. Before it attaches, fall back to the
427
511
  // registry this field already keeps up to date, which is the same place
428
512
  // `TextInput.isFocused()` reads from.
429
- isFocused: () => nativeRef.current?.isFocused() ??
430
- (registryKeyRef.current != null &&
431
- textInputRegistry?.currentlyFocusedInput() === registryKeyRef.current),
432
- setSelection: (start, end) => send((native) => native.setSelection(start, end ?? start)),
513
+ isFocused: () => hiddenRef.current ? false :
514
+ nativeRef.current?.isFocused() ??
515
+ (registryKeyRef.current != null &&
516
+ textInputRegistry?.currentlyFocusedInput() === registryKeyRef.current),
517
+ setSelection: (start, end) => unlessHidden((native) => native.setSelection(start, end ?? start)),
433
518
  get native() {
434
519
  return nativeRef.current;
435
520
  },
@@ -559,7 +644,10 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
559
644
  ? { width: size.width, height: size.height }
560
645
  : { height: size.height }
561
646
  : { height: resolvedFontSize * 1.25 }, [size, resolvedFontSize, autoWidth]);
562
- return (react_1.default.createElement(exports.NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? initialText, mostRecentEventCount: eventCountRef.current, mode: resolvedMode, plain: !reflows, fractionDigits: resolvedFractionDigits, maxIntegerDigits: maxIntegerDigits ?? 15, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, placeholder: placeholder ?? '', placeholderColor: processedPlaceholderColor, duration: duration ?? 400, easing: easing ?? 'expo', bounce: bounce ?? 0.15, effect: effect ?? 'auto', fontSize: resolvedFontSize, lineHeight: Math.max(0, lineHeight ?? 0), fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, caretColor: processedCursorColor, selectionColor: processedSelectionColor, caretHidden: caretHidden ?? false, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, variant: variant ?? 'none', label: label ?? '', labelBehavior: labelBehavior ?? 'float', labelColor: processedLabelColor, labelFocusedColor: processedLabelFocusedColor, labelFontSize: labelFontSize ?? 0, strokeColor: processedStrokeColor, focusedStrokeColor: processedFocusedStrokeColor, strokeWidth: strokeWidth ?? 1, cornerRadius: cornerRadius ?? 8, fillColor: processedFillColor, mask: resolvedMode === 'mask' ? (mask ?? '') : '', maskNotations: stableNotations, maskAutocomplete: maskAutocomplete ?? true, maskAutoSkip: maskAutoSkip ?? false, maskAffinityFormats: stableAffinityFormats, maskAffinityStrategy: maskAffinityStrategy ?? 'wholeString', maskTextCase: maskTextCase ?? 'none', maskCharacterMap: stableCharacterMap, maskSlotPlaceholder: maskSlotPlaceholder ?? (keepPlaceholder ? '_' : ''), keepPlaceholder: keepPlaceholder ?? false, onChangeMask: onChangeMaskCallback, keyboardType: resolvedKeyboardType, returnKeyType: resolvedReturnKeyType, autoCapitalize: autoCapitalize ?? 'sentences', autoCorrect: autoCorrect ?? true, editable: (editable ?? true) && !(readOnly ?? false), multiline: isMultiline, numberOfLines: Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0)), textAlignVertical: textAlignVertical ?? 'auto', scrollEnabled: scrollEnabled ?? true, autoFocus: autoFocus ?? false, fieldTestID: viewProps.testID ?? '', fieldAccessibilityLabel: resolvedAccessibilityLabel ?? '', submitBehavior: submitBehavior ??
647
+ return (react_1.default.createElement(exports.NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? uncontrolledText,
648
+ // An uncontrolled field's `text` is its initial text: a count of 0 is
649
+ // never caught up after the first edit, so native never puts it back.
650
+ mostRecentEventCount: value != null ? eventCountRef.current : 0, mode: resolvedMode, plain: !reflows, fractionDigits: resolvedFractionDigits, maxIntegerDigits: maxIntegerDigits ?? 15, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, placeholder: placeholder ?? '', placeholderColor: processedPlaceholderColor, duration: duration ?? 400, easing: easing ?? 'expo', bounce: bounce ?? 0.15, effect: effect ?? 'auto', fontSize: resolvedFontSize, lineHeight: Math.max(0, lineHeight ?? 0), fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, caretColor: processedCursorColor, selectionColor: processedSelectionColor, caretHidden: caretHidden ?? false, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, variant: variant ?? 'none', label: label ?? '', labelBehavior: labelBehavior ?? 'float', labelColor: processedLabelColor, labelFocusedColor: processedLabelFocusedColor, labelFontSize: labelFontSize ?? 0, strokeColor: processedStrokeColor, focusedStrokeColor: processedFocusedStrokeColor, strokeWidth: strokeWidth ?? 1, cornerRadius: cornerRadius ?? 8, fillColor: processedFillColor, mask: resolvedMode === 'mask' ? (mask ?? '') : '', maskNotations: stableNotations, maskAutocomplete: maskAutocomplete ?? true, maskAutoSkip: maskAutoSkip ?? false, maskAffinityFormats: stableAffinityFormats, maskAffinityStrategy: maskAffinityStrategy ?? 'wholeString', maskTextCase: maskTextCase ?? 'none', maskCharacterMap: stableCharacterMap, maskSlotPlaceholder: maskSlotPlaceholder ?? (keepPlaceholder ? '_' : ''), keepPlaceholder: keepPlaceholder ?? false, onChangeMask: onChangeMaskCallback, keyboardType: resolvedKeyboardType, returnKeyType: resolvedReturnKeyType, autoCapitalize: autoCapitalize ?? 'sentences', autoCorrect: autoCorrect ?? true, editable: (editable ?? true) && !(readOnly ?? false), multiline: isMultiline, numberOfLines: Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0)), textAlignVertical: textAlignVertical ?? 'auto', scrollEnabled: scrollEnabled ?? true, autoFocus: autoFocus ?? false, fieldTestID: viewProps.testID ?? '', fieldAccessibilityLabel: resolvedAccessibilityLabel ?? '', submitBehavior: submitBehavior ??
563
651
  // As `TextInput` resolves the legacy `blurOnSubmit`: a multiline
564
652
  // field's return key inserts a line break unless told to blur.
565
653
  (multiline
@@ -568,7 +656,7 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
568
656
  : 'newline'
569
657
  : blurOnSubmit === false
570
658
  ? 'submit'
571
- : 'blurAndSubmit'), secureTextEntry: secureTextEntry ?? false, keyboardAppearance: keyboardAppearance ?? 'default', textContentType: textContentType ?? autoComplete ?? '', enablesReturnKeyAutomatically: enablesReturnKeyAutomatically ?? false, showSoftInputOnFocus: resolvedShowSoftInput, selectTextOnFocus: selectTextOnFocus ?? false, clearTextOnFocus: clearTextOnFocus ?? false, contextMenuHidden: contextMenuHidden ?? false, spellCheck: spellCheck ?? autoCorrect ?? true, selectionStart: selection?.start ?? -1, selectionEnd: selection?.end ?? selection?.start ?? -1, maxLength: maxLength ?? 0, transformWorklet: transformId, onChangeTextWorklet: onChangeTextId, onChangeValueWorklet: onChangeValueId, onFocusChangeWorklet: onFocusId, onSelectionChangeWorklet: onSelectionChangeId, onSubmitEditingWorklet: onSubmitEditingId, onEndEditingWorklet: onEndEditingId, onKeyPressWorklet: onKeyPressId, onChangeText: onChangeTextCallback, onChangeValue: onChangeValueCallback, onFocusChange: onFocusChangeCallback, onSubmitEditing: onSubmitEditingCallback, onEndEditing: onEndEditingCallback, onSelectionChange: onSelectionChangeCallback, onKeyPress: onKeyPressCallback, onSizeChange: onSizeChange }));
659
+ : 'blurAndSubmit'), secureTextEntry: secureTextEntry ?? false, keyboardAppearance: keyboardAppearance ?? 'default', textContentType: textContentType ?? autoComplete ?? '', enablesReturnKeyAutomatically: enablesReturnKeyAutomatically ?? false, showSoftInputOnFocus: resolvedShowSoftInput, selectTextOnFocus: selectTextOnFocus ?? false, clearTextOnFocus: clearTextOnFocus ?? false, keyboardHandoffMs: keyboardHandoffMs ?? 0, returnKeyBar: returnKeyBar ?? true, contextMenuHidden: contextMenuHidden ?? false, spellCheck: spellCheck ?? autoCorrect ?? true, selectionStart: selection?.start ?? -1, selectionEnd: selection?.end ?? selection?.start ?? -1, maxLength: maxLength ?? 0, transformWorklet: transformId, onChangeTextWorklet: onChangeTextId, onChangeValueWorklet: onChangeValueId, onFocusChangeWorklet: onFocusId, onSelectionChangeWorklet: onSelectionChangeId, onSubmitEditingWorklet: onSubmitEditingId, onEndEditingWorklet: onEndEditingId, onKeyPressWorklet: onKeyPressId, onChangeText: onChangeTextCallback, onChangeValue: onChangeValueCallback, onFocusChange: onFocusChangeCallback, onSubmitEditing: onSubmitEditingCallback, onEndEditing: onEndEditingCallback, onSelectionChange: onSelectionChangeCallback, onKeyPress: onKeyPressCallback, onSizeChange: onSizeChange }));
572
660
  });
573
661
  // The name DevTools and error stacks show, as `TextInput` names itself.
574
662
  exports.NitroInput.displayName = 'NitroInput';
@@ -85,6 +85,8 @@
85
85
  "showSoftInputOnFocus": true,
86
86
  "selectTextOnFocus": true,
87
87
  "clearTextOnFocus": true,
88
+ "keyboardHandoffMs": true,
89
+ "returnKeyBar": true,
88
90
  "contextMenuHidden": true,
89
91
  "spellCheck": true,
90
92
  "selectionStart": true,
@@ -1,4 +1,4 @@
1
- import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
1
+ import React, { forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, } from 'react';
2
2
  import { I18nManager, StyleSheet, } from 'react-native';
3
3
  import { callback, getHostComponent, } from 'react-native-nitro-modules';
4
4
  import NitroInputViewConfig from '../nitrogen/generated/shared/json/NitroInputViewConfig.json';
@@ -68,6 +68,20 @@ const EMPTY_STRINGS = [];
68
68
  const EMPTY_MAPPINGS = [];
69
69
  /** Mounted fields, by the host instance React Native's registry stores. */
70
70
  const mountedFields = new WeakMap();
71
+ /** The same fields, iterable: `Keyboard.dismiss()` with nothing focused reaches one through it. */
72
+ const liveFields = new Set();
73
+ /**
74
+ * The last field that handed the keyboard off as it unmounted, kept until its
75
+ * hold is over: a screen may have no field left (a tap-only question) when it
76
+ * calls `Keyboard.dismiss()`, and the hold is released through a native blur.
77
+ */
78
+ let lastHandoff = null;
79
+ /**
80
+ * Which field a native view currently belongs to. A view can change hands:
81
+ * on iOS a hidden <Activity>'s views go back to the pool and another field
82
+ * may be given one; on Android they are kept for the same field.
83
+ */
84
+ const viewOwner = new WeakMap();
71
85
  let patchedRegistry = false;
72
86
  /**
73
87
  * `TextInputState.focusTextInput` / `blurTextInput` — which is how
@@ -105,7 +119,13 @@ function patchRegistryOnce() {
105
119
  const field = input != null ? mountedFields.get(input) : undefined;
106
120
  if (field)
107
121
  return field.blur();
108
- return originalBlur.call(registry, input);
122
+ const result = originalBlur.call(registry, input);
123
+ // `Keyboard.dismiss()` with no input focused: a field that just left the
124
+ // screen may still be holding the keyboard for the next one
125
+ // (`keyboardHandoffMs`). A native blur on any field lets that go.
126
+ if (input == null)
127
+ (liveFields.values().next().value ?? lastHandoff)?.blur();
128
+ return result;
109
129
  };
110
130
  }
111
131
  }
@@ -139,8 +159,28 @@ function warnIncompatible(what) {
139
159
  * Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
140
160
  * it to its content instead, and is on by default when the text reflows.
141
161
  */
142
- export const NitroInput = forwardRef(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, format, placeholder, placeholderTextColor, duration, easing, bounce, effect, fontSize, lineHeight, fontWeight, fontFamily, color, textAlign, cursorColor, selectionColor, caretHidden, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, variant, label, labelBehavior, labelColor, labelFocusedColor, labelFontSize, strokeColor, focusedStrokeColor, strokeWidth, cornerRadius, fillColor, keyboardType, inputMode, enterKeyHint, mask, maskNotations, maskAutocomplete, maskAutoSkip, maskAffinityFormats, maskAffinityStrategy, maskTextCase, maskCharacterMap, maskSlotPlaceholder, keepPlaceholder, returnKeyType, autoCapitalize, autoCorrect, editable, multiline, numberOfLines, rows, textAlignVertical, scrollEnabled, autoFocus, transition, autoWidth: autoWidthProp, submitBehavior, blurOnSubmit, secureTextEntry, keyboardAppearance, textContentType, autoComplete, enablesReturnKeyAutomatically, showSoftInputOnFocus, selectTextOnFocus, clearTextOnFocus, contextMenuHidden, spellCheck, readOnly, selection, onEndEditing, onSelectionChange, onKeyPress, maxLength, transform, onChangeText, onChange, onChangeValue, onChangeMask, onFocus, onBlur, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
162
+ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, format, placeholder, placeholderTextColor, duration, easing, bounce, effect, fontSize, lineHeight, fontWeight, fontFamily, color, textAlign, cursorColor, selectionColor, caretHidden, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, variant, label, labelBehavior, labelColor, labelFocusedColor, labelFontSize, strokeColor, focusedStrokeColor, strokeWidth, cornerRadius, fillColor, keyboardType, inputMode, enterKeyHint, mask, maskNotations, maskAutocomplete, maskAutoSkip, maskAffinityFormats, maskAffinityStrategy, maskTextCase, maskCharacterMap, maskSlotPlaceholder, keepPlaceholder, returnKeyType, autoCapitalize, autoCorrect, editable, multiline, numberOfLines, rows, textAlignVertical, scrollEnabled, autoFocus, transition, autoWidth: autoWidthProp, submitBehavior, blurOnSubmit, secureTextEntry, keyboardAppearance, textContentType, autoComplete, enablesReturnKeyAutomatically, showSoftInputOnFocus, selectTextOnFocus, clearTextOnFocus, keyboardHandoffMs, returnKeyBar, contextMenuHidden, spellCheck, readOnly, selection, onEndEditing, onSelectionChange, onKeyPress, maxLength, transform, onChangeText, onChange, onChangeValue, onChangeMask, onFocus, onBlur, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
143
163
  const nativeRef = useRef(null);
164
+ // `keyboardHandoffMs`: hand the keyboard off while this field still has it.
165
+ // A layout-effect cleanup runs in React's commit, so the native call is
166
+ // queued on the main thread before Fabric's removal of the view - by then
167
+ // UIKit would already have taken first responder away.
168
+ const handoffRef = useRef(keyboardHandoffMs ?? 0);
169
+ handoffRef.current = keyboardHandoffMs ?? 0;
170
+ useLayoutEffect(() => () => {
171
+ if (handoffRef.current > 0) {
172
+ const native = nativeRef.current;
173
+ native?.prepareForUnmount();
174
+ if (native) {
175
+ const handoff = { blur: () => native.blur() };
176
+ lastHandoff = handoff;
177
+ setTimeout(() => {
178
+ if (lastHandoff === handoff)
179
+ lastHandoff = null;
180
+ }, handoffRef.current + 100);
181
+ }
182
+ }
183
+ }, []);
144
184
  // What React Native's registry stores for this field. The React host
145
185
  // instance when there is one (iOS), otherwise a stable per-instance token:
146
186
  // on Android the Nitro host component hands out no instance, and the
@@ -206,9 +246,9 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
206
246
  const [, setEventCountState] = useState(0);
207
247
  const controlledRef = useRef(value != null);
208
248
  controlledRef.current = value != null;
209
- // The initial text of an uncontrolled field never changes afterwards, so
210
- // native applies it exactly once.
211
- const [initialText] = useState(() => defaultValue ?? '');
249
+ // An uncontrolled field's text for its native view: its initial text, and
250
+ // what it held when <Activity> last hid it (see the layout effect below).
251
+ const [uncontrolledText, setUncontrolledText] = useState(() => defaultValue ?? '');
212
252
  // Nitro callbacks must be wrapped with `callback()` and the wrapper object
213
253
  // has to be referentially stable, otherwise every render re-sets the prop.
214
254
  // Handlers are read through a ref so inline arrows don't re-set them either.
@@ -217,30 +257,70 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
217
257
  // does, as React Native queues a `TextInput`'s view commands. Without this
218
258
  // the common `useEffect(() => ref.current?.focus(), [])` was a silent no-op.
219
259
  const pendingCommands = useRef([]);
260
+ const [owner] = useState(() => ({}));
220
261
  const hybridRef = useMemo(() => callback((instance) => {
221
262
  nativeRef.current = instance;
263
+ viewOwner.set(instance, owner);
222
264
  const queued = pendingCommands.current;
223
265
  pendingCommands.current = [];
224
266
  for (const command of queued)
225
267
  command(instance);
226
268
  latest.current.onNativeRef?.(instance);
227
269
  }), []);
270
+ // React's <Activity> hides a subtree by deleting its native views (they go
271
+ // back to the view pool, and another field may be given one) and creates
272
+ // new ones when it is shown again, running layout-effect cleanups on hide
273
+ // and the effects again on show. So on hide: keep the text for the view the
274
+ // field gets back (an uncontrolled field's text lives only natively), and
275
+ // let go of the old view, or a handle kept from before would read and
276
+ // focus whichever field is given it next. While hidden, focus() and blur()
277
+ // do nothing and text changes wait for the field to be shown.
278
+ const hiddenRef = useRef(false);
279
+ const hiddenViewRef = useRef(null);
280
+ useLayoutEffect(() => {
281
+ hiddenRef.current = false;
282
+ // Shown again. Android keeps a hidden field's view, and calls no
283
+ // `hybridRef` for it again: take it back, unless another field has been
284
+ // given it (iOS), in which case this field's new view calls `hybridRef`.
285
+ const previous = hiddenViewRef.current;
286
+ hiddenViewRef.current = null;
287
+ if (nativeRef.current == null && previous != null && viewOwner.get(previous) === owner) {
288
+ nativeRef.current = previous;
289
+ const queued = pendingCommands.current;
290
+ pendingCommands.current = [];
291
+ for (const command of queued)
292
+ command(previous);
293
+ }
294
+ return () => {
295
+ const native = nativeRef.current;
296
+ if (native != null)
297
+ textRef.current = native.currentText();
298
+ hiddenViewRef.current = native;
299
+ nativeRef.current = null;
300
+ hiddenRef.current = true;
301
+ if (!controlledRef.current)
302
+ setUncontrolledText(textRef.current);
303
+ };
304
+ }, []);
228
305
  useEffect(() => {
229
306
  if (textInputRegistry == null)
230
307
  return;
231
308
  const key = hostRef.current ?? { nitroInput: true };
232
309
  registryKeyRef.current = key;
233
310
  patchRegistryOnce();
234
- mountedFields.set(key, {
311
+ const field = {
235
312
  focus: () => nativeRef.current?.focus(),
236
313
  blur: () => nativeRef.current?.blur(),
237
- });
314
+ };
315
+ mountedFields.set(key, field);
316
+ liveFields.add(field);
238
317
  textInputRegistry.registerInput(key);
239
318
  return () => {
240
319
  if (textInputRegistry.currentlyFocusedInput() === key)
241
320
  textInputRegistry.blurInput(key);
242
321
  textInputRegistry.unregisterInput(key);
243
322
  mountedFields.delete(key);
323
+ liveFields.delete(field);
244
324
  registryKeyRef.current = null;
245
325
  };
246
326
  }, []);
@@ -373,9 +453,13 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
373
453
  else
374
454
  pendingCommands.current.push(command);
375
455
  };
456
+ const unlessHidden = (command) => {
457
+ if (!hiddenRef.current)
458
+ send(command);
459
+ };
376
460
  return {
377
- focus: () => send((native) => native.focus()),
378
- blur: () => send((native) => native.blur()),
461
+ focus: () => unlessHidden((native) => native.focus()),
462
+ blur: () => unlessHidden((native) => native.blur()),
379
463
  clear: () => send((native) => native.clear()),
380
464
  setText: (text) => send((native) => native.replaceText(text)),
381
465
  setValue: (next) => send((native) => native.setValue(next)),
@@ -387,10 +471,11 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
387
471
  // actually holds first responder. Before it attaches, fall back to the
388
472
  // registry this field already keeps up to date, which is the same place
389
473
  // `TextInput.isFocused()` reads from.
390
- isFocused: () => nativeRef.current?.isFocused() ??
391
- (registryKeyRef.current != null &&
392
- textInputRegistry?.currentlyFocusedInput() === registryKeyRef.current),
393
- setSelection: (start, end) => send((native) => native.setSelection(start, end ?? start)),
474
+ isFocused: () => hiddenRef.current ? false :
475
+ nativeRef.current?.isFocused() ??
476
+ (registryKeyRef.current != null &&
477
+ textInputRegistry?.currentlyFocusedInput() === registryKeyRef.current),
478
+ setSelection: (start, end) => unlessHidden((native) => native.setSelection(start, end ?? start)),
394
479
  get native() {
395
480
  return nativeRef.current;
396
481
  },
@@ -520,7 +605,10 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
520
605
  ? { width: size.width, height: size.height }
521
606
  : { height: size.height }
522
607
  : { height: resolvedFontSize * 1.25 }, [size, resolvedFontSize, autoWidth]);
523
- return (React.createElement(NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? initialText, mostRecentEventCount: eventCountRef.current, mode: resolvedMode, plain: !reflows, fractionDigits: resolvedFractionDigits, maxIntegerDigits: maxIntegerDigits ?? 15, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, placeholder: placeholder ?? '', placeholderColor: processedPlaceholderColor, duration: duration ?? 400, easing: easing ?? 'expo', bounce: bounce ?? 0.15, effect: effect ?? 'auto', fontSize: resolvedFontSize, lineHeight: Math.max(0, lineHeight ?? 0), fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, caretColor: processedCursorColor, selectionColor: processedSelectionColor, caretHidden: caretHidden ?? false, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, variant: variant ?? 'none', label: label ?? '', labelBehavior: labelBehavior ?? 'float', labelColor: processedLabelColor, labelFocusedColor: processedLabelFocusedColor, labelFontSize: labelFontSize ?? 0, strokeColor: processedStrokeColor, focusedStrokeColor: processedFocusedStrokeColor, strokeWidth: strokeWidth ?? 1, cornerRadius: cornerRadius ?? 8, fillColor: processedFillColor, mask: resolvedMode === 'mask' ? (mask ?? '') : '', maskNotations: stableNotations, maskAutocomplete: maskAutocomplete ?? true, maskAutoSkip: maskAutoSkip ?? false, maskAffinityFormats: stableAffinityFormats, maskAffinityStrategy: maskAffinityStrategy ?? 'wholeString', maskTextCase: maskTextCase ?? 'none', maskCharacterMap: stableCharacterMap, maskSlotPlaceholder: maskSlotPlaceholder ?? (keepPlaceholder ? '_' : ''), keepPlaceholder: keepPlaceholder ?? false, onChangeMask: onChangeMaskCallback, keyboardType: resolvedKeyboardType, returnKeyType: resolvedReturnKeyType, autoCapitalize: autoCapitalize ?? 'sentences', autoCorrect: autoCorrect ?? true, editable: (editable ?? true) && !(readOnly ?? false), multiline: isMultiline, numberOfLines: Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0)), textAlignVertical: textAlignVertical ?? 'auto', scrollEnabled: scrollEnabled ?? true, autoFocus: autoFocus ?? false, fieldTestID: viewProps.testID ?? '', fieldAccessibilityLabel: resolvedAccessibilityLabel ?? '', submitBehavior: submitBehavior ??
608
+ return (React.createElement(NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? uncontrolledText,
609
+ // An uncontrolled field's `text` is its initial text: a count of 0 is
610
+ // never caught up after the first edit, so native never puts it back.
611
+ mostRecentEventCount: value != null ? eventCountRef.current : 0, mode: resolvedMode, plain: !reflows, fractionDigits: resolvedFractionDigits, maxIntegerDigits: maxIntegerDigits ?? 15, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, placeholder: placeholder ?? '', placeholderColor: processedPlaceholderColor, duration: duration ?? 400, easing: easing ?? 'expo', bounce: bounce ?? 0.15, effect: effect ?? 'auto', fontSize: resolvedFontSize, lineHeight: Math.max(0, lineHeight ?? 0), fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, caretColor: processedCursorColor, selectionColor: processedSelectionColor, caretHidden: caretHidden ?? false, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, variant: variant ?? 'none', label: label ?? '', labelBehavior: labelBehavior ?? 'float', labelColor: processedLabelColor, labelFocusedColor: processedLabelFocusedColor, labelFontSize: labelFontSize ?? 0, strokeColor: processedStrokeColor, focusedStrokeColor: processedFocusedStrokeColor, strokeWidth: strokeWidth ?? 1, cornerRadius: cornerRadius ?? 8, fillColor: processedFillColor, mask: resolvedMode === 'mask' ? (mask ?? '') : '', maskNotations: stableNotations, maskAutocomplete: maskAutocomplete ?? true, maskAutoSkip: maskAutoSkip ?? false, maskAffinityFormats: stableAffinityFormats, maskAffinityStrategy: maskAffinityStrategy ?? 'wholeString', maskTextCase: maskTextCase ?? 'none', maskCharacterMap: stableCharacterMap, maskSlotPlaceholder: maskSlotPlaceholder ?? (keepPlaceholder ? '_' : ''), keepPlaceholder: keepPlaceholder ?? false, onChangeMask: onChangeMaskCallback, keyboardType: resolvedKeyboardType, returnKeyType: resolvedReturnKeyType, autoCapitalize: autoCapitalize ?? 'sentences', autoCorrect: autoCorrect ?? true, editable: (editable ?? true) && !(readOnly ?? false), multiline: isMultiline, numberOfLines: Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0)), textAlignVertical: textAlignVertical ?? 'auto', scrollEnabled: scrollEnabled ?? true, autoFocus: autoFocus ?? false, fieldTestID: viewProps.testID ?? '', fieldAccessibilityLabel: resolvedAccessibilityLabel ?? '', submitBehavior: submitBehavior ??
524
612
  // As `TextInput` resolves the legacy `blurOnSubmit`: a multiline
525
613
  // field's return key inserts a line break unless told to blur.
526
614
  (multiline
@@ -529,7 +617,7 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
529
617
  : 'newline'
530
618
  : blurOnSubmit === false
531
619
  ? 'submit'
532
- : 'blurAndSubmit'), secureTextEntry: secureTextEntry ?? false, keyboardAppearance: keyboardAppearance ?? 'default', textContentType: textContentType ?? autoComplete ?? '', enablesReturnKeyAutomatically: enablesReturnKeyAutomatically ?? false, showSoftInputOnFocus: resolvedShowSoftInput, selectTextOnFocus: selectTextOnFocus ?? false, clearTextOnFocus: clearTextOnFocus ?? false, contextMenuHidden: contextMenuHidden ?? false, spellCheck: spellCheck ?? autoCorrect ?? true, selectionStart: selection?.start ?? -1, selectionEnd: selection?.end ?? selection?.start ?? -1, maxLength: maxLength ?? 0, transformWorklet: transformId, onChangeTextWorklet: onChangeTextId, onChangeValueWorklet: onChangeValueId, onFocusChangeWorklet: onFocusId, onSelectionChangeWorklet: onSelectionChangeId, onSubmitEditingWorklet: onSubmitEditingId, onEndEditingWorklet: onEndEditingId, onKeyPressWorklet: onKeyPressId, onChangeText: onChangeTextCallback, onChangeValue: onChangeValueCallback, onFocusChange: onFocusChangeCallback, onSubmitEditing: onSubmitEditingCallback, onEndEditing: onEndEditingCallback, onSelectionChange: onSelectionChangeCallback, onKeyPress: onKeyPressCallback, onSizeChange: onSizeChange }));
620
+ : 'blurAndSubmit'), secureTextEntry: secureTextEntry ?? false, keyboardAppearance: keyboardAppearance ?? 'default', textContentType: textContentType ?? autoComplete ?? '', enablesReturnKeyAutomatically: enablesReturnKeyAutomatically ?? false, showSoftInputOnFocus: resolvedShowSoftInput, selectTextOnFocus: selectTextOnFocus ?? false, clearTextOnFocus: clearTextOnFocus ?? false, keyboardHandoffMs: keyboardHandoffMs ?? 0, returnKeyBar: returnKeyBar ?? true, contextMenuHidden: contextMenuHidden ?? false, spellCheck: spellCheck ?? autoCorrect ?? true, selectionStart: selection?.start ?? -1, selectionEnd: selection?.end ?? selection?.start ?? -1, maxLength: maxLength ?? 0, transformWorklet: transformId, onChangeTextWorklet: onChangeTextId, onChangeValueWorklet: onChangeValueId, onFocusChangeWorklet: onFocusId, onSelectionChangeWorklet: onSelectionChangeId, onSubmitEditingWorklet: onSubmitEditingId, onEndEditingWorklet: onEndEditingId, onKeyPressWorklet: onKeyPressId, onChangeText: onChangeTextCallback, onChangeValue: onChangeValueCallback, onFocusChange: onFocusChangeCallback, onSubmitEditing: onSubmitEditingCallback, onEndEditing: onEndEditingCallback, onSelectionChange: onSelectionChangeCallback, onKeyPress: onKeyPressCallback, onSizeChange: onSizeChange }));
533
621
  });
534
622
  // The name DevTools and error stacks show, as `TextInput` names itself.
535
623
  NitroInput.displayName = 'NitroInput';
@@ -354,6 +354,22 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
354
354
  selectTextOnFocus?: boolean;
355
355
  /** Empty the field when it gains focus. Default: `false`. */
356
356
  clearTextOnFocus?: boolean;
357
+ /**
358
+ * When this field is popped or unmounted while it has the keyboard, keep the
359
+ * keyboard up this many milliseconds so the next field to focus (the screen
360
+ * you return to, the next step's field) takes it over in place instead of
361
+ * the keyboard dropping and rising again. If no field does, the keyboard
362
+ * hides when the time runs out; `Keyboard.dismiss()` hides it at once.
363
+ * 300-500 covers a stack pop. Default: `0` (off).
364
+ */
365
+ keyboardHandoffMs?: number;
366
+ /**
367
+ * iOS: on the number, phone and decimal pads, which have no return key, a
368
+ * bar over the keyboard with the `returnKeyType` key ("Next", "Done"...), as
369
+ * `TextInput` shows. `false` leaves the pad bare - for a screen that has its
370
+ * own button riding the keyboard. Default: `true`.
371
+ */
372
+ returnKeyBar?: boolean;
357
373
  /** Hides the Cut/Copy/Paste menu. Default: `false`. */
358
374
  contextMenuHidden?: boolean;
359
375
  /** Spell checking in `'text'` mode. Defaults to `autoCorrect`. */
@@ -351,6 +351,21 @@ export interface NitroInputProps extends HybridViewProps {
351
351
  selectTextOnFocus: boolean;
352
352
  /** Empty the field when it gains focus. Default: `false`. */
353
353
  clearTextOnFocus: boolean;
354
+ /**
355
+ * iOS: when this field loses its window while it has the keyboard (its
356
+ * screen is popped or unmounted), keep the keyboard up for this many
357
+ * milliseconds so the next field to focus takes it over in place, instead
358
+ * of the keyboard dropping and rising again. `0` lets it go at once.
359
+ * Default: `0`.
360
+ */
361
+ keyboardHandoffMs: number;
362
+ /**
363
+ * iOS: on the number, phone and decimal pads (no return key of their own),
364
+ * a bar over the keyboard with the `returnKeyType` key, as `TextInput`
365
+ * shows. `false` leaves the pad bare, for a screen with its own button on
366
+ * the keyboard. Default: `true`.
367
+ */
368
+ returnKeyBar: boolean;
354
369
  /** Hides the Cut/Copy/Paste menu. Default: `false`. */
355
370
  contextMenuHidden: boolean;
356
371
  /** Spell checking (`'text'` mode). Defaults to `autoCorrect`. */
@@ -439,5 +454,12 @@ export interface NitroInputMethods extends HybridViewMethods {
439
454
  * `end` defaults to `start` for a plain caret move; both are clamped.
440
455
  */
441
456
  setSelection(start: number, end: number): void;
457
+ /**
458
+ * The field is about to be unmounted: if it has the keyboard and
459
+ * `keyboardHandoffMs` is set, hand the keyboard to the stand-in now, while
460
+ * the field is still first responder (by the time its view is removed,
461
+ * UIKit has already taken that away). Called by `NitroInput` itself.
462
+ */
463
+ prepareForUnmount(): void;
442
464
  }
443
465
  export type NitroInputView = HybridView<NitroInputProps, NitroInputMethods>;
@@ -905,6 +905,24 @@ namespace margelo::nitro::nitroinput {
905
905
  static const auto method = _javaPart->javaClassStatic()->getMethod<void(jboolean /* clearTextOnFocus */)>("setClearTextOnFocus");
906
906
  method(_javaPart, clearTextOnFocus);
907
907
  }
908
+ double JHybridNitroInputViewSpec::getKeyboardHandoffMs() {
909
+ static const auto method = _javaPart->javaClassStatic()->getMethod<double()>("getKeyboardHandoffMs");
910
+ auto __result = method(_javaPart);
911
+ return __result;
912
+ }
913
+ void JHybridNitroInputViewSpec::setKeyboardHandoffMs(double keyboardHandoffMs) {
914
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(double /* keyboardHandoffMs */)>("setKeyboardHandoffMs");
915
+ method(_javaPart, keyboardHandoffMs);
916
+ }
917
+ bool JHybridNitroInputViewSpec::getReturnKeyBar() {
918
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("getReturnKeyBar");
919
+ auto __result = method(_javaPart);
920
+ return static_cast<bool>(__result);
921
+ }
922
+ void JHybridNitroInputViewSpec::setReturnKeyBar(bool returnKeyBar) {
923
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jboolean /* returnKeyBar */)>("setReturnKeyBar");
924
+ method(_javaPart, returnKeyBar);
925
+ }
908
926
  bool JHybridNitroInputViewSpec::getContextMenuHidden() {
909
927
  static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("getContextMenuHidden");
910
928
  auto __result = method(_javaPart);
@@ -1216,5 +1234,9 @@ namespace margelo::nitro::nitroinput {
1216
1234
  static const auto method = _javaPart->javaClassStatic()->getMethod<void(double /* start */, double /* end */)>("setSelection");
1217
1235
  method(_javaPart, start, end);
1218
1236
  }
1237
+ void JHybridNitroInputViewSpec::prepareForUnmount() {
1238
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("prepareForUnmount");
1239
+ method(_javaPart);
1240
+ }
1219
1241
 
1220
1242
  } // namespace margelo::nitro::nitroinput
@@ -212,6 +212,10 @@ namespace margelo::nitro::nitroinput {
212
212
  void setSelectTextOnFocus(bool selectTextOnFocus) override;
213
213
  bool getClearTextOnFocus() override;
214
214
  void setClearTextOnFocus(bool clearTextOnFocus) override;
215
+ double getKeyboardHandoffMs() override;
216
+ void setKeyboardHandoffMs(double keyboardHandoffMs) override;
217
+ bool getReturnKeyBar() override;
218
+ void setReturnKeyBar(bool returnKeyBar) override;
215
219
  bool getContextMenuHidden() override;
216
220
  void setContextMenuHidden(bool contextMenuHidden) override;
217
221
  bool getSpellCheck() override;
@@ -268,6 +272,7 @@ namespace margelo::nitro::nitroinput {
268
272
  double getValue() override;
269
273
  bool isFocused() override;
270
274
  void setSelection(double start, double end) override;
275
+ void prepareForUnmount() override;
271
276
 
272
277
  private:
273
278
  jni::global_ref<JHybridNitroInputViewSpec::JavaPart> _javaPart;
@@ -458,6 +458,16 @@ void JHybridNitroInputViewStateUpdater::updateViewProps(jni::alias_ref<jni::JCla
458
458
  : !newProps->clearTextOnFocus.hasSameValue(oldProps->clearTextOnFocus)) {
459
459
  hybridView->setClearTextOnFocus(newProps->clearTextOnFocus.get());
460
460
  }
461
+ if (oldProps == nullptr
462
+ ? newProps->keyboardHandoffMs.isProvided()
463
+ : !newProps->keyboardHandoffMs.hasSameValue(oldProps->keyboardHandoffMs)) {
464
+ hybridView->setKeyboardHandoffMs(newProps->keyboardHandoffMs.get());
465
+ }
466
+ if (oldProps == nullptr
467
+ ? newProps->returnKeyBar.isProvided()
468
+ : !newProps->returnKeyBar.hasSameValue(oldProps->returnKeyBar)) {
469
+ hybridView->setReturnKeyBar(newProps->returnKeyBar.get());
470
+ }
461
471
  if (oldProps == nullptr
462
472
  ? newProps->contextMenuHidden.isProvided()
463
473
  : !newProps->contextMenuHidden.hasSameValue(oldProps->contextMenuHidden)) {
@@ -513,6 +513,18 @@ abstract class HybridNitroInputViewSpec: HybridView() {
513
513
  @set:Keep
514
514
  abstract var clearTextOnFocus: Boolean
515
515
 
516
+ @get:DoNotStrip
517
+ @get:Keep
518
+ @set:DoNotStrip
519
+ @set:Keep
520
+ abstract var keyboardHandoffMs: Double
521
+
522
+ @get:DoNotStrip
523
+ @get:Keep
524
+ @set:DoNotStrip
525
+ @set:Keep
526
+ abstract var returnKeyBar: Boolean
527
+
516
528
  @get:DoNotStrip
517
529
  @get:Keep
518
530
  @set:DoNotStrip
@@ -753,6 +765,10 @@ abstract class HybridNitroInputViewSpec: HybridView() {
753
765
  @DoNotStrip
754
766
  @Keep
755
767
  abstract fun setSelection(start: Double, end: Double): Unit
768
+
769
+ @DoNotStrip
770
+ @Keep
771
+ abstract fun prepareForUnmount(): Unit
756
772
 
757
773
  // Default implementation of `HybridObject.toString()`
758
774
  override fun toString(): String {