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.
- package/CHANGELOG.md +305 -3
- package/NitroInput.podspec +4 -4
- package/README.md +378 -53
- package/android/CMakeLists.txt +5 -3
- package/android/src/main/cpp/JOutlineGeometry.hpp +1 -1
- package/android/src/main/cpp/JReflowEngine.cpp +132 -0
- package/android/src/main/cpp/{JMorphEngine.hpp → JReflowEngine.hpp} +7 -7
- package/android/src/main/cpp/JRollingEngine.cpp +222 -0
- package/android/src/main/cpp/JRollingEngine.hpp +68 -0
- package/android/src/main/cpp/cpp-adapter.cpp +4 -2
- package/android/src/main/java/com/margelo/nitro/nitroinput/AmountFormatter.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +471 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputPackage.kt +2 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +38 -16
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +1741 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/{MorphEngine.kt → ReflowEngine.kt} +2 -2
- package/android/src/main/java/com/margelo/nitro/nitroinput/RollingEngine.kt +59 -0
- package/cpp/AmountFormatter.cpp +5 -0
- package/cpp/AmountFormatter.hpp +10 -2
- package/cpp/{MorphEngine.cpp → ReflowEngine.cpp} +52 -47
- package/cpp/{MorphEngine.hpp → ReflowEngine.hpp} +12 -4
- package/cpp/RollingEngine.cpp +1224 -0
- package/cpp/RollingEngine.hpp +468 -0
- package/cpp/SwiftNonCopyable.hpp +22 -0
- package/cpp/worklets/NitroInputWorkletsBridge.cpp +3 -3
- package/cpp/worklets/NitroInputWorkletsBridge.hpp +1 -1
- package/ios/{HybridMorphInputView.swift → HybridNitroInputView.swift} +1 -1
- package/ios/HybridNitroNumberView.swift +439 -0
- package/ios/NitroInputView.swift +69 -45
- package/ios/NitroNumberView.swift +1934 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
- package/lib/commonjs/src/NitroInput.js +21 -52
- package/lib/commonjs/src/NitroNumber.js +139 -0
- package/lib/commonjs/src/index.js +4 -3
- package/lib/commonjs/src/specs/NitroNumber.nitro.js +2 -0
- package/lib/commonjs/src/styleHelpers.js +36 -0
- package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
- package/lib/module/src/NitroInput.js +12 -43
- package/lib/module/src/NitroNumber.js +100 -0
- package/lib/module/src/index.js +1 -1
- package/lib/module/src/specs/NitroNumber.nitro.js +1 -0
- package/lib/module/src/styleHelpers.js +32 -0
- package/lib/typescript/src/NitroInput.d.ts +28 -21
- package/lib/typescript/src/NitroNumber.d.ts +211 -0
- package/lib/typescript/src/index.d.ts +3 -2
- package/lib/typescript/src/specs/NitroInput.nitro.d.ts +9 -9
- package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +238 -0
- package/lib/typescript/src/styleHelpers.d.ts +3 -0
- package/nitro.json +10 -0
- package/nitrogen/generated/android/NitroInput+autolinking.cmake +4 -0
- package/nitrogen/generated/android/NitroInputOnLoad.cpp +20 -0
- package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +10 -10
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +536 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +156 -0
- package/nitrogen/generated/android/c++/JNitroNumberAffixAlign.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroNumberDirection.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroNumberEasing.hpp +67 -0
- package/nitrogen/generated/android/c++/JNitroNumberRevealStyle.hpp +58 -0
- package/nitrogen/generated/android/c++/JNitroNumberTextAlign.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroNumberTransition.hpp +61 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +299 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.hpp +54 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_double_double.kt +9 -9
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +363 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberAffixAlign.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberDirection.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberEasing.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberRevealStyle.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberTextAlign.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberTransition.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroNumberViewManager.kt +96 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroNumberViewStateUpdater.kt +23 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +25 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +248 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +23 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.mm +8 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.swift +12 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +432 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +414 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_double_double.swift +5 -5
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +102 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +1243 -0
- package/nitrogen/generated/ios/swift/NitroNumberAffixAlign.swift +48 -0
- package/nitrogen/generated/ios/swift/NitroNumberDirection.swift +44 -0
- package/nitrogen/generated/ios/swift/NitroNumberEasing.swift +52 -0
- package/nitrogen/generated/ios/swift/NitroNumberRevealStyle.swift +40 -0
- package/nitrogen/generated/ios/swift/NitroNumberTextAlign.swift +48 -0
- package/nitrogen/generated/ios/swift/NitroNumberTransition.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +115 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +175 -0
- package/nitrogen/generated/shared/c++/NitroNumberAffixAlign.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroNumberDirection.hpp +80 -0
- package/nitrogen/generated/shared/c++/NitroNumberEasing.hpp +88 -0
- package/nitrogen/generated/shared/c++/NitroNumberRevealStyle.hpp +76 -0
- package/nitrogen/generated/shared/c++/NitroNumberTextAlign.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroNumberTransition.hpp +80 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +124 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +227 -0
- package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
- package/package.json +15 -7
- package/src/NitroInput.tsx +37 -60
- package/src/NitroNumber.tsx +481 -0
- package/src/index.ts +20 -6
- package/src/specs/NitroInput.nitro.ts +9 -9
- package/src/specs/NitroNumber.nitro.ts +259 -0
- package/src/styleHelpers.ts +32 -0
- package/android/src/main/cpp/JMorphEngine.cpp +0 -132
- package/lib/commonjs/src/MorphInput.js +0 -42
- package/lib/module/src/MorphInput.js +0 -6
- package/lib/typescript/src/MorphInput.d.ts +0 -18
- package/src/MorphInput.tsx +0 -30
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HybridView,
|
|
3
|
+
HybridViewMethods,
|
|
4
|
+
HybridViewProps,
|
|
5
|
+
} from 'react-native-nitro-modules'
|
|
6
|
+
|
|
7
|
+
/** Horizontal alignment of the number inside the view's frame. */
|
|
8
|
+
/**
|
|
9
|
+
* `'auto'` is the start edge of the layout direction - left in a left-to-right
|
|
10
|
+
* app, right in a right-to-left one - which is what `Text` does with no
|
|
11
|
+
* `textAlign`; in a view that hugs the number it is the edge the parent keeps
|
|
12
|
+
* the view to (the end of a row: right), so the digits open and close against
|
|
13
|
+
* it. `'left'` and `'right'` are absolute, whatever the direction.
|
|
14
|
+
*/
|
|
15
|
+
export type NitroNumberTextAlign = 'auto' | 'left' | 'center' | 'right'
|
|
16
|
+
|
|
17
|
+
/** Timing curve used when a value change is rolled natively. */
|
|
18
|
+
export type NitroNumberEasing =
|
|
19
|
+
| 'linear'
|
|
20
|
+
| 'easeIn'
|
|
21
|
+
| 'easeOut'
|
|
22
|
+
| 'easeInOut'
|
|
23
|
+
| 'spring'
|
|
24
|
+
|
|
25
|
+
/** Which way the digits roll: `'auto'` follows the sign of the change. */
|
|
26
|
+
export type NitroNumberDirection = 'auto' | 'up' | 'down'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* How a value change plays. `'roll'` is the odometer: every changed digit
|
|
30
|
+
* rolls through the digits between its old and new glyph. `'numeric'` is the
|
|
31
|
+
* numeric transition of SwiftUI's `.contentTransition(.numericText())`: each
|
|
32
|
+
* changed glyph swaps in place, the old one softening, shrinking and sliding
|
|
33
|
+
* out while the new one slides in from the other side and comes into focus,
|
|
34
|
+
* digits cascading from the left; the unchanged digits stay put. `'scramble'`
|
|
35
|
+
* shows a different random digit every few frames until each changed digit
|
|
36
|
+
* locks on its target, from the left.
|
|
37
|
+
*/
|
|
38
|
+
export type NitroNumberTransition = 'roll' | 'numeric' | 'scramble'
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* How a jackpot reveal plays: `'count'` is the casino win-meter rollup (the
|
|
42
|
+
* figure counts up from 0, digits swapping in place); `'spin'` is the jackpot
|
|
43
|
+
* reels (every digit spins like a slot reel, then the reels lock one at a
|
|
44
|
+
* time from the left).
|
|
45
|
+
*/
|
|
46
|
+
export type NitroNumberRevealStyle = 'count' | 'spin'
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* How a prefix/suffix drawn at a different size lines up with the digits:
|
|
50
|
+
* `top` pins glyph tops (cap height), `bottom` pins the bottom of the line
|
|
51
|
+
* boxes, `baseline` shares the digits' baseline, `center` centres the boxes.
|
|
52
|
+
*/
|
|
53
|
+
export type NitroNumberAffixAlign = 'baseline' | 'center' | 'top' | 'bottom'
|
|
54
|
+
|
|
55
|
+
export interface NitroNumberProps extends HybridViewProps {
|
|
56
|
+
/**
|
|
57
|
+
* The number to display.
|
|
58
|
+
*
|
|
59
|
+
* When this prop changes, every digit rolls natively from its old glyph to
|
|
60
|
+
* its new glyph (in the direction of the change), using `duration` and
|
|
61
|
+
* `easing`. The very first value is displayed without an animation.
|
|
62
|
+
*
|
|
63
|
+
* Reading it on the hybrid ref returns the value the view is currently
|
|
64
|
+
* showing or rolling towards (also after `jumpTo` / `animateTo`).
|
|
65
|
+
*
|
|
66
|
+
* At most 18 digits are shown: `|value| × 10^fractionDigits` is clamped at
|
|
67
|
+
* 10^17 (the same limit for a jump and a roll), and a JS number carries exact
|
|
68
|
+
* integers only up to 2^53.
|
|
69
|
+
*/
|
|
70
|
+
value: number
|
|
71
|
+
/** Digits shown after the decimal separator. Default: `0`. */
|
|
72
|
+
fractionDigits?: number
|
|
73
|
+
/** Zero-pads the integer part to at least this many digits. Default: `1`. */
|
|
74
|
+
minimumIntegerDigits?: number
|
|
75
|
+
/** Inserted between every three integer digits. Empty string disables grouping. Default: `''`. */
|
|
76
|
+
groupingSeparator?: string
|
|
77
|
+
/** Placed between the integer and fraction digits. Default: `'.'`. */
|
|
78
|
+
decimalSeparator?: string
|
|
79
|
+
/** Static text drawn before the number (e.g. `'$'`). Default: `''`. */
|
|
80
|
+
prefix?: string
|
|
81
|
+
/** Static text drawn after the number (e.g. `'%'`). Default: `''`. */
|
|
82
|
+
suffix?: string
|
|
83
|
+
/**
|
|
84
|
+
* Duration in milliseconds of the native roll that plays when `value` changes.
|
|
85
|
+
* `0` snaps to the new value immediately. Default: `500`.
|
|
86
|
+
*/
|
|
87
|
+
duration?: number
|
|
88
|
+
/** Timing curve of the native roll. Default: `'easeInOut'`. */
|
|
89
|
+
easing?: NitroNumberEasing
|
|
90
|
+
/** Overshoot of the `'spring'` easing, from `0` (none) to `1`. Default: `0.15`. */
|
|
91
|
+
bounce?: number
|
|
92
|
+
/**
|
|
93
|
+
* Delay in ms between the start of each digit's roll, from the least
|
|
94
|
+
* significant digit upwards (a cascading carry). Default: `0`.
|
|
95
|
+
*/
|
|
96
|
+
stagger?: number
|
|
97
|
+
/**
|
|
98
|
+
* How a value change plays: the odometer roll, or the numeric transition
|
|
99
|
+
* (glyphs swap in place). Default: `'roll'`.
|
|
100
|
+
*/
|
|
101
|
+
transition?: NitroNumberTransition
|
|
102
|
+
/**
|
|
103
|
+
* The change flash: every digit whose glyph changes lights up in this
|
|
104
|
+
* colour when the value grew, fading back over `flashDuration`. A processed
|
|
105
|
+
* ARGB integer; `Infinity` (the wrapper's "unset") turns the flash off.
|
|
106
|
+
*/
|
|
107
|
+
flashUpColor?: number
|
|
108
|
+
/** The change flash's colour when the value shrank. `Infinity` = off. */
|
|
109
|
+
flashDownColor?: number
|
|
110
|
+
/** Milliseconds a change flash takes to fade. Default: `600`. */
|
|
111
|
+
flashDuration?: number
|
|
112
|
+
/**
|
|
113
|
+
* A punch of the whole figure on every value change, its peak overshoot
|
|
114
|
+
* as a fraction of the size, `0` (none, the default) to `1`; rung out like
|
|
115
|
+
* the reveal's landing pop.
|
|
116
|
+
*/
|
|
117
|
+
popOnChange?: number
|
|
118
|
+
/**
|
|
119
|
+
* Which way the digits roll. Default: `'auto'`.
|
|
120
|
+
*
|
|
121
|
+
* Named `rollDirection` and not `direction` because a Hybrid View's props
|
|
122
|
+
* derive from `react::ViewProps`, so React Native parses every name we
|
|
123
|
+
* declare as well: `direction` is Yoga's layout property, and it logged
|
|
124
|
+
* `Could not parse yoga::Direction: up` on every update. The public prop the
|
|
125
|
+
* wrapper exposes is still `direction`; see `NitroNumber.tsx`.
|
|
126
|
+
*/
|
|
127
|
+
rollDirection?: NitroNumberDirection
|
|
128
|
+
/**
|
|
129
|
+
* Jackpot reveal state. `0` (default): a normal NitroNumber, `value`
|
|
130
|
+
* changes roll. `1`: the view shows the opening frame of `value`, its layout
|
|
131
|
+
* with every digit blank except the mandatory ones ("$0.00"). `2`: the
|
|
132
|
+
* figure plays its `revealStyle` (counts up from 0, or spins its reels) to
|
|
133
|
+
* `value` and lands with a pop. The JS wrapper maps its `reveal` boolean to
|
|
134
|
+
* this; it is a number so the wrapper can always pass it (an optional prop
|
|
135
|
+
* that is removed reaches native as `null`, which Nitro's parser rejects).
|
|
136
|
+
*/
|
|
137
|
+
revealState?: number
|
|
138
|
+
/** How the reveal plays. Default: `'count'`. */
|
|
139
|
+
revealStyle?: NitroNumberRevealStyle
|
|
140
|
+
/** Duration of the reveal in ms (the count, or the time until the last reel locks). Default: `2200`. */
|
|
141
|
+
revealDuration?: number
|
|
142
|
+
/** Peak overshoot of the reveal's landing pop, `0` (none) to `1`. Default: `0.12`. */
|
|
143
|
+
revealBounce?: number
|
|
144
|
+
/**
|
|
145
|
+
* `'count'` style: how much smaller the figure opens, as a fraction of its
|
|
146
|
+
* size, growing to full size over the count (a big win's meter is enlarged
|
|
147
|
+
* as it climbs). `0` = no growth. Default: `0.2`.
|
|
148
|
+
*/
|
|
149
|
+
revealGrow?: number
|
|
150
|
+
/**
|
|
151
|
+
* `'spin'` style: delay in ms between one reel locking and the next, from
|
|
152
|
+
* the left. Shortened automatically when the reels wouldn't fit `revealDuration`. Default: `200`.
|
|
153
|
+
*/
|
|
154
|
+
revealStagger?: number
|
|
155
|
+
/**
|
|
156
|
+
* `'count'` style: win tiers, in the figure's units. When the count reaches
|
|
157
|
+
* one the figure punches, pauses on it for `revealMilestoneHold` and
|
|
158
|
+
* `onRevealMilestone` fires. Values at or above `value` are ignored.
|
|
159
|
+
*/
|
|
160
|
+
revealMilestones?: number[]
|
|
161
|
+
/** `'count'` style: ms the count pauses on each milestone. Default: `0`. */
|
|
162
|
+
revealMilestoneHold?: number
|
|
163
|
+
/**
|
|
164
|
+
* Shows a "shine" glint over the number: the ink keeps its color while a
|
|
165
|
+
* slanted, text-wide band of `shimmerColor` sweeps through the glyphs.
|
|
166
|
+
* Toggling fades the glint in/out. Default: `false`.
|
|
167
|
+
*/
|
|
168
|
+
loading?: boolean
|
|
169
|
+
/**
|
|
170
|
+
* Color of the glint's core as a processed ARGB integer. Defaults to a light
|
|
171
|
+
* neutral (`#D6D9E1`, or `#2B2E37` in dark mode).
|
|
172
|
+
*/
|
|
173
|
+
shimmerColor?: number
|
|
174
|
+
/** Duration of one sweep in ms (linear, repeating). Default: `950`. */
|
|
175
|
+
shimmerDuration?: number
|
|
176
|
+
/** Font size of the digits in points. Default: `32`. */
|
|
177
|
+
fontSize?: number
|
|
178
|
+
/** Font size of `prefix` in points. Defaults to `fontSize`. */
|
|
179
|
+
prefixFontSize?: number
|
|
180
|
+
/** Font size of `suffix` in points. Defaults to `fontSize`. */
|
|
181
|
+
suffixFontSize?: number
|
|
182
|
+
/** Vertical alignment of prefix and suffix relative to the digits. Default: `'baseline'`. */
|
|
183
|
+
affixAlign?: NitroNumberAffixAlign
|
|
184
|
+
/** Vertical alignment of `prefix` only. Defaults to `affixAlign`. */
|
|
185
|
+
prefixAlign?: NitroNumberAffixAlign
|
|
186
|
+
/** Vertical alignment of `suffix` only. Defaults to `affixAlign`. */
|
|
187
|
+
suffixAlign?: NitroNumberAffixAlign
|
|
188
|
+
/**
|
|
189
|
+
* When the view is narrower than the number (e.g. it has a fixed `width` or
|
|
190
|
+
* `maxWidth`), scale the whole number down so it fits. Default: `false`.
|
|
191
|
+
*/
|
|
192
|
+
adjustsFontSizeToFit?: boolean
|
|
193
|
+
/** Smallest scale `adjustsFontSizeToFit` may apply, `0`–`1`. Default: `0.5`. */
|
|
194
|
+
minimumFontScale?: number
|
|
195
|
+
/**
|
|
196
|
+
* Scale the fonts with the user's system text size (Dynamic Type / Android
|
|
197
|
+
* font scale), like `Text`. Off by default so amounts keep their design size.
|
|
198
|
+
*/
|
|
199
|
+
allowFontScaling?: boolean
|
|
200
|
+
/** Upper bound for `allowFontScaling`, e.g. `1.3`. `0` means no cap. Default: `0`. */
|
|
201
|
+
maxFontSizeMultiplier?: number
|
|
202
|
+
/** Numeric font weight, `100`–`900`. Default: `400`. */
|
|
203
|
+
fontWeight?: number
|
|
204
|
+
/** Font family name. Defaults to the system font. */
|
|
205
|
+
fontFamily?: string
|
|
206
|
+
/** Text color as a processed ARGB integer (from `processColor`). Defaults to the platform label color. */
|
|
207
|
+
color?: number
|
|
208
|
+
/** Where the number sits inside the view when the view is wider than the number. Default: `'auto'`, the start edge. */
|
|
209
|
+
textAlign?: NitroNumberTextAlign
|
|
210
|
+
/**
|
|
211
|
+
* Lay the figure out right-to-left: `'auto'` alignment resolves to the right
|
|
212
|
+
* edge, the prefix moves to the right and the suffix to the left, and the
|
|
213
|
+
* digits still read left to right. Fabric does not hand a Hybrid View its
|
|
214
|
+
* layout direction, so the JS side resolves it - from the view's
|
|
215
|
+
* `style.direction`, else `I18nManager.isRTL` - the way React Native
|
|
216
|
+
* resolves its own views. Default: `false`.
|
|
217
|
+
*/
|
|
218
|
+
rightToLeft?: boolean
|
|
219
|
+
/**
|
|
220
|
+
* Called whenever the settled (target) intrinsic size of the number changes,
|
|
221
|
+
* e.g. after the first layout, when a digit column appears/disappears, or
|
|
222
|
+
* when the font changes. `NitroNumber` uses this to size itself.
|
|
223
|
+
*/
|
|
224
|
+
onSizeChange?: (width: number, height: number) => void
|
|
225
|
+
/**
|
|
226
|
+
* Called when a reveal has landed: the count reached `value` and the landing
|
|
227
|
+
* pop has rung out. Sequence whatever follows the figure (a haptic, the next
|
|
228
|
+
* block of copy) from here.
|
|
229
|
+
*/
|
|
230
|
+
onRevealEnd?: () => void
|
|
231
|
+
/**
|
|
232
|
+
* Called when a count-style reveal reaches a milestone, with its index in
|
|
233
|
+
* the sorted usable milestones and its value: the moment to swap the win
|
|
234
|
+
* banner, fire the confetti and play the sting.
|
|
235
|
+
*/
|
|
236
|
+
onRevealMilestone?: (index: number, value: number) => void
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export interface NitroNumberMethods extends HybridViewMethods {
|
|
240
|
+
/**
|
|
241
|
+
* Displays `value` immediately, positioning the digit columns continuously
|
|
242
|
+
* (odometer style: `12.5` shows the last digit half way between `2` and `3`).
|
|
243
|
+
* No animation is started and any running roll is cancelled. Useful for
|
|
244
|
+
* scrubbing (scroll / drag handlers). Safe to call from any thread.
|
|
245
|
+
*/
|
|
246
|
+
jumpTo(value: number): void
|
|
247
|
+
/** Rolls to `value` natively, exactly like changing the `value` prop. Safe to call from any thread. */
|
|
248
|
+
animateTo(value: number): void
|
|
249
|
+
/**
|
|
250
|
+
* Plays a jackpot reveal to `value` in the current `revealStyle` (see the
|
|
251
|
+
* `reveal` prop) regardless of the prop's state. Safe to call from any thread.
|
|
252
|
+
*/
|
|
253
|
+
revealTo(value: number): void
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export type NitroNumberView = HybridView<
|
|
257
|
+
NitroNumberProps,
|
|
258
|
+
NitroNumberMethods
|
|
259
|
+
>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { processColor, type ColorValue, type TextStyle } from 'react-native'
|
|
2
|
+
|
|
3
|
+
// Style resolution shared by `NitroNumber` and `NitroInput`.
|
|
4
|
+
|
|
5
|
+
const FONT_WEIGHTS: Record<string, number> = {
|
|
6
|
+
normal: 400,
|
|
7
|
+
regular: 400,
|
|
8
|
+
bold: 700,
|
|
9
|
+
ultralight: 100,
|
|
10
|
+
thin: 200,
|
|
11
|
+
light: 300,
|
|
12
|
+
medium: 500,
|
|
13
|
+
semibold: 600,
|
|
14
|
+
condensedBold: 700,
|
|
15
|
+
condensed: 400,
|
|
16
|
+
heavy: 800,
|
|
17
|
+
black: 900,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function toNumericWeight(weight: TextStyle['fontWeight']): number | undefined {
|
|
21
|
+
if (weight == null) return undefined
|
|
22
|
+
if (typeof weight === 'number') return weight
|
|
23
|
+
const parsed = Number(weight)
|
|
24
|
+
if (!Number.isNaN(parsed)) return parsed
|
|
25
|
+
return FONT_WEIGHTS[weight]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function toProcessedColor(color: ColorValue | undefined): number | undefined {
|
|
29
|
+
if (color == null) return undefined
|
|
30
|
+
const processed = processColor(color)
|
|
31
|
+
return typeof processed === 'number' ? processed : undefined
|
|
32
|
+
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// JMorphEngine.cpp
|
|
3
|
-
// NitroInput
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
#include "JMorphEngine.hpp"
|
|
7
|
-
|
|
8
|
-
namespace margelo::nitro::nitroinput {
|
|
9
|
-
|
|
10
|
-
jni::local_ref<JMorphEngine::jhybriddata> JMorphEngine::initHybrid(jni::alias_ref<jhybridobject>) {
|
|
11
|
-
return makeCxxInstance();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
void JMorphEngine::registerNatives() {
|
|
15
|
-
registerHybrid({
|
|
16
|
-
makeNativeMethod("initHybrid", JMorphEngine::initHybrid),
|
|
17
|
-
makeNativeMethod("setTiming", JMorphEngine::setTiming),
|
|
18
|
-
makeNativeMethod("setEffect", JMorphEngine::setEffect),
|
|
19
|
-
makeNativeMethod("setReduceMotion", JMorphEngine::setReduceMotion),
|
|
20
|
-
makeNativeMethod("setRightToLeft", JMorphEngine::setRightToLeft),
|
|
21
|
-
makeNativeMethod("beginText", JMorphEngine::beginText),
|
|
22
|
-
makeNativeMethod("addGlyph", JMorphEngine::addGlyph),
|
|
23
|
-
makeNativeMethod("commitText", JMorphEngine::commitText),
|
|
24
|
-
makeNativeMethod("tick", JMorphEngine::tick),
|
|
25
|
-
makeNativeMethod("needsFrames", JMorphEngine::needsFrames),
|
|
26
|
-
makeNativeMethod("isAnimating", JMorphEngine::isAnimating),
|
|
27
|
-
makeNativeMethod("glyphCount", JMorphEngine::glyphCount),
|
|
28
|
-
makeNativeMethod("contentWidth", JMorphEngine::contentWidth),
|
|
29
|
-
makeNativeMethod("targetWidth", JMorphEngine::targetWidth),
|
|
30
|
-
makeNativeMethod("bodyCount", JMorphEngine::bodyCount),
|
|
31
|
-
makeNativeMethod("caretX", JMorphEngine::caretX),
|
|
32
|
-
makeNativeMethod("reset", JMorphEngine::reset),
|
|
33
|
-
makeNativeMethod("frameInto", JMorphEngine::frameInto),
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
void JMorphEngine::setTiming(double durationSeconds, int easing, double bounce) {
|
|
38
|
-
engine_.setTiming(durationSeconds, easing, bounce);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
void JMorphEngine::setEffect(int effect) {
|
|
42
|
-
engine_.setEffect(effect);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
void JMorphEngine::setReduceMotion(bool reduceMotion) {
|
|
46
|
-
engine_.setReduceMotion(reduceMotion);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
void JMorphEngine::setRightToLeft(bool rightToLeft) {
|
|
50
|
-
engine_.setRightToLeft(rightToLeft);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
void JMorphEngine::beginText() {
|
|
54
|
-
engine_.beginText();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
void JMorphEngine::addGlyph(int character, int role, int kind, double width, bool placeholder) {
|
|
58
|
-
engine_.addGlyph(static_cast<uint32_t>(character), role, kind, width, placeholder);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
void JMorphEngine::commitText(int caret, double now) {
|
|
62
|
-
engine_.commitText(caret, now);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
bool JMorphEngine::tick(double now) {
|
|
66
|
-
return engine_.tick(now);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
bool JMorphEngine::needsFrames() {
|
|
70
|
-
return engine_.needsFrames();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
bool JMorphEngine::isAnimating() {
|
|
74
|
-
return engine_.isAnimating();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
int JMorphEngine::glyphCount() {
|
|
78
|
-
return engine_.glyphCount();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
double JMorphEngine::contentWidth() {
|
|
82
|
-
return engine_.contentWidth();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
double JMorphEngine::targetWidth() {
|
|
86
|
-
return engine_.targetWidth();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
int JMorphEngine::bodyCount() {
|
|
90
|
-
return engine_.bodyCount();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
double JMorphEngine::caretX(int index) {
|
|
94
|
-
return engine_.caretX(index);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
void JMorphEngine::reset() {
|
|
98
|
-
engine_.reset();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
int JMorphEngine::frameInto(jni::alias_ref<jni::JArrayDouble> out) {
|
|
102
|
-
const auto& glyphs = engine_.glyphs();
|
|
103
|
-
const size_t count = glyphs.size();
|
|
104
|
-
constexpr size_t kPerGlyph = 11;
|
|
105
|
-
const size_t needed = 3 + count * kPerGlyph;
|
|
106
|
-
if (static_cast<size_t>(out->size()) < needed) {
|
|
107
|
-
return -1;
|
|
108
|
-
}
|
|
109
|
-
scratch_.resize(needed);
|
|
110
|
-
double* data = scratch_.data();
|
|
111
|
-
data[0] = static_cast<double>(count);
|
|
112
|
-
data[1] = engine_.contentWidth();
|
|
113
|
-
data[2] = engine_.targetWidth();
|
|
114
|
-
size_t i = 3;
|
|
115
|
-
for (const auto& g : glyphs) {
|
|
116
|
-
data[i++] = static_cast<double>(g.id);
|
|
117
|
-
data[i++] = static_cast<double>(g.character);
|
|
118
|
-
data[i++] = static_cast<double>(g.role);
|
|
119
|
-
data[i++] = static_cast<double>(g.kind);
|
|
120
|
-
data[i++] = g.width;
|
|
121
|
-
data[i++] = g.placeholder ? 1.0 : 0.0;
|
|
122
|
-
data[i++] = g.x;
|
|
123
|
-
data[i++] = g.y;
|
|
124
|
-
data[i++] = g.opacity;
|
|
125
|
-
data[i++] = g.scale;
|
|
126
|
-
data[i++] = g.exiting ? 1.0 : 0.0;
|
|
127
|
-
}
|
|
128
|
-
out->setRegion(0, needed, data);
|
|
129
|
-
return static_cast<int>(needed);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
} // namespace margelo::nitro::nitroinput
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.MorphInput = void 0;
|
|
37
|
-
const react_1 = __importStar(require("react"));
|
|
38
|
-
const NitroInput_1 = require("./NitroInput");
|
|
39
|
-
exports.MorphInput = (0, react_1.forwardRef)(function MorphInput({ autoWidth = 'auto', ...props }, ref) {
|
|
40
|
-
return react_1.default.createElement(NitroInput_1.NitroInput, { ...props, autoWidth: autoWidth, ref: ref, morph: true });
|
|
41
|
-
});
|
|
42
|
-
exports.MorphInput.displayName = 'MorphInput';
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef } from 'react';
|
|
2
|
-
import { NitroInput, } from './NitroInput';
|
|
3
|
-
export const MorphInput = forwardRef(function MorphInput({ autoWidth = 'auto', ...props }, ref) {
|
|
4
|
-
return React.createElement(NitroInput, { ...props, autoWidth: autoWidth, ref: ref, morph: true });
|
|
5
|
-
});
|
|
6
|
-
MorphInput.displayName = 'MorphInput';
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { type NitroInputHandle, type NitroInputProps, type NitroInputRef } from './NitroInput';
|
|
3
|
-
/**
|
|
4
|
-
* A field whose text morphs as it changes: digits roll into place, grouping
|
|
5
|
-
* separators slide through the line box, other characters fade and scale. In
|
|
6
|
-
* `mode="number"` every edit is formatted natively before a frame is drawn, so
|
|
7
|
-
* the morph and the formatting are the same event.
|
|
8
|
-
*
|
|
9
|
-
* This is {@link NitroInput} with the glyph engine on and content sizing
|
|
10
|
-
* inferred, which is what an amount wants — the box grows as digits arrive.
|
|
11
|
-
* Reach for it where the morph is the point; for an ordinary form field use
|
|
12
|
-
* `NitroInput`, which does not animate its characters and takes its width from
|
|
13
|
-
* its parent the way a `TextInput` does.
|
|
14
|
-
*/
|
|
15
|
-
export type MorphInputProps = Omit<NitroInputProps, 'morph'>;
|
|
16
|
-
export type MorphInputHandle = NitroInputHandle;
|
|
17
|
-
export type MorphInputRef = NitroInputRef;
|
|
18
|
-
export declare const MorphInput: React.ForwardRefExoticComponent<MorphInputProps & React.RefAttributes<NitroInputHandle>>;
|
package/src/MorphInput.tsx
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef } from 'react'
|
|
2
|
-
import {
|
|
3
|
-
NitroInput,
|
|
4
|
-
type NitroInputHandle,
|
|
5
|
-
type NitroInputProps,
|
|
6
|
-
type NitroInputRef,
|
|
7
|
-
} from './NitroInput'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A field whose text morphs as it changes: digits roll into place, grouping
|
|
11
|
-
* separators slide through the line box, other characters fade and scale. In
|
|
12
|
-
* `mode="number"` every edit is formatted natively before a frame is drawn, so
|
|
13
|
-
* the morph and the formatting are the same event.
|
|
14
|
-
*
|
|
15
|
-
* This is {@link NitroInput} with the glyph engine on and content sizing
|
|
16
|
-
* inferred, which is what an amount wants — the box grows as digits arrive.
|
|
17
|
-
* Reach for it where the morph is the point; for an ordinary form field use
|
|
18
|
-
* `NitroInput`, which does not animate its characters and takes its width from
|
|
19
|
-
* its parent the way a `TextInput` does.
|
|
20
|
-
*/
|
|
21
|
-
export type MorphInputProps = Omit<NitroInputProps, 'morph'>
|
|
22
|
-
export type MorphInputHandle = NitroInputHandle
|
|
23
|
-
export type MorphInputRef = NitroInputRef
|
|
24
|
-
|
|
25
|
-
export const MorphInput = forwardRef<MorphInputHandle, MorphInputProps>(
|
|
26
|
-
function MorphInput({ autoWidth = 'auto', ...props }, ref) {
|
|
27
|
-
return <NitroInput {...props} autoWidth={autoWidth} ref={ref} morph />
|
|
28
|
-
}
|
|
29
|
-
)
|
|
30
|
-
MorphInput.displayName = 'MorphInput'
|