react-native-nitro-input 0.3.1 → 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 (51) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/README.md +75 -3
  3. package/android/src/main/cpp/JMaskEngine.cpp +45 -0
  4. package/android/src/main/cpp/JMaskEngine.hpp +9 -0
  5. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +49 -4
  6. package/android/src/main/java/com/margelo/nitro/nitroinput/MaskEngine.kt +16 -0
  7. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +266 -8
  8. package/android/src/main/java/com/margelo/nitro/nitroinput/UnmountHandoffs.kt +57 -0
  9. package/cpp/MaskEngine.cpp +294 -33
  10. package/cpp/MaskEngine.hpp +68 -0
  11. package/ios/HybridNitroInputView.swift +37 -4
  12. package/ios/NitroInputCommands.mm +10 -0
  13. package/ios/NitroInputView.swift +474 -20
  14. package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +8 -0
  15. package/lib/commonjs/src/NitroInput.js +116 -15
  16. package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +8 -0
  17. package/lib/module/src/NitroInput.js +117 -16
  18. package/lib/typescript/src/NitroInput.d.ts +55 -1
  19. package/lib/typescript/src/index.d.ts +1 -1
  20. package/lib/typescript/src/specs/NitroInput.nitro.d.ts +65 -0
  21. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +124 -0
  22. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +17 -0
  23. package/nitrogen/generated/android/c++/JNitroInputCharacterMapping.hpp +61 -0
  24. package/nitrogen/generated/android/c++/JNitroInputMaskAffinity.hpp +64 -0
  25. package/nitrogen/generated/android/c++/JNitroInputTextCase.hpp +61 -0
  26. package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +40 -0
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +52 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputCharacterMapping.kt +56 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputMaskAffinity.kt +25 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputTextCase.kt +24 -0
  31. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +25 -11
  32. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +9 -0
  33. package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +68 -0
  34. package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +48 -0
  35. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +9 -0
  36. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +111 -0
  37. package/nitrogen/generated/ios/swift/NitroInputCharacterMapping.swift +34 -0
  38. package/nitrogen/generated/ios/swift/NitroInputMaskAffinity.swift +48 -0
  39. package/nitrogen/generated/ios/swift/NitroInputTextCase.swift +44 -0
  40. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +17 -0
  41. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +26 -0
  42. package/nitrogen/generated/shared/c++/NitroInputCharacterMapping.hpp +87 -0
  43. package/nitrogen/generated/shared/c++/NitroInputMaskAffinity.hpp +84 -0
  44. package/nitrogen/generated/shared/c++/NitroInputTextCase.hpp +80 -0
  45. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +16 -0
  46. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +27 -0
  47. package/nitrogen/generated/shared/json/NitroInputViewConfig.json +8 -0
  48. package/package.json +2 -2
  49. package/src/NitroInput.tsx +190 -11
  50. package/src/index.ts +3 -0
  51. package/src/specs/NitroInput.nitro.ts +68 -0
@@ -14,6 +14,12 @@
14
14
  "maskNotations": true,
15
15
  "maskAutocomplete": true,
16
16
  "maskAutoSkip": true,
17
+ "maskAffinityFormats": true,
18
+ "maskAffinityStrategy": true,
19
+ "maskTextCase": true,
20
+ "maskCharacterMap": true,
21
+ "maskSlotPlaceholder": true,
22
+ "keepPlaceholder": true,
17
23
  "groupingSeparator": true,
18
24
  "decimalSeparator": true,
19
25
  "variant": true,
@@ -79,6 +85,8 @@
79
85
  "showSoftInputOnFocus": true,
80
86
  "selectTextOnFocus": true,
81
87
  "clearTextOnFocus": true,
88
+ "keyboardHandoffMs": true,
89
+ "returnKeyBar": true,
82
90
  "contextMenuHidden": true,
83
91
  "spellCheck": true,
84
92
  "selectionStart": true,
@@ -103,8 +103,24 @@ function reactTagOf(host) {
103
103
  return typeof tag === 'number' ? tag : 0;
104
104
  }
105
105
  const EMPTY_NOTATIONS = [];
106
+ const EMPTY_STRINGS = [];
107
+ const EMPTY_MAPPINGS = [];
106
108
  /** Mounted fields, by the host instance React Native's registry stores. */
107
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();
108
124
  let patchedRegistry = false;
