react-native-nitro-input 0.3.8 → 0.4.1

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 (108) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/README.md +6 -1
  3. package/android/src/main/java/com/margelo/nitro/nitroinput/DigitSlots.kt +143 -0
  4. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputMeasure.kt +52 -0
  5. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +80 -80
  6. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +18 -18
  7. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextView.kt +14 -14
  8. package/android/src/main/java/com/margelo/nitro/nitroinput/InputFonts.kt +244 -0
  9. package/android/src/main/java/com/margelo/nitro/nitroinput/InputSizing.kt +404 -0
  10. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +168 -338
  11. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +178 -30
  12. package/ios/HybridNitroInputView.swift +73 -75
  13. package/ios/HybridNitroNumberView.swift +18 -18
  14. package/ios/HybridNitroTextView.swift +14 -14
  15. package/ios/InputSizing.swift +628 -0
  16. package/ios/NitroInputView.swift +180 -209
  17. package/ios/NitroNumberView.swift +98 -23
  18. package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +14 -8
  19. package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
  20. package/lib/commonjs/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
  21. package/lib/commonjs/src/NitroInput.js +166 -23
  22. package/lib/commonjs/src/NitroNumber.js +1 -1
  23. package/lib/commonjs/src/NitroText.js +6 -6
  24. package/lib/commonjs/src/specs/NitroInputMeasure.nitro.js +2 -0
  25. package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +14 -8
  26. package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
  27. package/lib/module/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
  28. package/lib/module/src/NitroInput.js +167 -24
  29. package/lib/module/src/NitroNumber.js +1 -1
  30. package/lib/module/src/NitroText.js +6 -6
  31. package/lib/module/src/specs/NitroInputMeasure.nitro.js +1 -0
  32. package/lib/typescript/src/NitroInput.d.ts +20 -16
  33. package/lib/typescript/src/specs/NitroInput.nitro.d.ts +21 -8
  34. package/lib/typescript/src/specs/NitroInputMeasure.nitro.d.ts +69 -0
  35. package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +6 -6
  36. package/lib/typescript/src/specs/NitroText.nitro.d.ts +6 -6
  37. package/nitro.json +10 -0
  38. package/nitrogen/generated/android/NitroInput+autolinking.cmake +2 -0
  39. package/nitrogen/generated/android/NitroInputOnLoad.cpp +16 -0
  40. package/nitrogen/generated/android/c++/JHybridNitroInputMeasureSpec.cpp +93 -0
  41. package/nitrogen/generated/android/c++/JHybridNitroInputMeasureSpec.hpp +63 -0
  42. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +94 -40
  43. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +28 -16
  44. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +30 -30
  45. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +12 -12
  46. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.cpp +30 -30
  47. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.hpp +12 -12
  48. package/nitrogen/generated/android/c++/JNitroInputSize.hpp +61 -0
  49. package/nitrogen/generated/android/c++/JNitroInputSizing.hpp +292 -0
  50. package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +54 -24
  51. package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +18 -18
  52. package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.cpp +18 -18
  53. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputMeasureSpec.kt +56 -0
  54. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +44 -8
  55. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +6 -6
  56. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextViewSpec.kt +6 -6
  57. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSize.kt +56 -0
  58. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSizing.kt +256 -0
  59. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +17 -0
  60. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +29 -0
  61. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +11 -0
  62. package/nitrogen/generated/ios/NitroInputAutolinking.mm +8 -0
  63. package/nitrogen/generated/ios/NitroInputAutolinking.swift +12 -0
  64. package/nitrogen/generated/ios/c++/HybridNitroInputMeasureSpecSwift.cpp +11 -0
  65. package/nitrogen/generated/ios/c++/HybridNitroInputMeasureSpecSwift.hpp +112 -0
  66. package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +68 -32
  67. package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +24 -24
  68. package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.hpp +24 -24
  69. package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +68 -32
  70. package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +24 -24
  71. package/nitrogen/generated/ios/c++/views/HybridNitroTextViewComponent.mm +24 -24
  72. package/nitrogen/generated/ios/swift/HybridNitroInputMeasureSpec.swift +55 -0
  73. package/nitrogen/generated/ios/swift/HybridNitroInputMeasureSpec_cxx.swift +138 -0
  74. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +14 -8
  75. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +90 -24
  76. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +6 -6
  77. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +18 -18
  78. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec.swift +6 -6
  79. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec_cxx.swift +18 -18
  80. package/nitrogen/generated/ios/swift/NitroInputSize.swift +34 -0
  81. package/nitrogen/generated/ios/swift/NitroInputSizing.swift +252 -0
  82. package/nitrogen/generated/shared/c++/HybridNitroInputMeasureSpec.cpp +21 -0
  83. package/nitrogen/generated/shared/c++/HybridNitroInputMeasureSpec.hpp +66 -0
  84. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +28 -16
  85. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +28 -16
  86. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +12 -12
  87. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +12 -12
  88. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.cpp +12 -12
  89. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.hpp +12 -12
  90. package/nitrogen/generated/shared/c++/NitroInputSize.hpp +87 -0
  91. package/nitrogen/generated/shared/c++/NitroInputSizing.hpp +271 -0
  92. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +28 -16
  93. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +42 -24
  94. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +12 -12
  95. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +18 -18
  96. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.cpp +12 -12
  97. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.hpp +18 -18
  98. package/nitrogen/generated/shared/json/NitroInputViewConfig.json +14 -8
  99. package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
  100. package/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
  101. package/package.json +4 -2
  102. package/src/NitroInput.tsx +215 -64
  103. package/src/NitroNumber.tsx +6 -6
  104. package/src/NitroText.tsx +6 -6
  105. package/src/specs/NitroInput.nitro.ts +21 -8
  106. package/src/specs/NitroInputMeasure.nitro.ts +78 -0
  107. package/src/specs/NitroNumber.nitro.ts +6 -6
  108. package/src/specs/NitroText.nitro.ts +6 -6
