react-native-nitro-input 0.1.0 → 0.2.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 (116) hide show
  1. package/CHANGELOG.md +305 -3
  2. package/NitroInput.podspec +4 -4
  3. package/README.md +378 -53
  4. package/android/CMakeLists.txt +5 -3
  5. package/android/src/main/cpp/JOutlineGeometry.hpp +1 -1
  6. package/android/src/main/cpp/JReflowEngine.cpp +132 -0
  7. package/android/src/main/cpp/{JMorphEngine.hpp → JReflowEngine.hpp} +7 -7
  8. package/android/src/main/cpp/JRollingEngine.cpp +222 -0
  9. package/android/src/main/cpp/JRollingEngine.hpp +68 -0
  10. package/android/src/main/cpp/cpp-adapter.cpp +4 -2
  11. package/android/src/main/java/com/margelo/nitro/nitroinput/AmountFormatter.kt +1 -1
  12. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +1 -1
  13. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +471 -0
  14. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputPackage.kt +2 -1
  15. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +38 -16
  16. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +1741 -0
  17. package/android/src/main/java/com/margelo/nitro/nitroinput/{MorphEngine.kt → ReflowEngine.kt} +2 -2
  18. package/android/src/main/java/com/margelo/nitro/nitroinput/RollingEngine.kt +59 -0
  19. package/cpp/AmountFormatter.cpp +5 -0
  20. package/cpp/AmountFormatter.hpp +10 -2
  21. package/cpp/{MorphEngine.cpp → ReflowEngine.cpp} +52 -47
  22. package/cpp/{MorphEngine.hpp → ReflowEngine.hpp} +12 -4
  23. package/cpp/RollingEngine.cpp +1224 -0
  24. package/cpp/RollingEngine.hpp +468 -0
  25. package/cpp/SwiftNonCopyable.hpp +22 -0
  26. package/cpp/worklets/NitroInputWorkletsBridge.cpp +3 -3
  27. package/cpp/worklets/NitroInputWorkletsBridge.hpp +1 -1
  28. package/ios/{HybridMorphInputView.swift → HybridNitroInputView.swift} +1 -1
  29. package/ios/HybridNitroNumberView.swift +439 -0
  30. package/ios/NitroInputView.swift +69 -45
  31. package/ios/NitroNumberView.swift +1934 -0
  32. package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
  33. package/lib/commonjs/src/NitroInput.js +21 -52
  34. package/lib/commonjs/src/NitroNumber.js +139 -0
  35. package/lib/commonjs/src/index.js +4 -3
  36. package/lib/commonjs/src/specs/NitroNumber.nitro.js +2 -0
  37. package/lib/commonjs/src/styleHelpers.js +36 -0
  38. package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
  39. package/lib/module/src/NitroInput.js +12 -43
  40. package/lib/module/src/NitroNumber.js +100 -0
  41. package/lib/module/src/index.js +1 -1
  42. package/lib/module/src/specs/NitroNumber.nitro.js +1 -0
  43. package/lib/module/src/styleHelpers.js +32 -0
  44. package/lib/typescript/src/NitroInput.d.ts +28 -21
  45. package/lib/typescript/src/NitroNumber.d.ts +211 -0
  46. package/lib/typescript/src/index.d.ts +3 -2
  47. package/lib/typescript/src/specs/NitroInput.nitro.d.ts +9 -9
  48. package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +238 -0
  49. package/lib/typescript/src/styleHelpers.d.ts +3 -0
  50. package/nitro.json +10 -0
  51. package/nitrogen/generated/android/NitroInput+autolinking.cmake +4 -0
  52. package/nitrogen/generated/android/NitroInputOnLoad.cpp +20 -0
  53. package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
  54. package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +10 -10
  55. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +536 -0
  56. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +156 -0
  57. package/nitrogen/generated/android/c++/JNitroNumberAffixAlign.hpp +64 -0
  58. package/nitrogen/generated/android/c++/JNitroNumberDirection.hpp +61 -0
  59. package/nitrogen/generated/android/c++/JNitroNumberEasing.hpp +67 -0
  60. package/nitrogen/generated/android/c++/JNitroNumberRevealStyle.hpp +58 -0
  61. package/nitrogen/generated/android/c++/JNitroNumberTextAlign.hpp +64 -0
  62. package/nitrogen/generated/android/c++/JNitroNumberTransition.hpp +61 -0
  63. package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +299 -0
  64. package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.hpp +54 -0
  65. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void.kt +78 -0
  66. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_double_double.kt +9 -9
  67. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +363 -0
  68. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberAffixAlign.kt +25 -0
  69. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberDirection.kt +24 -0
  70. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberEasing.kt +26 -0
  71. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberRevealStyle.kt +23 -0
  72. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberTextAlign.kt +25 -0
  73. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberTransition.kt +24 -0
  74. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroNumberViewManager.kt +96 -0
  75. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroNumberViewStateUpdater.kt +23 -0
  76. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +25 -0
  77. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +248 -0
  78. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +23 -0
  79. package/nitrogen/generated/ios/NitroInputAutolinking.mm +8 -0
  80. package/nitrogen/generated/ios/NitroInputAutolinking.swift +12 -0
  81. package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.cpp +11 -0
  82. package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +432 -0
  83. package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +414 -0
  84. package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
  85. package/nitrogen/generated/ios/swift/Func_void_double_double.swift +5 -5
  86. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +102 -0
  87. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +1243 -0
  88. package/nitrogen/generated/ios/swift/NitroNumberAffixAlign.swift +48 -0
  89. package/nitrogen/generated/ios/swift/NitroNumberDirection.swift +44 -0
  90. package/nitrogen/generated/ios/swift/NitroNumberEasing.swift +52 -0
  91. package/nitrogen/generated/ios/swift/NitroNumberRevealStyle.swift +40 -0
  92. package/nitrogen/generated/ios/swift/NitroNumberTextAlign.swift +48 -0
  93. package/nitrogen/generated/ios/swift/NitroNumberTransition.swift +44 -0
  94. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +115 -0
  95. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +175 -0
  96. package/nitrogen/generated/shared/c++/NitroNumberAffixAlign.hpp +84 -0
  97. package/nitrogen/generated/shared/c++/NitroNumberDirection.hpp +80 -0
  98. package/nitrogen/generated/shared/c++/NitroNumberEasing.hpp +88 -0
  99. package/nitrogen/generated/shared/c++/NitroNumberRevealStyle.hpp +76 -0
  100. package/nitrogen/generated/shared/c++/NitroNumberTextAlign.hpp +84 -0
  101. package/nitrogen/generated/shared/c++/NitroNumberTransition.hpp +80 -0
  102. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +124 -0
  103. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +227 -0
  104. package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
  105. package/package.json +15 -7
  106. package/src/NitroInput.tsx +37 -60
  107. package/src/NitroNumber.tsx +481 -0
  108. package/src/index.ts +20 -6
  109. package/src/specs/NitroInput.nitro.ts +9 -9
  110. package/src/specs/NitroNumber.nitro.ts +259 -0
  111. package/src/styleHelpers.ts +32 -0
  112. package/android/src/main/cpp/JMorphEngine.cpp +0 -132
  113. package/lib/commonjs/src/MorphInput.js +0 -42
  114. package/lib/module/src/MorphInput.js +0 -6
  115. package/lib/typescript/src/MorphInput.d.ts +0 -18
  116. package/src/MorphInput.tsx +0 -30
