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,468 @@
1
+ //
2
+ // RollingEngine.hpp
3
+ // NitroInput
4
+ //
5
+ // The platform-independent state machine behind the rolling number view.
6
+ // Both native views (NitroNumberView.swift, NitroNumberView.kt) feed it
7
+ // values and time, and draw whatever it reports: one "wheel" per digit with a
8
+ // continuous position on a 0–9 strip (or, in the numeric transition, a glyph
9
+ // swapping in place), the sign factor, the loading fade and the shimmer
10
+ // phase. No rendering, no fonts, no threading in here.
11
+ //
12
+ // Time is in seconds on any monotonic clock (CACurrentMediaTime,
13
+ // Choreographer frame time). The API deliberately uses plain ints/doubles so
14
+ // it imports cleanly into Swift (C++ interop) and bridges trivially over JNI.
15
+ //
16
+
17
+ #pragma once
18
+
19
+ #include <cstdint>
20
+ #include <vector>
21
+
22
+ #include "SwiftNonCopyable.hpp"
23
+
24
+ namespace margelo::nitro::nitroinput {
25
+
26
+ class SWIFT_NONCOPYABLE RollingEngine final {
27
+ public:
28
+ struct Wheel {
29
+ /// Glyph index on the strip. Interior wheels wrap modulo 10; linear wheels
30
+ /// use -1 for "blank" and never wrap.
31
+ double position;
32
+ /// Horizontal extent, 0…1. Wheels appear/disappear by growing/shrinking.
33
+ double width;
34
+ /// The strip is [blank, 0, 1, …, 9] (appearing/disappearing wheels).
35
+ bool linear;
36
+ /// Glyph 0 is drawn blank (the emerging odometer wheel).
37
+ bool blankZero;
38
+
39
+ // The numeric transition (`setTransition(1)`, after SwiftUI's
40
+ // `.contentTransition(.numericText())`): a wheel swaps its glyph in place
41
+ // instead of rolling through the ones between. `blend` runs 0 → 1 from
42
+ // `fromGlyph` to `toGlyph` (a digit, or -1 for blank) and is 1 for a wheel
43
+ // that is settled or not part of the change; while it is below 1 a
44
+ // renderer draws the two glyphs as `kNumeric*` below describes and ignores
45
+ // `position`. `fromAbove`: the new glyph arrives from above and the old one
46
+ // leaves downwards, which is how a value that shrank plays; a value that
47
+ // grew is the mirror image, the glyphs moving up the way an odometer's do
48
+ // (checked frame by frame against SwiftUI's own transition). `focus` is
49
+ // the arriving glyph's blur clock (0 fully blurred, 1 sharp), `blurOut`
50
+ // the leaving glyph's (0 sharp, 1 fully blurred), and `grow` the
51
+ // size-and-opacity clock (0 the arriving glyph small and clear, 1 full
52
+ // size and opaque); see `kNumeric*` below.
53
+ double fromGlyph = -1;
54
+ double toGlyph = -1;
55
+ double blend = 1;
56
+ bool fromAbove = true;
57
+ double focus = 1;
58
+ double grow = 1;
59
+ double blurOut = 1;
60
+ /// The change flash (`setFlash`): 1 from the moment this wheel's glyph
61
+ /// changed until the wheel has landed (its stagger delay and the
62
+ /// transition's duration; a snap lands at once), then fading to 0 over
63
+ /// the flash's duration; a renderer mixes the wheel's ink towards the up
64
+ /// or the down colour by this much. `flashUp`: the value grew.
65
+ double flash = 0;
66
+ bool flashUp = true;
67
+ };
68
+
69
+ // The numeric transition as the renderers draw it, in line heights, so all
70
+ // three (Core Animation, Canvas, the docs' canvas) agree. A changing wheel
71
+ // runs four clocks, each the step response of a damped spring scaled to
72
+ // the wheel's duration D (`damped()`). The figures are SwiftUI's: fitted to
73
+ // its frames at 60 fps (a model of the renderers rendered from the real
74
+ // glyphs and optimised until it reproduced them pixel for pixel), and in
75
+ // agreement with the constants published by react-native-numeric-text.
76
+ // The transaction's easing and bounce are not consulted, as SwiftUI's own
77
+ // transition does not consult its animation:
78
+ // `blend` the position: ζ kNumericPositionZeta (about 12 % overshoot, so it
79
+ // runs past 1 and comes back), settled at D
80
+ // `grow` size and opacity: critically damped, settled at kNumericGrowSettle · D
81
+ // `focus` the arriving glyph's blur: ζ kNumericFocusZeta, settled at kNumericFocusSettle · D
82
+ // `blurOut` the leaving glyph's blur: critically damped, settled at kNumericBlurOutSettle · D
83
+ // With b = blend (only the offsets follow it past 1), g = grow, f = focus,
84
+ // o = blurOut and d = +1 when `fromAbove`, else -1:
85
+ // leaving glyph: offset d · kNumericOffset · b, scale 1 → kNumericScale by g, alpha 1 - g, blur o
86
+ // arriving glyph: offset -d · kNumericOffset · (1 - b), scale kNumericScale → 1 by g, alpha g, blur 1 - f
87
+ // both scaled about their centre, blur being kNumericBlur line heights of
88
+ // gaussian sigma at 1 (SwiftUI's own; a renderer that cannot blur
89
+ // per frame keeps a ladder of blurred copies and cross-fades the two
90
+ // nearest, never a sharp copy with a blurred one, which reads as a digit
91
+ // inside a glow). The transition runs kNumericTail · D. A wheel is swapping while any clock is below 1. The
92
+ // columns that change start spread evenly over `stagger` seconds from the
93
+ // leftmost, however many there are (delay = stagger · i / (n - 1)).
94
+ static constexpr double kNumericOffset = 0.34;
95
+ static constexpr double kNumericScale = 0.4;
96
+ static constexpr double kNumericBlur = 0.08;
97
+ static constexpr double kNumericPositionZeta = 0.54;
98
+ static constexpr double kNumericGrowSettle = 0.65;
99
+ static constexpr double kNumericFocusZeta = 0.85;
100
+ static constexpr double kNumericFocusSettle = 0.74;
101
+ static constexpr double kNumericBlurOutSettle = 0.46;
102
+ /// The numeric transition lasts this many durations: the position spring
103
+ /// settles to 2 % at D, which is still a pixel at a large size, and
104
+ /// SwiftUI lets it ring out; ended at D the last pixel snapped.
105
+ static constexpr double kNumericTail = 1.45;
106
+
107
+ // The scramble (2) is planned like the numeric transition but the wheel
108
+ // shows a different random digit every kScrambleStepSeconds until it locks
109
+ // on its target; `position` is that digit and `blend` stays 1, so a
110
+ // renderer needs nothing new.
111
+ static constexpr double kScrambleStepSeconds = 0.045;
112
+
113
+ // Easing: 0 linear, 1 easeIn, 2 easeOut, 3 easeInOut, 4 spring.
114
+ // Direction: 0 auto (sign of the change), 1 up, 2 down.
115
+ // Transition: 0 roll (the odometer), 1 numeric (glyphs swap in place),
116
+ // 2 scramble.
117
+
118
+ RollingEngine();
119
+ // Defined in the .cpp (see SwiftNonCopyable.hpp).
120
+ ~RollingEngine();
121
+ RollingEngine(const RollingEngine&);
122
+ RollingEngine& operator=(const RollingEngine&);
123
+ RollingEngine(RollingEngine&&) noexcept;
124
+ RollingEngine& operator=(RollingEngine&&) noexcept;
125
+
126
+ // MARK: Configuration
127
+
128
+ /// Digits after the decimal separator (0…9) and zero-padding of the integer
129
+ /// part (1…15). Snaps to the current target when they change.
130
+ void setFormat(int fractionDigits, int minimumIntegerDigits);
131
+ /// `setFormat` with the change played: the digits keep their place value,
132
+ /// the decimal columns that go close and the ones that come open blank
133
+ /// (swapping or rolling their digit in), the decimal separator fading with
134
+ /// them (a currency switch: "£9,587.05" to "¥1,856,853"). Snaps as
135
+ /// `setFormat` does during a reveal, before a value has been shown, with a
136
+ /// zero duration or under Reduce Motion.
137
+ void changeFormat(int fractionDigits, int minimumIntegerDigits, double now);
138
+ /// The decimal columns laid out now: `fractionDigits` plus the ones still
139
+ /// closing after `changeFormat` took some away.
140
+ int displayFractionDigits() const { return fractionDigits_ + trailingPad_; }
141
+ /// Opacity and width of the decimal separator, 0…1: 1 while there are
142
+ /// decimals, easing in or out as `changeFormat` adds or removes them.
143
+ double decimalFactor() const { return decimalFactor_; }
144
+ void setTiming(double durationSeconds, int easing, double bounce, double staggerSeconds, int direction);
145
+ /// How a value change plays: 0 rolls every digit through the ones between
146
+ /// (the odometer), 1 swaps each changed glyph in place (the numeric
147
+ /// transition), 2 scrambles each changed digit until it locks. In the
148
+ /// numeric transition the stagger runs from the leftmost digit to the
149
+ /// right, the way the effect cascades on iOS, and the direction decides
150
+ /// which way the glyphs move. Takes effect from the next `animateTo`.
151
+ void setTransition(int transition);
152
+ int transition() const { return transitionStyle_; }
153
+ /// The change flash: every digit whose glyph changes lights up, stays lit
154
+ /// while it moves, and fades back over `seconds` once it has landed
155
+ /// (`Wheel::flash`). 0 turns it off. A jump (`setValue`) never flashes; a
156
+ /// reveal's count never does either.
157
+ void setFlash(double seconds);
158
+ /// A punch of the whole figure on every value change, `overshoot` 0 (none)
159
+ /// to 1, rung out like the reveal's landing pop; part of `revealScale()`.
160
+ void setPopOnChange(double overshoot);
161
+ /// Reduce Motion / "remove animations": rolls snap and the shimmer freezes.
162
+ void setReduceMotion(bool reduceMotion);
163
+
164
+ // MARK: Commands
165
+
166
+ /// Shows `value` immediately with continuously positioned wheels (odometer
167
+ /// carry rule). Cancels any running roll.
168
+ ///
169
+ /// Both this and `animateTo` work on |value| × 10^fractionDigits, clamped to
170
+ /// `kMaxMagnitude` (10^17, 18 wheels at most); a double only carries exact
171
+ /// integers up to 2^53, so figures beyond that lose their low digits either way.
172
+ void setValue(double value);
173
+ /// Rolls every wheel to `value` (shortest path in the roll direction,
174
+ /// blank↔digit for appearing/disappearing wheels), or, in the numeric
175
+ /// transition, swaps every changed glyph in place. Snaps when nothing has
176
+ /// been shown yet, the duration is 0, or Reduce Motion is on.
177
+ void animateTo(double value, double now);
178
+ /// Toggles the loading glint with a 250 ms cross-fade.
179
+ void setLoading(bool loading, double now);
180
+ /// Advances the roll, the reveal and the loading fade to `now`. Returns `needsFrames()`.
181
+ bool tick(double now);
182
+ /// Back to the pristine state (view recycling).
183
+ void reset();
184
+
185
+ // MARK: Jackpot reveal
186
+ //
187
+ // Two casino "you won" presentations, both landing with a pop (a velocity
188
+ // kick on `revealScale()` rung out by a damped spring):
189
+ //
190
+ // - Style 0, count (the win-meter rollup): the figure opens at 0 and
191
+ // tallies up to the target like a slot's win counter: it takes off at
192
+ // once, runs at a constant rate and brakes into the total (and into each
193
+ // milestone, tier by tier, when there are milestones), swelling slightly
194
+ // as it climbs. Digits swap in place (the count's own speed is the
195
+ // animation, there is no roll) and leading digits appear as the count
196
+ // reaches their place; the layout is the target's from the first frame,
197
+ // so nothing reflows.
198
+ // - Style 1, spin (the jackpot reels): every digit spins like a slot reel,
199
+ // then the reels brake and lock one at a time from the left, each with a
200
+ // small mechanical bounce, the last one landing at the duration.
201
+
202
+ /// Timing of a reveal: the total duration, the landing pop's peak overshoot
203
+ /// (`0` = no pop), the style (0 count, 1 spin) and, for the spin style, the
204
+ /// delay between reel stops (shortened when the reels don't fit the
205
+ /// duration). Defaults: 2.2 s, 0.12, count, 0.2 s.
206
+ void setRevealTiming(double durationSeconds, double bounce, int style, double staggerSeconds);
207
+ /// Count style: how much smaller the figure opens, as a fraction of its
208
+ /// size, growing to full size over the count (`0` = no growth). Default 0.2.
209
+ void setRevealGrow(double grow);
210
+ /// Shows the opening frame of a reveal for `value`: its layout with the
211
+ /// mandatory digits at 0 and every other digit blank ("$0", "$0.00").
212
+ /// Cancels any roll.
213
+ void holdReveal(double value);
214
+ /// Counts from 0 up to `value`. Snaps when the duration is 0 or Reduce
215
+ /// Motion is on. Called while a reveal is running it re-targets the count.
216
+ void reveal(double value, double now);
217
+ /// True while a reveal counts or its landing pop rings out.
218
+ bool isRevealing() const { return reveal_.active; }
219
+ /// Scale of the figure about its centre: a reveal's growth times its
220
+ /// punches, times the change pop (`setPopOnChange`); 1 when idle.
221
+ double revealScale() const { return revealScale_ * popScale_; }
222
+ /// Wall-clock length of a whole reveal (count, milestone holds, landing pop).
223
+ double revealTotalSeconds() const;
224
+
225
+ // Milestones of a count-style reveal: the win tiers of a casino rollup
226
+ // ("Big win" → "Mega win" → "Epic win"). When the count reaches one it
227
+ // punches (a smaller landing pop) and pauses on it for the hold while
228
+ // `revealMilestonesReached()` advances, so the app can slam its banner in
229
+ // on the beat. Values are in the figure's units, ascending; ones at or
230
+ // above the target are ignored. The spin style has no count and ignores them.
231
+
232
+ void clearRevealMilestones();
233
+ void addRevealMilestone(double value);
234
+ /// Pause on each milestone, in seconds (0 = punch without stopping).
235
+ void setRevealMilestoneHold(double holdSeconds);
236
+ /// How many milestones the running (or finished) reveal has reached.
237
+ int revealMilestonesReached() const { return reveal_.milestonesReached; }
238
+ /// The value (in the figure's units) of the reveal's `index`-th usable milestone.
239
+ double revealMilestoneValue(int index) const;
240
+
241
+ // MARK: Text changes
242
+ //
243
+ // The text around the digits (the prefix, the suffix and the two
244
+ // separators) is laid out by the renderers, but when one of them changes
245
+ // while a value is on screen (a currency switch: "11.459,69 €" becomes
246
+ // "£9,587.05") it plays like SwiftUI's numeric text, the characters being
247
+ // part of its string: the old text softens and fades out while the new one
248
+ // comes into focus, and the slot's width eases from one to the other. The
249
+ // engine runs each slot's clocks so every renderer agrees; a renderer keeps
250
+ // the text that is leaving.
251
+
252
+ enum TextSlot : int { PrefixText = 0, SuffixText = 1, GroupingText = 2, DecimalText = 3 };
253
+ static constexpr int kTextSlots = 4;
254
+ struct TextChange {
255
+ /// Opacity of the arriving text and of the leaving one's complement, and
256
+ /// how far the slot's width has gone from the old text's to the new one's.
257
+ double grow = 1;
258
+ /// The arriving text's focus (0 fully blurred, 1 sharp).
259
+ double focus = 1;
260
+ /// The leaving text's blur (0 sharp, 1 fully blurred).
261
+ double blurOut = 1;
262
+ bool active = false;
263
+ };
264
+ /// A slot's text changed at `now`: its swap starts over, from the text on
265
+ /// screen. Snaps (no swap) before a value has been shown, with a zero
266
+ /// duration, or under Reduce Motion. Uses the numeric transition's clocks
267
+ /// and the duration of `setTiming`, whatever the transition.
268
+ void changeText(int slot, double now);
269
+ TextChange textChange(int slot) const;
270
+
271
+ // MARK: Render state
272
+
273
+ const std::vector<Wheel>& wheels() const { return wheels_; }
274
+ int wheelCount() const { return static_cast<int>(wheels_.size()); }
275
+ Wheel wheelAt(int index) const { return wheels_[static_cast<size_t>(index)]; }
276
+ double signFactor() const { return signFactor_; }
277
+ /// 0 = normal, 1 = fully in loading mode.
278
+ double loadingProgress() const { return loadingProgress_; }
279
+ bool loading() const { return loading_; }
280
+ /// Sweep progress 0…1 for a glint with the given period; 0 under Reduce Motion.
281
+ double shimmerPhase(double now, double periodSeconds) const;
282
+ /// Whether anything is still moving (roll, fade, or an active glint).
283
+ bool needsFrames() const;
284
+ /// True while a roll (`animateTo`) or a reveal's count is in progress; false
285
+ /// for the loading fade or a reveal's landing pop alone.
286
+ bool isRolling() const;
287
+
288
+ // MARK: Settled target (intrinsic size, accessibility)
289
+
290
+ double targetValue() const { return targetValue_; }
291
+ bool hasShownValue() const { return hasShownValue_; }
292
+ int settledPowerCount() const { return settledPowerCount_; }
293
+ bool settledNegative() const { return settledNegative_; }
294
+ /// Digit of the rounded target at 10^power (power 0 = least significant).
295
+ int targetDigit(int power) const;
296
+ int fractionDigits() const { return fractionDigits_; }
297
+ int minimumIntegerDigits() const { return minimumIntegerDigits_; }
298
+
299
+ private:
300
+ struct Target {
301
+ uint64_t magnitude; // |value| * 10^fractionDigits, rounded
302
+ bool negative;
303
+ int powerCount;
304
+ int digit(int power) const;
305
+ };
306
+ struct WheelTransition {
307
+ Wheel from;
308
+ Wheel to;
309
+ /// Numeric: the wheel was already swapping to this glyph when the value
310
+ /// was re-targeted, and its swap carries on rather than restarting or
311
+ /// being cut short. `clock` is how far into the swap it was (seconds).
312
+ bool continues = false;
313
+ double clock = 0;
314
+ };
315
+ struct Transition {
316
+ bool active = false;
317
+ double start = 0;
318
+ double duration = 0;
319
+ std::vector<double> delays; // per wheel, least significant first
320
+ /// The largest entry of `delays`, so a tick needn't scan them.
321
+ double maxDelay = 0;
322
+ std::vector<WheelTransition> wheels;
323
+ double signFrom = 0;
324
+ double signTo = 0;
325
+ double decimalFrom = 1;
326
+ double decimalTo = 1;
327
+ std::vector<Wheel> finals;
328
+ /// True when this roll re-targeted wheels that were already moving. Such a
329
+ /// roll skips the ease-in half of the curve so rapid updates keep flowing
330
+ /// instead of restarting from rest on every call.
331
+ bool fromMotion = false;
332
+ /// The transition style this was planned with (see `setTransition`).
333
+ int style = 0;
334
+ /// Any glyph-swap style: wheels blend between glyphs instead of rolling.
335
+ bool numeric = false;
336
+ };
337
+ /// One wheel's change flash: when its glyph last changed, how long the
338
+ /// wheel was still moving after that (the tint holds until it lands), and
339
+ /// which way.
340
+ struct Flash {
341
+ double start = -1;
342
+ double hold = 0;
343
+ bool up = true;
344
+ };
345
+
346
+ /// One slot reel of a spin-style reveal (index 0 is the leftmost digit).
347
+ struct Reel {
348
+ /// Strip position while free-spinning is `phase + speed * elapsed`.
349
+ double phase;
350
+ /// When the brake engages and when the reel has locked.
351
+ double brakeStart;
352
+ double stop;
353
+ /// Position at `brakeStart` and the distance braked over, ending on the digit.
354
+ double from;
355
+ double travel;
356
+ };
357
+ struct Reveal {
358
+ bool active = false;
359
+ /// True while the count / the reels are still moving (not during the landing pop).
360
+ bool counting = false;
361
+ /// True while the opening frame is held (`holdReveal`), so a format change
362
+ /// re-holds it instead of snapping to the full target.
363
+ bool holding = false;
364
+ double start = 0;
365
+ Target target{0, false, 1};
366
+ std::vector<Reel> reels; // spin style only, leftmost first
367
+ /// Count style: for each usable milestone, its magnitude and the curve
368
+ /// time (seconds into the count) at which the count reaches it.
369
+ std::vector<double> milestoneMagnitudes;
370
+ std::vector<double> milestoneTimes;
371
+ int milestonesReached = 0;
372
+ };
373
+
374
+ Target makeTarget(double value) const;
375
+ void snap(const Target& target);
376
+ void settle(const Target& target);
377
+ /// The digit a wheel shows, or is arriving at: -1 for blank.
378
+ static int shownGlyph(const Wheel& wheel);
379
+ void planRoll(Transition& next, const Target& target, bool increasing, int count, int mandatory) const;
380
+ void planNumeric(Transition& next, const Target& target, bool increasing, int count, int mandatory, double now) const;
381
+ void apply(double elapsed);
382
+ /// The flash and the pop follow the clock, not the transition: they keep
383
+ /// fading after a roll has finished or a snap had none.
384
+ void applyEffects(double now);
385
+ void finish();
386
+ void cancelReveal();
387
+ void planReels();
388
+ void planMilestones();
389
+ void applyReveal(double elapsed);
390
+ void applyRevealCount(double elapsed);
391
+ void applyRevealSpin(double elapsed);
392
+ /// A punch `tau` seconds after its kick: one overshoot peaking at `overshoot`, then settling.
393
+ static double punch(double tau, double overshoot);
394
+ /// One tally run: constant-rate count with a ramp in and a brake out.
395
+ static double tally(double t, double rampIn, double rampOut);
396
+ double ease(double t) const;
397
+ /// The curve used when re-targeting mid-roll: the ease-in curves collapse to
398
+ /// their ease-out / linear counterparts so a wheel in motion never stalls.
399
+ double easeFromMotion(double t) const;
400
+ static double spring(double t, double bounce);
401
+ /// Step response of a damped spring with damping ratio `zeta`, scaled so it
402
+ /// has settled (within 2 %) at t == `settle`; 0 at t <= 0.
403
+ static double damped(double t, double zeta, double settle);
404
+ static double wrap(double x);
405
+ static int digitCount(uint64_t n);
406
+
407
+ // configuration
408
+ int fractionDigits_ = 0;
409
+ /// Decimal columns below the format's, closing after `changeFormat` (0 at rest).
410
+ int trailingPad_ = 0;
411
+ double decimalFactor_ = 1;
412
+ int minimumIntegerDigits_ = 1;
413
+ double duration_ = 0.5;
414
+ int easing_ = 3;
415
+ double bounce_ = 0.15;
416
+ double stagger_ = 0;
417
+ int direction_ = 0;
418
+ int transitionStyle_ = 0;
419
+ double flashSeconds_ = 0;
420
+ double popOnChange_ = 0;
421
+ bool reduceMotion_ = false;
422
+ double revealDuration_ = 2.2;
423
+ double revealBounce_ = 0.12;
424
+ int revealStyle_ = 0;
425
+ double revealStagger_ = 0.2;
426
+ double revealGrow_ = 0.2;
427
+ std::vector<double> revealMilestones_;
428
+ double revealMilestoneHold_ = 0;
429
+
430
+ // state
431
+ std::vector<Wheel> wheels_;
432
+ double signFactor_ = 0;
433
+ bool hasShownValue_ = false;
434
+ double targetValue_ = 0;
435
+ Target target_{0, false, 1};
436
+ int settledPowerCount_ = 1;
437
+ bool settledNegative_ = false;
438
+ Transition transition_;
439
+ Reveal reveal_;
440
+ double revealScale_ = 1;
441
+ /// Per wheel (least significant first), kept across transitions.
442
+ std::vector<Flash> flashes_;
443
+ double popStart_ = -1;
444
+ double popScale_ = 1;
445
+ struct TextClock {
446
+ double start = -1;
447
+ };
448
+ TextClock textClocks_[kTextSlots];
449
+ TextChange textChanges_[kTextSlots];
450
+ bool textActive_ = false;
451
+ void applyText(double now);
452
+ /// Drops the running transition's layout state, for a path that rebuilds
453
+ /// the wheels itself (a snap, a jump, a reveal): the decimal columns that
454
+ /// were closing go with it.
455
+ void endTransition();
456
+ /// The clock of the last `tick`, for `needsFrames` on the effects.
457
+ double lastNow_ = 0;
458
+ bool effectsActive_ = false;
459
+
460
+ bool loading_ = false;
461
+ double loadingProgress_ = 0;
462
+ bool loadingFadeActive_ = false;
463
+ double loadingFadeFrom_ = 0;
464
+ double loadingFadeStart_ = 0;
465
+ double shimmerStart_ = 0;
466
+ };
467
+
468
+ } // namespace margelo::nitro::nitroinput
@@ -0,0 +1,22 @@
1
+ //
2
+ // SwiftNonCopyable.hpp
3
+ // NitroInput
4
+ //
5
+ // `SWIFT_NONCOPYABLE` for the engines Swift holds as stored properties.
6
+ // Swift calls a C++ `const` method on a copy of the object when it reads it
7
+ // from a class property: a copy constructor per call, every vector with it,
8
+ // dozens of times a frame. Marked noncopyable, Swift borrows the object in
9
+ // place instead. A class so marked needs its move constructor and
10
+ // destructor defined out of line, in its .cpp, where they are compiled.
11
+ // Nothing for C++ itself, Android or WebAssembly.
12
+ //
13
+
14
+ #pragma once
15
+
16
+ #if defined(__APPLE__) && __has_include(<swift/bridging>)
17
+ #include <swift/bridging>
18
+ #endif
19
+
20
+ #ifndef SWIFT_NONCOPYABLE
21
+ #define SWIFT_NONCOPYABLE
22
+ #endif
@@ -6,7 +6,7 @@
6
6
  #include "NitroInputWorkletsBridge.hpp"