@@ -40,7 +40,9 @@
40
40
  "signPlacement": true,
41
41
  "prefixAlign": true,
42
42
  "suffixAlign": true,
43
- "letterSpacing": true,
43
+ "textLetterSpacing": true,
44
+ "tabularNums": true,
45
+ "slotDigits": true,
44
46
  "prefixSpacing": true,
45
47
  "suffixSpacing": true,
46
48
  "prefixOffset": true,
@@ -51,12 +53,12 @@
51
53
  "easing": true,
52
54
  "bounce": true,
53
55
  "effect": true,
54
- "fontSize": true,
55
- "lineHeight": true,
56
- "fontWeight": true,
57
- "fontFamily": true,
58
- "color": true,
59
- "textAlign": true,
56
+ "textSize": true,
57
+ "textLineHeight": true,
58
+ "textWeight": true,
59
+ "textFamily": true,
60
+ "textColor": true,
61
+ "textAlignment": true,
60
62
  "rightToLeft": true,
61
63
  "caretColor": true,
62
64
  "selectionColor": true,
@@ -72,7 +74,11 @@
72
74
  "editable": true,
73
75
  "multiline": true,
74
76
  "numberOfLines": true,
75
- "textAlignVertical": true,
77
+ "textVerticalAlignment": true,
78
+ "textInsetLeft": true,
79
+ "textInsetTop": true,
80
+ "textInsetRight": true,
81
+ "textInsetBottom": true,
76
82
  "scrollEnabled": true,
77
83
  "autoFocus": true,
78
84
  "fieldTestID": true,
@@ -37,13 +37,13 @@
37
37
  "shimmerBaseColor": true,
38
38
  "shimmerDirection": true,
39
39
  "shimmerDelay": true,
40
- "fontSize": true,
40
+ "textSize": true,
41
41
  "prefixFontSize": true,
42
42
  "suffixFontSize": true,
43
43
  "affixAlign": true,
44
44
  "prefixAlign": true,
45
45
  "suffixAlign": true,
46
- "letterSpacing": true,
46
+ "textLetterSpacing": true,
47
47
  "prefixSpacing": true,
48
48
  "suffixSpacing": true,
49
49
  "prefixOffset": true,
@@ -66,10 +66,10 @@
66
66
  "minimumFontScale": true,
67
67
  "allowFontScaling": true,
68
68
  "maxFontSizeMultiplier": true,
69
- "fontWeight": true,
70
- "fontFamily": true,
71
- "color": true,
72
- "textAlign": true,
69
+ "textWeight": true,
70
+ "textFamily": true,
71
+ "textColor": true,
72
+ "textAlignment": true,
73
73
  "rightToLeft": true,
74
74
  "onSizeChange": true,
75
75
  "onRevealEnd": true,
@@ -5,12 +5,12 @@
5
5
  "directEventTypes": {},
6
6
  "validAttributes": {
7
7
  "text": true,
8
- "fontSize": true,
9
- "fontWeight": true,
10
- "fontFamily": true,
11
- "color": true,
12
- "letterSpacing": true,
13
- "textAlign": true,
8
+ "textSize": true,
9
+ "textWeight": true,
10
+ "textFamily": true,
11
+ "textColor": true,
12
+ "textLetterSpacing": true,
13
+ "textAlignment": true,
14
14
  "rightToLeft": true,
15
15
  "duration": true,
16
16
  "easing": true,
@@ -1,6 +1,6 @@
1
1
  import React, { forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, } from 'react';
2
2
  import { I18nManager, StyleSheet, } from 'react-native';
3
- import { callback, getHostComponent, } from 'react-native-nitro-modules';
3
+ import { callback, getHostComponent, NitroModules, } from 'react-native-nitro-modules';
4
4
  import NitroInputViewConfig from '../nitrogen/generated/shared/json/NitroInputViewConfig.json';
5
5
  import { allocateWorkletId, isWorklet, registerFocusChange, registerKeyPress, registerSelectionChange, registerTextEvent, registerCallback, registerTransform, unregisterWorklet, } from './worklets';
6
6
  import { toNumericWeight, toProcessedColor } from './styleHelpers';
@@ -145,21 +145,75 @@ function warnIncompatible(what) {
145
145
  'field is drawn by the system view, and an amount, a mask and their ' +
146
146
  'affixes are single-line. Drop one of the two.');
147
147
  }