@@ -0,0 +1,100 @@
1
+ import React, { forwardRef, useImperativeHandle, useMemo, useRef, useState, } from 'react';
2
+ import { I18nManager, StyleSheet, } from 'react-native';
3
+ import { callback, getHostComponent, } from 'react-native-nitro-modules';
4
+ import NitroNumberViewConfig from '../nitrogen/generated/shared/json/NitroNumberViewConfig.json';
5
+ import { toNumericWeight, toProcessedColor } from './styleHelpers';
6
+ /**
7
+ * The raw Nitro host component. Prefer {@link NitroNumber}, which adds
8
+ * auto-sizing, color/weight conversion and a convenient handle.
9
+ */
10
+ export const NativeNitroNumberView = getHostComponent('NitroNumberView', () => NitroNumberViewConfig);
11
+ /** Each transition's own timing, used when the props leave it unsaid. */
12
+ const TRANSITION_DEFAULTS = {
13
+ roll: { duration: 500, easing: 'easeInOut', stagger: 0 },
14
+ numeric: { duration: 480, easing: 'spring', stagger: 150 },
15
+ scramble: { duration: 500, easing: 'linear', stagger: 60 },
16
+ };
17
+ /**
18
+ * A number that animates its changes natively: an odometer roll, SwiftUI's
19
+ * numeric transition or a scramble.
20
+ *
21
+ * Change `value` and every digit rolls to its new glyph on the native side.
22
+ * Use the ref's `animateTo` / `jumpTo` for imperative updates.
23
+ *
24
+ * The view sizes itself to its content unless you pass an explicit `width` /
25
+ * `height` in `style`.
26
+ */
27
+ export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigits, minimumIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, transition, flashUpColor, flashDownColor, flashDuration, popOnChange, duration, easing, bounce, stagger, direction, reveal, revealStyle, revealDuration, revealBounce, revealGrow, revealStagger, revealMilestones, revealMilestoneHold, onRevealEnd, onRevealMilestone, loading, shimmerColor, shimmerDuration, fontSize, prefixFontSize, suffixFontSize, affixAlign, prefixAlign, suffixAlign, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, fontWeight, fontFamily, color, textAlign, onNativeRef, style, ...viewProps }, ref) {
28
+ const nativeRef = useRef(null);
29
+ const latestOnNativeRef = useRef(onNativeRef);
30
+ latestOnNativeRef.current = onNativeRef;
31
+ const latestOnRevealEnd = useRef(onRevealEnd);
32
+ latestOnRevealEnd.current = onRevealEnd;
33
+ const latestOnRevealMilestone = useRef(onRevealMilestone);
34
+ latestOnRevealMilestone.current = onRevealMilestone;
35
+ const latestValue = useRef(value);
36
+ latestValue.current = value;
37
+ const [size, setSize] = useState(null);
38
+ // Nitro callbacks must be wrapped with `callback()` and the wrapper object
39
+ // has to be referentially stable, otherwise every render re-sets the prop.
40
+ const hybridRef = useMemo(() => callback((instance) => {
41
+ nativeRef.current = instance;
42
+ latestOnNativeRef.current?.(instance);
43
+ }), []);
44
+ const onSizeChange = useMemo(() => callback((width, height) => {
45
+ setSize((previous) => previous !== null &&
46
+ previous.width === width &&
47
+ previous.height === height
48
+ ? previous
49
+ : { width, height });
50
+ }), []);
51
+ // Stable like the others; the latest handler is read through a ref so a
52
+ // caller passing an inline arrow doesn't re-set the native prop each render.
53
+ const onRevealEndCallback = useMemo(() => callback(() => {
54
+ latestOnRevealEnd.current?.();
55
+ }), []);
56
+ const onRevealMilestoneCallback = useMemo(() => callback((index, milestone) => {
57
+ latestOnRevealMilestone.current?.(index, milestone);
58
+ }), []);
59
+ // A new array literal each render must not re-set the native prop. Always an
60
+ // array (empty = no tiers): removing the prop would reach native as `null`,
61
+ // which Nitro's array parser rejects ("Value is null, expected an Object").
62
+ const milestonesKey = revealMilestones?.join(',') ?? '';
63
+ const stableMilestones = useMemo(() => (revealMilestones ? [...revealMilestones] : []),
64
+ // eslint-disable-next-line react-hooks/exhaustive-deps
65
+ [milestonesKey]);
66
+ // One handle for the component's lifetime: `getValue` reads the latest
67
+ // prop through a ref, so a value change doesn't hand the parent a new object.
68
+ useImperativeHandle(ref, () => ({
69
+ jumpTo: (next) => nativeRef.current?.jumpTo(next),
70
+ animateTo: (next) => nativeRef.current?.animateTo(next),
71
+ revealTo: (next) => nativeRef.current?.revealTo(next),
72
+ getValue: () => nativeRef.current?.value ?? latestValue.current,
73
+ get native() {
74
+ return nativeRef.current;
75
+ },
76
+ }), []);
77
+ // Every native prop is sent with an explicit value: an optional prop that
78
+ // is *removed* reaches native as `null`, which Nitro's parser rejects and
79
+ // React Native turns into a fatal error. `Infinity` stands for "platform
80
+ // default" where there is no value to express it (colors), `''` for fonts.
81
+ // Not `NaN`: Nitro only calls a native setter when a prop's value changed,
82
+ // and NaN never equals itself, so a NaN sentinel re-set the colour on every
83
+ // render and had the whole configuration re-applied on every value change.
84
+ const processedColor = useMemo(() => toProcessedColor(color) ?? Infinity, [color]);
85
+ const processedShimmerColor = useMemo(() => toProcessedColor(shimmerColor) ?? Infinity, [shimmerColor]);
86
+ const processedFlashUp = useMemo(() => toProcessedColor(flashUpColor) ?? Infinity, [flashUpColor]);
87
+ const processedFlashDown = useMemo(() => toProcessedColor(flashDownColor) ?? Infinity, [flashDownColor]);
88
+ const numericWeight = toNumericWeight(fontWeight) ?? 400;
89
+ const resolvedFontSize = fontSize ?? 32;
90
+ const resolvedAffixAlign = affixAlign ?? 'baseline';
91
+ const autoSize = useMemo(() => size !== null
92
+ ? { width: size.width, height: size.height }
93
+ : { height: (fontSize ?? 32) * 1.25 }, [size, fontSize]);
94
+ // The layout direction, resolved the way React Native resolves it for its
95
+ // own views: the view's `style.direction` if it says, else the app's. Fabric
96
+ // does not hand a Hybrid View its resolved direction, so native is told.
97
+ const layoutDirection = useMemo(() => StyleSheet.flatten(style)?.direction, [style]);
98
+ const rightToLeft = layoutDirection === 'rtl' || (layoutDirection !== 'ltr' && I18nManager.isRTL);
99
+ return (React.createElement(NativeNitroNumberView, { ...viewProps, style: [autoSize, style], hybridRef: hybridRef, value: value, fractionDigits: fractionDigits ?? 0, minimumIntegerDigits: minimumIntegerDigits ?? 1, groupingSeparator: groupingSeparator ?? '', decimalSeparator: decimalSeparator ?? '.', prefix: prefix ?? '', suffix: suffix ?? '', transition: transition ?? 'roll', flashUpColor: processedFlashUp, flashDownColor: processedFlashDown, flashDuration: flashDuration ?? 600, popOnChange: popOnChange ?? 0, duration: duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration, easing: easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing, bounce: bounce ?? 0.15, stagger: stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger, rollDirection: direction ?? 'auto', revealState: reveal === undefined ? 0 : reveal ? 2 : 1, revealStyle: revealStyle ?? 'count', revealDuration: revealDuration ?? 2200, revealBounce: revealBounce ?? 0.12, revealGrow: revealGrow ?? 0.2, revealStagger: revealStagger ?? 200, revealMilestones: stableMilestones, revealMilestoneHold: revealMilestoneHold ?? 0, onRevealEnd: onRevealEndCallback, onRevealMilestone: onRevealMilestoneCallback, loading: loading ?? false, shimmerColor: processedShimmerColor, shimmerDuration: shimmerDuration ?? 950, fontSize: resolvedFontSize, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, affixAlign: resolvedAffixAlign, prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, onSizeChange: onSizeChange }));
100
+ });
@@ -1,4 +1,4 @@
1
1
  export { NitroInput, NativeNitroInputView, } from './NitroInput';