109
125
  /**
110
126
  * `TextInputState.focusTextInput` / `blurTextInput` — which is how
@@ -142,7 +158,13 @@ function patchRegistryOnce() {
142
158
  const field = input != null ? mountedFields.get(input) : undefined;
143
159
  if (field)
144
160
  return field.blur();
145
- 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;
146
168
  };
147
169
  }
148
170
  }
@@ -176,8 +198,28 @@ function warnIncompatible(what) {
176
198
  * Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
177
199
  * it to its content instead, and is on by default when the text reflows.
178
200
  */
179
- 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, 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) {
180
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
+ }, []);
181
223
  // What React Native's registry stores for this field. The React host
182
224
  // instance when there is one (iOS), otherwise a stable per-instance token:
183
225
  // on Android the Nitro host component hands out no instance, and the
@@ -243,9 +285,9 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
243
285
  const [, setEventCountState] = (0, react_1.useState)(0);
244
286
  const controlledRef = (0, react_1.useRef)(value != null);
245
287
  controlledRef.current = value != null;
246
- // The initial text of an uncontrolled field never changes afterwards, so
247
- // native applies it exactly once.
248
- 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 ?? '');
249
291
  // Nitro callbacks must be wrapped with `callback()` and the wrapper object
250
292
  // has to be referentially stable, otherwise every render re-sets the prop.
251
293
  // Handlers are read through a ref so inline arrows don't re-set them either.
@@ -254,30 +296,70 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
254
296
  // does, as React Native queues a `TextInput`'s view commands. Without this
255
297
  // the common `useEffect(() => ref.current?.focus(), [])` was a silent no-op.
256
298
  const pendingCommands = (0, react_1.useRef)([]);
299
+ const [owner] = (0, react_1.useState)(() => ({}));
257
300
  const hybridRef = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((instance) => {
258
301
  nativeRef.current = instance;
302
+ viewOwner.set(instance, owner);
259
303
  const queued = pendingCommands.current;
260
304
  pendingCommands.current = [];
261
305
  for (const command of queued)
262
306
  command(instance);
263
307
  latest.current.onNativeRef?.(instance);
264
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
+ }, []);
265
344
  (0, react_1.useEffect)(() => {
266
345
  if (textInputRegistry == null)
267
346
  return;
268
347
  const key = hostRef.current ?? { nitroInput: true };
269
348
  registryKeyRef.current = key;
270
349
  patchRegistryOnce();
271
- mountedFields.set(key, {
350
+ const field = {
272
351
  focus: () => nativeRef.current?.focus(),
273
352
  blur: () => nativeRef.current?.blur(),
274
- });
353
+ };
354
+ mountedFields.set(key, field);
355
+ liveFields.add(field);
275
356
  textInputRegistry.registerInput(key);
276
357
  return () => {
277
358
  if (textInputRegistry.currentlyFocusedInput() === key)
278
359
  textInputRegistry.blurInput(key);
279
360
  textInputRegistry.unregisterInput(key);
280
361
  mountedFields.delete(key);
362
+ liveFields.delete(field);
281
363
  registryKeyRef.current = null;
282
364
  };
283
365
  }, []);
@@ -410,9 +492,13 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
410
492
  else
411
493
  pendingCommands.current.push(command);
412
494
  };
495
+ const unlessHidden = (command) => {
496
+ if (!hiddenRef.current)
497
+ send(command);
498
+ };
413
499
  return {
414
- focus: () => send((native) => native.focus()),
415
- blur: () => send((native) => native.blur()),
500
+ focus: () => unlessHidden((native) => native.focus()),
501
+ blur: () => unlessHidden((native) => native.blur()),
416
502
  clear: () => send((native) => native.clear()),
417
503
  setText: (text) => send((native) => native.replaceText(text)),
418
504
  setValue: (next) => send((native) => native.setValue(next)),
@@ -424,10 +510,11 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
424
510
  // actually holds first responder. Before it attaches, fall back to the
425
511
  // registry this field already keeps up to date, which is the same place
426
512
  // `TextInput.isFocused()` reads from.
427
- isFocused: () => nativeRef.current?.isFocused() ??
428
- (registryKeyRef.current != null &&
429
- textInputRegistry?.currentlyFocusedInput() === registryKeyRef.current),
430
- 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)),
431
518
  get native() {
432
519
  return nativeRef.current;
433
520
  },