148
+ const NO_INSETS = { left: 0, top: 0, right: 0, bottom: 0 };
148
149
  /**
149
- * A native text input: a system field (`UITextField` / `EditText`) that owns
150
- * the keyboard, editing, selection, paste and accessibility, with native
151
- * formatting (`mode="number"`), native masking (`mode="mask"`), an outlined
152
- * or filled frame with a floating label, and optionally the glyph engine
153
- * (`transition="reflow"`), under which characters that stay glide to their new place, new
154
- * ones slide or fade in and removed ones leave alongside their neighbours.
155
- * In `'number'` mode every edit is formatted on the native side before a
156
- * frame is drawn, with the caret kept in place, so there is never an
157
- * unformatted frame and never a round trip through JS.
158
- *
159
- * Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
160
- * it to its content instead, and is on by default when the text reflows.
150
+ * The style's padding plus border per edge, resolved the way Yoga does: a
151
+ * start / end edge before left / right, then horizontal / vertical, then all.
152
+ * A size measured for the text gets them added, as `TextInput`'s is, so a
153
+ * padded field grows rather than squeezing its text. Percentages are not
154
+ * resolved here (they need the parent's size) and count as 0.
161
155
  */
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, focusedValue, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
156
+ function styleInsets(flat, rightToLeft) {
157
+ if (flat == null)
158
+ return NO_INSETS;
159
+ const n = (key) => {
160
+ const value = flat[key];
161
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
162
+ };
163
+ const start = rightToLeft ? 'End' : 'Start';
164
+ const end = rightToLeft ? 'Start' : 'End';
165
+ const insets = {
166
+ left: (n(`padding${start}`) ?? n('paddingLeft') ?? n('paddingHorizontal') ?? n('padding') ?? 0) +
167
+ (n(`border${start}Width`) ?? n('borderLeftWidth') ?? n('borderWidth') ?? 0),
168
+ right: (n(`padding${end}`) ?? n('paddingRight') ?? n('paddingHorizontal') ?? n('padding') ?? 0) +
169
+ (n(`border${end}Width`) ?? n('borderRightWidth') ?? n('borderWidth') ?? 0),
170
+ top: (n('paddingTop') ?? n('paddingVertical') ?? n('padding') ?? 0) + (n('borderTopWidth') ?? n('borderWidth') ?? 0),
171
+ bottom: (n('paddingBottom') ?? n('paddingVertical') ?? n('padding') ?? 0) +
172
+ (n('borderBottomWidth') ?? n('borderWidth') ?? 0),
173
+ };
174
+ return insets.left === 0 && insets.right === 0 && insets.top === 0 && insets.bottom === 0 ? NO_INSETS : insets;
175
+ }
176
+ function styleTextAlign(value, rightToLeft) {
177
+ switch (value) {
178
+ case undefined:
179
+ return undefined;
180
+ // `justify` has no meaning on one line: the start edge, as on a TextInput.
181
+ case 'start':
182
+ case 'justify':
183
+ return 'auto';
184
+ case 'end':
185
+ return rightToLeft ? 'left' : 'right';
186
+ default:
187
+ return value;
188
+ }
189
+ }
190
+ function styleTextAlignVertical(value) {
191
+ return value ?? undefined;
192
+ }
193
+ // One per app, made on first use. `null` when the native side has none (an
194
+ // app built against an older version, or a test without native modules): the
195
+ // field then takes its size from the view's first report, as it used to.
196
+ let measurer;
197
+ function measureSizing(sizing) {
198
+ if (measurer === undefined) {
199
+ try {
200
+ const made = NitroModules.createHybridObject('NitroInputMeasure');
201
+ measurer = typeof made?.measure === 'function' ? made : null;
202
+ }
203
+ catch {
204
+ measurer = null;
205
+ }
206
+ }
207
+ if (measurer === null)
208
+ return null;
209
+ try {
210
+ return measurer.measure(sizing);
211
+ }
212
+ catch {
213
+ return null;
214
+ }
215
+ }
216
+ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, letterSpacing: letterSpacingProp, tabularNums, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, format, placeholder, placeholderTextColor, duration, easing, bounce, effect, fontSize: fontSizeProp, lineHeight: lineHeightProp, fontWeight: fontWeightProp, fontFamily: fontFamilyProp, color: colorProp, textAlign: textAlignProp, 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: textAlignVerticalProp, 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, focusedValue, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
163
217
  const nativeRef = useRef(null);
164
218
  // `keyboardHandoffMs`: hand the keyboard off while this field still has it.
165
219
  // A layout-effect cleanup runs in React's commit, so the native call is
@@ -222,6 +276,11 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
222
276
  if (value != null)
223
277
  textRef.current = value;
224
278
  const [size, setSize] = useState(null);
279
+ // The size measured before the view existed (see `measureSizing`), and
280
+ // whether the view has reported its own since.
281
+ const seedRef = useRef(null);
282
+ const seedKeyRef = useRef('');
283
+ const reportedRef = useRef(false);
225
284
  // Worklets are registered on the UI runtime and referenced by id; a
226
285
  // handler marked 'worklet' runs there instead of on the JS thread.
227
286
  const transformId = useWorkletId(transform, registerTransform);
@@ -327,11 +386,24 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
327
386
  // A field with a width of its own (the usual case) never needs a React
328
387
  // commit per keystroke: only the height (font-dependent) is taken from native.
329
388
  const flat = useMemo(() => StyleSheet.flatten(style), [style]);
389
+ // `TextInput` takes its typography from `style`; so does this, under the
390
+ // props of the same name, which win. (Fabric hands a view its style's keys
391
+ // as props too; the view's own are named so that none can be one of them -
392
+ // see PropNameCollisions.test.)
393
+ const fontSize = fontSizeProp ?? flat?.fontSize;
394
+ const lineHeight = lineHeightProp ?? flat?.lineHeight;
395
+ const fontWeight = fontWeightProp ?? flat?.fontWeight;
396
+ const fontFamily = fontFamilyProp ?? flat?.fontFamily;
397
+ const color = colorProp ?? flat?.color;
398
+ const letterSpacing = letterSpacingProp ?? flat?.letterSpacing;
399
+ const textAlignVertical = textAlignVerticalProp ?? styleTextAlignVertical(flat?.textAlignVertical);
330
400
  // The layout direction, resolved the way React Native resolves it for its
331
401
  // own views: the field's `style.direction` if it says, else the app's.