2
- export { MorphInput, } from './MorphInput';
3
2
  export { isWorklet, } from './worklets';
4
3
  export { useNitroInputState, } from './useNitroInputState';
4
+ export { NitroNumber, NativeNitroNumberView, } from './NitroNumber';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ import { processColor } from 'react-native';
2
+ // Style resolution shared by `NitroNumber` and `NitroInput`.
3
+ const FONT_WEIGHTS = {
4
+ normal: 400,
5
+ regular: 400,
6
+ bold: 700,
7
+ ultralight: 100,
8
+ thin: 200,
9
+ light: 300,
10
+ medium: 500,
11
+ semibold: 600,
12
+ condensedBold: 700,
13
+ condensed: 400,
14
+ heavy: 800,
15
+ black: 900,
16
+ };
17
+ export function toNumericWeight(weight) {
18
+ if (weight == null)
19
+ return undefined;
20
+ if (typeof weight === 'number')
21
+ return weight;
22
+ const parsed = Number(weight);
23
+ if (!Number.isNaN(parsed))
24
+ return parsed;
25
+ return FONT_WEIGHTS[weight];
26
+ }
27
+ export function toProcessedColor(color) {
28
+ if (color == null)
29
+ return undefined;
30
+ const processed = processColor(color);
31
+ return typeof processed === 'number' ? processed : undefined;
32
+ }
@@ -168,7 +168,7 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
168
168
  * Where a negative amount's sign sits relative to `prefix`. `'beforeAffix'`