@@ -484,6 +571,17 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
484
571
  const stableNotations = (0, react_1.useMemo)(() => (notationsKey !== '' && maskNotations ? [...maskNotations] : EMPTY_NOTATIONS),
485
572
  // eslint-disable-next-line react-hooks/exhaustive-deps
486
573
  [notationsKey]);
574
+ // The same for the affinity formats and the character map.
575
+ const affinityKey = maskAffinityFormats != null && maskAffinityFormats.length > 0 ? JSON.stringify(maskAffinityFormats) : '';
576
+ const stableAffinityFormats = (0, react_1.useMemo)(() => (affinityKey !== '' && maskAffinityFormats ? [...maskAffinityFormats] : EMPTY_STRINGS),
577
+ // eslint-disable-next-line react-hooks/exhaustive-deps
578
+ [affinityKey]);
579
+ const characterMapKey = maskCharacterMap != null && Object.keys(maskCharacterMap).length > 0 ? JSON.stringify(maskCharacterMap) : '';
580
+ const stableCharacterMap = (0, react_1.useMemo)(() => characterMapKey !== '' && maskCharacterMap
581
+ ? Object.entries(maskCharacterMap).map(([from, to]) => ({ from, to }))
582
+ : EMPTY_MAPPINGS,
583
+ // eslint-disable-next-line react-hooks/exhaustive-deps
584
+ [characterMapKey]);
487
585
  const resolvedFractionDigits = fractionDigits ?? derived?.fractionDigits ?? 2;
488
586
  const resolvedKeyboardType = keyboardType ??
489
587
  (inputMode != null
@@ -546,7 +644,10 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
546
644
  ? { width: size.width, height: size.height }
547
645
  : { height: size.height }
548
646
  : { height: resolvedFontSize * 1.25 }, [size, resolvedFontSize, autoWidth]);
549
- 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, 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 ??
550
651
  // As `TextInput` resolves the legacy `blurOnSubmit`: a multiline
551
652
  // field's return key inserts a line break unless told to blur.
552
653
  (multiline
@@ -555,7 +656,7 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
555
656
  : 'newline'
556
657
  : blurOnSubmit === false
557
658
  ? 'submit'
558
- : '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 }));
559
660
  });
560
661
  // The name DevTools and error stacks show, as `TextInput` names itself.
561
662
  exports.NitroInput.displayName = 'NitroInput';
@@ -14,6 +14,12 @@
14
14
  "maskNotations": true,
15
15
  "maskAutocomplete": true,
16
16
  "maskAutoSkip": true,
17
+ "maskAffinityFormats": true,
18
+ "maskAffinityStrategy": true,
19
+ "maskTextCase": true,
20
+ "maskCharacterMap": true,
21
+ "maskSlotPlaceholder": true,
22
+ "keepPlaceholder": true,
17
23
  "groupingSeparator": true,
18
24
  "decimalSeparator": true,
19
25
  "variant": true,
@@ -79,6 +85,8 @@
79
85
  "showSoftInputOnFocus": true,
80
86
  "selectTextOnFocus": true,
81
87
  "clearTextOnFocus": true,
88
+ "keyboardHandoffMs": true,
89
+ "returnKeyBar": true,
82
90
  "contextMenuHidden": true,
83
91
  "spellCheck": true,
84
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';
@@ -64,8 +64,24 @@ function reactTagOf(host) {
64
64
  return typeof tag === 'number' ? tag : 0;
65
65
  }
66
66
  const EMPTY_NOTATIONS = [];
67
+ const EMPTY_STRINGS = [];
68
+ const EMPTY_MAPPINGS = [];
67
69
  /** Mounted fields, by the host instance React Native's registry stores. */
68
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();
69
85
  let patchedRegistry = false;
70
86
  /**
71
87
  * `TextInputState.focusTextInput` / `blurTextInput` — which is how
@@ -103,7 +119,13 @@ function patchRegistryOnce() {
103
119
  const field = input != null ? mountedFields.get(input) : undefined;
104
120
  if (field)
105
121
  return field.blur();
106
- 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;
107
129
  };
108
130
  }
109
131
  }
@@ -137,8 +159,28 @@ function warnIncompatible(what) {
137
159
  * Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
138
160
  * it to its content instead, and is on by default when the text reflows.
139
161
  */
140
- 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, 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) {
141
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
+ }, []);
142
184
  // What React Native's registry stores for this field. The React host