332
402
  // Fabric does not hand a Hybrid View its resolved direction, so native is
333
403
  // told outright.
334
404
  const rightToLeft = flat?.direction === 'rtl' || (flat?.direction !== 'ltr' && I18nManager.isRTL);
405
+ const textAlign = textAlignProp ?? styleTextAlign(flat?.textAlign, rightToLeft);
406
+ const insets = useMemo(() => styleInsets(flat, rightToLeft), [flat, rightToLeft]);
335
407
  // `TextInput` stretches to its parent; sizing to content is this
336
408
  // component's own behaviour, and it is what stops it being a drop-in.
337
409
  // `NitroInput` turns it off so flexbox gives it the parent's width, the
@@ -349,13 +421,17 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
349
421
  const measuredRef = useRef(measured);
350
422
  measuredRef.current = measured;
351
423
  const onSizeChange = useMemo(() => callback((width, height) => {
424
+ reportedRef.current = true;
352
425
  if (!measuredRef.current)
353
426
  return;
354
427
  setSize((previous) => {
428
+ // Until the first report the field shows the seed; a report that
429
+ // matches it leaves `size` as it is, and costs no commit.
430
+ const shown = previous ?? seedRef.current;
355
431
  if (!autoWidthRef.current) {
356
- return previous !== null && previous.height === height ? previous : { width: previous?.width ?? width, height };
432
+ return shown !== null && shown.height === height ? previous : { width: shown?.width ?? width, height };
357
433
  }
358
- return previous !== null && previous.width === width && previous.height === height
434
+ return shown !== null && shown.width === width && shown.height === height
359
435
  ? previous
360
436
  : { width, height };
361
437
  });
@@ -600,15 +676,82 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
600
676
  hostViewProps.importantForAccessibility = resolvedImportance;
601
677
  if (resolvedLabelledBy != null)
602
678
  hostViewProps.accessibilityLabelledBy = resolvedLabelledBy;
603
- const autoSize = useMemo(() => size !== null
604
- ? autoWidth
605
- ? { width: size.width, height: size.height }
606
- : { height: size.height }
607
- : { height: resolvedFontSize * 1.25 }, [size, resolvedFontSize, autoWidth]);
608
- return (React.createElement(NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? uncontrolledText,
679
+ // What the field's size follows. Sent to the view as props and, before
680
+ // the view exists, to `measureSizing`, so the two see the same values.
681
+ const sizing = {
682
+ text: value ?? uncontrolledText,
683
+ mode: resolvedMode,
684
+ plain: !reflows,
685
+ multiline: isMultiline,
686
+ secureTextEntry: secureTextEntry ?? false,
687
+ maxLength: maxLength ?? 0,
688
+ fractionDigits: resolvedFractionDigits,
689
+ maxIntegerDigits: maxIntegerDigits ?? 15,
690
+ groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? ',',
691
+ decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.',
692
+ prefix: resolvedPrefix,
693
+ suffix: resolvedSuffix,
694
+ signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix',
695
+ placeholder: placeholder ?? '',
696
+ mask: resolvedMode === 'mask' ? (mask ?? '') : '',
697
+ maskNotations: stableNotations,
698
+ maskAutocomplete: maskAutocomplete ?? true,
699
+ maskAutoSkip: maskAutoSkip ?? false,
700
+ maskAffinityFormats: stableAffinityFormats,
701
+ maskAffinityStrategy: maskAffinityStrategy ?? 'wholeString',
702
+ maskTextCase: maskTextCase ?? 'none',
703
+ maskCharacterMap: stableCharacterMap,
704
+ maskSlotPlaceholder: maskSlotPlaceholder ?? (keepPlaceholder ? '_' : ''),
705
+ keepPlaceholder: keepPlaceholder ?? false,
706
+ textSize: resolvedFontSize,
707
+ textLineHeight: Math.max(0, lineHeight ?? 0),
708
+ prefixFontSize: prefixFontSize ?? resolvedFontSize,
709
+ suffixFontSize: suffixFontSize ?? resolvedFontSize,
710
+ textWeight: numericWeight,
711
+ textFamily: fontFamily ?? '',
712
+ textLetterSpacing: letterSpacing ?? 0,
713
+ tabularNums: tabularNums ?? !flat?.fontVariant?.includes('proportional-nums'),
714
+ slotDigits: tabularNums === true,
715
+ prefixSpacing: prefixSpacing ?? Infinity,
716
+ suffixSpacing: suffixSpacing ?? Infinity,
717
+ allowFontScaling: allowFontScaling ?? false,
718
+ maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0,
719
+ variant: variant ?? 'none',
720
+ label: label ?? '',
721
+ labelBehavior: labelBehavior ?? 'float',
722
+ labelFontSize: labelFontSize ?? 0,
723
+ cornerRadius: cornerRadius ?? 8,
724
+ };
725
+ // Until the view reports its size, the field lays out at the size it will
726
+ // report, measured now with the view's own code - as `TextInput` measures
727
+ // in its shadow node - rather than at its parent's width for the commit
728
+ // the report takes. Not for a wrapping field (its height needs the width
729
+ // it will get), a `transform` (a worklet, run on the UI thread) or a
730
+ // style that sets both dimensions. Measured again only when what it
731
+ // follows changes.
732
+ if (!reportedRef.current) {
733
+ const seedKey = measured && !isMultiline && transformId === 0 ? JSON.stringify(sizing) : '';
734
+ if (seedKey !== seedKeyRef.current) {
735
+ seedKeyRef.current = seedKey;
736
+ seedRef.current = seedKey === '' ? null : measureSizing(sizing);
737
+ }
738
+ }
739
+ const shownSize = size ?? seedRef.current;
740
+ // The size measured for the text, plus the style's padding and border
741
+ // (Yoga's box includes them; `TextInput`'s measured size gets them too).
742
+ const autoSize = useMemo(() => {
743
+ const extraWidth = insets.left + insets.right;
744
+ const extraHeight = insets.top + insets.bottom;
745
+ return shownSize !== null
746
+ ? autoWidth
747
+ ? { width: shownSize.width + extraWidth, height: shownSize.height + extraHeight }
748
+ : { height: shownSize.height + extraHeight }
749
+ : { height: resolvedFontSize * 1.25 + extraHeight };
750
+ }, [shownSize, resolvedFontSize, autoWidth, insets]);
751
+ return (React.createElement(NativeNitroInputView, { ...hostViewProps, ...sizing, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef,
609
752
  // An uncontrolled field's `text` is its initial text: a count of 0 is
610
753
  // 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 ??
754
+ mostRecentEventCount: value != null ? eventCountRef.current : 0, prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, placeholderColor: processedPlaceholderColor, duration: duration ?? 400, easing: easing ?? 'expo', bounce: bounce ?? 0.15, effect: effect ?? 'auto', textColor: processedColor, textAlignment: textAlign ?? 'auto', rightToLeft: rightToLeft, caretColor: processedCursorColor, selectionColor: processedSelectionColor, caretHidden: caretHidden ?? false, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, labelColor: processedLabelColor, labelFocusedColor: processedLabelFocusedColor, strokeColor: processedStrokeColor, focusedStrokeColor: processedFocusedStrokeColor, strokeWidth: strokeWidth ?? 1, fillColor: processedFillColor, onChangeMask: onChangeMaskCallback, keyboardType: resolvedKeyboardType, returnKeyType: resolvedReturnKeyType, autoCapitalize: autoCapitalize ?? 'sentences', autoCorrect: autoCorrect ?? true, editable: (editable ?? true) && !(readOnly ?? false), numberOfLines: Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0)), textVerticalAlignment: textAlignVertical ?? 'auto', textInsetLeft: insets.left, textInsetTop: insets.top, textInsetRight: insets.right, textInsetBottom: insets.bottom, scrollEnabled: scrollEnabled ?? true, autoFocus: autoFocus ?? false, fieldTestID: viewProps.testID ?? '', fieldAccessibilityLabel: resolvedAccessibilityLabel ?? '', submitBehavior: submitBehavior ??
612
755
  // As `TextInput` resolves the legacy `blurOnSubmit`: a multiline
613
756
  // field's return key inserts a line break unless told to blur.
614
757
  (multiline
@@ -617,7 +760,7 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
617
760
  : 'newline'
618
761
  : blurOnSubmit === false
619
762
  ? 'submit'
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 }));
763
+ : 'blurAndSubmit'), 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, 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 }));
621
764
  });