169
169
  * (the default) reads `-$1,234.56`; `'afterAffix'` reads `$-1,234.56`, which
170
170
  * suits a symbol styled as an ornament rather than read as part of the
171
- * number. Only the morph honours it - a plain field's affixes are accessory
171
+ * number. Only the reflow honours it - a plain field's affixes are accessory
172
172
  * views outside the text, so it is always `'afterAffix'`.
173
173
  */
174
174
  signPlacement?: NitroInputSignPlacement;
@@ -176,13 +176,13 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
176
176
  prefixAlign?: NitroInputAffixAlign;
177
177
  /** Alignment of `suffix` only. Defaults to `affixAlign`. */
178
178
  suffixAlign?: NitroInputAffixAlign;
179
- /** Shown while the field is empty and morphed away by the first character. In `'number'` mode `'0'` reads well. */
179
+ /** Shown while the field is empty and reflowed away by the first character. In `'number'` mode `'0'` reads well. */
180
180
  placeholder?: string;
181
181
  /** Color of the placeholder. Defaults to the platform placeholder color. */
182
182
  placeholderTextColor?: ColorValue;
183
- /** Duration in ms of the morph played on every change. `0` snaps. Default: `400`. */
183
+ /** Duration in ms of the reflow played on every change. `0` snaps. Default: `400`. */
184
184
  duration?: number;
185
- /** Timing curve of the morph. Default: `'expo'` (Torph's `cubic-bezier(0.19, 1, 0.22, 1)`). */
185
+ /** Timing curve of the reflow. Default: `'expo'` (Torph's `cubic-bezier(0.19, 1, 0.22, 1)`). */
186
186
  easing?: NitroInputEasing;
187
187
  /** Overshoot of the `'spring'` easing, `0`–`1`. Default: `0.15`. */
188
188
  bounce?: number;
@@ -199,7 +199,7 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
199
199
  * line occupies rather than extra leading. Omit to use the font's own.
200
200
  *
201
201
  * Unlike `TextInput`, a line height *tighter* than the font is centred
202
- * correctly too, and it applies to single-line and morphing fields, not only
202
+ * correctly too, and it applies to single-line and reflowing fields, not only
203
203
  * wrapped ones.
204
204
  */
205
205
  lineHeight?: number;
@@ -247,8 +247,8 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
247
247
  *
248
248
  * A multiline field is always drawn by the system view and is always
249
249
  * `'text'` mode: the glyph engine lays one run out on one baseline, so it
250
- * cannot morph wrapped text, and an amount or a mask is a single-line idea.
251
- * `morph`, `mode="number"`, `mode="mask"` and the `prefix` / `suffix`
250
+ * cannot reflow wrapped text, and an amount or a mask is a single-line idea.
251
+ * `transition="reflow"`, `mode="number"`, `mode="mask"` and the `prefix` / `suffix`
252
252
  * affixes are ignored alongside it, with one warning each in development.
253
253
  * The return key inserts a line break unless `submitBehavior` says otherwise.
254
254
  */
@@ -306,20 +306,22 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
306
306
  end?: number;
307
307
  };
308
308
  /**
309
- * Run the glyph engine, so text morphs as it changes rather than simply
310
- * appearing. Off by default: this is a text field first, and a `TextInput`
311
- * does not animate its characters. {@link MorphInput} is this component with
312
- * it on, which is what an amount field wants.
309
+ * How the text changes. `'none'` (the default) draws it the instant it
310
+ * changes: this is a text field first, and a `TextInput` does not animate
311
+ * its characters. `'reflow'` runs the glyph engine, so characters that stay
312
+ * glide to their new place, new ones slide or fade in and removed ones leave
313
+ * alongside their neighbours, which is what an amount field wants. A
314
+ * multiline field is always `'none'`.
313
315
  */
314
- morph?: boolean;
316
+ transition?: NitroInputTransition;
315
317
  /**
316
318
  * Whether the field sizes itself to its content.
317
319
  *
318
- * `false` (the default) takes no width of its own, so flexbox stretches it to
319
- * its parent the way a `TextInput` is stretched — that is what makes this a
320
- * drop-in. `true` always sizes to content. `'auto'` infers it: on unless
321
- * `style` gives a `width` or `flex`, which is what lets an amount grow as
322
- * digits arrive, and is what {@link MorphInput} uses.
320
+ * `false` takes no width of its own, so flexbox stretches it to its parent
321
+ * the way a `TextInput` is stretched — that is what makes this a drop-in.
322
+ * `true` always sizes to content. `'auto'` infers it: on unless `style`
323
+ * gives a `width` or `flex`, which is what lets an amount grow as digits
324
+ * arrive. Default: `'auto'` with `transition="reflow"`, else `false`.
323
325
  */
