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
@@ -11,12 +11,14 @@ import {
11
11
  I18nManager,
12
12
  StyleSheet,
13
13
  type ColorValue,
14
+ type StyleProp,
14
15
  type TextStyle,
15
16
  type ViewProps,
16
17
  } from 'react-native'
17
18
  import {
18
19
  callback,
19
20
  getHostComponent,
21
+ NitroModules,
20
22
  type HybridRef,
21
23
  } from 'react-native-nitro-modules'
22
24
  import NitroInputViewConfig from '../nitrogen/generated/shared/json/NitroInputViewConfig.json'
@@ -42,6 +44,7 @@ import type {
42
44
  NitroInputTextCase,
43
45
  NitroInputCharacterMapping,
44
46
  } from './specs/NitroInput.nitro'
47
+ import type { NitroInputMeasure, NitroInputSizing } from './specs/NitroInputMeasure.nitro'
45
48
  import {
46
49
  allocateWorkletId,
47
50
  isWorklet,
@@ -275,7 +278,14 @@ export interface NitroInputKeyPressEvent {
275
278
  nativeEvent: { key: string; eventCount: number; target: number }
276
279
  }
277
280
 
278
- export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus' | 'onBlur'> {
281
+ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus' | 'onBlur' | 'style'> {
282
+ /**
283
+ * As `TextInput`'s: a view style, and the text styles it reads its
284
+ * typography from (`fontSize`, `fontWeight`, `fontFamily`, `color`,
285
+ * `letterSpacing`, `lineHeight`, `textAlign`, `textAlignVertical`). The props
286
+ * of the same name win over it.
287
+ */
288
+ style?: StyleProp<TextStyle>
279
289
  /**
280
290
  * The text to show (controlled). The native side formats and shows what the
281
291
  * user types on its own; this prop is applied when it changes to something
@@ -435,6 +445,17 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
435
445
  * Default: `0`.
436
446
  */
437
447
  letterSpacing?: number
448
+ /**
449
+ * Unset (the default): the font's tabular figures, where it has them (the
450
+ * system fonts do), at no cost. `true`: every digit as wide as the widest
451
+ * even in a font without them (Open Runde), laid out that wide and centred,
452
+ * so typing over a `keepPlaceholder` mask never moves what is still to come
453
+ * and an amount keeps its width as its digits change; that layout costs a
454
+ * little on each change. `false`: the font's proportional figures. A
455
+ * style's `fontVariant: ['proportional-nums']` is `false` too, as on a
456
+ * `TextInput`; the prop wins.
457
+ */
458
+ tabularNums?: boolean
438
459
  /** Points between the prefix and the text, in place of the letter spacing there. Defaults to the letter spacing. */
439
460
  prefixSpacing?: number
440
461
  /** Points between the text and the suffix, in place of the letter spacing there. Defaults to the letter spacing. */
@@ -734,6 +755,85 @@ export type NitroInputTransition = 'none' | 'reflow'
734
755
  * Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
735
756
  * it to its content instead, and is on by default when the text reflows.
736
757
  */
758
+ interface Insets {
759
+ left: number
760
+ top: number
761
+ right: number
762
+ bottom: number
763
+ }
764
+ const NO_INSETS: Insets = { left: 0, top: 0, right: 0, bottom: 0 }
765
+
766
+ /**
767
+ * The style's padding plus border per edge, resolved the way Yoga does: a
768
+ * start / end edge before left / right, then horizontal / vertical, then all.
769
+ * A size measured for the text gets them added, as `TextInput`'s is, so a
770
+ * padded field grows rather than squeezing its text. Percentages are not
771
+ * resolved here (they need the parent's size) and count as 0.
772
+ */
773
+ function styleInsets(flat: Record<string, unknown> | undefined, rightToLeft: boolean): Insets {
774
+ if (flat == null) return NO_INSETS
775
+ const n = (key: string): number | undefined => {
776
+ const value = flat[key]
777
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined
778
+ }
779
+ const start = rightToLeft ? 'End' : 'Start'
780
+ const end = rightToLeft ? 'Start' : 'End'
781
+ const insets = {
782
+ left:
783
+ (n(`padding${start}`) ?? n('paddingLeft') ?? n('paddingHorizontal') ?? n('padding') ?? 0) +
784
+ (n(`border${start}Width`) ?? n('borderLeftWidth') ?? n('borderWidth') ?? 0),
785
+ right:
786
+ (n(`padding${end}`) ?? n('paddingRight') ?? n('paddingHorizontal') ?? n('padding') ?? 0) +
787
+ (n(`border${end}Width`) ?? n('borderRightWidth') ?? n('borderWidth') ?? 0),
788
+ top:
789
+ (n('paddingTop') ?? n('paddingVertical') ?? n('padding') ?? 0) + (n('borderTopWidth') ?? n('borderWidth') ?? 0),
790
+ bottom:
791
+ (n('paddingBottom') ?? n('paddingVertical') ?? n('padding') ?? 0) +
792
+ (n('borderBottomWidth') ?? n('borderWidth') ?? 0),
793
+ }
794
+ return insets.left === 0 && insets.right === 0 && insets.top === 0 && insets.bottom === 0 ? NO_INSETS : insets
795
+ }
796
+
797
+ function styleTextAlign(value: TextStyle['textAlign'], rightToLeft: boolean): NitroInputTextAlign | undefined {
798
+ switch (value) {
799
+ case undefined:
800
+ return undefined
801
+ // `justify` has no meaning on one line: the start edge, as on a TextInput.
802
+ case 'start':
803
+ case 'justify':
804
+ return 'auto'
805
+ case 'end':
806
+ return rightToLeft ? 'left' : 'right'
807
+ default:
808
+ return value
809
+ }
810
+ }
811
+
812
+ function styleTextAlignVertical(value: TextStyle['textAlignVertical']): NitroInputTextAlignVertical | undefined {
813
+ return value ?? undefined
814
+ }
815
+
816
+ // One per app, made on first use. `null` when the native side has none (an
817
+ // app built against an older version, or a test without native modules): the
818
+ // field then takes its size from the view's first report, as it used to.
819
+ let measurer: NitroInputMeasure | null | undefined
820
+ function measureSizing(sizing: NitroInputSizing): Size | null {
821
+ if (measurer === undefined) {
822
+ try {
823
+ const made = NitroModules.createHybridObject<NitroInputMeasure>('NitroInputMeasure')
824
+ measurer = typeof made?.measure === 'function' ? made : null
825
+ } catch {
826
+ measurer = null
827
+ }
828
+ }
829
+ if (measurer === null) return null
830
+ try {
831
+ return measurer.measure(sizing)
832
+ } catch {
833
+ return null
834
+ }
835
+ }
836
+
737
837
  export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
738
838
  function NitroInput(
739
839
  {
@@ -752,7 +852,8 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
752
852
  signPlacement,
753
853
  prefixAlign,
754
854
  suffixAlign,
755
- letterSpacing,
855
+ letterSpacing: letterSpacingProp,
856
+ tabularNums,
756
857
  prefixSpacing,
757
858
  suffixSpacing,
758
859
  prefixOffset,
@@ -764,12 +865,12 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
764
865
  easing,
765
866
  bounce,
766
867
  effect,
767
- fontSize,
768
- lineHeight,
769
- fontWeight,
770
- fontFamily,
771
- color,
772
- textAlign,
868
+ fontSize: fontSizeProp,
869
+ lineHeight: lineHeightProp,
870
+ fontWeight: fontWeightProp,
871
+ fontFamily: fontFamilyProp,
872
+ color: colorProp,
873
+ textAlign: textAlignProp,
773
874
  cursorColor,
774
875
  selectionColor,
775
876
  caretHidden,
@@ -808,7 +909,7 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
808
909
  multiline,
809
910
  numberOfLines,
810
911
  rows,
811
- textAlignVertical,
912
+ textAlignVertical: textAlignVerticalProp,
812
913
  scrollEnabled,
813
914
  autoFocus,
814
915
  transition,
@@ -912,6 +1013,11 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
912
1013
  if (value != null) textRef.current = value
913
1014
 
914
1015
  const [size, setSize] = useState<Size | null>(null)
1016
+ // The size measured before the view existed (see `measureSizing`), and
1017
+ // whether the view has reported its own since.
1018
+ const seedRef = useRef<Size | null>(null)
1019
+ const seedKeyRef = useRef('')
1020
+ const reportedRef = useRef(false)
915
1021
  // Worklets are registered on the UI runtime and referenced by id; a
916
1022
  // handler marked 'worklet' runs there instead of on the JS thread.
917
1023
  const transformId = useWorkletId(transform, registerTransform)
@@ -1035,16 +1141,29 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
1035
1141
  const flat = useMemo(
1036
1142
  () =>
1037
1143
  StyleSheet.flatten(style) as
1038
- | { width?: unknown; flex?: unknown; height?: unknown; direction?: unknown }
1144
+ | ({ width?: unknown; flex?: unknown; height?: unknown; direction?: unknown } & TextStyle)
1039
1145
  | undefined,
1040
1146
  [style]
1041
1147
  )
1148
+ // `TextInput` takes its typography from `style`; so does this, under the
1149
+ // props of the same name, which win. (Fabric hands a view its style's keys
1150
+ // as props too; the view's own are named so that none can be one of them -
1151
+ // see PropNameCollisions.test.)
1152
+ const fontSize = fontSizeProp ?? flat?.fontSize
1153
+ const lineHeight = lineHeightProp ?? flat?.lineHeight
1154
+ const fontWeight = fontWeightProp ?? flat?.fontWeight
1155
+ const fontFamily = fontFamilyProp ?? flat?.fontFamily
1156
+ const color = colorProp ?? flat?.color
1157
+ const letterSpacing = letterSpacingProp ?? flat?.letterSpacing
1158
+ const textAlignVertical = textAlignVerticalProp ?? styleTextAlignVertical(flat?.textAlignVertical)
1042
1159
  // The layout direction, resolved the way React Native resolves it for its
1043
1160
  // own views: the field's `style.direction` if it says, else the app's.
1044
1161
  // Fabric does not hand a Hybrid View its resolved direction, so native is
1045
1162
  // told outright.
1046
1163
  const rightToLeft =
1047
1164
  flat?.direction === 'rtl' || (flat?.direction !== 'ltr' && I18nManager.isRTL)
1165
+ const textAlign = textAlignProp ?? styleTextAlign(flat?.textAlign, rightToLeft)
1166
+ const insets = useMemo(() => styleInsets(flat as Record<string, unknown> | undefined, rightToLeft), [flat, rightToLeft])
1048
1167
  // `TextInput` stretches to its parent; sizing to content is this
1049
1168
  // component's own behaviour, and it is what stops it being a drop-in.
1050
1169
  // `NitroInput` turns it off so flexbox gives it the parent's width, the
@@ -1066,12 +1185,16 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
1066
1185
  const onSizeChange = useMemo(
1067
1186
  () =>
1068
1187
  callback((width: number, height: number) => {
1188
+ reportedRef.current = true
1069
1189
  if (!measuredRef.current) return
1070
1190
  setSize((previous) => {
1191
+ // Until the first report the field shows the seed; a report that
1192
+ // matches it leaves `size` as it is, and costs no commit.
1193
+ const shown = previous ?? seedRef.current
1071
1194
  if (!autoWidthRef.current) {
1072
- return previous !== null && previous.height === height ? previous : { width: previous?.width ?? width, height }
1195
+ return shown !== null && shown.height === height ? previous : { width: shown?.width ?? width, height }
1073
1196
  }
1074
- return previous !== null && previous.width === width && previous.height === height
1197
+ return shown !== null && shown.width === width && shown.height === height
1075
1198
  ? previous
1076
1199
  : { width, height }
1077
1200
  })
@@ -1392,94 +1515,124 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
1392
1515
  if (resolvedImportance != null) hostViewProps.importantForAccessibility = resolvedImportance
1393
1516
  if (resolvedLabelledBy != null) hostViewProps.accessibilityLabelledBy = resolvedLabelledBy
1394
1517
 
1395
- const autoSize = useMemo(
1396
- () =>
1397
- size !== null
1398
- ? autoWidth
1399
- ? { width: size.width, height: size.height }
1400
- : { height: size.height }
1401
- : { height: resolvedFontSize * 1.25 },
1402
- [size, resolvedFontSize, autoWidth]
1403
- )
1518
+ // What the field's size follows. Sent to the view as props and, before
1519
+ // the view exists, to `measureSizing`, so the two see the same values.
1520
+ const sizing: NitroInputSizing = {
1521
+ text: value ?? uncontrolledText,
1522
+ mode: resolvedMode,
1523
+ plain: !reflows,
1524
+ multiline: isMultiline,
1525
+ secureTextEntry: secureTextEntry ?? false,
1526
+ maxLength: maxLength ?? 0,
1527
+ fractionDigits: resolvedFractionDigits,
1528
+ maxIntegerDigits: maxIntegerDigits ?? 15,
1529
+ groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? ',',
1530
+ decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.',
1531
+ prefix: resolvedPrefix,
1532
+ suffix: resolvedSuffix,
1533
+ signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix',
1534
+ placeholder: placeholder ?? '',
1535
+ mask: resolvedMode === 'mask' ? (mask ?? '') : '',
1536
+ maskNotations: stableNotations,
1537
+ maskAutocomplete: maskAutocomplete ?? true,
1538
+ maskAutoSkip: maskAutoSkip ?? false,
1539
+ maskAffinityFormats: stableAffinityFormats,
1540
+ maskAffinityStrategy: maskAffinityStrategy ?? 'wholeString',
1541
+ maskTextCase: maskTextCase ?? 'none',
1542
+ maskCharacterMap: stableCharacterMap,
1543
+ maskSlotPlaceholder: maskSlotPlaceholder ?? (keepPlaceholder ? '_' : ''),
1544
+ keepPlaceholder: keepPlaceholder ?? false,
1545
+ textSize: resolvedFontSize,
1546
+ textLineHeight: Math.max(0, lineHeight ?? 0),
1547
+ prefixFontSize: prefixFontSize ?? resolvedFontSize,
1548
+ suffixFontSize: suffixFontSize ?? resolvedFontSize,
1549
+ textWeight: numericWeight,
1550
+ textFamily: fontFamily ?? '',
1551
+ textLetterSpacing: letterSpacing ?? 0,
1552
+ tabularNums: tabularNums ?? !flat?.fontVariant?.includes('proportional-nums'),
1553
+ slotDigits: tabularNums === true,
1554
+ prefixSpacing: prefixSpacing ?? Infinity,
1555
+ suffixSpacing: suffixSpacing ?? Infinity,
1556
+ allowFontScaling: allowFontScaling ?? false,
1557
+ maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0,
1558
+ variant: variant ?? 'none',
1559
+ label: label ?? '',
1560
+ labelBehavior: labelBehavior ?? 'float',
1561
+ labelFontSize: labelFontSize ?? 0,
1562
+ cornerRadius: cornerRadius ?? 8,
1563
+ }
1564
+ // Until the view reports its size, the field lays out at the size it will
1565
+ // report, measured now with the view's own code - as `TextInput` measures
1566
+ // in its shadow node - rather than at its parent's width for the commit
1567
+ // the report takes. Not for a wrapping field (its height needs the width
1568
+ // it will get), a `transform` (a worklet, run on the UI thread) or a
1569
+ // style that sets both dimensions. Measured again only when what it
1570
+ // follows changes.
1571
+ if (!reportedRef.current) {
1572
+ const seedKey = measured && !isMultiline && transformId === 0 ? JSON.stringify(sizing) : ''
1573
+ if (seedKey !== seedKeyRef.current) {
1574
+ seedKeyRef.current = seedKey
1575
+ seedRef.current = seedKey === '' ? null : measureSizing(sizing)
1576
+ }
1577
+ }
1578
+ const shownSize = size ?? seedRef.current
1579
+ // The size measured for the text, plus the style's padding and border
1580
+ // (Yoga's box includes them; `TextInput`'s measured size gets them too).
1581
+ const autoSize = useMemo(() => {
1582
+ const extraWidth = insets.left + insets.right
1583
+ const extraHeight = insets.top + insets.bottom
1584
+ return shownSize !== null
1585
+ ? autoWidth
1586
+ ? { width: shownSize.width + extraWidth, height: shownSize.height + extraHeight }
1587
+ : { height: shownSize.height + extraHeight }
1588
+ : { height: resolvedFontSize * 1.25 + extraHeight }
1589
+ }, [shownSize, resolvedFontSize, autoWidth, insets])
1404
1590
 
1405
1591
  return (
1406
1592
  <NativeNitroInputView
1407
1593
  {...hostViewProps}
1594
+ {...sizing}
1408
1595
  ref={hostRef as React.Ref<never>}
1409
1596
  style={[autoSize, style]}
1410
1597
  hybridRef={hybridRef}
1411
- text={value ?? uncontrolledText}
1412
1598
  // An uncontrolled field's `text` is its initial text: a count of 0 is
1413
1599
  // never caught up after the first edit, so native never puts it back.
1414
1600
  mostRecentEventCount={value != null ? eventCountRef.current : 0}
1415
- mode={resolvedMode}
1416
- plain={!reflows}
1417
- fractionDigits={resolvedFractionDigits}
1418
- maxIntegerDigits={maxIntegerDigits ?? 15}
1419
- groupingSeparator={groupingSeparator ?? derived?.groupingSeparator ?? ','}
1420
- decimalSeparator={decimalSeparator ?? derived?.decimalSeparator ?? '.'}
1421
- prefix={resolvedPrefix}
1422
- suffix={resolvedSuffix}
1423
- prefixFontSize={prefixFontSize ?? resolvedFontSize}
1424
- suffixFontSize={suffixFontSize ?? resolvedFontSize}
1425
- signPlacement={signPlacement ?? derived?.signPlacement ?? 'beforeAffix'}
1426
1601
  prefixAlign={prefixAlign ?? resolvedAffixAlign}
1427
1602
  suffixAlign={suffixAlign ?? resolvedAffixAlign}
1428
- letterSpacing={letterSpacing ?? 0}
1429
- prefixSpacing={prefixSpacing ?? Infinity}
1430
- suffixSpacing={suffixSpacing ?? Infinity}
1431
1603
  prefixOffset={prefixOffset ?? 0}
1432
1604
  suffixOffset={suffixOffset ?? 0}
1433
- placeholder={placeholder ?? ''}
1434
1605
  placeholderColor={processedPlaceholderColor}
1435
1606
  duration={duration ?? 400}
1436
1607
  easing={easing ?? 'expo'}
1437
1608
  bounce={bounce ?? 0.15}
1438
1609
  effect={effect ?? 'auto'}
1439
- fontSize={resolvedFontSize}
1440
- lineHeight={Math.max(0, lineHeight ?? 0)}
1441
- fontWeight={numericWeight}
1442
- fontFamily={fontFamily ?? ''}
1443
- color={processedColor}
1444
- textAlign={textAlign ?? 'auto'}
1610
+ textColor={processedColor}
1611
+ textAlignment={textAlign ?? 'auto'}
1445
1612
  rightToLeft={rightToLeft}
1446
1613
  caretColor={processedCursorColor}
1447
1614
  selectionColor={processedSelectionColor}
1448
1615
  caretHidden={caretHidden ?? false}
1449
1616
  adjustsFontSizeToFit={adjustsFontSizeToFit ?? false}
1450
1617
  minimumFontScale={minimumFontScale ?? 0.5}
1451
- allowFontScaling={allowFontScaling ?? false}
1452
- maxFontSizeMultiplier={maxFontSizeMultiplier ?? 0}
1453
- variant={variant ?? 'none'}
1454
- label={label ?? ''}
1455
- labelBehavior={labelBehavior ?? 'float'}
1456
1618
  labelColor={processedLabelColor}
1457
1619
  labelFocusedColor={processedLabelFocusedColor}
1458
- labelFontSize={labelFontSize ?? 0}
1459
1620
  strokeColor={processedStrokeColor}
1460
1621
  focusedStrokeColor={processedFocusedStrokeColor}
1461
1622
  strokeWidth={strokeWidth ?? 1}
1462
- cornerRadius={cornerRadius ?? 8}
1463
1623
  fillColor={processedFillColor}
1464
- mask={resolvedMode === 'mask' ? (mask ?? '') : ''}
1465
- maskNotations={stableNotations}
1466
- maskAutocomplete={maskAutocomplete ?? true}
1467
- maskAutoSkip={maskAutoSkip ?? false}
1468
- maskAffinityFormats={stableAffinityFormats}
1469
- maskAffinityStrategy={maskAffinityStrategy ?? 'wholeString'}
1470
- maskTextCase={maskTextCase ?? 'none'}
1471
- maskCharacterMap={stableCharacterMap}
1472
- maskSlotPlaceholder={maskSlotPlaceholder ?? (keepPlaceholder ? '_' : '')}
1473
- keepPlaceholder={keepPlaceholder ?? false}
1474
1624
  onChangeMask={onChangeMaskCallback}
1475
1625
  keyboardType={resolvedKeyboardType}
1476
1626
  returnKeyType={resolvedReturnKeyType}
1477
1627
  autoCapitalize={autoCapitalize ?? 'sentences'}
1478
1628
  autoCorrect={autoCorrect ?? true}
1479
1629
  editable={(editable ?? true) && !(readOnly ?? false)}
1480
- multiline={isMultiline}
1481
1630
  numberOfLines={Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0))}
1482
- textAlignVertical={textAlignVertical ?? 'auto'}
1631
+ textVerticalAlignment={textAlignVertical ?? 'auto'}
1632
+ textInsetLeft={insets.left}
1633
+ textInsetTop={insets.top}
1634
+ textInsetRight={insets.right}
1635
+ textInsetBottom={insets.bottom}
1483
1636
  scrollEnabled={scrollEnabled ?? true}
1484
1637
  autoFocus={autoFocus ?? false}
1485
1638
  fieldTestID={viewProps.testID ?? ''}
@@ -1496,7 +1649,6 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
1496
1649
  ? 'submit'
1497
1650
  : 'blurAndSubmit')
1498
1651
  }
1499
- secureTextEntry={secureTextEntry ?? false}
1500
1652
  keyboardAppearance={keyboardAppearance ?? 'default'}
1501
1653
  textContentType={textContentType ?? autoComplete ?? ''}
1502
1654
  enablesReturnKeyAutomatically={enablesReturnKeyAutomatically ?? false}
@@ -1509,7 +1661,6 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
1509
1661
  spellCheck={spellCheck ?? autoCorrect ?? true}
1510
1662
  selectionStart={selection?.start ?? -1}
1511
1663
  selectionEnd={selection?.end ?? selection?.start ?? -1}
1512
- maxLength={maxLength ?? 0}
1513
1664
  transformWorklet={transformId}
1514
1665
  onChangeTextWorklet={onChangeTextId}
1515
1666
  onChangeValueWorklet={onChangeValueId}
@@ -693,13 +693,13 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
693
693
  shimmerBaseColor={processedShimmerBase}
694
694
  shimmerDirection={shimmerDirection ?? 'auto'}
695
695
  shimmerDelay={shimmerDelay ?? 0}
696
- fontSize={resolvedFontSize}
696
+ textSize={resolvedFontSize}
697
697
  prefixFontSize={prefixFontSize ?? resolvedFontSize}
698
698
  suffixFontSize={suffixFontSize ?? resolvedFontSize}
699
699
  affixAlign={resolvedAffixAlign}
700
700
  prefixAlign={prefixAlign ?? resolvedAffixAlign}
701
701
  suffixAlign={suffixAlign ?? resolvedAffixAlign}
702
- letterSpacing={letterSpacing ?? 0}
702
+ textLetterSpacing={letterSpacing ?? 0}
703
703
  prefixSpacing={prefixSpacing ?? Infinity}
704
704
  suffixSpacing={suffixSpacing ?? Infinity}
705
705
  prefixOffset={prefixOffset ?? 0}
@@ -722,10 +722,10 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
722
722
  minimumFontScale={minimumFontScale ?? 0.5}
723
723
  allowFontScaling={allowFontScaling ?? false}
724
724
  maxFontSizeMultiplier={maxFontSizeMultiplier ?? 0}
725
- fontWeight={numericWeight}
726
- fontFamily={fontFamily ?? ''}
727
- color={processedColor}
728
- textAlign={textAlign ?? 'auto'}
725
+ textWeight={numericWeight}
726
+ textFamily={fontFamily ?? ''}
727
+ textColor={processedColor}
728
+ textAlignment={textAlign ?? 'auto'}
729
729
  rightToLeft={rightToLeft}
730
730
  onSizeChange={onSizeChange}
731
731
  />
package/src/NitroText.tsx CHANGED
@@ -134,13 +134,13 @@ export function NitroText({
134
134
  const native: NativeNitroTextProps & Record<string, unknown> = viewProps as never
135
135
  native.text = text
136
136
  native.style = style == null ? { width: Math.ceil(width), height } : [{ width: Math.ceil(width), height }, style]
137
- if (size !== 17) native.fontSize = size
138
- if (weight !== 400) native.fontWeight = weight
139
- if (family !== '') native.fontFamily = family
140
- if (spacing !== 0) native.letterSpacing = spacing
137
+ if (size !== 17) native.textSize = size
138
+ if (weight !== 400) native.textWeight = weight
139
+ if (family !== '') native.textFamily = family
140
+ if (spacing !== 0) native.textLetterSpacing = spacing
141
141
  const processedColor = toProcessedColor(color)
142
- if (processedColor !== undefined) native.color = processedColor
143
- if (textAlign !== undefined) native.textAlign = textAlign
142
+ if (processedColor !== undefined) native.textColor = processedColor
143
+ if (textAlign !== undefined) native.textAlignment = textAlign
144
144
  if (duration !== undefined) native.duration = duration
145
145
  if (easing !== undefined) native.easing = easing
146
146
  if (bounce !== undefined) native.bounce = bounce
@@ -267,7 +267,11 @@ export interface NitroInputProps extends HybridViewProps {
267
267
  /** Vertical alignment of `suffix` relative to the text (the wrapper folds its `affixAlign` into this). */
268
268
  suffixAlign: NitroInputAffixAlign
269
269
  /** Points added after every glyph, like `Text`'s `letterSpacing`; an affix gets it in proportion to its size. */
270
- letterSpacing: number
270
+ textLetterSpacing: number
271
+ /** The font's tabular figures (`tnum`) rather than its proportional ones. */
272
+ tabularNums: boolean
273
+ /** Every digit laid out as wide as the widest, centred: tabular figures for a font without them. */
274
+ slotDigits: boolean
271
275
  /** Points between the prefix and the text, in place of the letter spacing there. Not finite: the letter spacing. */
272
276
  prefixSpacing: number
273
277
  /** Points between the text and the suffix, in place of the letter spacing there. Not finite: the letter spacing. */
@@ -289,7 +293,7 @@ export interface NitroInputProps extends HybridViewProps {
289
293
  /** How characters enter and leave. Default: `'auto'`. */
290
294
  effect: NitroInputEffect
291
295
  /** Font size of the text in points. Default: `32`. */
292
- fontSize: number
296
+ textSize: number
293
297
  /**
294
298
  * Height of the line box in points — the CSS meaning: the total height a
295
299
  * line occupies, not extra leading. `0` (the default) uses the font's own.
@@ -302,15 +306,15 @@ export interface NitroInputProps extends HybridViewProps {
302
306
  * `lineHeight < font.lineHeight`), and the reason a compressed `lineHeight`
303
307
  * renders off-centre on a `TextInput`.
304
308
  */
305
- lineHeight: number
309
+ textLineHeight: number
306
310
  /** Numeric font weight, `100`–`900`. Default: `400`. */
307
- fontWeight: number
311
+ textWeight: number
308
312
  /** Font family name; empty = system font. */
309
- fontFamily: string
313
+ textFamily: string
310
314
  /** Text color as a processed ARGB integer; `NaN` = platform label color. */
311
- color: number
315
+ textColor: number
312
316
  /** Where the text sits when the view is wider than it. Default: `'auto'`, the start edge. */
313
- textAlign: NitroInputTextAlign
317
+ textAlignment: NitroInputTextAlign
314
318
  /**
315
319
  * Lay the field out right-to-left: `'auto'` alignment resolves to the right
316
320
  * edge, the prefix moves to the right and the suffix to the left, and a
@@ -361,7 +365,16 @@ export interface NitroInputProps extends HybridViewProps {
361
365
  */
362
366
  numberOfLines: number
363
367
  /** `multiline`: where the text sits in the box. Default: `'auto'` (top). */
364
- textAlignVertical: NitroInputTextAlignVertical
368
+ textVerticalAlignment: NitroInputTextAlignVertical
369
+ /**
370
+ * The style's padding and border, in points, resolved per edge by
371
+ * `NitroInput`. Android insets the text, the overlay and the frame by them;
372
+ * on iOS React Native already lays the view's content out inside them.
373
+ */
374
+ textInsetLeft: number
375
+ textInsetTop: number
376
+ textInsetRight: number
377
+ textInsetBottom: number
365
378
  /**
366
379
  * `multiline`: whether the field scrolls once the text is taller than it.
367
380
  * Turning it off lets a growing field drive its own height. Default: `true`.
@@ -0,0 +1,78 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules'
2
+ import type {
3
+ NitroInputCharacterMapping,
4
+ NitroInputLabelBehavior,
5
+ NitroInputMaskAffinity,
6
+ NitroInputMode,
7
+ NitroInputNotation,
8
+ NitroInputSignPlacement,
9
+ NitroInputTextCase,
10
+ NitroInputVariant,
11
+ } from './NitroInput.nitro'
12
+
13
+ /**
14
+ * What a field's size follows: the subset of `NitroInputProps` the
15
+ * native views read when they report `onSizeChange`, under the same names and
16
+ * already resolved the same way by `NitroInput`.
17
+ */
18
+ export interface NitroInputSizing {
19
+ text: string
20
+ mode: NitroInputMode
21
+ plain: boolean
22
+ multiline: boolean
23
+ secureTextEntry: boolean
24
+ maxLength: number
25
+ fractionDigits: number
26
+ maxIntegerDigits: number
27
+ groupingSeparator: string
28
+ decimalSeparator: string
29
+ prefix: string
30
+ suffix: string
31
+ signPlacement: NitroInputSignPlacement
32
+ placeholder: string
33
+ mask: string
34
+ maskNotations: NitroInputNotation[]
35
+ maskAutocomplete: boolean
36
+ maskAutoSkip: boolean
37
+ maskAffinityFormats: string[]
38
+ maskAffinityStrategy: NitroInputMaskAffinity
39
+ maskTextCase: NitroInputTextCase
40
+ maskCharacterMap: NitroInputCharacterMapping[]
41
+ maskSlotPlaceholder: string
42
+ keepPlaceholder: boolean
43
+ textSize: number
44
+ textLineHeight: number
45
+ prefixFontSize: number
46
+ suffixFontSize: number
47
+ textWeight: number
48
+ textFamily: string
49
+ textLetterSpacing: number
50
+ tabularNums: boolean
51
+ slotDigits: boolean
52
+ prefixSpacing: number
53
+ suffixSpacing: number
54
+ allowFontScaling: boolean
55
+ maxFontSizeMultiplier: number
56
+ variant: NitroInputVariant
57
+ label: string
58
+ labelBehavior: NitroInputLabelBehavior
59
+ labelFontSize: number
60
+ cornerRadius: number
61
+ }
62
+
63
+ /** A size in points (iOS) or dp (Android). */
64
+ export interface NitroInputSize {
65
+ width: number
66
+ height: number
67
+ }
68
+
69
+ /**
70
+ * Measures a single-line field on the JS thread, before its view exists, with
71
+ * the code the view sizes itself with: `NitroInput` lays out at its real size
72
+ * in the commit that mounts it, as React Native's `TextInput` does, instead of
73
+ * at its parent's width until the view's first `onSizeChange` arrives.
74
+ */
75
+ export interface NitroInputMeasure extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
76
+ /** What the field reports through `onSizeChange` once mounted, unfocused. */
77
+ measure(sizing: NitroInputSizing): NitroInputSize
78
+ }
@@ -196,7 +196,7 @@ export interface NitroNumberProps extends HybridViewProps {
196
196
  /** A pause after each sweep, in ms. Default: `0`. */
197
197
  shimmerDelay?: number
198
198
  /** Font size of the digits in points. Default: `32`. */
199
- fontSize?: number
199
+ textSize?: number
200
200
  /** Font size of `prefix` in points. Defaults to `fontSize`. */
201
201
  prefixFontSize?: number
202
202
  /** Font size of `suffix` in points. Defaults to `fontSize`. */
@@ -208,7 +208,7 @@ export interface NitroNumberProps extends HybridViewProps {
208
208
  /** Vertical alignment of `suffix` only. Defaults to `affixAlign`. */
209
209
  suffixAlign?: NitroNumberAffixAlign
210
210
  /** Points added after every glyph, like `Text`'s `letterSpacing`; an affix gets it in proportion to its size. Default: `0`. */
211
- letterSpacing?: number
211
+ textLetterSpacing?: number
212
212
  /** Points between the prefix and the digits, in place of the letter spacing there. Not finite: the letter spacing. */
213
213
  prefixSpacing?: number
214
214
  /** Points between the digits and the suffix, in place of the letter spacing there. Not finite: the letter spacing. */
@@ -274,13 +274,13 @@ export interface NitroNumberProps extends HybridViewProps {
274
274
  /** Upper bound for `allowFontScaling`, e.g. `1.3`. `0` means no cap. Default: `0`. */
275
275
  maxFontSizeMultiplier?: number
276
276
  /** Numeric font weight, `100`–`900`. Default: `400`. */
277
- fontWeight?: number
277
+ textWeight?: number
278
278
  /** Font family name. Defaults to the system font. */
279
- fontFamily?: string
279
+ textFamily?: string
280
280
  /** Text color as a processed ARGB integer (from `processColor`). Defaults to the platform label color. */
281
- color?: number
281
+ textColor?: number
282
282
  /** Where the number sits inside the view when the view is wider than the number. Default: `'auto'`, the start edge. */
283
- textAlign?: NitroNumberTextAlign
283
+ textAlignment?: NitroNumberTextAlign
284
284
  /**
285
285
  * Lay the figure out right-to-left: `'auto'` alignment resolves to the right
286
286
  * edge, the prefix moves to the right and the suffix to the left, and the