143
185
  // instance when there is one (iOS), otherwise a stable per-instance token:
144
186
  // on Android the Nitro host component hands out no instance, and the
@@ -204,9 +246,9 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
204
246
  const [, setEventCountState] = useState(0);
205
247
  const controlledRef = useRef(value != null);
206
248
  controlledRef.current = value != null;
207
- // The initial text of an uncontrolled field never changes afterwards, so
208
- // native applies it exactly once.
209
- 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 ?? '');
210
252
  // Nitro callbacks must be wrapped with `callback()` and the wrapper object
211
253
  // has to be referentially stable, otherwise every render re-sets the prop.
212
254
  // Handlers are read through a ref so inline arrows don't re-set them either.
@@ -215,30 +257,70 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
215
257
  // does, as React Native queues a `TextInput`'s view commands. Without this
216
258
  // the common `useEffect(() => ref.current?.focus(), [])` was a silent no-op.
217
259
  const pendingCommands = useRef([]);
260
+ const [owner] = useState(() => ({}));
218
261
  const hybridRef = useMemo(() => callback((instance) => {
219
262
  nativeRef.current = instance;
263
+ viewOwner.set(instance, owner);
220
264
  const queued = pendingCommands.current;
221
265
  pendingCommands.current = [];
222
266
  for (const command of queued)
223
267
  command(instance);
224
268
  latest.current.onNativeRef?.(instance);
225
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
+ }, []);
226
305
  useEffect(() => {
227
306
  if (textInputRegistry == null)
228
307
  return;
229
308
  const key = hostRef.current ?? { nitroInput: true };
230
309
  registryKeyRef.current = key;
231
310
  patchRegistryOnce();
232
- mountedFields.set(key, {
311
+ const field = {
233
312
  focus: () => nativeRef.current?.focus(),
234
313
  blur: () => nativeRef.current?.blur(),
235
- });
314
+ };
315
+ mountedFields.set(key, field);
316
+ liveFields.add(field);
236
317
  textInputRegistry.registerInput(key);
237
318
  return () => {
238
319
  if (textInputRegistry.currentlyFocusedInput() === key)
239
320
  textInputRegistry.blurInput(key);
240
321
  textInputRegistry.unregisterInput(key);
241
322
  mountedFields.delete(key);
323
+ liveFields.delete(field);
242
324
  registryKeyRef.current = null;
243
325
  };
244
326
  }, []);
@@ -371,9 +453,13 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
371
453
  else
372
454
  pendingCommands.current.push(command);
373
455
  };
456
+ const unlessHidden = (command) => {
457
+ if (!hiddenRef.current)
458
+ send(command);
459
+ };
374
460
  return {
375
- focus: () => send((native) => native.focus()),
376
- blur: () => send((native) => native.blur()),
461
+ focus: () => unlessHidden((native) => native.focus()),
462
+ blur: () => unlessHidden((native) => native.blur()),
377
463
  clear: () => send((native) => native.clear()),
378
464
  setText: (text) => send((native) => native.replaceText(text)),
379
465
  setValue: (next) => send((native) => native.setValue(next)),
@@ -385,10 +471,11 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
385
471
  // actually holds first responder. Before it attaches, fall back to the
386
472
  // registry this field already keeps up to date, which is the same place
387
473
  // `TextInput.isFocused()` reads from.
388
- isFocused: () => nativeRef.current?.isFocused() ??
389
- (registryKeyRef.current != null &&
390
- textInputRegistry?.currentlyFocusedInput() === registryKeyRef.current),
391
- 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)),
392
479
  get native() {
393
480
  return nativeRef.current;
394
481
  },
@@ -445,6 +532,17 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
445
532
  const stableNotations = useMemo(() => (notationsKey !== '' && maskNotations ? [...maskNotations] : EMPTY_NOTATIONS),
446
533
  // eslint-disable-next-line react-hooks/exhaustive-deps
447
534
  [notationsKey]);
