react-native-nitro-input 0.3.8 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/README.md +5 -1
  3. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputMeasure.kt +52 -0
  4. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +74 -80
  5. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +18 -18
  6. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextView.kt +14 -14
  7. package/android/src/main/java/com/margelo/nitro/nitroinput/InputFonts.kt +199 -0
  8. package/android/src/main/java/com/margelo/nitro/nitroinput/InputSizing.kt +398 -0
  9. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +112 -333
  10. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +178 -30
  11. package/ios/HybridNitroInputView.swift +69 -75
  12. package/ios/HybridNitroNumberView.swift +18 -18
  13. package/ios/HybridNitroTextView.swift +14 -14
  14. package/ios/InputSizing.swift +534 -0
  15. package/ios/NitroInputView.swift +102 -198
  16. package/ios/NitroNumberView.swift +98 -23
  17. package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +12 -8
  18. package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
  19. package/lib/commonjs/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
  20. package/lib/commonjs/src/NitroInput.js +164 -23
  21. package/lib/commonjs/src/NitroNumber.js +1 -1
  22. package/lib/commonjs/src/NitroText.js +6 -6
  23. package/lib/commonjs/src/specs/NitroInputMeasure.nitro.js +2 -0
  24. package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +12 -8
  25. package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
  26. package/lib/module/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
  27. package/lib/module/src/NitroInput.js +165 -24
  28. package/lib/module/src/NitroNumber.js +1 -1
  29. package/lib/module/src/NitroText.js +6 -6
  30. package/lib/module/src/specs/NitroInputMeasure.nitro.js +1 -0
  31. package/lib/typescript/src/NitroInput.d.ts +9 -16
  32. package/lib/typescript/src/specs/NitroInput.nitro.d.ts +17 -8
  33. package/lib/typescript/src/specs/NitroInputMeasure.nitro.d.ts +67 -0
  34. package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +6 -6
  35. package/lib/typescript/src/specs/NitroText.nitro.d.ts +6 -6
  36. package/nitro.json +10 -0
  37. package/nitrogen/generated/android/NitroInput+autolinking.cmake +2 -0
  38. package/nitrogen/generated/android/NitroInputOnLoad.cpp +16 -0
  39. package/nitrogen/generated/android/c++/JHybridNitroInputMeasureSpec.cpp +93 -0
  40. package/nitrogen/generated/android/c++/JHybridNitroInputMeasureSpec.hpp +63 -0
  41. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +76 -40
  42. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +24 -16
  43. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +30 -30
  44. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +12 -12
  45. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.cpp +30 -30
  46. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.hpp +12 -12
  47. package/nitrogen/generated/android/c++/JNitroInputSize.hpp +61 -0
  48. package/nitrogen/generated/android/c++/JNitroInputSizing.hpp +284 -0
  49. package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +44 -24
  50. package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +18 -18
  51. package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.cpp +18 -18
  52. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputMeasureSpec.kt +56 -0
  53. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +32 -8
  54. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +6 -6
  55. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextViewSpec.kt +6 -6
  56. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSize.kt +56 -0
  57. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSizing.kt +246 -0
  58. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +17 -0
  59. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +29 -0
  60. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +11 -0
  61. package/nitrogen/generated/ios/NitroInputAutolinking.mm +8 -0
  62. package/nitrogen/generated/ios/NitroInputAutolinking.swift +12 -0
  63. package/nitrogen/generated/ios/c++/HybridNitroInputMeasureSpecSwift.cpp +11 -0
  64. package/nitrogen/generated/ios/c++/HybridNitroInputMeasureSpecSwift.hpp +112 -0
  65. package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +56 -32
  66. package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +24 -24
  67. package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.hpp +24 -24
  68. package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +56 -32
  69. package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +24 -24
  70. package/nitrogen/generated/ios/c++/views/HybridNitroTextViewComponent.mm +24 -24
  71. package/nitrogen/generated/ios/swift/HybridNitroInputMeasureSpec.swift +55 -0
  72. package/nitrogen/generated/ios/swift/HybridNitroInputMeasureSpec_cxx.swift +138 -0
  73. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +12 -8
  74. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +68 -24
  75. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +6 -6
  76. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +18 -18
  77. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec.swift +6 -6
  78. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec_cxx.swift +18 -18
  79. package/nitrogen/generated/ios/swift/NitroInputSize.swift +34 -0
  80. package/nitrogen/generated/ios/swift/NitroInputSizing.swift +242 -0
  81. package/nitrogen/generated/shared/c++/HybridNitroInputMeasureSpec.cpp +21 -0
  82. package/nitrogen/generated/shared/c++/HybridNitroInputMeasureSpec.hpp +66 -0
  83. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +24 -16
  84. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +24 -16
  85. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +12 -12
  86. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +12 -12
  87. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.cpp +12 -12
  88. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.hpp +12 -12
  89. package/nitrogen/generated/shared/c++/NitroInputSize.hpp +87 -0
  90. package/nitrogen/generated/shared/c++/NitroInputSizing.hpp +263 -0
  91. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +24 -16
  92. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +36 -24
  93. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +12 -12
  94. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +18 -18
  95. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.cpp +12 -12
  96. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.hpp +18 -18
  97. package/nitrogen/generated/shared/json/NitroInputViewConfig.json +12 -8
  98. package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
  99. package/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
  100. package/package.json +4 -2
  101. package/src/NitroInput.tsx +201 -64
  102. package/src/NitroNumber.tsx +6 -6
  103. package/src/NitroText.tsx +6 -6
  104. package/src/specs/NitroInput.nitro.ts +17 -8
  105. package/src/specs/NitroInputMeasure.nitro.ts +76 -0
  106. package/src/specs/NitroNumber.nitro.ts +6 -6
  107. 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
