react-native-nitro-input 0.3.7 → 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 (129) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/README.md +9 -4
  3. package/android/CMakeLists.txt +1 -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 +74 -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 +199 -0
  9. package/android/src/main/java/com/margelo/nitro/nitroinput/InputSizing.kt +398 -0
  10. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +112 -333
  11. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +178 -30
  12. package/cpp/RollingEngine.cpp +68 -5
  13. package/cpp/RollingEngine.hpp +13 -0
  14. package/cpp/numberformat/FormatFigure.cpp +134 -0
  15. package/cpp/numberformat/FormatFigure.hpp +65 -0
  16. package/cpp/numberformat/HybridNitroNumberFormat.cpp +32 -10
  17. package/cpp/numberformat/HybridNitroNumberFormat.hpp +9 -1
  18. package/ios/HybridNitroInputView.swift +69 -75
  19. package/ios/HybridNitroNumberView.swift +18 -18
  20. package/ios/HybridNitroTextView.swift +14 -14
  21. package/ios/InputSizing.swift +534 -0
  22. package/ios/NitroInputView.swift +102 -198
  23. package/ios/NitroNumberView.swift +98 -23
  24. package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +12 -8
  25. package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
  26. package/lib/commonjs/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
  27. package/lib/commonjs/src/NitroInput.js +164 -23
  28. package/lib/commonjs/src/NitroNumber.js +19 -11
  29. package/lib/commonjs/src/NitroText.js +6 -6
  30. package/lib/commonjs/src/NumberFormat.js +20 -0
  31. package/lib/commonjs/src/formatProps.js +57 -81
  32. package/lib/commonjs/src/specs/NitroInputMeasure.nitro.js +2 -0
  33. package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +12 -8
  34. package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
  35. package/lib/module/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
  36. package/lib/module/src/NitroInput.js +165 -24
  37. package/lib/module/src/NitroNumber.js +20 -12
  38. package/lib/module/src/NitroText.js +6 -6
  39. package/lib/module/src/NumberFormat.js +18 -0
  40. package/lib/module/src/formatProps.js +54 -81
  41. package/lib/module/src/specs/NitroInputMeasure.nitro.js +1 -0
  42. package/lib/typescript/src/NitroInput.d.ts +9 -16
  43. package/lib/typescript/src/NitroNumber.d.ts +25 -7
  44. package/lib/typescript/src/NumberFormat.d.ts +15 -1
  45. package/lib/typescript/src/formatProps.d.ts +23 -18
  46. package/lib/typescript/src/specs/NitroInput.nitro.d.ts +17 -8
  47. package/lib/typescript/src/specs/NitroInputMeasure.nitro.d.ts +67 -0
  48. package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +6 -6
  49. package/lib/typescript/src/specs/NitroText.nitro.d.ts +6 -6
  50. package/lib/typescript/src/specs/NumberFormat.nitro.d.ts +33 -0
  51. package/nitro.json +10 -0
  52. package/nitrogen/generated/android/NitroInput+autolinking.cmake +2 -0
  53. package/nitrogen/generated/android/NitroInputOnLoad.cpp +16 -0
  54. package/nitrogen/generated/android/c++/JHybridNitroInputMeasureSpec.cpp +93 -0
  55. package/nitrogen/generated/android/c++/JHybridNitroInputMeasureSpec.hpp +63 -0
  56. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +76 -40
  57. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +24 -16
  58. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +30 -30
  59. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +12 -12
  60. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.cpp +30 -30
  61. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.hpp +12 -12
  62. package/nitrogen/generated/android/c++/JNitroInputSize.hpp +61 -0
  63. package/nitrogen/generated/android/c++/JNitroInputSizing.hpp +284 -0
  64. package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +44 -24
  65. package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +18 -18
  66. package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.cpp +18 -18
  67. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputMeasureSpec.kt +56 -0
  68. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +32 -8
  69. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +6 -6
  70. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextViewSpec.kt +6 -6
  71. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSize.kt +56 -0
  72. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSizing.kt +246 -0
  73. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +17 -0
  74. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +29 -0
  75. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +11 -0
  76. package/nitrogen/generated/ios/NitroInputAutolinking.mm +8 -0
  77. package/nitrogen/generated/ios/NitroInputAutolinking.swift +12 -0
  78. package/nitrogen/generated/ios/c++/HybridNitroInputMeasureSpecSwift.cpp +11 -0
  79. package/nitrogen/generated/ios/c++/HybridNitroInputMeasureSpecSwift.hpp +112 -0
  80. package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +56 -32
  81. package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +24 -24
  82. package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.hpp +24 -24
  83. package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +56 -32
  84. package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +24 -24
  85. package/nitrogen/generated/ios/c++/views/HybridNitroTextViewComponent.mm +24 -24
  86. package/nitrogen/generated/ios/swift/HybridNitroInputMeasureSpec.swift +55 -0
  87. package/nitrogen/generated/ios/swift/HybridNitroInputMeasureSpec_cxx.swift +138 -0
  88. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +12 -8
  89. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +68 -24
  90. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +6 -6
  91. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +18 -18
  92. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec.swift +6 -6
  93. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec_cxx.swift +18 -18
  94. package/nitrogen/generated/ios/swift/NitroInputSize.swift +34 -0
  95. package/nitrogen/generated/ios/swift/NitroInputSizing.swift +242 -0
  96. package/nitrogen/generated/shared/c++/HybridNitroInputMeasureSpec.cpp +21 -0
  97. package/nitrogen/generated/shared/c++/HybridNitroInputMeasureSpec.hpp +66 -0
  98. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +24 -16
  99. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +24 -16
  100. package/nitrogen/generated/shared/c++/HybridNitroNumberFormatSpec.cpp +2 -0
  101. package/nitrogen/generated/shared/c++/HybridNitroNumberFormatSpec.hpp +8 -0
  102. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +12 -12
  103. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +12 -12
  104. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.cpp +12 -12
  105. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.hpp +12 -12
  106. package/nitrogen/generated/shared/c++/NitroInputSize.hpp +87 -0
  107. package/nitrogen/generated/shared/c++/NitroInputSizing.hpp +263 -0
  108. package/nitrogen/generated/shared/c++/NumberFigure.hpp +95 -0
  109. package/nitrogen/generated/shared/c++/NumberFormatLayout.hpp +112 -0
  110. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +24 -16
  111. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +36 -24
  112. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +12 -12
  113. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +18 -18
  114. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.cpp +12 -12
  115. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.hpp +18 -18
  116. package/nitrogen/generated/shared/json/NitroInputViewConfig.json +12 -8
  117. package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
  118. package/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
  119. package/package.json +5 -3
  120. package/src/NitroInput.tsx +201 -64
  121. package/src/NitroNumber.tsx +54 -25
  122. package/src/NitroText.tsx +6 -6
  123. package/src/NumberFormat.ts +22 -0
  124. package/src/formatProps.ts +59 -99
  125. package/src/specs/NitroInput.nitro.ts +17 -8
  126. package/src/specs/NitroInputMeasure.nitro.ts +76 -0
  127. package/src/specs/NitroNumber.nitro.ts +6 -6
  128. package/src/specs/NitroText.nitro.ts +6 -6
  129. package/src/specs/NumberFormat.nitro.ts +35 -0