535
+ // The same for the affinity formats and the character map.
536
+ const affinityKey = maskAffinityFormats != null && maskAffinityFormats.length > 0 ? JSON.stringify(maskAffinityFormats) : '';
537
+ const stableAffinityFormats = useMemo(() => (affinityKey !== '' && maskAffinityFormats ? [...maskAffinityFormats] : EMPTY_STRINGS),
538
+ // eslint-disable-next-line react-hooks/exhaustive-deps
539
+ [affinityKey]);
540
+ const characterMapKey = maskCharacterMap != null && Object.keys(maskCharacterMap).length > 0 ? JSON.stringify(maskCharacterMap) : '';
541
+ const stableCharacterMap = useMemo(() => characterMapKey !== '' && maskCharacterMap
542
+ ? Object.entries(maskCharacterMap).map(([from, to]) => ({ from, to }))
543
+ : EMPTY_MAPPINGS,
544
+ // eslint-disable-next-line react-hooks/exhaustive-deps
545
+ [characterMapKey]);
448
546
  const resolvedFractionDigits = fractionDigits ?? derived?.fractionDigits ?? 2;
449
547
  const resolvedKeyboardType = keyboardType ??
450
548
  (inputMode != null
@@ -507,7 +605,10 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
507
605
  ? { width: size.width, height: size.height }
508
606
  : { height: size.height }
509
607
  : { height: resolvedFontSize * 1.25 }, [size, resolvedFontSize, autoWidth]);
510
- 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, 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 ??
511
612
  // As `TextInput` resolves the legacy `blurOnSubmit`: a multiline
512
613
  // field's return key inserts a line break unless told to blur.
513
614
  (multiline
@@ -516,7 +617,7 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
516
617
  : 'newline'
517
618
  : blurOnSubmit === false
518
619
  ? 'submit'
519
- : '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 }));
520
621
  });
521
622
  // The name DevTools and error stacks show, as `TextInput` names itself.
522
623
  NitroInput.displayName = 'NitroInput';
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { type ColorValue, type TextStyle, type ViewProps } from 'react-native';
3
3
  import { type HybridRef } from 'react-native-nitro-modules';
4
- import type { NitroInputAffixAlign, NitroInputAutoCapitalize, NitroInputEasing, NitroInputEffect, NitroInputKeyboardAppearance, NitroInputKeyboardType, NitroInputLabelBehavior, NitroInputMethods, NitroInputMode, NitroInputProps as NativeNitroInputProps, NitroInputReturnKeyType, NitroInputSubmitBehavior, NitroInputTextAlign, NitroInputTextAlignVertical, NitroInputSignPlacement, NitroInputVariant, NitroInputNotation } from './specs/NitroInput.nitro';
4
+ import type { NitroInputAffixAlign, NitroInputAutoCapitalize, NitroInputEasing, NitroInputEffect, NitroInputKeyboardAppearance, NitroInputKeyboardType, NitroInputLabelBehavior, NitroInputMethods, NitroInputMode, NitroInputProps as NativeNitroInputProps, NitroInputReturnKeyType, NitroInputSubmitBehavior, NitroInputTextAlign, NitroInputTextAlignVertical, NitroInputSignPlacement, NitroInputVariant, NitroInputNotation, NitroInputMaskAffinity, NitroInputTextCase } from './specs/NitroInput.nitro';
5
5
  import { type NitroInputSelection, type NitroInputTransform } from './worklets';
6
6
  import type { NumberFormat } from './NumberFormat';
7
7
  /** React Native's `inputMode`, the HTML-aligned alias for `keyboardType`. */
@@ -136,6 +136,44 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
136
136
  maskAutocomplete?: boolean;
137
137
  /** `'mask'`: backspace walks back over autocompleted constants. Default: `false`. */
138
138
  maskAutoSkip?: boolean;