@@ -734,6 +744,85 @@ export type NitroInputTransition = 'none' | 'reflow'
734
744
  * Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
735
745
  * it to its content instead, and is on by default when the text reflows.
736
746
  */
747
+ interface Insets {
748
+ left: number
749
+ top: number
750
+ right: number
751
+ bottom: number
752
+ }
753
+ const NO_INSETS: Insets = { left: 0, top: 0, right: 0, bottom: 0 }
754
+
755
+ /**
756
+ * The style's padding plus border per edge, resolved the way Yoga does: a
757
+ * start / end edge before left / right, then horizontal / vertical, then all.
758
+ * A size measured for the text gets them added, as `TextInput`'s is, so a
759
+ * padded field grows rather than squeezing its text. Percentages are not
760
+ * resolved here (they need the parent's size) and count as 0.
761
+ */
762
+ function styleInsets(flat: Record<string, unknown> | undefined, rightToLeft: boolean): Insets {
763
+ if (flat == null) return NO_INSETS
764
+ const n = (key: string): number | undefined => {
765
+ const value = flat[key]
766
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined
767
+ }
768
+ const start = rightToLeft ? 'End' : 'Start'
769
+ const end = rightToLeft ? 'Start' : 'End'
770
+ const insets = {
771
+ left:
772
+ (n(`padding${start}`) ?? n('paddingLeft') ?? n('paddingHorizontal') ?? n('padding') ?? 0) +
773
+ (n(`border${start}Width`) ?? n('borderLeftWidth') ?? n('borderWidth') ?? 0),
774
+ right:
775
+ (n(`padding${end}`) ?? n('paddingRight') ?? n('paddingHorizontal') ?? n('padding') ?? 0) +
776
+ (n(`border${end}Width`) ?? n('borderRightWidth') ?? n('borderWidth') ?? 0),
777
+ top:
778
+ (n('paddingTop') ?? n('paddingVertical') ?? n('padding') ?? 0) + (n('borderTopWidth') ?? n('borderWidth') ?? 0),
779
+ bottom:
780
+ (n('paddingBottom') ?? n('paddingVertical') ?? n('padding') ?? 0) +
781
+ (n('borderBottomWidth') ?? n('borderWidth') ?? 0),
782
+ }
783
+ return insets.left === 0 && insets.right === 0 && insets.top === 0 && insets.bottom === 0 ? NO_INSETS : insets
784
+ }
785
+
786
+ function styleTextAlign(value: TextStyle['textAlign'], rightToLeft: boolean): NitroInputTextAlign | undefined {
787
+ switch (value) {
788
+ case undefined:
789
+ return undefined
790
+ // `justify` has no meaning on one line: the start edge, as on a TextInput.
791
+ case 'start':
792
+ case 'justify':
793
+ return 'auto'
794
+ case 'end':
795
+ return rightToLeft ? 'left' : 'right'
796
+ default:
797
+ return value
798
+ }
799
+ }
800
+
801
+ function styleTextAlignVertical(value: TextStyle['textAlignVertical']): NitroInputTextAlignVertical | undefined {
802
+ return value ?? undefined
803
+ }
804
+
805
+ // One per app, made on first use. `null` when the native side has none (an
806
+ // app built against an older version, or a test without native modules): the
807
+ // field then takes its size from the view's first report, as it used to.
808
+ let measurer: NitroInputMeasure | null | undefined
809
+ function measureSizing(sizing: NitroInputSizing): Size | null {
810
+ if (measurer === undefined) {
811
+ try {
812
+ const made = NitroModules.createHybridObject<NitroInputMeasure>('NitroInputMeasure')
813
+ measurer = typeof made?.measure === 'function' ? made : null
814
+ } catch {
815
+ measurer = null
816
+ }
817
+ }
818
+ if (measurer === null) return null
819
+ try {
820
+ return measurer.measure(sizing)
821
+ } catch {
822
+ return null
823
+ }
824
+ }
825
+
737
826
  export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