324
326
  autoWidth?: boolean | 'auto';
325
327
  /** `'text'` mode: most characters accepted. Default: unlimited. */
@@ -378,7 +380,7 @@ export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus'
378
380
  export interface NitroInputHandle {
379
381
  focus(): void;
380
382
  blur(): void;
381
- /** Empties the field, morphing the characters away. */
383
+ /** Empties the field, reflowing the characters away. */
382
384
  clear(): void;
383
385
  /** Replaces the text (formatted in `'number'` mode), caret at the end. */
384
386
  setText(text: string): void;
@@ -394,18 +396,23 @@ export interface NitroInputHandle {
394
396
  /** The native Nitro object, or `null` before mount. */
395
397
  readonly native: NitroInputRef | null;
396
398
  }
399
+ /**
400
+ * How a `NitroInput`'s text changes: drawn at once (`'none'`), or reflowed by
401
+ * the glyph engine (`'reflow'`).
402
+ */
403
+ export type NitroInputTransition = 'none' | 'reflow';
397
404
  /**
398
405
  * A native text input: a system field (`UITextField` / `EditText`) that owns
399
406
  * the keyboard, editing, selection, paste and accessibility, with native
400
407
  * formatting (`mode="number"`), native masking (`mode="mask"`), an outlined
401
408
  * or filled frame with a floating label, and optionally the glyph engine
402
- * (`morph`), under which characters that stay glide to their new place, new
409
+ * (`transition="reflow"`), under which characters that stay glide to their new place, new
403
410
  * ones slide or fade in and removed ones leave alongside their neighbours.
404
411
  * In `'number'` mode every edit is formatted on the native side before a
405
412
  * frame is drawn, with the caret kept in place, so there is never an
406
413
  * unformatted frame and never a round trip through JS.
407
414
  *
408
- * Like a `TextInput`, it takes its width from its parent; `autoWidth`
409
- * (`'auto'` in {@link MorphInput}) sizes it to its content instead.
415
+ * Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
416
+ * it to its content instead, and is on by default when the text reflows.
410
417
  */
411
418
  export declare const NitroInput: React.ForwardRefExoticComponent<NitroInputProps & React.RefAttributes<NitroInputHandle>>;
@@ -0,0 +1,211 @@
1
+ import React from 'react';
2
+ import { type ColorValue, type TextStyle, type ViewProps } from 'react-native';
3
+ import { type HybridRef } from 'react-native-nitro-modules';
4
+ import type { NitroNumberAffixAlign, NitroNumberDirection, NitroNumberTransition, NitroNumberEasing, NitroNumberMethods, NitroNumberProps as NativeNitroNumberProps, NitroNumberRevealStyle, NitroNumberTextAlign } from './specs/NitroNumber.nitro';
5
+ /**
6
+ * The raw Nitro host component. Prefer {@link NitroNumber}, which adds
7
+ * auto-sizing, color/weight conversion and a convenient handle.
8
+ */
9
+ export declare const NativeNitroNumberView: import("react-native-nitro-modules").ReactNativeView<NativeNitroNumberProps, NitroNumberMethods>;
10
+ /** The native Nitro `HybridObject` behind a mounted {@link NitroNumber}. */
11
+ export type NitroNumberRef = HybridRef<NativeNitroNumberProps, NitroNumberMethods>;
12
+ export interface NitroNumberProps extends Omit<ViewProps, 'children'> {
13
+ /**
14
+ * The number to display. Every change rolls each digit natively to its new
15
+ * glyph, in the direction of the change. The first value is shown instantly.
16
+ * At most 18 digits are shown: `|value| × 10^fractionDigits` is clamped at
17
+ * 10^17, and a JS number carries exact integers only up to 2^53.
18
+ */
19
+ value: number;
20
+ /** Digits shown after the decimal separator. Default: `0`. */
21
+ fractionDigits?: number;
22
+ /** Zero-pads the integer part to at least this many digits. Default: `1`. */
23
+ minimumIntegerDigits?: number;
24
+ /** Inserted between every three integer digits (e.g. `','`). Default: none. */
25
+ groupingSeparator?: string;
26
+ /** Placed between integer and fraction digits. Default: `'.'`. */
27
+ decimalSeparator?: string;
28
+ /** Static text drawn before the number, e.g. `'$'`. */
29
+ prefix?: string;
30
+ /** Static text drawn after the number, e.g. `'%'`. */
31
+ suffix?: string;
32
+ /**
33
+ * How a value change plays. `'roll'` (default) is the odometer: every
34
+ * changed digit rolls through the digits between its old and new glyph, in
35
+ * the direction of the change. `'numeric'` is the numeric transition, the
36
+ * effect of SwiftUI's `.contentTransition(.numericText())`: each changed
37
+ * glyph swaps in place, the old one softening, shrinking and sliding out
38
+ * while the new one slides in from the other side and comes into focus, the
39
+ * digits cascading from the left; unchanged digits stay put. `'scramble'`
40
+ * shows a different random digit every few frames until each changed digit
41
+ * locks on its target, from the left.
42
+ *
43
+ * Each swap style has its own defaults for `duration`, `easing` and
44
+ * `stagger`: numeric 480 / (its own clocks) / 150, scramble 500 / `'linear'` / 60.
45
+ */
46
+ transition?: NitroNumberTransition;
47
+ /**
48
+ * The change flash: every digit whose glyph changes lights up in this
49
+ * colour when the value grew (e.g. a green), stays lit while it moves,
50
+ * and fades back over `flashDuration` once it has landed. Unset: no flash.
51
+ */
52
+ flashUpColor?: ColorValue;
53
+ /** The change flash's colour when the value shrank (e.g. a red). Unset: no flash. */
54
+ flashDownColor?: ColorValue;
55
+ /** Milliseconds a change flash takes to fade, once the digit has landed. Default: `600`. */
56
+ flashDuration?: number;
57
+ /**
58
+ * A punch of the whole figure on every value change, its peak overshoot
59
+ * as a fraction of the size, `0` (none, the default) to `1`; rung out like
60
+ * the reveal's landing pop. `0.08` is a nudge, `0.2` a slam.
61
+ */
62
+ popOnChange?: number;
63
+ /** Duration in ms of the roll played when `value` changes. `0` snaps. Default: `500` (each swap transition has its own, see `transition`). */
64
+ duration?: number;
65
+ /** Timing curve of the roll. Default: `'easeInOut'` (the scramble has its own, see `transition`; the numeric transition keeps SwiftUI's own clocks and ignores it). */
66
+ easing?: NitroNumberEasing;
67
+ /** Overshoot of the `'spring'` easing, `0`–`1`. Default: `0.15` (the numeric transition has its own, fixed). */
68
+ bounce?: number;
69
+ /**
70
+ * Delay in ms between the start of each digit's roll, least significant
71
+ * digit first, so a change cascades like a mechanical carry. In the numeric
72
+ * transition it is the span of the whole cascade instead: the digits that
73
+ * change start spread evenly over it from the leftmost to the rightmost,
74
+ * however many there are, the way the effect cascades on iOS. Default: `0`
75
+ * (`150` for the numeric transition).
76
+ */
77
+ stagger?: number;
78
+ /** Which way the digits roll. `'auto'` follows the sign of the change. Default: `'auto'`. */
79
+ direction?: NitroNumberDirection;
80
+ /**
81
+ * Jackpot reveal, the casino "you won" presentation. While `false` the view
82
+ * holds the opening frame of `value` ("$0.00": its layout, every digit blank
83
+ * except the mandatory ones); when it turns `true` the figure plays its
84
+ * `revealStyle` to `value` and lands with a pop. Pair it with
85
+ * `textAlign="center"` for a centred hero figure. Leave it `undefined` for
86
+ * a normal NitroNumber. To let the user skip the reveal, call `jumpTo(value)`.
87
+ */
88
+ reveal?: boolean;
89
+ /**
90
+ * `'count'` (default) is the win-meter rollup: the figure tallies up from 0
91
+ * like a slot's win counter, taking off at once, running at a constant
92
+ * rate and braking into the total (and into each tier with
93
+ * `revealMilestones`), swelling slightly as it climbs, digits swapping in
94
+ * place and leading digits appearing as the count reaches them. `'spin'`
95
+ * is the jackpot reels: every digit spins like a slot reel, then the reels
96
+ * brake and lock one at a time from the left, each with a mechanical bounce.
97
+ */
98
+ revealStyle?: NitroNumberRevealStyle;
99
+ /** Duration of the reveal in ms (the count, or the time until the last reel locks). Default: `2200`. */
100
+ revealDuration?: number;
101
+ /** Peak overshoot of the reveal's landing pop, `0` (none) to `1`. Default: `0.12`. */
102
+ revealBounce?: number;
103
+ /**
104
+ * `'count'` style: how much smaller the figure opens, as a fraction of its
105
+ * size, growing to full size over the count, the way a big win's meter is
106
+ * enlarged as it climbs. `0` = no growth. Default: `0.2`.
107
+ */
108
+ revealGrow?: number;
109
+ /** `'spin'` style: ms between one reel locking and the next, shortened to fit `revealDuration`. Default: `200`. */
110
+ revealStagger?: number;
111
+ /**
112
+ * `'count'` style: the win tiers of a casino rollup ("Big win" → "Mega win"
113
+ * → "Epic win"), in the figure's units. When the count reaches one, the
114
+ * figure punches, pauses on it for `revealMilestoneHold` and
115
+ * `onRevealMilestone` fires, so the app can slam its banner in, fire the
116
+ * confetti and play the sting on that beat. Values at or above `value` are ignored.
117
+ */
118
+ revealMilestones?: number[];
119
+ /** `'count'` style: ms the count pauses on each milestone (the banner's moment). Default: `0`. */
120
+ revealMilestoneHold?: number;
121
+ /** Called once a reveal has landed (count finished or last reel locked, and the pop rung out). */
122
+ onRevealEnd?: () => void;
123
+ /** Called when the count reaches a milestone: its index among the usable milestones and its value. */
124
+ onRevealMilestone?: (index: number, value: number) => void;
125
+ /**
126
+ * Loading glint: the ink keeps its color while a slanted, text-wide band of
127
+ * `shimmerColor` sweeps through the glyphs (a "shine" skeleton). Toggling
128
+ * cross-fades; the number keeps its size so nothing jumps when the value
129
+ * arrives. Default: `false`.
130
+ */
131
+ loading?: boolean;
132
+ /** Color of the glint's core, e.g. your theme's lightest neutral. Defaults to `#D6D9E1` (`#2B2E37` in dark mode). */
133
+ shimmerColor?: ColorValue;
134
+ /** Duration of one sweep in ms (linear, repeating). Default: `950`. */
135
+ shimmerDuration?: number;
136
+ /** Font size of the digits in points. Default: `32`. */
137
+ fontSize?: number;
138
+ /** Font size of `prefix`, e.g. a smaller currency symbol. Defaults to `fontSize`. */
139
+ prefixFontSize?: number;
140
+ /** Font size of `suffix`, e.g. a smaller currency code. Defaults to `fontSize`. */
141
+ suffixFontSize?: number;
142
+ /**
143
+ * How prefix and suffix line up with the digits: `'top'` pins glyph tops,
144
+ * `'bottom'` pins the bottom of the line boxes, `'baseline'` shares the
145
+ * digits' baseline, `'center'` centres. Default: `'baseline'`.
146
+ */
147
+ affixAlign?: NitroNumberAffixAlign;
148
+ /** Alignment of `prefix` only. Defaults to `affixAlign`. */
149
+ prefixAlign?: NitroNumberAffixAlign;
150
+ /** Alignment of `suffix` only. Defaults to `affixAlign`. */
151
+ suffixAlign?: NitroNumberAffixAlign;
152
+ /**
153
+ * Scale the number down when the view is narrower than its content, and back
154
+ * up (never above `fontSize`) when it fits again. Give the view a fixed
155
+ * `width` in `style`; the view keeps its full-size height so the box around
156
+ * it never moves, only the amount scales. Like `Text`'s prop. Default: `false`.
157
+ */
158
+ adjustsFontSizeToFit?: boolean;
159
+ /** Smallest scale `adjustsFontSizeToFit` may apply, `0`–`1`. Default: `0.5`. */
160
+ minimumFontScale?: number;
161
+ /**
162
+ * Scale the fonts with the system text size (Dynamic Type / Android font
163
+ * scale) like `Text` does. Off by default so amounts keep their design size.
164
+ */
165
+ allowFontScaling?: boolean;
166
+ /** Upper bound for `allowFontScaling`, e.g. `1.3`. `0` means no cap. Default: `0`. */
167
+ maxFontSizeMultiplier?: number;
168
+ /** Font weight, like `Text`'s `fontWeight`. Default: `'normal'`. */
169
+ fontWeight?: TextStyle['fontWeight'];
170
+ /** Font family name, like `Text`'s `fontFamily`. Defaults to the system font. */
171
+ fontFamily?: string;
172
+ /** Text color. Defaults to the platform's primary label color. */
173
+ color?: ColorValue;
174
+ /**
175
+ * Where the number sits when the view is wider than its content, e.g. when
176
+ * you give it a fixed `width` so it doesn't reflow as digits appear.
177
+ * Default: `'auto'`: the start edge of the layout direction, as `Text`.
178
+ * `'left'` and `'right'` are absolute.
179
+ */
180
+ textAlign?: NitroNumberTextAlign;
181
+ /** Receives the native Nitro object once the view is mounted. */
182
+ onNativeRef?: (ref: NitroNumberRef) => void;
183
+ }
184
+ /** Imperative handle exposed through `ref`. Methods are no-ops before mount. */
185
+ export interface NitroNumberHandle {
186
+ /**
187
+ * Shows `value` immediately with continuously positioned digits (odometer
188
+ * style, `12.5` shows the last digit half way between `2` and `3`). No roll
189
+ * is played. Useful for scrubbing, e.g. from a scroll or drag handler.
190
+ */
191
+ jumpTo(value: number): void;
192
+ /** Rolls to `value` natively, exactly like changing the `value` prop. */
193
+ animateTo(value: number): void;
194
+ /** Plays a jackpot reveal to `value` (counts up from 0), whatever the `reveal` prop says. */
195
+ revealTo(value: number): void;
196
+ /** The value currently shown or being rolled towards. */
197
+ getValue(): number;
198
+ /** The native Nitro object, or `null` before mount. */
199
+ readonly native: NitroNumberRef | null;
200
+ }
201
+ /**
202
+ * A number that animates its changes natively: an odometer roll, SwiftUI's
203
+ * numeric transition or a scramble.
204
+ *
205
+ * Change `value` and every digit rolls to its new glyph on the native side.
206
+ * Use the ref's `animateTo` / `jumpTo` for imperative updates.
207
+ *
208
+ * The view sizes itself to its content unless you pass an explicit `width` /
209
+ * `height` in `style`.
210
+ */
211
+ export declare const NitroNumber: React.ForwardRefExoticComponent<NitroNumberProps & React.RefAttributes<NitroNumberHandle>>;
@@ -1,6 +1,7 @@
1
- export { NitroInput, NativeNitroInputView, type NitroInputProps, type NitroInputHandle, type NitroInputRef, type NitroInputTextEvent, type NitroInputFocusEvent, type NitroInputSelectionEvent, type NitroInputKeyPressEvent, type InputMode, type EnterKeyHint, } from './NitroInput';
2
- export { MorphInput, type MorphInputProps, type MorphInputHandle, type MorphInputRef, } from './MorphInput';
1
+ export { NitroInput, NativeNitroInputView, type NitroInputProps, type NitroInputHandle, type NitroInputRef, type NitroInputTextEvent, type NitroInputFocusEvent, type NitroInputSelectionEvent, type NitroInputKeyPressEvent, type NitroInputTransition, type InputMode, type EnterKeyHint, } from './NitroInput';
3
2
  export { isWorklet, type NitroInputSelection, type NitroInputTransform, type WorkletTextEvent, type WorkletFocusEvent, type WorkletSelectionEvent, type WorkletKeyPressEvent, } from './worklets';
4
3
  export { useNitroInputState, type NitroInputState, type SharedValueLike, } from './useNitroInputState';
5
4
  export type { NitroInputLabelBehavior, NitroInputMode, NitroInputNotation, NitroInputVariant, NitroInputEasing, NitroInputEffect, NitroInputTextAlign, NitroInputTextAlignVertical, NitroInputAffixAlign, NitroInputSignPlacement, NitroInputKeyboardType, NitroInputReturnKeyType, NitroInputAutoCapitalize, NitroInputSubmitBehavior, NitroInputKeyboardAppearance, NitroInputMethods, NitroInputProps as NativeNitroInputProps, NitroInputView, } from './specs/NitroInput.nitro';
6
5
  export type { NitroInputWorklets } from './specs/NitroInputWorklets.nitro';
6
+ export { NitroNumber, NativeNitroNumberView, type NitroNumberProps, type NitroNumberHandle, type NitroNumberRef, } from './NitroNumber';
7
+ export type { NitroNumberAffixAlign, NitroNumberDirection, NitroNumberTransition, NitroNumberEasing, NitroNumberRevealStyle, NitroNumberTextAlign, NitroNumberMethods, NitroNumberProps as NativeNitroNumberProps, NitroNumberView, } from './specs/NitroNumber.nitro';
@@ -18,7 +18,7 @@ export interface NitroInputNotation {
18
18
  isOptional: boolean;
19
19
  }
20
20
  /**
21
- * Timing curve of the morph. `'expo'` is Torph's default
21
+ * Timing curve of the reflow. `'expo'` is Torph's default
22
22
  * (`cubic-bezier(0.19, 1, 0.22, 1)`): a fast take-off that settles gently.
23
23
  */
24
24
  export type NitroInputEasing = 'expo' | 'easeOut' | 'easeInOut' | 'linear' | 'spring';
@@ -56,7 +56,7 @@ export type NitroInputTextAlignVertical = 'auto' | 'top' | 'center' | 'bottom';
56
56
  * `'beforeAffix'` (the default) reads `-$1,234.56`, which is how a locale that
57
57
  * leads with its symbol writes it. `'afterAffix'` reads `$-1,234.56`, which
58
58
  * suits a symbol styled as an ornament rather than read as part of the number -
59
- * small, raised, in another colour. Only the morph honours it: a plain field's
59
+ * small, raised, in another colour. Only the reflow honours it: a plain field's
60
60
  * affixes are accessory views that sit outside the text, so it is always
61
61
  * `'afterAffix'`.
62
62
  */
@@ -92,7 +92,7 @@ export interface NitroInputProps extends HybridViewProps {
92
92
  /** `'text'`, `'number'` or `'mask'`. Default: `'text'`. */
93
93
  mode: NitroInputMode;
94
94
  /**
95
- * Draw the text with the system field itself and skip the morph overlay
95
+ * Draw the text with the system field itself and skip the reflow overlay
96
96
  * entirely: no glyph engine, no per-glyph layers, no custom caret. This is
97
97
  * what `NitroInput` renders — an ordinary native input that keeps the rest of
98
98
  * the component (native formatting, the focus path, the text-input registry
@@ -176,13 +176,13 @@ export interface NitroInputProps extends HybridViewProps {
176
176
  prefixAlign: NitroInputAffixAlign;
177
177
  /** Vertical alignment of `suffix` relative to the text (the wrapper folds its `affixAlign` into this). */
178
178
  suffixAlign: NitroInputAffixAlign;
179
- /** Shown (and morphed away) while the field is empty. Default: `''`. */
179
+ /** Shown (and reflowed away) while the field is empty. Default: `''`. */
180
180
  placeholder: string;
181
181
  /** Color of the placeholder as a processed ARGB integer; `NaN` = platform default. */
182
182
  placeholderColor: number;
183
- /** Duration in ms of the morph played on every change. `0` snaps. Default: `400`. */
183
+ /** Duration in ms of the reflow played on every change. `0` snaps. Default: `400`. */
184
184
  duration: number;
185
- /** Timing curve of the morph. Default: `'expo'`. */
185
+ /** Timing curve of the reflow. Default: `'expo'`. */
186
186
  easing: NitroInputEasing;
187
187
  /** Overshoot of the `'spring'` easing, `0`–`1`. Default: `0.15`. */
188
188
  bounce: number;
@@ -248,9 +248,9 @@ export interface NitroInputProps extends HybridViewProps {
248
248
  * Let the text wrap onto more than one line.
249
249
  *
250
250
  * A multiline field is always drawn by the system view — the glyph engine
251
- * lays one run out on one baseline, so it cannot morph wrapped text — and it
251
+ * lays one run out on one baseline, so it cannot reflow wrapped text — and it
252
252
  * is always `'text'` mode, since an amount and a mask are single-line ideas.
253
- * Setting `morph`, `'number'` or `'mask'` alongside it is ignored, with a
253
+ * Setting `transition="reflow"`, `'number'` or `'mask'` alongside it is ignored, with a
254
254
  * warning. Default: `false`.
255
255
  */
256
256
  multiline: boolean;
@@ -366,7 +366,7 @@ export interface NitroInputProps extends HybridViewProps {
366
366
  export interface NitroInputMethods extends HybridViewMethods {
367
367
  focus(): void;
368
368
  blur(): void;
369
- /** Empties the field (morphing the characters away). */
369
+ /** Empties the field (reflowing the characters away). */
370
370
  clear(): void;
371
371
  /**
372
372
  * Replaces the text (formatted in `'number'` mode), caret at the end.