7
7
  #include "NitroInputWorkletsBridgeJSI.hpp"
8
8
 
9
- #if MORPH_INPUT_WORKLETS
9
+ #if NITRO_INPUT_WORKLETS
10
10
 
11
11
  #include <jsi/jsi.h>
12
12
  #include <worklets/Compat/Holders.h>
@@ -168,7 +168,7 @@ void runKeyPress(int id, const std::string& key) {
168
168
 
169
169
  } // namespace margelo::nitro::nitroinput::nitroinputworklets
170
170
 
171
- #else // MORPH_INPUT_WORKLETS
171
+ #else // NITRO_INPUT_WORKLETS
172
172
 
173
173
  namespace margelo::nitro::nitroinput::nitroinputworklets {
174
174
 
@@ -200,4 +200,4 @@ void runKeyPress(int, const std::string&) {}
200
200
 
201
201
  } // namespace margelo::nitro::nitroinput::nitroinputworklets
202
202
 
203
- #endif // MORPH_INPUT_WORKLETS
203
+ #endif // NITRO_INPUT_WORKLETS
@@ -10,7 +10,7 @@
10
10
  //
11
11
  // This header is plain C++ (no JSI, no worklets types) so Swift can import
12
12
  // it. Everything compiles to no-ops when `react-native-worklets` is not
13
- // installed (`MORPH_INPUT_WORKLETS` undefined).
13
+ // installed (`NITRO_INPUT_WORKLETS` undefined).
14
14
  //
15
15
 
16
16
  #pragma once
@@ -263,7 +263,7 @@ final class HybridNitroInputView: HybridNitroInputViewSpec, RecyclableView {
263
263
  /// difference, on the first mount (Fabric hands later mounts the pooled
264
264
  /// views of earlier ones). iPhone 11 Pro and 13 Pro Max, 2026-09-22: a
265
265
  /// NitroInput is about 120 KB of malloc and 140–155 KB of footprint per
266
- /// field (a `TextInput` 120 and 100–110), a MorphInput 20–30 and 30–65.
266
+ /// field (a `TextInput` 120 and 100–110), a reflowing one 20–30 and 30–65.
267
267
  /// One constant for both, because Nitro reads it once when the handle is
268
268
  /// created, before the props say which one this is.
269
269
  var memorySize: Int { 96 * 1024 }