139
+ /**
140
+ * `'mask'`: more patterns the text may take, e.g. a 4-6-5 Amex card beside
141
+ * a 4-4-4-4 `mask`: `['{34}[00] [000000] [00000]', '{37}[00] [000000] [00000]']`.
142
+ * Every edit is masked with each and the best, by `maskAffinityStrategy`, is
143
+ * kept; `mask` wins ties.
144
+ */
145
+ maskAffinityFormats?: string[];
146
+ /**
147
+ * `'mask'`: how the best of `maskAffinityFormats` is chosen. `'wholeString'`
148
+ * the format that accepts the most characters and inserts the fewest,
149
+ * `'prefix'` the one whose output starts most like what was typed,
150
+ * `'capacity'` / `'extractedValueCapacity'` the fullest format that still
151
+ * holds all of the text / all of its value characters. Default: `'wholeString'`.
152
+ */
153
+ maskAffinityStrategy?: NitroInputMaskAffinity;
154
+ /** `'mask'`: uppercases or lowercases letters as they are typed or pasted. Default: `'none'`. */
155
+ maskTextCase?: NitroInputTextCase;
156
+ /**
157
+ * `'mask'`: characters replaced before masking, one character each:
158
+ * `{ 'С': 'C' }` turns a Cyrillic look-alike into a Latin letter,
159
+ * `{ ',': '.' }` lets a comma through to a dot-decimal mask. An empty
160
+ * replacement drops the character.
161
+ */
162
+ maskCharacterMap?: Record<string, string>;
163
+ /**
164
+ * `'mask'`: the character each empty slot shows in the kept placeholder and
165
+ * in `onChangeMask`'s tail. Default: `'_'` with `keepPlaceholder`, otherwise
166
+ * the slot's own notation character.
167
+ */
168
+ maskSlotPlaceholder?: string;
169
+ /**
170
+ * `'mask'`: keeps the rest of the placeholder visible after what has been
171
+ * typed: with `placeholder="1234 5678 9012"`, typing "12345" shows
172
+ * "1234 5" and then "678 9012" greyed. Without a `placeholder` the mask
173
+ * itself is shown, its empty slots as `maskSlotPlaceholder`:
174
+ * `+1 (212) ___-____`. Default: `false`.
175
+ */
176
+ keepPlaceholder?: boolean;
139
177
  /**
140
178
  * `'mask'` mode: called whenever the text changes, from a keystroke,
141
179
  * `setText` / `clear` or the `value` prop alike, with the masked text, the
@@ -316,6 +354,22 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
316
354
  selectTextOnFocus?: boolean;
317
355
  /** Empty the field when it gains focus. Default: `false`. */
318
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;
319
373
  /** Hides the Cut/Copy/Paste menu. Default: `false`. */
320
374
  contextMenuHidden?: boolean;
321
375
  /** Spell checking in `'text'` mode. Defaults to `autoCorrect`. */
@@ -1,7 +1,7 @@
1
1
  export { NitroInput, NativeNitroInputView, type NitroInputProps, type NitroInputHandle, type NitroInputRef, type NitroInputTextEvent, type NitroInputFocusEvent, type NitroInputSelectionEvent, type NitroInputKeyPressEvent, type NitroInputTransition, type InputMode, type EnterKeyHint, } from './NitroInput';
2
2
  export { isWorklet, type NitroInputSelection, type NitroInputTransform, type WorkletTextEvent, type WorkletFocusEvent, type WorkletSelectionEvent, type WorkletKeyPressEvent, } from './worklets';
3
3
  export { useNitroInputState, type NitroInputState, type SharedValueLike, } from './useNitroInputState';
4
- export type { NitroInputLabelBehavior, NitroInputMode, NitroInputNotation, NitroInputVariant, NitroInputEasing, NitroInputEffect, NitroInputTextAlign, NitroInputTextAlignVertical, NitroInputAffixAlign, NitroInputSignPlacement, NitroInputKeyboardType, NitroInputReturnKeyType, NitroInputAutoCapitalize, NitroInputSubmitBehavior, NitroInputKeyboardAppearance, NitroInputMethods, NitroInputProps as NativeNitroInputProps, NitroInputView, } from './specs/NitroInput.nitro';
4
+ export type { NitroInputLabelBehavior, NitroInputMode, NitroInputNotation, NitroInputMaskAffinity, NitroInputTextCase, NitroInputCharacterMapping, NitroInputVariant, NitroInputEasing, NitroInputEffect, NitroInputTextAlign, NitroInputTextAlignVertical, NitroInputAffixAlign, NitroInputSignPlacement, NitroInputKeyboardType, NitroInputReturnKeyType, NitroInputAutoCapitalize, NitroInputSubmitBehavior, NitroInputKeyboardAppearance, NitroInputMethods, NitroInputProps as NativeNitroInputProps, NitroInputView, } from './specs/NitroInput.nitro';
5
5
  export type { NitroInputWorklets } from './specs/NitroInputWorklets.nitro';
6
6
  export { NitroNumber, NativeNitroNumberView, type NitroNumberProps, type NitroNumberHandle, type NitroNumberRef, } from './NitroNumber';
7
7
  export { NitroTime, type NitroTimeProps, type NitroTimeFormat } from './NitroTime';