622
765
  // The name DevTools and error stacks show, as `TextInput` names itself.
623
766
  NitroInput.displayName = 'NitroInput';
@@ -155,5 +155,5 @@ export const NitroNumber = forwardRef(function NitroNumber({ value, minorDigits,
155
155
  // does not hand a Hybrid View its resolved direction, so native is told.
156
156
  const layoutDirection = useMemo(() => StyleSheet.flatten(style)?.direction, [style]);
157
157
  const rightToLeft = layoutDirection === 'rtl' || (layoutDirection !== 'ltr' && I18nManager.isRTL);
158
- return (React.createElement(NativeNitroNumberView, { ...viewProps, style: [autoSize, style], hybridRef: hybridRef, value: shownValue, fractionDigits: fractionDigits ?? figure?.fractionDigits ?? 0, minimumIntegerDigits: minimumIntegerDigits ?? derived?.minimumIntegerDigits ?? 1, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? '', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: prefix ?? compact?.prefix ?? derived?.prefix ?? '', suffix: suffix ?? compact?.suffix ?? derived?.suffix ?? '', transition: transition ?? 'roll', flashUpColor: processedFlashUp, flashDownColor: processedFlashDown, flashDuration: flashDuration ?? 600, popOnChange: popOnChange ?? 0, duration: still ? 0 : duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration, easing: easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing, bounce: bounce ?? 0.15, stagger: stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger, rollDirection: direction ?? compactDirection ?? 'auto', revealState: reveal === undefined ? 0 : reveal ? 2 : 1, revealStyle: revealStyle ?? 'count', revealDuration: still ? 0 : revealDuration ?? 2200, revealBounce: revealBounce ?? 0.12, revealGrow: revealGrow ?? 0.2, revealStagger: revealStagger ?? 200, revealMilestones: stableMilestones, revealMilestoneHold: revealMilestoneHold ?? 0, onRevealEnd: onRevealEndCallback, onRevealMilestone: onRevealMilestoneCallback, onAnimationStart: onAnimationStartCallback, onAnimationEnd: onAnimationEndCallback, loading: loading ?? false, shimmerColor: processedShimmerColor, shimmerDuration: shimmerDuration ?? 950, shimmerAngle: shimmerAngle ?? 31, shimmerWidth: shimmerWidth ?? 1, shimmerBaseColor: processedShimmerBase, shimmerDirection: shimmerDirection ?? 'auto', shimmerDelay: shimmerDelay ?? 0, fontSize: resolvedFontSize, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, affixAlign: resolvedAffixAlign, prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, tabularNums: tabularNums ?? true, signDisplay: signDisplay ?? derived?.signDisplay ?? 'auto', plusSign: plusSign ?? derived?.plusSign ?? '+', minusSign: minusSign ?? derived?.minusSign ?? '-', digitGlyphs: stableGlyphs, groupingSizes: stableGroups, digitMax: digitMax, continuous: continuous ?? false, prefixColor: processedPrefixColor, suffixColor: processedSuffixColor, fractionColor: processedFractionColor, fractionFontSize: fractionFontSize ?? Infinity, fractionAlign: fractionAlign ?? 'baseline', respectReduceMotion: respectReduceMotion ?? true, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, onSizeChange: onSizeChange }));
158
+ return (React.createElement(NativeNitroNumberView, { ...viewProps, style: [autoSize, style], hybridRef: hybridRef, value: shownValue, fractionDigits: fractionDigits ?? figure?.fractionDigits ?? 0, minimumIntegerDigits: minimumIntegerDigits ?? derived?.minimumIntegerDigits ?? 1, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? '', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: prefix ?? compact?.prefix ?? derived?.prefix ?? '', suffix: suffix ?? compact?.suffix ?? derived?.suffix ?? '', transition: transition ?? 'roll', flashUpColor: processedFlashUp, flashDownColor: processedFlashDown, flashDuration: flashDuration ?? 600, popOnChange: popOnChange ?? 0, duration: still ? 0 : duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration, easing: easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing, bounce: bounce ?? 0.15, stagger: stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger, rollDirection: direction ?? compactDirection ?? 'auto', revealState: reveal === undefined ? 0 : reveal ? 2 : 1, revealStyle: revealStyle ?? 'count', revealDuration: still ? 0 : revealDuration ?? 2200, revealBounce: revealBounce ?? 0.12, revealGrow: revealGrow ?? 0.2, revealStagger: revealStagger ?? 200, revealMilestones: stableMilestones, revealMilestoneHold: revealMilestoneHold ?? 0, onRevealEnd: onRevealEndCallback, onRevealMilestone: onRevealMilestoneCallback, onAnimationStart: onAnimationStartCallback, onAnimationEnd: onAnimationEndCallback, loading: loading ?? false, shimmerColor: processedShimmerColor, shimmerDuration: shimmerDuration ?? 950, shimmerAngle: shimmerAngle ?? 31, shimmerWidth: shimmerWidth ?? 1, shimmerBaseColor: processedShimmerBase, shimmerDirection: shimmerDirection ?? 'auto', shimmerDelay: shimmerDelay ?? 0, textSize: resolvedFontSize, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, affixAlign: resolvedAffixAlign, prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, textLetterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, tabularNums: tabularNums ?? true, signDisplay: signDisplay ?? derived?.signDisplay ?? 'auto', plusSign: plusSign ?? derived?.plusSign ?? '+', minusSign: minusSign ?? derived?.minusSign ?? '-', digitGlyphs: stableGlyphs, groupingSizes: stableGroups, digitMax: digitMax, continuous: continuous ?? false, prefixColor: processedPrefixColor, suffixColor: processedSuffixColor, fractionColor: processedFractionColor, fractionFontSize: fractionFontSize ?? Infinity, fractionAlign: fractionAlign ?? 'baseline', respectReduceMotion: respectReduceMotion ?? true, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, textWeight: numericWeight, textFamily: fontFamily ?? '', textColor: processedColor, textAlignment: textAlign ?? 'auto', rightToLeft: rightToLeft, onSizeChange: onSizeChange }));
159
159
  });
@@ -46,18 +46,18 @@ export function NitroText({ children, fontSize, fontWeight, fontFamily, color, l
46
46
  native.text = text;
47
47
  native.style = style == null ? { width: Math.ceil(width), height } : [{ width: Math.ceil(width), height }, style];
48
48
  if (size !== 17)
49
- native.fontSize = size;
49
+ native.textSize = size;
50
50
  if (weight !== 400)
51
- native.fontWeight = weight;
51
+ native.textWeight = weight;
52
52
  if (family !== '')
53
- native.fontFamily = family;
53
+ native.textFamily = family;
54
54
  if (spacing !== 0)
55
- native.letterSpacing = spacing;
55
+ native.textLetterSpacing = spacing;
56
56
  const processedColor = toProcessedColor(color);
57
57
  if (processedColor !== undefined)
58
- native.color = processedColor;
58
+ native.textColor = processedColor;
59
59
  if (textAlign !== undefined)
60
- native.textAlign = textAlign;
60
+ native.textAlignment = textAlign;
61
61
  if (duration !== undefined)
62
62
  native.duration = duration;
63
63
  if (easing !== undefined)
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type ColorValue, type TextStyle, type ViewProps } from 'react-native';
2
+ import { type ColorValue, type StyleProp, type TextStyle, type ViewProps } from 'react-native';
3
3
  import { type HybridRef } from 'react-native-nitro-modules';
4
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';
@@ -67,7 +67,14 @@ export interface NitroInputKeyPressEvent {
67
67
  target: number;
68
68
  };
69
69
  }
70
- export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus' | 'onBlur'> {
70
+ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus' | 'onBlur' | 'style'> {
71
+ /**
72
+ * As `TextInput`'s: a view style, and the text styles it reads its
73
+ * typography from (`fontSize`, `fontWeight`, `fontFamily`, `color`,
74
+ * `letterSpacing`, `lineHeight`, `textAlign`, `textAlignVertical`). The props
75
+ * of the same name win over it.
76
+ */
77
+ style?: StyleProp<TextStyle>;
71
78
  /**
72
79
  * The text to show (controlled). The native side formats and shows what the
73
80
  * user types on its own; this prop is applied when it changes to something
@@ -222,6 +229,17 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
222
229
  * Default: `0`.
223
230
  */
224
231
  letterSpacing?: number;
232
+ /**
233
+ * Unset (the default): the font's tabular figures, where it has them (the
234
+ * system fonts do), at no cost. `true`: every digit as wide as the widest
235
+ * even in a font without them (Open Runde), laid out that wide and centred,
236
+ * so typing over a `keepPlaceholder` mask never moves what is still to come
237
+ * and an amount keeps its width as its digits change; that layout costs a
238
+ * little on each change. `false`: the font's proportional figures. A
239
+ * style's `fontVariant: ['proportional-nums']` is `false` too, as on a
240
+ * `TextInput`; the prop wins.
241
+ */
242
+ tabularNums?: boolean;
225
243
  /** Points between the prefix and the text, in place of the letter spacing there. Defaults to the letter spacing. */
226
244
  prefixSpacing?: number;
227
245
  /** Points between the text and the suffix, in place of the letter spacing there. Defaults to the letter spacing. */
@@ -494,18 +512,4 @@ export interface NitroInputHandle {
494
512
  * the glyph engine (`'reflow'`).
495
513
  */
496
514
  export type NitroInputTransition = 'none' | 'reflow';
497
- /**
498
- * A native text input: a system field (`UITextField` / `EditText`) that owns
499
- * the keyboard, editing, selection, paste and accessibility, with native
500
- * formatting (`mode="number"`), native masking (`mode="mask"`), an outlined
501
- * or filled frame with a floating label, and optionally the glyph engine
502
- * (`transition="reflow"`), under which characters that stay glide to their new place, new
503
- * ones slide or fade in and removed ones leave alongside their neighbours.
504
- * In `'number'` mode every edit is formatted on the native side before a
505
- * frame is drawn, with the caret kept in place, so there is never an
506
- * unformatted frame and never a round trip through JS.
507
- *
508
- * Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
509
- * it to its content instead, and is on by default when the text reflows.
510
- */
511
515
  export declare const NitroInput: React.ForwardRefExoticComponent<NitroInputProps & React.RefAttributes<NitroInputHandle>>;
@@ -220,7 +220,11 @@ export interface NitroInputProps extends HybridViewProps {
220
220
  /** Vertical alignment of `suffix` relative to the text (the wrapper folds its `affixAlign` into this). */
221
221
  suffixAlign: NitroInputAffixAlign;
222
222
  /** Points added after every glyph, like `Text`'s `letterSpacing`; an affix gets it in proportion to its size. */
223
- letterSpacing: number;
223
+ textLetterSpacing: number;
224
+ /** The font's tabular figures (`tnum`) rather than its proportional ones. */
225
+ tabularNums: boolean;
226
+ /** Every digit laid out as wide as the widest, centred: tabular figures for a font without them. */
227
+ slotDigits: boolean;
224
228
  /** Points between the prefix and the text, in place of the letter spacing there. Not finite: the letter spacing. */
225
229
  prefixSpacing: number;
226
230
  /** Points between the text and the suffix, in place of the letter spacing there. Not finite: the letter spacing. */
@@ -242,7 +246,7 @@ export interface NitroInputProps extends HybridViewProps {
242
246
  /** How characters enter and leave. Default: `'auto'`. */
243
247
  effect: NitroInputEffect;
244
248
  /** Font size of the text in points. Default: `32`. */
245
- fontSize: number;
249
+ textSize: number;
246
250
  /**
247
251
  * Height of the line box in points — the CSS meaning: the total height a
248
252
  * line occupies, not extra leading. `0` (the default) uses the font's own.
@@ -255,15 +259,15 @@ export interface NitroInputProps extends HybridViewProps {
255
259
  * `lineHeight < font.lineHeight`), and the reason a compressed `lineHeight`
256
260
  * renders off-centre on a `TextInput`.
257
261
  */
258
- lineHeight: number;
262
+ textLineHeight: number;
259
263
  /** Numeric font weight, `100`–`900`. Default: `400`. */
260
- fontWeight: number;
264
+ textWeight: number;
261
265
  /** Font family name; empty = system font. */
262
- fontFamily: string;
266
+ textFamily: string;
263
267
  /** Text color as a processed ARGB integer; `NaN` = platform label color. */
264
- color: number;
268
+ textColor: number;
265
269
  /** Where the text sits when the view is wider than it. Default: `'auto'`, the start edge. */
266
- textAlign: NitroInputTextAlign;
270
+ textAlignment: NitroInputTextAlign;
267
271
  /**
268
272
  * Lay the field out right-to-left: `'auto'` alignment resolves to the right
269
273
  * edge, the prefix moves to the right and the suffix to the left, and a
@@ -314,7 +318,16 @@ export interface NitroInputProps extends HybridViewProps {
314
318
  */
315
319
  numberOfLines: number;
316
320
  /** `multiline`: where the text sits in the box. Default: `'auto'` (top). */
317
- textAlignVertical: NitroInputTextAlignVertical;
321
+ textVerticalAlignment: NitroInputTextAlignVertical;
322
+ /**
323
+ * The style's padding and border, in points, resolved per edge by
324
+ * `NitroInput`. Android insets the text, the overlay and the frame by them;
325
+ * on iOS React Native already lays the view's content out inside them.
326
+ */
327
+ textInsetLeft: number;
328
+ textInsetTop: number;
329
+ textInsetRight: number;
330
+ textInsetBottom: number;
318
331
  /**
319
332
  * `multiline`: whether the field scrolls once the text is taller than it.
320
333
  * Turning it off lets a growing field drive its own height. Default: `true`.
@@ -0,0 +1,69 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { NitroInputCharacterMapping, NitroInputLabelBehavior, NitroInputMaskAffinity, NitroInputMode, NitroInputNotation, NitroInputSignPlacement, NitroInputTextCase, NitroInputVariant } from './NitroInput.nitro';
3
+ /**
4
+ * What a field's size follows: the subset of `NitroInputProps` the
5
+ * native views read when they report `onSizeChange`, under the same names and
6
+ * already resolved the same way by `NitroInput`.
7
+ */
8
+ export interface NitroInputSizing {
9
+ text: string;
10
+ mode: NitroInputMode;
11
+ plain: boolean;
12
+ multiline: boolean;
13
+ secureTextEntry: boolean;
14
+ maxLength: number;
15
+ fractionDigits: number;
16
+ maxIntegerDigits: number;
17
+ groupingSeparator: string;
18
+ decimalSeparator: string;
19
+ prefix: string;
20
+ suffix: string;
21
+ signPlacement: NitroInputSignPlacement;
22
+ placeholder: string;
23
+ mask: string;
24
+ maskNotations: NitroInputNotation[];
25
+ maskAutocomplete: boolean;
26
+ maskAutoSkip: boolean;
27
+ maskAffinityFormats: string[];
28
+ maskAffinityStrategy: NitroInputMaskAffinity;
29
+ maskTextCase: NitroInputTextCase;
30
+ maskCharacterMap: NitroInputCharacterMapping[];
31
+ maskSlotPlaceholder: string;
32
+ keepPlaceholder: boolean;
33
+ textSize: number;
34
+ textLineHeight: number;
35
+ prefixFontSize: number;
36
+ suffixFontSize: number;
37
+ textWeight: number;
38
+ textFamily: string;
39
+ textLetterSpacing: number;
40
+ tabularNums: boolean;
41
+ slotDigits: boolean;
42
+ prefixSpacing: number;
43
+ suffixSpacing: number;
44
+ allowFontScaling: boolean;
45
+ maxFontSizeMultiplier: number;
46
+ variant: NitroInputVariant;
47
+ label: string;
48
+ labelBehavior: NitroInputLabelBehavior;
49
+ labelFontSize: number;
50
+ cornerRadius: number;
51
+ }
52
+ /** A size in points (iOS) or dp (Android). */
53
+ export interface NitroInputSize {
54
+ width: number;
55
+ height: number;
56
+ }
57
+ /**
58
+ * Measures a single-line field on the JS thread, before its view exists, with
59
+ * the code the view sizes itself with: `NitroInput` lays out at its real size
60
+ * in the commit that mounts it, as React Native's `TextInput` does, instead of
61
+ * at its parent's width until the view's first `onSizeChange` arrives.
62
+ */
63
+ export interface NitroInputMeasure extends HybridObject<{
64
+ ios: 'swift';
65
+ android: 'kotlin';
66
+ }> {
67
+ /** What the field reports through `onSizeChange` once mounted, unfocused. */
68
+ measure(sizing: NitroInputSizing): NitroInputSize;
69
+ }
@@ -178,7 +178,7 @@ export interface NitroNumberProps extends HybridViewProps {
178
178
  /** A pause after each sweep, in ms. Default: `0`. */
179
179
  shimmerDelay?: number;
180
180
  /** Font size of the digits in points. Default: `32`. */
181
- fontSize?: number;
181
+ textSize?: number;
182
182
  /** Font size of `prefix` in points. Defaults to `fontSize`. */
183
183
  prefixFontSize?: number;
184
184
  /** Font size of `suffix` in points. Defaults to `fontSize`. */
@@ -190,7 +190,7 @@ export interface NitroNumberProps extends HybridViewProps {
190
190
  /** Vertical alignment of `suffix` only. Defaults to `affixAlign`. */
191
191
  suffixAlign?: NitroNumberAffixAlign;
192
192
  /** Points added after every glyph, like `Text`'s `letterSpacing`; an affix gets it in proportion to its size. Default: `0`. */
193
- letterSpacing?: number;
193
+ textLetterSpacing?: number;
194
194
  /** Points between the prefix and the digits, in place of the letter spacing there. Not finite: the letter spacing. */
195
195
  prefixSpacing?: number;
196
196
  /** Points between the digits and the suffix, in place of the letter spacing there. Not finite: the letter spacing. */
@@ -256,13 +256,13 @@ export interface NitroNumberProps extends HybridViewProps {
256
256
  /** Upper bound for `allowFontScaling`, e.g. `1.3`. `0` means no cap. Default: `0`. */
257
257
  maxFontSizeMultiplier?: number;
258
258
  /** Numeric font weight, `100`–`900`. Default: `400`. */
259
- fontWeight?: number;
259
+ textWeight?: number;
260
260
  /** Font family name. Defaults to the system font. */
261
- fontFamily?: string;
261
+ textFamily?: string;
262
262
  /** Text color as a processed ARGB integer (from `processColor`). Defaults to the platform label color. */
263
- color?: number;
263
+ textColor?: number;
264
264
  /** Where the number sits inside the view when the view is wider than the number. Default: `'auto'`, the start edge. */
265
- textAlign?: NitroNumberTextAlign;
265
+ textAlignment?: NitroNumberTextAlign;
266
266
  /**
267
267
  * Lay the figure out right-to-left: `'auto'` alignment resolves to the right
268
268
  * edge, the prefix moves to the right and the suffix to the left, and the