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,481 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useImperativeHandle,
|
|
4
|
+
useMemo,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react'
|
|
8
|
+
import {
|
|
9
|
+
I18nManager,
|
|
10
|
+
StyleSheet,
|
|
11
|
+
type ColorValue,
|
|
12
|
+
type TextStyle,
|
|
13
|
+
type ViewProps,
|
|
14
|
+
} from 'react-native'
|
|
15
|
+
import {
|
|
16
|
+
callback,
|
|
17
|
+
getHostComponent,
|
|
18
|
+
type HybridRef,
|
|
19
|
+
} from 'react-native-nitro-modules'
|
|
20
|
+
import NitroNumberViewConfig from '../nitrogen/generated/shared/json/NitroNumberViewConfig.json'
|
|
21
|
+
import type {
|
|
22
|
+
NitroNumberAffixAlign,
|
|
23
|
+
NitroNumberDirection,
|
|
24
|
+
NitroNumberTransition,
|
|
25
|
+
NitroNumberEasing,
|
|
26
|
+
NitroNumberMethods,
|
|
27
|
+
NitroNumberProps as NativeNitroNumberProps,
|
|
28
|
+
NitroNumberRevealStyle,
|
|
29
|
+
NitroNumberTextAlign,
|
|
30
|
+
} from './specs/NitroNumber.nitro'
|
|
31
|
+
import { toNumericWeight, toProcessedColor } from './styleHelpers'
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The raw Nitro host component. Prefer {@link NitroNumber}, which adds
|
|
35
|
+
* auto-sizing, color/weight conversion and a convenient handle.
|
|
36
|
+
*/
|
|
37
|
+
export const NativeNitroNumberView = getHostComponent<
|
|
38
|
+
NativeNitroNumberProps,
|
|
39
|
+
NitroNumberMethods
|
|
40
|
+
>('NitroNumberView', () => NitroNumberViewConfig)
|
|
41
|
+
|
|
42
|
+
/** The native Nitro `HybridObject` behind a mounted {@link NitroNumber}. */
|
|
43
|
+
export type NitroNumberRef = HybridRef<
|
|
44
|
+
NativeNitroNumberProps,
|
|
45
|
+
NitroNumberMethods
|
|
46
|
+
>
|
|
47
|
+
|
|
48
|
+
export interface NitroNumberProps extends Omit<ViewProps, 'children'> {
|
|
49
|
+
/**
|
|
50
|
+
* The number to display. Every change rolls each digit natively to its new
|
|
51
|
+
* glyph, in the direction of the change. The first value is shown instantly.
|
|
52
|
+
* At most 18 digits are shown: `|value| × 10^fractionDigits` is clamped at
|
|
53
|
+
* 10^17, and a JS number carries exact integers only up to 2^53.
|
|
54
|
+
*/
|
|
55
|
+
value: number
|
|
56
|
+
/** Digits shown after the decimal separator. Default: `0`. */
|
|
57
|
+
fractionDigits?: number
|
|
58
|
+
/** Zero-pads the integer part to at least this many digits. Default: `1`. */
|
|
59
|
+
minimumIntegerDigits?: number
|
|
60
|
+
/** Inserted between every three integer digits (e.g. `','`). Default: none. */
|
|
61
|
+
groupingSeparator?: string
|
|
62
|
+
/** Placed between integer and fraction digits. Default: `'.'`. */
|
|
63
|
+
decimalSeparator?: string
|
|
64
|
+
/** Static text drawn before the number, e.g. `'$'`. */
|
|
65
|
+
prefix?: string
|
|
66
|
+
/** Static text drawn after the number, e.g. `'%'`. */
|
|
67
|
+
suffix?: string
|
|
68
|
+
/**
|
|
69
|
+
* How a value change plays. `'roll'` (default) is the odometer: every
|
|
70
|
+
* changed digit rolls through the digits between its old and new glyph, in
|
|
71
|
+
* the direction of the change. `'numeric'` is the numeric transition, the
|
|
72
|
+
* effect of SwiftUI's `.contentTransition(.numericText())`: each changed
|
|
73
|
+
* glyph swaps in place, the old one softening, shrinking and sliding out
|
|
74
|
+
* while the new one slides in from the other side and comes into focus, the
|
|
75
|
+
* digits cascading from the left; unchanged digits stay put. `'scramble'`
|
|
76
|
+
* shows a different random digit every few frames until each changed digit
|
|
77
|
+
* locks on its target, from the left.
|
|
78
|
+
*
|
|
79
|
+
* Each swap style has its own defaults for `duration`, `easing` and
|
|
80
|
+
* `stagger`: numeric 480 / (its own clocks) / 150, scramble 500 / `'linear'` / 60.
|
|
81
|
+
*/
|
|
82
|
+
transition?: NitroNumberTransition
|
|
83
|
+
/**
|
|
84
|
+
* The change flash: every digit whose glyph changes lights up in this
|
|
85
|
+
* colour when the value grew (e.g. a green), stays lit while it moves,
|
|
86
|
+
* and fades back over `flashDuration` once it has landed. Unset: no flash.
|
|
87
|
+
*/
|
|
88
|
+
flashUpColor?: ColorValue
|
|
89
|
+
/** The change flash's colour when the value shrank (e.g. a red). Unset: no flash. */
|
|
90
|
+
flashDownColor?: ColorValue
|
|
91
|
+
/** Milliseconds a change flash takes to fade, once the digit has landed. Default: `600`. */
|
|
92
|
+
flashDuration?: number
|
|
93
|
+
/**
|
|
94
|
+
* A punch of the whole figure on every value change, its peak overshoot
|
|
95
|
+
* as a fraction of the size, `0` (none, the default) to `1`; rung out like
|
|
96
|
+
* the reveal's landing pop. `0.08` is a nudge, `0.2` a slam.
|
|
97
|
+
*/
|
|
98
|
+
popOnChange?: number
|
|
99
|
+
/** Duration in ms of the roll played when `value` changes. `0` snaps. Default: `500` (each swap transition has its own, see `transition`). */
|
|
100
|
+
duration?: number
|
|
101
|
+
/** 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). */
|
|
102
|
+
easing?: NitroNumberEasing
|
|
103
|
+
/** Overshoot of the `'spring'` easing, `0`–`1`. Default: `0.15` (the numeric transition has its own, fixed). */
|
|
104
|
+
bounce?: number
|
|
105
|
+
/**
|
|
106
|
+
* Delay in ms between the start of each digit's roll, least significant
|
|
107
|
+
* digit first, so a change cascades like a mechanical carry. In the numeric
|
|
108
|
+
* transition it is the span of the whole cascade instead: the digits that
|
|
109
|
+
* change start spread evenly over it from the leftmost to the rightmost,
|
|
110
|
+
* however many there are, the way the effect cascades on iOS. Default: `0`
|
|
111
|
+
* (`150` for the numeric transition).
|
|
112
|
+
*/
|
|
113
|
+
stagger?: number
|
|
114
|
+
/** Which way the digits roll. `'auto'` follows the sign of the change. Default: `'auto'`. */
|
|
115
|
+
direction?: NitroNumberDirection
|
|
116
|
+
/**
|
|
117
|
+
* Jackpot reveal, the casino "you won" presentation. While `false` the view
|
|
118
|
+
* holds the opening frame of `value` ("$0.00": its layout, every digit blank
|
|
119
|
+
* except the mandatory ones); when it turns `true` the figure plays its
|
|
120
|
+
* `revealStyle` to `value` and lands with a pop. Pair it with
|
|
121
|
+
* `textAlign="center"` for a centred hero figure. Leave it `undefined` for
|
|
122
|
+
* a normal NitroNumber. To let the user skip the reveal, call `jumpTo(value)`.
|
|
123
|
+
*/
|
|
124
|
+
reveal?: boolean
|
|
125
|
+
/**
|
|
126
|
+
* `'count'` (default) is the win-meter rollup: the figure tallies up from 0
|
|
127
|
+
* like a slot's win counter, taking off at once, running at a constant
|
|
128
|
+
* rate and braking into the total (and into each tier with
|
|
129
|
+
* `revealMilestones`), swelling slightly as it climbs, digits swapping in
|
|
130
|
+
* place and leading digits appearing as the count reaches them. `'spin'`
|
|
131
|
+
* is the jackpot reels: every digit spins like a slot reel, then the reels
|
|
132
|
+
* brake and lock one at a time from the left, each with a mechanical bounce.
|
|
133
|
+
*/
|
|
134
|
+
revealStyle?: NitroNumberRevealStyle
|
|
135
|
+
/** Duration of the reveal in ms (the count, or the time until the last reel locks). Default: `2200`. */
|
|
136
|
+
revealDuration?: number
|
|
137
|
+
/** Peak overshoot of the reveal's landing pop, `0` (none) to `1`. Default: `0.12`. */
|
|
138
|
+
revealBounce?: number
|
|
139
|
+
/**
|
|
140
|
+
* `'count'` style: how much smaller the figure opens, as a fraction of its
|
|
141
|
+
* size, growing to full size over the count, the way a big win's meter is
|
|
142
|
+
* enlarged as it climbs. `0` = no growth. Default: `0.2`.
|
|
143
|
+
*/
|
|
144
|
+
revealGrow?: number
|
|
145
|
+
/** `'spin'` style: ms between one reel locking and the next, shortened to fit `revealDuration`. Default: `200`. */
|
|
146
|
+
revealStagger?: number
|
|
147
|
+
/**
|
|
148
|
+
* `'count'` style: the win tiers of a casino rollup ("Big win" → "Mega win"
|
|
149
|
+
* → "Epic win"), in the figure's units. When the count reaches one, the
|
|
150
|
+
* figure punches, pauses on it for `revealMilestoneHold` and
|
|
151
|
+
* `onRevealMilestone` fires, so the app can slam its banner in, fire the
|
|
152
|
+
* confetti and play the sting on that beat. Values at or above `value` are ignored.
|
|
153
|
+
*/
|
|
154
|
+
revealMilestones?: number[]
|
|
155
|
+
/** `'count'` style: ms the count pauses on each milestone (the banner's moment). Default: `0`. */
|
|
156
|
+
revealMilestoneHold?: number
|
|
157
|
+
/** Called once a reveal has landed (count finished or last reel locked, and the pop rung out). */
|
|
158
|
+
onRevealEnd?: () => void
|
|
159
|
+
/** Called when the count reaches a milestone: its index among the usable milestones and its value. */
|
|
160
|
+
onRevealMilestone?: (index: number, value: number) => void
|
|
161
|
+
/**
|
|
162
|
+
* Loading glint: the ink keeps its color while a slanted, text-wide band of
|
|
163
|
+
* `shimmerColor` sweeps through the glyphs (a "shine" skeleton). Toggling
|
|
164
|
+
* cross-fades; the number keeps its size so nothing jumps when the value
|
|
165
|
+
* arrives. Default: `false`.
|
|
166
|
+
*/
|
|
167
|
+
loading?: boolean
|
|
168
|
+
/** Color of the glint's core, e.g. your theme's lightest neutral. Defaults to `#D6D9E1` (`#2B2E37` in dark mode). */
|
|
169
|
+
shimmerColor?: ColorValue
|
|
170
|
+
/** Duration of one sweep in ms (linear, repeating). Default: `950`. */
|
|
171
|
+
shimmerDuration?: number
|
|
172
|
+
/** Font size of the digits in points. Default: `32`. */
|
|
173
|
+
fontSize?: number
|
|
174
|
+
/** Font size of `prefix`, e.g. a smaller currency symbol. Defaults to `fontSize`. */
|
|
175
|
+
prefixFontSize?: number
|
|
176
|
+
/** Font size of `suffix`, e.g. a smaller currency code. Defaults to `fontSize`. */
|
|
177
|
+
suffixFontSize?: number
|
|
178
|
+
/**
|
|
179
|
+
* How prefix and suffix line up with the digits: `'top'` pins glyph tops,
|
|
180
|
+
* `'bottom'` pins the bottom of the line boxes, `'baseline'` shares the
|
|
181
|
+
* digits' baseline, `'center'` centres. Default: `'baseline'`.
|
|
182
|
+
*/
|
|
183
|
+
affixAlign?: NitroNumberAffixAlign
|
|
184
|
+
/** Alignment of `prefix` only. Defaults to `affixAlign`. */
|
|
185
|
+
prefixAlign?: NitroNumberAffixAlign
|
|
186
|
+
/** Alignment of `suffix` only. Defaults to `affixAlign`. */
|
|
187
|
+
suffixAlign?: NitroNumberAffixAlign
|
|
188
|
+
/**
|
|
189
|
+
* Scale the number down when the view is narrower than its content, and back
|
|
190
|
+
* up (never above `fontSize`) when it fits again. Give the view a fixed
|
|
191
|
+
* `width` in `style`; the view keeps its full-size height so the box around
|
|
192
|
+
* it never moves, only the amount scales. Like `Text`'s prop. Default: `false`.
|
|
193
|
+
*/
|
|
194
|
+
adjustsFontSizeToFit?: boolean
|
|
195
|
+
/** Smallest scale `adjustsFontSizeToFit` may apply, `0`–`1`. Default: `0.5`. */
|
|
196
|
+
minimumFontScale?: number
|
|
197
|
+
/**
|
|
198
|
+
* Scale the fonts with the system text size (Dynamic Type / Android font
|
|
199
|
+
* scale) like `Text` does. Off by default so amounts keep their design size.
|
|
200
|
+
*/
|
|
201
|
+
allowFontScaling?: boolean
|
|
202
|
+
/** Upper bound for `allowFontScaling`, e.g. `1.3`. `0` means no cap. Default: `0`. */
|
|
203
|
+
maxFontSizeMultiplier?: number
|
|
204
|
+
/** Font weight, like `Text`'s `fontWeight`. Default: `'normal'`. */
|
|
205
|
+
fontWeight?: TextStyle['fontWeight']
|
|
206
|
+
/** Font family name, like `Text`'s `fontFamily`. Defaults to the system font. */
|
|
207
|
+
fontFamily?: string
|
|
208
|
+
/** Text color. Defaults to the platform's primary label color. */
|
|
209
|
+
color?: ColorValue
|
|
210
|
+
/**
|
|
211
|
+
* Where the number sits when the view is wider than its content, e.g. when
|
|
212
|
+
* you give it a fixed `width` so it doesn't reflow as digits appear.
|
|
213
|
+
* Default: `'auto'`: the start edge of the layout direction, as `Text`.
|
|
214
|
+
* `'left'` and `'right'` are absolute.
|
|
215
|
+
*/
|
|
216
|
+
textAlign?: NitroNumberTextAlign
|
|
217
|
+
/** Receives the native Nitro object once the view is mounted. */
|
|
218
|
+
onNativeRef?: (ref: NitroNumberRef) => void
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Imperative handle exposed through `ref`. Methods are no-ops before mount. */
|
|
222
|
+
export interface NitroNumberHandle {
|
|
223
|
+
/**
|
|
224
|
+
* Shows `value` immediately with continuously positioned digits (odometer
|
|
225
|
+
* style, `12.5` shows the last digit half way between `2` and `3`). No roll
|
|
226
|
+
* is played. Useful for scrubbing, e.g. from a scroll or drag handler.
|
|
227
|
+
*/
|
|
228
|
+
jumpTo(value: number): void
|
|
229
|
+
/** Rolls to `value` natively, exactly like changing the `value` prop. */
|
|
230
|
+
animateTo(value: number): void
|
|
231
|
+
/** Plays a jackpot reveal to `value` (counts up from 0), whatever the `reveal` prop says. */
|
|
232
|
+
revealTo(value: number): void
|
|
233
|
+
/** The value currently shown or being rolled towards. */
|
|
234
|
+
getValue(): number
|
|
235
|
+
/** The native Nitro object, or `null` before mount. */
|
|
236
|
+
readonly native: NitroNumberRef | null
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
interface Size {
|
|
240
|
+
width: number
|
|
241
|
+
height: number
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Each transition's own timing, used when the props leave it unsaid. */
|
|
245
|
+
const TRANSITION_DEFAULTS: Record<NitroNumberTransition, { duration: number; easing: NitroNumberEasing; stagger: number }> = {
|
|
246
|
+
roll: { duration: 500, easing: 'easeInOut', stagger: 0 },
|
|
247
|
+
numeric: { duration: 480, easing: 'spring', stagger: 150 },
|
|
248
|
+
scramble: { duration: 500, easing: 'linear', stagger: 60 },
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* A number that animates its changes natively: an odometer roll, SwiftUI's
|
|
253
|
+
* numeric transition or a scramble.
|
|
254
|
+
*
|
|
255
|
+
* Change `value` and every digit rolls to its new glyph on the native side.
|
|
256
|
+
* Use the ref's `animateTo` / `jumpTo` for imperative updates.
|
|
257
|
+
*
|
|
258
|
+
* The view sizes itself to its content unless you pass an explicit `width` /
|
|
259
|
+
* `height` in `style`.
|
|
260
|
+
*/
|
|
261
|
+
export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
|
|
262
|
+
function NitroNumber(
|
|
263
|
+
{
|
|
264
|
+
value,
|
|
265
|
+
fractionDigits,
|
|
266
|
+
minimumIntegerDigits,
|
|
267
|
+
groupingSeparator,
|
|
268
|
+
decimalSeparator,
|
|
269
|
+
prefix,
|
|
270
|
+
suffix,
|
|
271
|
+
transition,
|
|
272
|
+
flashUpColor,
|
|
273
|
+
flashDownColor,
|
|
274
|
+
flashDuration,
|
|
275
|
+
popOnChange,
|
|
276
|
+
duration,
|
|
277
|
+
easing,
|
|
278
|
+
bounce,
|
|
279
|
+
stagger,
|
|
280
|
+
direction,
|
|
281
|
+
reveal,
|
|
282
|
+
revealStyle,
|
|
283
|
+
revealDuration,
|
|
284
|
+
revealBounce,
|
|
285
|
+
revealGrow,
|
|
286
|
+
revealStagger,
|
|
287
|
+
revealMilestones,
|
|
288
|
+
revealMilestoneHold,
|
|
289
|
+
onRevealEnd,
|
|
290
|
+
onRevealMilestone,
|
|
291
|
+
loading,
|
|
292
|
+
shimmerColor,
|
|
293
|
+
shimmerDuration,
|
|
294
|
+
fontSize,
|
|
295
|
+
prefixFontSize,
|
|
296
|
+
suffixFontSize,
|
|
297
|
+
affixAlign,
|
|
298
|
+
prefixAlign,
|
|
299
|
+
suffixAlign,
|
|
300
|
+
adjustsFontSizeToFit,
|
|
301
|
+
minimumFontScale,
|
|
302
|
+
allowFontScaling,
|
|
303
|
+
maxFontSizeMultiplier,
|
|
304
|
+
fontWeight,
|
|
305
|
+
fontFamily,
|
|
306
|
+
color,
|
|
307
|
+
textAlign,
|
|
308
|
+
onNativeRef,
|
|
309
|
+
style,
|
|
310
|
+
...viewProps
|
|
311
|
+
},
|
|
312
|
+
ref
|
|
313
|
+
) {
|
|
314
|
+
const nativeRef = useRef<NitroNumberRef | null>(null)
|
|
315
|
+
const latestOnNativeRef = useRef(onNativeRef)
|
|
316
|
+
latestOnNativeRef.current = onNativeRef
|
|
317
|
+
const latestOnRevealEnd = useRef(onRevealEnd)
|
|
318
|
+
latestOnRevealEnd.current = onRevealEnd
|
|
319
|
+
const latestOnRevealMilestone = useRef(onRevealMilestone)
|
|
320
|
+
latestOnRevealMilestone.current = onRevealMilestone
|
|
321
|
+
const latestValue = useRef(value)
|
|
322
|
+
latestValue.current = value
|
|
323
|
+
|
|
324
|
+
const [size, setSize] = useState<Size | null>(null)
|
|
325
|
+
|
|
326
|
+
// Nitro callbacks must be wrapped with `callback()` and the wrapper object
|
|
327
|
+
// has to be referentially stable, otherwise every render re-sets the prop.
|
|
328
|
+
const hybridRef = useMemo(
|
|
329
|
+
() =>
|
|
330
|
+
callback((instance: NitroNumberRef) => {
|
|
331
|
+
nativeRef.current = instance
|
|
332
|
+
latestOnNativeRef.current?.(instance)
|
|
333
|
+
}),
|
|
334
|
+
[]
|
|
335
|
+
)
|
|
336
|
+
const onSizeChange = useMemo(
|
|
337
|
+
() =>
|
|
338
|
+
callback((width: number, height: number) => {
|
|
339
|
+
setSize((previous) =>
|
|
340
|
+
previous !== null &&
|
|
341
|
+
previous.width === width &&
|
|
342
|
+
previous.height === height
|
|
343
|
+
? previous
|
|
344
|
+
: { width, height }
|
|
345
|
+
)
|
|
346
|
+
}),
|
|
347
|
+
[]
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
// Stable like the others; the latest handler is read through a ref so a
|
|
351
|
+
// caller passing an inline arrow doesn't re-set the native prop each render.
|
|
352
|
+
const onRevealEndCallback = useMemo(
|
|
353
|
+
() =>
|
|
354
|
+
callback(() => {
|
|
355
|
+
latestOnRevealEnd.current?.()
|
|
356
|
+
}),
|
|
357
|
+
[]
|
|
358
|
+
)
|
|
359
|
+
const onRevealMilestoneCallback = useMemo(
|
|
360
|
+
() =>
|
|
361
|
+
callback((index: number, milestone: number) => {
|
|
362
|
+
latestOnRevealMilestone.current?.(index, milestone)
|
|
363
|
+
}),
|
|
364
|
+
[]
|
|
365
|
+
)
|
|
366
|
+
// A new array literal each render must not re-set the native prop. Always an
|
|
367
|
+
// array (empty = no tiers): removing the prop would reach native as `null`,
|
|
368
|
+
// which Nitro's array parser rejects ("Value is null, expected an Object").
|
|
369
|
+
const milestonesKey = revealMilestones?.join(',') ?? ''
|
|
370
|
+
const stableMilestones = useMemo(
|
|
371
|
+
() => (revealMilestones ? [...revealMilestones] : []),
|
|
372
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
373
|
+
[milestonesKey]
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
// One handle for the component's lifetime: `getValue` reads the latest
|
|
377
|
+
// prop through a ref, so a value change doesn't hand the parent a new object.
|
|
378
|
+
useImperativeHandle(
|
|
379
|
+
ref,
|
|
380
|
+
() => ({
|
|
381
|
+
jumpTo: (next) => nativeRef.current?.jumpTo(next),
|
|
382
|
+
animateTo: (next) => nativeRef.current?.animateTo(next),
|
|
383
|
+
revealTo: (next) => nativeRef.current?.revealTo(next),
|
|
384
|
+
getValue: () => nativeRef.current?.value ?? latestValue.current,
|
|
385
|
+
get native() {
|
|
386
|
+
return nativeRef.current
|
|
387
|
+
},
|
|
388
|
+
}),
|
|
389
|
+
[]
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
// Every native prop is sent with an explicit value: an optional prop that
|
|
393
|
+
// is *removed* reaches native as `null`, which Nitro's parser rejects and
|
|
394
|
+
// React Native turns into a fatal error. `Infinity` stands for "platform
|
|
395
|
+
// default" where there is no value to express it (colors), `''` for fonts.
|
|
396
|
+
// Not `NaN`: Nitro only calls a native setter when a prop's value changed,
|
|
397
|
+
// and NaN never equals itself, so a NaN sentinel re-set the colour on every
|
|
398
|
+
// render and had the whole configuration re-applied on every value change.
|
|
399
|
+
const processedColor = useMemo(() => toProcessedColor(color) ?? Infinity, [color])
|
|
400
|
+
const processedShimmerColor = useMemo(
|
|
401
|
+
() => toProcessedColor(shimmerColor) ?? Infinity,
|
|
402
|
+
[shimmerColor]
|
|
403
|
+
)
|
|
404
|
+
const processedFlashUp = useMemo(() => toProcessedColor(flashUpColor) ?? Infinity, [flashUpColor])
|
|
405
|
+
const processedFlashDown = useMemo(() => toProcessedColor(flashDownColor) ?? Infinity, [flashDownColor])
|
|
406
|
+
const numericWeight = toNumericWeight(fontWeight) ?? 400
|
|
407
|
+
const resolvedFontSize = fontSize ?? 32
|
|
408
|
+
const resolvedAffixAlign = affixAlign ?? 'baseline'
|
|
409
|
+
|
|
410
|
+
const autoSize = useMemo(
|
|
411
|
+
() =>
|
|
412
|
+
size !== null
|
|
413
|
+
? { width: size.width, height: size.height }
|
|
414
|
+
: { height: (fontSize ?? 32) * 1.25 },
|
|
415
|
+
[size, fontSize]
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
// The layout direction, resolved the way React Native resolves it for its
|
|
419
|
+
// own views: the view's `style.direction` if it says, else the app's. Fabric
|
|
420
|
+
// does not hand a Hybrid View its resolved direction, so native is told.
|
|
421
|
+
const layoutDirection = useMemo(
|
|
422
|
+
() => (StyleSheet.flatten(style) as { direction?: unknown } | undefined)?.direction,
|
|
423
|
+
[style]
|
|
424
|
+
)
|
|
425
|
+
const rightToLeft = layoutDirection === 'rtl' || (layoutDirection !== 'ltr' && I18nManager.isRTL)
|
|
426
|
+
|
|
427
|
+
return (
|
|
428
|
+
<NativeNitroNumberView
|
|
429
|
+
{...viewProps}
|
|
430
|
+
style={[autoSize, style]}
|
|
431
|
+
hybridRef={hybridRef}
|
|
432
|
+
value={value}
|
|
433
|
+
fractionDigits={fractionDigits ?? 0}
|
|
434
|
+
minimumIntegerDigits={minimumIntegerDigits ?? 1}
|
|
435
|
+
groupingSeparator={groupingSeparator ?? ''}
|
|
436
|
+
decimalSeparator={decimalSeparator ?? '.'}
|
|
437
|
+
prefix={prefix ?? ''}
|
|
438
|
+
suffix={suffix ?? ''}
|
|
439
|
+
transition={transition ?? 'roll'}
|
|
440
|
+
flashUpColor={processedFlashUp}
|
|
441
|
+
flashDownColor={processedFlashDown}
|
|
442
|
+
flashDuration={flashDuration ?? 600}
|
|
443
|
+
popOnChange={popOnChange ?? 0}
|
|
444
|
+
duration={duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration}
|
|
445
|
+
easing={easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing}
|
|
446
|
+
bounce={bounce ?? 0.15}
|
|
447
|
+
stagger={stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger}
|
|
448
|
+
rollDirection={direction ?? 'auto'}
|
|
449
|
+
revealState={reveal === undefined ? 0 : reveal ? 2 : 1}
|
|
450
|
+
revealStyle={revealStyle ?? 'count'}
|
|
451
|
+
revealDuration={revealDuration ?? 2200}
|
|
452
|
+
revealBounce={revealBounce ?? 0.12}
|
|
453
|
+
revealGrow={revealGrow ?? 0.2}
|
|
454
|
+
revealStagger={revealStagger ?? 200}
|
|
455
|
+
revealMilestones={stableMilestones}
|
|
456
|
+
revealMilestoneHold={revealMilestoneHold ?? 0}
|
|
457
|
+
onRevealEnd={onRevealEndCallback}
|
|
458
|
+
onRevealMilestone={onRevealMilestoneCallback}
|
|
459
|
+
loading={loading ?? false}
|
|
460
|
+
shimmerColor={processedShimmerColor}
|
|
461
|
+
shimmerDuration={shimmerDuration ?? 950}
|
|
462
|
+
fontSize={resolvedFontSize}
|
|
463
|
+
prefixFontSize={prefixFontSize ?? resolvedFontSize}
|
|
464
|
+
suffixFontSize={suffixFontSize ?? resolvedFontSize}
|
|
465
|
+
affixAlign={resolvedAffixAlign}
|
|
466
|
+
prefixAlign={prefixAlign ?? resolvedAffixAlign}
|
|
467
|
+
suffixAlign={suffixAlign ?? resolvedAffixAlign}
|
|
468
|
+
adjustsFontSizeToFit={adjustsFontSizeToFit ?? false}
|
|
469
|
+
minimumFontScale={minimumFontScale ?? 0.5}
|
|
470
|
+
allowFontScaling={allowFontScaling ?? false}
|
|
471
|
+
maxFontSizeMultiplier={maxFontSizeMultiplier ?? 0}
|
|
472
|
+
fontWeight={numericWeight}
|
|
473
|
+
fontFamily={fontFamily ?? ''}
|
|
474
|
+
color={processedColor}
|
|
475
|
+
textAlign={textAlign ?? 'auto'}
|
|
476
|
+
rightToLeft={rightToLeft}
|
|
477
|
+
onSizeChange={onSizeChange}
|
|
478
|
+
/>
|
|
479
|
+
)
|
|
480
|
+
}
|
|
481
|
+
)
|
package/src/index.ts
CHANGED
|
@@ -8,15 +8,10 @@ export {
|
|
|
8
8
|
type NitroInputFocusEvent,
|
|
9
9
|
type NitroInputSelectionEvent,
|
|
10
10
|
type NitroInputKeyPressEvent,
|
|
11
|
+
type NitroInputTransition,
|
|
11
12
|
type InputMode,
|
|
12
13
|
type EnterKeyHint,
|
|
13
14
|
} from './NitroInput'
|
|
14
|
-
export {
|
|
15
|
-
MorphInput,
|
|
16
|
-
type MorphInputProps,
|
|
17
|
-
type MorphInputHandle,
|
|
18
|
-
type MorphInputRef,
|
|
19
|
-
} from './MorphInput'
|
|
20
15
|
export {
|
|
21
16
|
isWorklet,
|
|
22
17
|
type NitroInputSelection,
|
|
@@ -53,3 +48,22 @@ export type {
|
|
|
53
48
|
NitroInputView,
|
|
54
49
|
} from './specs/NitroInput.nitro'
|
|
55
50
|
export type { NitroInputWorklets } from './specs/NitroInputWorklets.nitro'
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
NitroNumber,
|
|
54
|
+
NativeNitroNumberView,
|
|
55
|
+
type NitroNumberProps,
|
|
56
|
+
type NitroNumberHandle,
|
|
57
|
+
type NitroNumberRef,
|
|
58
|
+
} from './NitroNumber'
|
|
59
|
+
export type {
|
|
60
|
+
NitroNumberAffixAlign,
|
|
61
|
+
NitroNumberDirection,
|
|
62
|
+
NitroNumberTransition,
|
|
63
|
+
NitroNumberEasing,
|
|
64
|
+
NitroNumberRevealStyle,
|
|
65
|
+
NitroNumberTextAlign,
|
|
66
|
+
NitroNumberMethods,
|
|
67
|
+
NitroNumberProps as NativeNitroNumberProps,
|
|
68
|
+
NitroNumberView,
|
|
69
|
+
} from './specs/NitroNumber.nitro'
|
|
@@ -25,7 +25,7 @@ export interface NitroInputNotation {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Timing curve of the
|
|
28
|
+
* Timing curve of the reflow. `'expo'` is Torph's default
|
|
29
29
|
* (`cubic-bezier(0.19, 1, 0.22, 1)`): a fast take-off that settles gently.
|
|
30
30
|
*/
|
|
31
31
|
export type NitroInputEasing =
|
|
@@ -74,7 +74,7 @@ export type NitroInputTextAlignVertical = 'auto' | 'top' | 'center' | 'bottom'
|
|
|
74
74
|
* `'beforeAffix'` (the default) reads `-$1,234.56`, which is how a locale that
|
|
75
75
|
* leads with its symbol writes it. `'afterAffix'` reads `$-1,234.56`, which
|
|
76
76
|
* suits a symbol styled as an ornament rather than read as part of the number -
|
|
77
|
-
* small, raised, in another colour. Only the
|
|
77
|
+
* small, raised, in another colour. Only the reflow honours it: a plain field's
|
|
78
78
|
* affixes are accessory views that sit outside the text, so it is always
|
|
79
79
|
* `'afterAffix'`.
|
|
80
80
|
*/
|
|
@@ -136,7 +136,7 @@ export interface NitroInputProps extends HybridViewProps {
|
|
|
136
136
|
/** `'text'`, `'number'` or `'mask'`. Default: `'text'`. */
|
|
137
137
|
mode: NitroInputMode
|
|
138
138
|
/**
|
|
139
|
-
* Draw the text with the system field itself and skip the
|
|
139
|
+
* Draw the text with the system field itself and skip the reflow overlay
|
|
140
140
|
* entirely: no glyph engine, no per-glyph layers, no custom caret. This is
|
|
141
141
|
* what `NitroInput` renders — an ordinary native input that keeps the rest of
|
|
142
142
|
* the component (native formatting, the focus path, the text-input registry
|
|
@@ -220,13 +220,13 @@ export interface NitroInputProps extends HybridViewProps {
|
|
|
220
220
|
prefixAlign: NitroInputAffixAlign
|
|
221
221
|
/** Vertical alignment of `suffix` relative to the text (the wrapper folds its `affixAlign` into this). */
|
|
222
222
|
suffixAlign: NitroInputAffixAlign
|
|
223
|
-
/** Shown (and
|
|
223
|
+
/** Shown (and reflowed away) while the field is empty. Default: `''`. */
|
|
224
224
|
placeholder: string
|
|
225
225
|
/** Color of the placeholder as a processed ARGB integer; `NaN` = platform default. */
|
|
226
226
|
placeholderColor: number
|
|
227
|
-
/** Duration in ms of the
|
|
227
|
+
/** Duration in ms of the reflow played on every change. `0` snaps. Default: `400`. */
|
|
228
228
|
duration: number
|
|
229
|
-
/** Timing curve of the
|
|
229
|
+
/** Timing curve of the reflow. Default: `'expo'`. */
|
|
230
230
|
easing: NitroInputEasing
|
|
231
231
|
/** Overshoot of the `'spring'` easing, `0`–`1`. Default: `0.15`. */
|
|
232
232
|
bounce: number
|
|
@@ -292,9 +292,9 @@ export interface NitroInputProps extends HybridViewProps {
|
|
|
292
292
|
* Let the text wrap onto more than one line.
|
|
293
293
|
*
|
|
294
294
|
* A multiline field is always drawn by the system view — the glyph engine
|
|
295
|
-
* lays one run out on one baseline, so it cannot
|
|
295
|
+
* lays one run out on one baseline, so it cannot reflow wrapped text — and it
|
|
296
296
|
* is always `'text'` mode, since an amount and a mask are single-line ideas.
|
|
297
|
-
* Setting `
|
|
297
|
+
* Setting `transition="reflow"`, `'number'` or `'mask'` alongside it is ignored, with a
|
|
298
298
|
* warning. Default: `false`.
|
|
299
299
|
*/
|
|
300
300
|
multiline: boolean
|
|
@@ -411,7 +411,7 @@ export interface NitroInputProps extends HybridViewProps {
|
|
|
411
411
|
export interface NitroInputMethods extends HybridViewMethods {
|
|
412
412
|
focus(): void
|
|
413
413
|
blur(): void
|
|
414
|
-
/** Empties the field (
|
|
414
|
+
/** Empties the field (reflowing the characters away). */
|
|
415
415
|
clear(): void
|
|
416
416
|
/**
|
|
417
417
|
* Replaces the text (formatted in `'number'` mode), caret at the end.
|