@@ -14,11 +14,28 @@ export interface NitroNumberProps extends Omit<ViewProps, 'children'> {
14
14
  /**
15
15
  * The number to display. Every change rolls each digit natively to its new
16
16
  * glyph, in the direction of the change. The first value is shown instantly.
17
- * At most 18 digits are shown: `|value| × 10^fractionDigits` is clamped at
18
- * 10^17, and a JS number carries exact integers only up to 2^53.
17
+ *
18
+ * A `bigint` or a decimal string (`"1234.56"`) is taken as is, with no
19
+ * conversion on your side: money kept as minor units passes straight in
20
+ * with `minorDigits`. With a `format`, it is rounded by the format, in
21
+ * decimal, so it never goes through a double first. The digits themselves
22
+ * animate as a double: exact while `|value| × 10^fractionDigits` stays
23
+ * within 2^53, and at most 18 digits are shown.
24
+ */
25
+ value: number | bigint | string;
26
+ /**
27
+ * The decimal places `value` is counted in: `value={123456n}` with
28
+ * `minorDigits={2}` is 1234.56, cents to dollars without dividing. Applied
29
+ * to a bigint or a decimal string exactly. Default: `0`.
30
+ */
31
+ minorDigits?: number;
32
+ /**
33
+ * Digits shown after the decimal separator. Default: `0`, or with a
34
+ * `format`, what the format shows for each value: its
35
+ * `trailingZeroDisplay`, a minimum below its maximum and significant
36
+ * digits all decide it per value, and the decimal columns roll in and out as
37
+ * the count changes. Set, it holds every value to this many.
19
38
  */
20
- value: number;
21
- /** Digits shown after the decimal separator. Default: `0`. */
22
39
  fractionDigits?: number;
23
40
  /** Zero-pads the integer part to at least this many digits. Default: `1`. */
24
41
  minimumIntegerDigits?: number;
@@ -192,9 +209,10 @@ export interface NitroNumberProps extends Omit<ViewProps, 'children'> {
192
209
  tabularNums?: boolean;
193
210
  /**
194
211
  * A `NumberFormat` the number follows: its prefix and suffix (the currency
195
- * where the locale puts it), grouping and decimal separators, fraction
196
- * digits and minimum integer digits. The individual props override what it
197
- * says.
212
+ * where the locale puts it), grouping and decimal separators, minimum
213
+ * integer digits, and per value the digits it prints: rounded with its
214
+ * `roundingMode`, trimmed by its `trailingZeroDisplay`. The figure is what
215
+ * `format.format(value)` shows. The individual props override what it says.
198
216
  */
199
217
  format?: NumberFormat;
200
218
  /**
@@ -1,4 +1,4 @@
1
- import type { NumberFormatOptions, NumberFormatPart, ResolvedNumberFormatOptions } from './specs/NumberFormat.nitro';
1
+ import type { NumberFigure, NumberFormatLayout, NumberFormatOptions, NumberFormatPart, ResolvedNumberFormatOptions } from './specs/NumberFormat.nitro';
2
2
  /**
3
3
  * A number formatter with the API of `Intl.NumberFormat`, formatted natively.
4
4
  *
@@ -44,4 +44,18 @@ export interface NumberFormatConstructor {
44
44
  * @internal
45
45
  */
46
46
  export declare function sharedFormatterOf(value: unknown): object | undefined;
47
+ /**
48
+ * What `format` shows for `value`, as `NitroNumber` rolls it: the figure
49
+ * rounded and trimmed as the format prints it, and the text around it. Read
50
+ * in C++ off the formatter's own parts, from the number, bigint or decimal
51
+ * string itself.
52
+ * @internal
53
+ */
54
+ export declare function figureOf(format: NumberFormat, value: number | bigint | string): NumberFigure;
55
+ /**
56
+ * The prefix, suffix, separators, sign placement, grouping and digits of
57
+ * `format`, read in C++ off its parts.
58
+ * @internal
59
+ */
60
+ export declare function layoutOf(format: NumberFormat): NumberFormatLayout;
47
61
  export declare const NumberFormat: NumberFormatConstructor;
@@ -1,11 +1,16 @@
1
- import { NumberFormat } from './NumberFormat';
1
+ import { type NumberFormat } from './NumberFormat';
2
+ export { figureOf } from './NumberFormat';
2
3
  /** What `NitroNumber` and `NitroInput` take from a `NumberFormat` through their `format` prop. */
3
4
  export interface FormatProps {
4
5
  prefix: string;
5
6
  suffix: string;
6
7
  groupingSeparator: string;
7
8
  decimalSeparator: string;
8
- /** The digits after the decimal separator: the format's maximum. */
9
+ /**
10
+ * The digits after the decimal separator: the format's maximum. What one
11
+ * value shows can be fewer (`trailingZeroDisplay`, a minimum below the
12
+ * maximum): `figureOf` says per value.
13
+ */
9
14
  fractionDigits: number;
10
15
  minimumIntegerDigits: number;
11
16
  /** Whether a negative amount's sign comes before the prefix ("-$5") or after it ("$-5"). */
@@ -20,28 +25,28 @@ export interface FormatProps {
20
25
  digitGlyphs: string[];
21
26
  /** The first digit group and every later one, from the decimal point ([3, 2]: 12,34,567). */
22
27
  groupingSizes: number[];
23
- /** Compact notation: the prefix, suffix and digits follow the value (`compactParts`). */
28
+ /** Compact notation: the prefix, suffix and digits follow the value (`figureOf`). */
24
29
  compact: boolean;
25
30
  }
26
31
  /**
27
- * The prefix, suffix, separators and digit counts of `format`, read off its
28
- * parts once and cached per formatter. The components keep their own model
29
- * (a sign, a prefix, digits in groups, a suffix), so a format outside it
32
+ * The prefix, suffix, separators and digit counts of `format`, read in C++
33
+ * off its parts once and cached per formatter. The components keep their own
34
+ * model (a sign, a prefix, digits in groups, a suffix), so a format outside it
30
35
  * (accounting parentheses, a unit between the digits) is followed as far as
31
36
  * that model goes.
32
37
  */
33
38
  export declare function formatProps(format: NumberFormat): FormatProps;
34
- /** What a compact format shows for one value: the figure to roll and the text around it. */
35
- export interface CompactParts {
36
- /** The figure as the digits show it: 1.2 for "1.2K". */
37
- value: number;
38
- fractionDigits: number;
39
- prefix: string;
40
- suffix: string;
41
- }
39
+ /** A value as `NumberFormat` takes it: a number, a bigint or a decimal string. */
40
+ export type NumericInput = number | bigint | string;
42
41
  /**
43
- * Compact notation's parts for `value`: "1.2K" is the figure 1.2 with the
44
- * suffix "K", so the digits roll and the suffix swaps as the value crosses
45
- * a thousand, a million…
42
+ * `value` read in units of 10^-`minorDigits`, exactly: 123456n with 2 minor
43
+ * digits is "1234.56". A bigint or a numeric string is shifted as text, so no
44
+ * digit goes through a double: a decimal ("1234.5"), one with an exponent
45
+ * ("1e5" becomes "1e3"), or a 0x / 0o / 0b integer, as `Intl.NumberFormat`
46
+ * reads strings. A number that is a safe integer is shifted the same way, any
47
+ * other number is divided. A string that is not a number ("1,234.56") comes
48
+ * back as it is, which the format shows as NaN, never as a wrong amount.
46
49
  */
47
- export declare function compactParts(format: NumberFormat, value: number): CompactParts;
50
+ export declare function withMinorDigits(value: NumericInput, minorDigits: number | undefined): NumericInput;
51
+ /** `value` as a double, for comparisons and for the engine when there is no format. */
52
+ export declare function toNumber(value: NumericInput): number;
@@ -220,7 +220,7 @@ 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
224
  /** Points between the prefix and the text, in place of the letter spacing there. Not finite: the letter spacing. */
225
225
  prefixSpacing: number;
226
226
  /** Points between the text and the suffix, in place of the letter spacing there. Not finite: the letter spacing. */
@@ -242,7 +242,7 @@ export interface NitroInputProps extends HybridViewProps {
242
242
  /** How characters enter and leave. Default: `'auto'`. */
243
243
  effect: NitroInputEffect;
244
244
  /** Font size of the text in points. Default: `32`. */
245
- fontSize: number;
245
+ textSize: number;
246
246
  /**
247
247
  * Height of the line box in points — the CSS meaning: the total height a
248
248
  * line occupies, not extra leading. `0` (the default) uses the font's own.
@@ -255,15 +255,15 @@ export interface NitroInputProps extends HybridViewProps {
255
255
  * `lineHeight < font.lineHeight`), and the reason a compressed `lineHeight`
256
256
  * renders off-centre on a `TextInput`.
257
257
  */
258
- lineHeight: number;
258
+ textLineHeight: number;
259
259
  /** Numeric font weight, `100`–`900`. Default: `400`. */
260
- fontWeight: number;
260
+ textWeight: number;
261
261
  /** Font family name; empty = system font. */
262
- fontFamily: string;
262
+ textFamily: string;
263
263
  /** Text color as a processed ARGB integer; `NaN` = platform label color. */
264
- color: number;
264
+ textColor: number;
265
265
  /** Where the text sits when the view is wider than it. Default: `'auto'`, the start edge. */
266
- textAlign: NitroInputTextAlign;
266
+ textAlignment: NitroInputTextAlign;
267
267
  /**
268
268
  * Lay the field out right-to-left: `'auto'` alignment resolves to the right
269
269
  * edge, the prefix moves to the right and the suffix to the left, and a
@@ -314,7 +314,16 @@ export interface NitroInputProps extends HybridViewProps {
314
314
  */
315
315
  numberOfLines: number;
316
316
  /** `multiline`: where the text sits in the box. Default: `'auto'` (top). */
317
- textAlignVertical: NitroInputTextAlignVertical;
317
+ textVerticalAlignment: NitroInputTextAlignVertical;
318
+ /**
319
+ * The style's padding and border, in points, resolved per edge by
320
+ * `NitroInput`. Android insets the text, the overlay and the frame by them;
321
+ * on iOS React Native already lays the view's content out inside them.
322
+ */
323
+ textInsetLeft: number;
324
+ textInsetTop: number;
325
+ textInsetRight: number;
326
+ textInsetBottom: number;
318
327
  /**
319
328
  * `multiline`: whether the field scrolls once the text is taller than it.
320
329
  * Turning it off lets a growing field drive its own height. Default: `true`.
@@ -0,0 +1,67 @@
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
+ prefixSpacing: number;
41
+ suffixSpacing: number;
42
+ allowFontScaling: boolean;
43
+ maxFontSizeMultiplier: number;
44
+ variant: NitroInputVariant;
45
+ label: string;
46
+ labelBehavior: NitroInputLabelBehavior;
47
+ labelFontSize: number;
48
+ cornerRadius: number;
49
+ }
50
+ /** A size in points (iOS) or dp (Android). */
51
+ export interface NitroInputSize {
52
+ width: number;
53
+ height: number;
54
+ }
55
+ /**
56
+ * Measures a single-line field on the JS thread, before its view exists, with
57
+ * the code the view sizes itself with: `NitroInput` lays out at its real size
58
+ * in the commit that mounts it, as React Native's `TextInput` does, instead of
59
+ * at its parent's width until the view's first `onSizeChange` arrives.
60
+ */
61
+ export interface NitroInputMeasure extends HybridObject<{
62
+ ios: 'swift';
63
+ android: 'kotlin';
64
+ }> {
65
+ /** What the field reports through `onSizeChange` once mounted, unfocused. */
66
+ measure(sizing: NitroInputSizing): NitroInputSize;
67
+ }
@@ -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
@@ -15,16 +15,16 @@ import type { NitroInputEasing, NitroInputEffect } from './NitroInput.nitro';
15
15
  export interface NitroTextProps extends HybridViewProps {
16
16
  text: string;
17
17
  /** In points, already scaled for the system text size when the wrapper was asked to. Default 17. */
18
- fontSize?: number;
18
+ textSize?: number;
19
19
  /** Numeric weight, 100–900. Default 400. */
20
- fontWeight?: number;
20
+ textWeight?: number;
21
21
  /** Default: the system font. */
22
- fontFamily?: string;
22
+ textFamily?: string;
23
23
  /** Processed ARGB. Default: the platform label colour. */
24
- color?: number;
24
+ textColor?: number;
25
25
  /** Points after every character. */
26
- letterSpacing?: number;
27
- textAlign?: NitroNumberTextAlign;
26
+ textLetterSpacing?: number;
27
+ textAlignment?: NitroNumberTextAlign;
28
28
  rightToLeft?: boolean;
29
29
  /** Of a morph, in ms. Default 400. */
30
30
  duration?: number;
@@ -62,6 +62,35 @@ export interface NumberFormatPart {
62
62
  type: string;
63
63
  value: string;
64
64
  }
65
+ /**
66
+ * One value as `NitroNumber` rolls it: the figure its digits show, rounded and
67
+ * trimmed as the format prints it, and the text around it.
68
+ */
69
+ export interface NumberFigure {
70
+ /** The figure as the digits show it, signed: 1.2 for "1.2K", 2.12 for "$2.12"; 0 (never -0) when it rounds to nothing, or for NaN and infinities. */
71
+ value: number;
72
+ /** The fraction digits this value shows ("$1,234" 0, "$1,234.50" 2); the format's maximum for NaN and infinities. */
73
+ fractionDigits: number;
74
+ /** The text before the number, without the sign. */
75
+ prefix: string;
76
+ /** The text after the number, without the sign. */
77
+ suffix: string;
78
+ }
79
+ /** The shape of a format, as `NitroNumber` and `NitroInput` lay a number out. */
80
+ export interface NumberFormatLayout {
81
+ prefix: string;
82
+ suffix: string;
83
+ /** Empty when the format does not group. */
84
+ groupingSeparator: string;
85
+ decimalSeparator: string;
86
+ /** A negative amount's sign comes after the prefix ("$-5"), not before it ("-$5"). */
87
+ signAfterAffix: boolean;
88
+ minusSign: string;
89
+ /** The group nearest the decimal point and every one before it ([3, 2]: 12,34,567). */
90
+ groupingSizes: number[];
91
+ /** The format's digits 0…9, or empty for Latin ones. */
92
+ digitGlyphs: string[];
93
+ }
65
94
  /**
66
95
  * A number formatter with the API of `Intl.NumberFormat`. It learns a
67
96
  * locale's format once from the platform (Foundation on iOS, ICU on Android)
@@ -76,6 +105,10 @@ export interface NitroNumberFormat extends HybridObject<{
76
105
  format(value: number | Int64 | string): string;
77
106
  formatToParts(value: number | Int64 | string): NumberFormatPart[];
78
107
  resolvedOptions(): ResolvedNumberFormatOptions;
108
+ /** For the components, not part of `Intl.NumberFormat`: what `value` shows, as a figure. */
109
+ figure(value: number | Int64 | string): NumberFigure;
110
+ /** For the components, not part of `Intl.NumberFormat`: the shape of the format. */
111
+ layout(): NumberFormatLayout;
79
112
  }
80
113
  export interface NitroNumberFormatFactory extends HybridObject<{
81
114
  ios: 'c++';
package/nitro.json CHANGED
@@ -74,6 +74,16 @@
74
74
  "language": "kotlin",
75
75
  "implementationClassName": "HybridNitroTextMeasure"
76
76
  }
77
+ },
78
+ "NitroInputMeasure": {
79
+ "ios": {
80
+ "language": "swift",
81
+ "implementationClassName": "HybridNitroInputMeasure"
82
+ },
83
+ "android": {
84
+ "language": "kotlin",
85
+ "implementationClassName": "HybridNitroInputMeasure"
86
+ }
77
87
  }
78
88
  },
79
89
  "ignorePaths": [
@@ -35,6 +35,7 @@ target_sources(
35
35
  # Shared Nitrogen C++ sources
36
36
  ../nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp
37
37
  ../nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp
38
+ ../nitrogen/generated/shared/c++/HybridNitroInputMeasureSpec.cpp
38
39
  ../nitrogen/generated/shared/c++/HybridNitroInputWorkletsSpec.cpp
39
40
  ../nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp
40
41
  ../nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp
@@ -48,6 +49,7 @@ target_sources(
48
49
  # Android-specific Nitrogen C++ sources
49
50
  ../nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp
50
51
  ../nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp
52
+ ../nitrogen/generated/android/c++/JHybridNitroInputMeasureSpec.cpp
51
53
  ../nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp
52
54
  ../nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp
53
55
  ../nitrogen/generated/android/c++/JHybridNitroTextMeasureSpec.cpp
@@ -23,6 +23,7 @@
23
23
  #include "JFunc_void_std__string.hpp"
24
24
  #include "JFunc_void_double_double.hpp"
25
25
  #include "views/JHybridNitroInputViewStateUpdater.hpp"
26
+ #include "JHybridNitroInputMeasureSpec.hpp"
26
27
  #include "JHybridNitroNumberViewSpec.hpp"
27
28
  #include "JFunc_void.hpp"
28
29
  #include "views/JHybridNitroNumberViewStateUpdater.hpp"
@@ -83,6 +84,14 @@ struct JHybridNitroTextMeasureSpecImpl: public jni::JavaClass<JHybridNitroTextMe
83
84
  return javaPart->getJHybridNitroTextMeasureSpec();
84
85
  }
85
86
  };
87
+ struct JHybridNitroInputMeasureSpecImpl: public jni::JavaClass<JHybridNitroInputMeasureSpecImpl, JHybridNitroInputMeasureSpec::JavaPart> {
88
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroinput/HybridNitroInputMeasure;";
89
+ static std::shared_ptr<JHybridNitroInputMeasureSpec> create() {
90
+ static const auto constructorFn = javaClassStatic()->getConstructor<JHybridNitroInputMeasureSpecImpl::javaobject()>();
91
+ jni::local_ref<JHybridNitroInputMeasureSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
92
+ return javaPart->getJHybridNitroInputMeasureSpec();
93
+ }
94
+ };
86
95
 
87
96
  void registerAllNatives() {
88
97
  using namespace margelo::nitro;
@@ -97,6 +106,7 @@ void registerAllNatives() {
97
106
  margelo::nitro::nitroinput::JFunc_void_std__string_cxx::registerNatives();
98
107
  margelo::nitro::nitroinput::JFunc_void_double_double_cxx::registerNatives();
99
108
  margelo::nitro::nitroinput::views::JHybridNitroInputViewStateUpdater::registerNatives();
109
+ margelo::nitro::nitroinput::JHybridNitroInputMeasureSpec::CxxPart::registerNatives();
100
110
  margelo::nitro::nitroinput::JHybridNitroNumberViewSpec::CxxPart::registerNatives();
101
111
  margelo::nitro::nitroinput::JFunc_void_cxx::registerNatives();
102
112
  margelo::nitro::nitroinput::views::JHybridNitroNumberViewStateUpdater::registerNatives();
@@ -155,6 +165,12 @@ void registerAllNatives() {
155
165
  return JHybridNitroTextMeasureSpecImpl::create();
156
166
  }
157
167
  );
168
+ HybridObjectRegistry::registerHybridObjectConstructor(
169
+ "NitroInputMeasure",
170
+ []() -> std::shared_ptr<HybridObject> {
171
+ return JHybridNitroInputMeasureSpecImpl::create();
172
+ }
173
+ );
158
174
  }
159
175
 
160
176
  } // namespace margelo::nitro::nitroinput
@@ -0,0 +1,93 @@
1
+ ///
2
+ /// JHybridNitroInputMeasureSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "JHybridNitroInputMeasureSpec.hpp"
9
+
10
+ // Forward declaration of `NitroInputSize` to properly resolve imports.
11
+ namespace margelo::nitro::nitroinput { struct NitroInputSize; }
12
+ // Forward declaration of `NitroInputSizing` to properly resolve imports.
13
+ namespace margelo::nitro::nitroinput { struct NitroInputSizing; }
14
+ // Forward declaration of `NitroInputMode` to properly resolve imports.
15
+ namespace margelo::nitro::nitroinput { enum class NitroInputMode; }
16
+ // Forward declaration of `NitroInputSignPlacement` to properly resolve imports.
17
+ namespace margelo::nitro::nitroinput { enum class NitroInputSignPlacement; }
18
+ // Forward declaration of `NitroInputNotation` to properly resolve imports.
19
+ namespace margelo::nitro::nitroinput { struct NitroInputNotation; }
20
+ // Forward declaration of `NitroInputMaskAffinity` to properly resolve imports.
21
+ namespace margelo::nitro::nitroinput { enum class NitroInputMaskAffinity; }
22
+ // Forward declaration of `NitroInputTextCase` to properly resolve imports.
23
+ namespace margelo::nitro::nitroinput { enum class NitroInputTextCase; }
24
+ // Forward declaration of `NitroInputCharacterMapping` to properly resolve imports.
25
+ namespace margelo::nitro::nitroinput { struct NitroInputCharacterMapping; }
26
+ // Forward declaration of `NitroInputVariant` to properly resolve imports.
27
+ namespace margelo::nitro::nitroinput { enum class NitroInputVariant; }
28
+ // Forward declaration of `NitroInputLabelBehavior` to properly resolve imports.
29
+ namespace margelo::nitro::nitroinput { enum class NitroInputLabelBehavior; }
30
+
31
+ #include "NitroInputSize.hpp"
32
+ #include "JNitroInputSize.hpp"
33
+ #include "NitroInputSizing.hpp"
34
+ #include "JNitroInputSizing.hpp"
35
+ #include <string>
36
+ #include "NitroInputMode.hpp"
37
+ #include "JNitroInputMode.hpp"
38
+ #include "NitroInputSignPlacement.hpp"
39
+ #include "JNitroInputSignPlacement.hpp"
40
+ #include "NitroInputNotation.hpp"
41
+ #include <vector>
42
+ #include "JNitroInputNotation.hpp"
43
+ #include "NitroInputMaskAffinity.hpp"
44
+ #include "JNitroInputMaskAffinity.hpp"
45
+ #include "NitroInputTextCase.hpp"
46
+ #include "JNitroInputTextCase.hpp"
47
+ #include "NitroInputCharacterMapping.hpp"
48
+ #include "JNitroInputCharacterMapping.hpp"
49
+ #include "NitroInputVariant.hpp"
50
+ #include "JNitroInputVariant.hpp"
51
+ #include "NitroInputLabelBehavior.hpp"
52
+ #include "JNitroInputLabelBehavior.hpp"
53
+
54
+ namespace margelo::nitro::nitroinput {
55
+
56
+ std::shared_ptr<JHybridNitroInputMeasureSpec> JHybridNitroInputMeasureSpec::JavaPart::getJHybridNitroInputMeasureSpec() {
57
+ auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
58
+ auto castHybridObject = std::dynamic_pointer_cast<JHybridNitroInputMeasureSpec>(hybridObject);
59
+ if (castHybridObject == nullptr) [[unlikely]] {
60
+ throw std::runtime_error("Failed to downcast JHybridObject to JHybridNitroInputMeasureSpec!");
61
+ }
62
+ return castHybridObject;
63
+ }
64
+
65
+ jni::local_ref<JHybridNitroInputMeasureSpec::CxxPart::jhybriddata> JHybridNitroInputMeasureSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
66
+ return makeCxxInstance(jThis);
67
+ }
68
+
69
+ std::shared_ptr<JHybridObject> JHybridNitroInputMeasureSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
70
+ auto castJavaPart = jni::dynamic_ref_cast<JHybridNitroInputMeasureSpec::JavaPart>(javaPart);
71
+ if (castJavaPart == nullptr) [[unlikely]] {
72
+ throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridNitroInputMeasureSpec::JavaPart!");
73
+ }
74
+ return std::make_shared<JHybridNitroInputMeasureSpec>(castJavaPart);
75
+ }
76
+
77
+ void JHybridNitroInputMeasureSpec::CxxPart::registerNatives() {
78
+ registerHybrid({
79
+ makeNativeMethod("initHybrid", JHybridNitroInputMeasureSpec::CxxPart::initHybrid),
80
+ });
81
+ }
82
+
83
+ // Properties
84
+
85
+
86
+ // Methods
87
+ NitroInputSize JHybridNitroInputMeasureSpec::measure(const NitroInputSizing& sizing) {
88
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JNitroInputSize>(jni::alias_ref<JNitroInputSizing> /* sizing */)>("measure");
89
+ auto __result = method(_javaPart, JNitroInputSizing::fromCpp(sizing));
90
+ return __result->toCpp();
91
+ }
92
+
93
+ } // namespace margelo::nitro::nitroinput
@@ -0,0 +1,63 @@
1
+ ///
2
+ /// HybridNitroInputMeasureSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <NitroModules/JHybridObject.hpp>
11
+ #include <fbjni/fbjni.h>
12
+ #include "HybridNitroInputMeasureSpec.hpp"
13
+
14
+
15
+
16
+
17
+ namespace margelo::nitro::nitroinput {
18
+
19
+ using namespace facebook;
20
+
21
+ class JHybridNitroInputMeasureSpec: public virtual HybridNitroInputMeasureSpec, public virtual JHybridObject {
22
+ public:
23
+ struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroinput/HybridNitroInputMeasureSpec;";
25
+ std::shared_ptr<JHybridNitroInputMeasureSpec> getJHybridNitroInputMeasureSpec();
26
+ };
27
+ struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
28
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroinput/HybridNitroInputMeasureSpec$CxxPart;";
29
+ static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
30
+ static void registerNatives();
31
+ using HybridBase::HybridBase;
32
+ protected:
33
+ std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
34
+ };
35
+
36
+ public:
37
+ explicit JHybridNitroInputMeasureSpec(const jni::local_ref<JHybridNitroInputMeasureSpec::JavaPart>& javaPart):
38
+ HybridObject(HybridNitroInputMeasureSpec::TAG),
39
+ JHybridObject(javaPart),
40
+ _javaPart(jni::make_global(javaPart)) {}
41
+ ~JHybridNitroInputMeasureSpec() override {
42
+ // Hermes GC can destroy JS objects on a non-JNI Thread.
43
+ jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
44
+ }
45
+
46
+ public:
47
+ inline const jni::global_ref<JHybridNitroInputMeasureSpec::JavaPart>& getJavaPart() const noexcept {
48
+ return _javaPart;
49
+ }
50
+
51
+ public:
52
+ // Properties
53
+
54
+
55
+ public:
56
+ // Methods
57
+ NitroInputSize measure(const NitroInputSizing& sizing) override;
58
+
59
+ private:
60
+ jni::global_ref<JHybridNitroInputMeasureSpec::JavaPart> _javaPart;
61
+ };
62
+
63
+ } // namespace margelo::nitro::nitroinput