738
827
  function NitroInput(
739
828
  {
@@ -752,7 +841,7 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
752
841
  signPlacement,
753
842
  prefixAlign,
754
843
  suffixAlign,
755
- letterSpacing,
844
+ letterSpacing: letterSpacingProp,
756
845
  prefixSpacing,
757
846
  suffixSpacing,
758
847
  prefixOffset,
@@ -764,12 +853,12 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
764
853
  easing,
765
854
  bounce,
766
855
  effect,
767
- fontSize,
768
- lineHeight,
769
- fontWeight,
770
- fontFamily,
771
- color,
772
- textAlign,
856
+ fontSize: fontSizeProp,
857
+ lineHeight: lineHeightProp,
858
+ fontWeight: fontWeightProp,
859
+ fontFamily: fontFamilyProp,
860
+ color: colorProp,
861
+ textAlign: textAlignProp,
773
862
  cursorColor,
774
863
  selectionColor,
775
864
  caretHidden,
@@ -808,7 +897,7 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
808
897
  multiline,
809
898
  numberOfLines,
810
899
  rows,
811
- textAlignVertical,
900
+ textAlignVertical: textAlignVerticalProp,
812
901
  scrollEnabled,
813
902
  autoFocus,
814
903
  transition,
@@ -912,6 +1001,11 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
912
1001
  if (value != null) textRef.current = value
913
1002
 
914
1003
  const [size, setSize] = useState<Size | null>(null)
1004
+ // The size measured before the view existed (see `measureSizing`), and
1005
+ // whether the view has reported its own since.
1006
+ const seedRef = useRef<Size | null>(null)
1007
+ const seedKeyRef = useRef('')
1008
+ const reportedRef = useRef(false)
915
1009
  // Worklets are registered on the UI runtime and referenced by id; a
916
1010
  // handler marked 'worklet' runs there instead of on the JS thread.
917
1011
  const transformId = useWorkletId(transform, registerTransform)
@@ -1035,16 +1129,29 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
1035
1129
  const flat = useMemo(
1036
1130
  () =>
1037
1131
  StyleSheet.flatten(style) as
1038
- | { width?: unknown; flex?: unknown; height?: unknown; direction?: unknown }
1132
+ | ({ width?: unknown; flex?: unknown; height?: unknown; direction?: unknown } & TextStyle)
1039
1133
  | undefined,
1040
1134
  [style]
1041
1135
  )
1136
+ // `TextInput` takes its typography from `style`; so does this, under the
1137
+ // props of the same name, which win. (Fabric hands a view its style's keys
1138
+ // as props too; the view's own are named so that none can be one of them -
1139
+ // see PropNameCollisions.test.)
1140
+ const fontSize = fontSizeProp ?? flat?.fontSize
1141
+ const lineHeight = lineHeightProp ?? flat?.lineHeight
1142
+ const fontWeight = fontWeightProp ?? flat?.fontWeight
1143
+ const fontFamily = fontFamilyProp ?? flat?.fontFamily
1144
+ const color = colorProp ?? flat?.color
1145
+ const letterSpacing = letterSpacingProp ?? flat?.letterSpacing
1146
+ const textAlignVertical = textAlignVerticalProp ?? styleTextAlignVertical(flat?.textAlignVertical)
1042
1147
  // The layout direction, resolved the way React Native resolves it for its
1043
1148
  // own views: the field's `style.direction` if it says, else the app's.
1044
1149
  // Fabric does not hand a Hybrid View its resolved direction, so native is
1045
1150
  // told outright.
1046
1151
  const rightToLeft =
1047
1152
  flat?.direction === 'rtl' || (flat?.direction !== 'ltr' && I18nManager.isRTL)
1153
+ const textAlign = textAlignProp ?? styleTextAlign(flat?.textAlign, rightToLeft)
1154
+ const insets = useMemo(() => styleInsets(flat as Record<string, unknown> | undefined, rightToLeft), [flat, rightToLeft])
1048
1155
  // `TextInput` stretches to its parent; sizing to content is this
1049
1156
  // component's own behaviour, and it is what stops it being a drop-in.
1050
1157
  // `NitroInput` turns it off so flexbox gives it the parent's width, the
@@ -1066,12 +1173,16 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
1066
1173
  const onSizeChange = useMemo(
1067
1174
  () =>
1068
1175
  callback((width: number, height: number) => {
1176
+ reportedRef.current = true
1069
1177
  if (!measuredRef.current) return
1070
1178
  setSize((previous) => {
1179
+ // Until the first report the field shows the seed; a report that
1180
+ // matches it leaves `size` as it is, and costs no commit.
1181
+ const shown = previous ?? seedRef.current
1071
1182
  if (!autoWidthRef.current) {
1072
- return previous !== null && previous.height === height ? previous : { width: previous?.width ?? width, height }
1183
+ return shown !== null && shown.height === height ? previous : { width: shown?.width ?? width, height }
1073
1184
  }
1074
- return previous !== null && previous.width === width && previous.height === height
1185
+ return shown !== null && shown.width === width && shown.height === height
1075
1186
  ? previous
1076
1187
  : { width, height }
1077
1188
  })
@@ -1392,94 +1503,122 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
1392
1503
  if (resolvedImportance != null) hostViewProps.importantForAccessibility = resolvedImportance
1393
1504
  if (resolvedLabelledBy != null) hostViewProps.accessibilityLabelledBy = resolvedLabelledBy
1394
1505
 
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
- )
1506
+ // What the field's size follows. Sent to the view as props and, before
1507
+ // the view exists, to `measureSizing`, so the two see the same values.
1508
+ const sizing: NitroInputSizing = {
1509
+ text: value ?? uncontrolledText,
1510
+ mode: resolvedMode,
1511
+ plain: !reflows,
1512
+ multiline: isMultiline,
1513
+ secureTextEntry: secureTextEntry ?? false,
1514
+ maxLength: maxLength ?? 0,
1515
+ fractionDigits: resolvedFractionDigits,
1516
+ maxIntegerDigits: maxIntegerDigits ?? 15,
1517
+ groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? ',',
1518
+ decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.',
1519
+ prefix: resolvedPrefix,
1520
+ suffix: resolvedSuffix,
1521
+ signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix',
1522
+ placeholder: placeholder ?? '',
1523
+ mask: resolvedMode === 'mask' ? (mask ?? '') : '',
1524
+ maskNotations: stableNotations,
1525
+ maskAutocomplete: maskAutocomplete ?? true,
1526
+ maskAutoSkip: maskAutoSkip ?? false,
1527
+ maskAffinityFormats: stableAffinityFormats,
1528
+ maskAffinityStrategy: maskAffinityStrategy ?? 'wholeString',
1529
+ maskTextCase: maskTextCase ?? 'none',
1530
+ maskCharacterMap: stableCharacterMap,
1531
+ maskSlotPlaceholder: maskSlotPlaceholder ?? (keepPlaceholder ? '_' : ''),
1532
+ keepPlaceholder: keepPlaceholder ?? false,
1533
+ textSize: resolvedFontSize,
1534
+ textLineHeight: Math.max(0, lineHeight ?? 0),
1535
+ prefixFontSize: prefixFontSize ?? resolvedFontSize,
1536
+ suffixFontSize: suffixFontSize ?? resolvedFontSize,
1537
+ textWeight: numericWeight,
1538
+ textFamily: fontFamily ?? '',
1539
+ textLetterSpacing: letterSpacing ?? 0,
1540
+ prefixSpacing: prefixSpacing ?? Infinity,
1541
+ suffixSpacing: suffixSpacing ?? Infinity,
1542
+ allowFontScaling: allowFontScaling ?? false,
1543
+ maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0,
1544
+ variant: variant ?? 'none',
1545
+ label: label ?? '',
1546
+ labelBehavior: labelBehavior ?? 'float',
1547
+ labelFontSize: labelFontSize ?? 0,
1548
+ cornerRadius: cornerRadius ?? 8,
1549
+ }
1550
+ // Until the view reports its size, the field lays out at the size it will
1551
+ // report, measured now with the view's own code - as `TextInput` measures
1552
+ // in its shadow node - rather than at its parent's width for the commit
1553
+ // the report takes. Not for a wrapping field (its height needs the width
1554
+ // it will get), a `transform` (a worklet, run on the UI thread) or a
1555
+ // style that sets both dimensions. Measured again only when what it
1556
+ // follows changes.
1557
+ if (!reportedRef.current) {
1558
+ const seedKey = measured && !isMultiline && transformId === 0 ? JSON.stringify(sizing) : ''
1559
+ if (seedKey !== seedKeyRef.current) {
1560
+ seedKeyRef.current = seedKey
1561
+ seedRef.current = seedKey === '' ? null : measureSizing(sizing)
1562
+ }
1563
+ }
1564
+ const shownSize = size ?? seedRef.current
1565
+ // The size measured for the text, plus the style's padding and border
1566
+ // (Yoga's box includes them; `TextInput`'s measured size gets them too).
1567
+ const autoSize = useMemo(() => {
1568
+ const extraWidth = insets.left + insets.right
1569
+ const extraHeight = insets.top + insets.bottom
1570
+ return shownSize !== null
1571
+ ? autoWidth
1572
+ ? { width: shownSize.width + extraWidth, height: shownSize.height + extraHeight }
1573
+ : { height: shownSize.height + extraHeight }
1574
+ : { height: resolvedFontSize * 1.25 + extraHeight }
1575
+ }, [shownSize, resolvedFontSize, autoWidth, insets])
1404
1576
 
1405
1577
  return (
1406
1578
  <NativeNitroInputView
1407
1579
  {...hostViewProps}
1580
+ {...sizing}
1408
1581
  ref={hostRef as React.Ref<never>}
1409
1582
  style={[autoSize, style]}
1410
1583
  hybridRef={hybridRef}
1411
- text={value ?? uncontrolledText}
1412
1584
  // An uncontrolled field's `text` is its initial text: a count of 0 is
1413
1585
  // never caught up after the first edit, so native never puts it back.
1414
1586
  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
1587
  prefixAlign={prefixAlign ?? resolvedAffixAlign}
1427
1588
  suffixAlign={suffixAlign ?? resolvedAffixAlign}
1428
- letterSpacing={letterSpacing ?? 0}
1429
- prefixSpacing={prefixSpacing ?? Infinity}
1430
- suffixSpacing={suffixSpacing ?? Infinity}
1431
1589
  prefixOffset={prefixOffset ?? 0}
1432
1590
  suffixOffset={suffixOffset ?? 0}
1433
- placeholder={placeholder ?? ''}
1434
1591
  placeholderColor={processedPlaceholderColor}
1435
1592
  duration={duration ?? 400}
1436
1593
  easing={easing ?? 'expo'}
1437
1594
  bounce={bounce ?? 0.15}
1438
1595
  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'}
1596
+ textColor={processedColor}
1597
+ textAlignment={textAlign ?? 'auto'}
1445
1598
  rightToLeft={rightToLeft}
1446
1599
  caretColor={processedCursorColor}
1447
1600
  selectionColor={processedSelectionColor}
1448
1601
  caretHidden={caretHidden ?? false}
1449
1602
  adjustsFontSizeToFit={adjustsFontSizeToFit ?? false}
1450
1603
  minimumFontScale={minimumFontScale ?? 0.5}
1451
- allowFontScaling={allowFontScaling ?? false}
1452
- maxFontSizeMultiplier={maxFontSizeMultiplier ?? 0}
1453
- variant={variant ?? 'none'}
1454
- label={label ?? ''}
1455
- labelBehavior={labelBehavior ?? 'float'}
1456
1604
  labelColor={processedLabelColor}
1457
1605
  labelFocusedColor={processedLabelFocusedColor}
1458
- labelFontSize={labelFontSize ?? 0}
1459
1606
  strokeColor={processedStrokeColor}
1460
1607
  focusedStrokeColor={processedFocusedStrokeColor}
1461
1608
  strokeWidth={strokeWidth ?? 1}
1462
- cornerRadius={cornerRadius ?? 8}
1463
1609
  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
1610
  onChangeMask={onChangeMaskCallback}
1475
1611
  keyboardType={resolvedKeyboardType}
1476
1612
  returnKeyType={resolvedReturnKeyType}
1477
1613
  autoCapitalize={autoCapitalize ?? 'sentences'}
1478
1614
  autoCorrect={autoCorrect ?? true}
1479
1615
  editable={(editable ?? true) && !(readOnly ?? false)}
1480
- multiline={isMultiline}
1481
1616
  numberOfLines={Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0))}
1482
- textAlignVertical={textAlignVertical ?? 'auto'}
1617
+ textVerticalAlignment={textAlignVertical ?? 'auto'}
1618
+ textInsetLeft={insets.left}
1619
+ textInsetTop={insets.top}
1620
+ textInsetRight={insets.right}
1621
+ textInsetBottom={insets.bottom}
1483
1622
  scrollEnabled={scrollEnabled ?? true}
1484
1623
  autoFocus={autoFocus ?? false}
1485
1624
  fieldTestID={viewProps.testID ?? ''}
@@ -1496,7 +1635,6 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
1496
1635
  ? 'submit'
1497
1636
  : 'blurAndSubmit')
1498
1637
  }
1499
- secureTextEntry={secureTextEntry ?? false}
1500
1638
  keyboardAppearance={keyboardAppearance ?? 'default'}
1501
1639
  textContentType={textContentType ?? autoComplete ?? ''}
1502
1640
  enablesReturnKeyAutomatically={enablesReturnKeyAutomatically ?? false}
@@ -1509,7 +1647,6 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
1509
1647
  spellCheck={spellCheck ?? autoCorrect ?? true}
1510
1648
  selectionStart={selection?.start ?? -1}
1511
1649
  selectionEnd={selection?.end ?? selection?.start ?? -1}
1512
- maxLength={maxLength ?? 0}
1513
1650
  transformWorklet={transformId}
1514
1651
  onChangeTextWorklet={onChangeTextId}
1515
1652
  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,7 @@ 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
271
  /** Points between the prefix and the text, in place of the letter spacing there. Not finite: the letter spacing. */
272
272
  prefixSpacing: number
273
273
  /** Points between the text and the suffix, in place of the letter spacing there. Not finite: the letter spacing. */
@@ -289,7 +289,7 @@ export interface NitroInputProps extends HybridViewProps {
289
289
  /** How characters enter and leave. Default: `'auto'`. */
290
290
  effect: NitroInputEffect
291
291
  /** Font size of the text in points. Default: `32`. */
292
- fontSize: number
292
+ textSize: number
293
293
  /**
294
294
  * Height of the line box in points — the CSS meaning: the total height a
295
295
  * line occupies, not extra leading. `0` (the default) uses the font's own.
@@ -302,15 +302,15 @@ export interface NitroInputProps extends HybridViewProps {
302
302
  * `lineHeight < font.lineHeight`), and the reason a compressed `lineHeight`
303
303
  * renders off-centre on a `TextInput`.
304
304
  */
305
- lineHeight: number
305
+ textLineHeight: number
306
306
  /** Numeric font weight, `100`–`900`. Default: `400`. */
307
- fontWeight: number
307
+ textWeight: number
308
308
  /** Font family name; empty = system font. */
309
- fontFamily: string
309
+ textFamily: string
310
310
  /** Text color as a processed ARGB integer; `NaN` = platform label color. */
311
- color: number
311
+ textColor: number
312
312
  /** Where the text sits when the view is wider than it. Default: `'auto'`, the start edge. */
313
- textAlign: NitroInputTextAlign
313
+ textAlignment: NitroInputTextAlign
314
314
  /**
315
315
  * Lay the field out right-to-left: `'auto'` alignment resolves to the right
316
316
  * edge, the prefix moves to the right and the suffix to the left, and a
@@ -361,7 +361,16 @@ export interface NitroInputProps extends HybridViewProps {
361
361
  */
362
362
  numberOfLines: number
363
363
  /** `multiline`: where the text sits in the box. Default: `'auto'` (top). */
364
- textAlignVertical: NitroInputTextAlignVertical
364
+ textVerticalAlignment: NitroInputTextAlignVertical
365
+ /**
366
+ * The style's padding and border, in points, resolved per edge by
367
+ * `NitroInput`. Android insets the text, the overlay and the frame by them;
368
+ * on iOS React Native already lays the view's content out inside them.
369
+ */
370
+ textInsetLeft: number
371
+ textInsetTop: number
372
+ textInsetRight: number
373
+ textInsetBottom: number
365
374
  /**
366
375
  * `multiline`: whether the field scrolls once the text is taller than it.
367
376
  * Turning it off lets a growing field drive its own height. Default: `true`.
@@ -0,0 +1,76 @@
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
+ prefixSpacing: number
51
+ suffixSpacing: number
52
+ allowFontScaling: boolean
53
+ maxFontSizeMultiplier: number
54
+ variant: NitroInputVariant
55
+ label: string
56
+ labelBehavior: NitroInputLabelBehavior
57
+ labelFontSize: number
58
+ cornerRadius: number
59
+ }
60
+
61
+ /** A size in points (iOS) or dp (Android). */
62
+ export interface NitroInputSize {
63
+ width: number
64
+ height: number
65
+ }
66
+
67
+ /**
68
+ * Measures a single-line field on the JS thread, before its view exists, with
69
+ * the code the view sizes itself with: `NitroInput` lays out at its real size
70
+ * in the commit that mounts it, as React Native's `TextInput` does, instead of
71
+ * at its parent's width until the view's first `onSizeChange` arrives.
72
+ */
73
+ export interface NitroInputMeasure extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
74
+ /** What the field reports through `onSizeChange` once mounted, unfocused. */
75
+ measure(sizing: NitroInputSizing): NitroInputSize
76
+ }
@@ -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
@@ -21,16 +21,16 @@ import type { NitroInputEasing, NitroInputEffect } from './NitroInput.nitro'
21
21
  export interface NitroTextProps extends HybridViewProps {
22
22
  text: string
23
23
  /** In points, already scaled for the system text size when the wrapper was asked to. Default 17. */
24
- fontSize?: number
24
+ textSize?: number
25
25
  /** Numeric weight, 100–900. Default 400. */
26
- fontWeight?: number
26
+ textWeight?: number
27
27
  /** Default: the system font. */
28
- fontFamily?: string
28
+ textFamily?: string
29
29
  /** Processed ARGB. Default: the platform label colour. */
30
- color?: number
30
+ textColor?: number
31
31
  /** Points after every character. */
32
- letterSpacing?: number
33
- textAlign?: NitroNumberTextAlign
32
+ textLetterSpacing?: number
33
+ textAlignment?: NitroNumberTextAlign
34
34
  rightToLeft?: boolean
35
35
  /** Of a morph, in ms. Default 400. */
36
36
  duration?: number