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
package/README.md
CHANGED
|
@@ -1,7 +1,33 @@
|
|
|
1
1
|
# react-native-nitro-input
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Native text for React Native, built with [Nitro Modules](https://nitro.margelo.com):
|
|
4
|
+
two components that share one formatting model, one set of glyph renderers and
|
|
5
|
+
one native module.
|
|
6
|
+
|
|
7
|
+
- **[`NitroInput`](#nitroinput)**: a text input. The system field owns the
|
|
8
|
+
keyboard, editing, selection and accessibility; amounts are formatted and
|
|
9
|
+
masks applied in C++ before a frame is drawn, and the characters can reflow
|
|
10
|
+
as they change.
|
|
11
|
+
- **[`NitroNumber`](#nitronumber)**: a number that animates its changes.
|
|
12
|
+
Every digit is a wheel that rolls to its new glyph, or swaps in place the way
|
|
13
|
+
SwiftUI's `.contentTransition(.numericText())` does.
|
|
14
|
+
|
|
15
|
+
Fabric only (new architecture), React Native ≥ 0.78, Nitro Modules ≥ 0.37.
|
|
16
|
+
|
|
17
|
+
Docs, live demos and benchmarks: **https://ronickg.github.io/react-native-nitro-input/**
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
bun add react-native-nitro-input react-native-nitro-modules
|
|
23
|
+
cd ios && pod install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
> **Android and Nitro 0.37:** Nitro never hands a Hybrid View its `backgroundColor`, `border*`, `opacity`, `transform`, `testID` or accessibility props on Android with React Native 0.86+ — the `style` on every example below would be dropped. Fixed upstream in [margelo/nitro#1655](https://github.com/margelo/nitro/pull/1655); until it ships, apply the [patch from this repository](https://github.com/ronickg/react-native-nitro-input/blob/main/patches/react-native-nitro-modules@0.37.1.patch) with `patchedDependencies` (Bun) or patch-package.
|
|
27
|
+
|
|
28
|
+
## NitroInput
|
|
29
|
+
|
|
30
|
+
A native **text input**: a
|
|
5
31
|
system text field (`UITextField` / `EditText`) that owns the keyboard, editing,
|
|
6
32
|
selection, paste and accessibility, with native formatting, native masking and
|
|
7
33
|
an outlined or filled frame with a floating label on top of it.
|
|
@@ -12,9 +38,9 @@ import { NitroInput } from 'react-native-nitro-input'
|
|
|
12
38
|
<NitroInput variant="outlined" label="Email address" keyboardType="email-address" />
|
|
13
39
|
```
|
|
14
40
|
|
|
15
|
-
`
|
|
16
|
-
where
|
|
17
|
-
|
|
41
|
+
`transition="reflow"` animates the characters as they change, for the one case
|
|
42
|
+
where that is the point — an amount. It is not the default, and for an
|
|
43
|
+
ordinary form field you do not want it.
|
|
18
44
|
|
|
19
45
|
- **It is a real input.** Focus, blur, return key, keyboard types,
|
|
20
46
|
auto-capitalisation, max length, selection, the text-input registry, all the
|
|
@@ -31,26 +57,14 @@ and for an ordinary form field you do not want it.
|
|
|
31
57
|
decimals, a currency `prefix` / `suffix`, the caret kept where you typed. No
|
|
32
58
|
JS round trip, so none of the flicker, caret jumps or dropped keystrokes of a
|
|
33
59
|
controlled `TextInput` that formats in `onChangeText`.
|
|
34
|
-
- **Same formatting model as [`
|
|
60
|
+
- **Same formatting model as [`NitroNumber`](#nitronumber)**:
|
|
35
61
|
prefix/suffix at their own font sizes, pinned to the top, bottom, baseline or
|
|
36
62
|
centre of the digits; grouping and decimal separators of your choice.
|
|
37
63
|
- **One C++ engine per concern** drives both platforms — formatting, masking,
|
|
38
|
-
the frame geometry, and (with `
|
|
64
|
+
the frame geometry, and (with `transition="reflow"`) the glyph matching and curves. Swift
|
|
39
65
|
and Kotlin only measure, draw and talk to the keyboard.
|
|
40
|
-
- Fabric only (new architecture), React Native ≥ 0.78, Nitro Modules ≥ 0.37.
|
|
41
66
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
## Install
|
|
45
|
-
|
|
46
|
-
```sh
|
|
47
|
-
bun add react-native-nitro-input react-native-nitro-modules
|
|
48
|
-
cd ios && pod install
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
> **Android and Nitro 0.37:** Nitro never hands a Hybrid View its `backgroundColor`, `border*`, `opacity`, `transform`, `testID` or accessibility props on Android with React Native 0.86+ — the `style` on every example below would be dropped. Fixed upstream in [margelo/nitro#1655](https://github.com/margelo/nitro/pull/1655); until it ships, apply the [patch from this repository](https://github.com/ronickg/react-native-nitro-rolling-number/blob/main/patches/react-native-nitro-modules@0.37.1.patch) with `patchedDependencies` (Bun) or patch-package.
|
|
52
|
-
|
|
53
|
-
## Usage
|
|
67
|
+
Guide: **https://ronickg.github.io/react-native-nitro-input/docs/nitro-input**
|
|
54
68
|
|
|
55
69
|
### A text field
|
|
56
70
|
|
|
@@ -66,9 +80,9 @@ cd ios && pod install
|
|
|
66
80
|
```
|
|
67
81
|
|
|
68
82
|
`NitroInput` does not animate its characters: they appear the instant you type
|
|
69
|
-
them, the way a `TextInput` does. Pass `
|
|
70
|
-
|
|
71
|
-
|
|
83
|
+
them, the way a `TextInput` does. Pass `transition="reflow"` to turn the glyph
|
|
84
|
+
engine on — see [An amount field](#an-amount-field-the-reflow), which is where
|
|
85
|
+
it earns itself.
|
|
72
86
|
|
|
73
87
|
### A masked field
|
|
74
88
|
|
|
@@ -160,27 +174,27 @@ content, and `scrollEnabled={false}` hands the height to the content entirely.
|
|
|
160
174
|
`textAlignVertical` says where the text sits in a taller box. A multiline field
|
|
161
175
|
is always drawn by the system view and is always `mode="text"`: the glyph
|
|
162
176
|
engine lays one run out on one baseline, and an amount, a mask and their
|
|
163
|
-
affixes are single-line ideas, so `
|
|
177
|
+
affixes are single-line ideas, so `transition="reflow"`, `mode="number"`, `mode="mask"`,
|
|
164
178
|
`prefix` and `suffix` are ignored alongside it, with one warning each in
|
|
165
179
|
development. Its return key inserts a line break, as a `TextInput`'s does;
|
|
166
180
|
`submitBehavior="blurAndSubmit"` (or `blurOnSubmit`) makes it submit instead.
|
|
167
181
|
|
|
168
|
-
### An amount field (the
|
|
182
|
+
### An amount field (the reflow)
|
|
169
183
|
|
|
170
|
-
This is the one case the
|
|
171
|
-
|
|
172
|
-
arrive.
|
|
184
|
+
This is the one case the reflow is for, so it passes `transition="reflow"`.
|
|
185
|
+
A reflowing field also sizes its box to its content by default
|
|
186
|
+
(`autoWidth="auto"`), so it grows as digits arrive.
|
|
173
187
|
|
|
174
188
|
With the engine running, `mode="text"` fades and scales characters in and out
|
|
175
189
|
(Torph's text morph) while digits and separators slide in `mode="number"`,
|
|
176
190
|
unless you force one style with `effect="slide"` / `effect="fade"`.
|
|
177
191
|
|
|
178
192
|
```tsx
|
|
179
|
-
import {
|
|
193
|
+
import { NitroInput } from 'react-native-nitro-input'
|
|
180
194
|
|
|
181
195
|
const [amount, setAmount] = useState(NaN)
|
|
182
196
|
|
|
183
|
-
<
|
|
197
|
+
<NitroInput transition="reflow"
|
|
184
198
|
mode="number"
|
|
185
199
|
prefix="$"
|
|
186
200
|
prefixFontSize={28}
|
|
@@ -209,34 +223,34 @@ formatted string) and keep the field uncontrolled, or pass `value` to drive it:
|
|
|
209
223
|
```tsx
|
|
210
224
|
const [text, setText] = useState('')
|
|
211
225
|
|
|
212
|
-
<
|
|
226
|
+
<NitroInput transition="reflow" mode="number" value={text} onChangeText={setText} prefix="$" />
|
|
213
227
|
```
|
|
214
228
|
|
|
215
229
|
A `value` that merely echoes `onChangeText` back never fights the user: native
|
|
216
230
|
already shows it. A `value` that differs (a "Max" button, a clamp) is applied
|
|
217
|
-
and
|
|
231
|
+
and reflows in.
|
|
218
232
|
|
|
219
233
|
### Currency layouts
|
|
220
234
|
|
|
221
235
|
```tsx
|
|
222
236
|
// "$" smaller than the amount, aligned to the top of the digits
|
|
223
|
-
<
|
|
237
|
+
<NitroInput transition="reflow" mode="number" prefix="$" prefixFontSize={22} affixAlign="top" fontSize={44} />
|
|
224
238
|
|
|
225
239
|
// currency code after the amount, smaller and sitting on the baseline of the digits' ink
|
|
226
|
-
<
|
|
240
|
+
<NitroInput transition="reflow" mode="number" suffix=" USD" suffixFontSize={18} suffixAlign="bottom" />
|
|
227
241
|
|
|
228
242
|
// European separators: 1.234,56
|
|
229
|
-
<
|
|
243
|
+
<NitroInput transition="reflow" mode="number" groupingSeparator="." decimalSeparator="," />
|
|
230
244
|
|
|
231
245
|
// whole numbers only (no decimal key accepted), at most six digits
|
|
232
|
-
<
|
|
246
|
+
<NitroInput transition="reflow" mode="number" fractionDigits={0} maxIntegerDigits={6} />
|
|
233
247
|
|
|
234
248
|
// a big centred amount that shrinks when it gets long
|
|
235
|
-
<
|
|
249
|
+
<NitroInput transition="reflow" mode="number" fontSize={64} adjustsFontSizeToFit minimumFontScale={0.4} textAlign="center" style={{ width: '100%' }} />
|
|
236
250
|
```
|
|
237
251
|
|
|
238
252
|
In a right-to-left layout the prefix sits at the right edge and the suffix at
|
|
239
|
-
the left, plain or
|
|
253
|
+
the left, plain or reflowed; the digits keep reading left to right.
|
|
240
254
|
|
|
241
255
|
Whatever the keyboard's decimal key produces (`.` or `,`) counts as the
|
|
242
256
|
decimal separator; nobody types a grouping separator on purpose. The rules
|
|
@@ -353,13 +367,13 @@ the worklets UI runtime is handed to native once, the worklet is called with
|
|
|
353
367
|
### Imperative
|
|
354
368
|
|
|
355
369
|
```tsx
|
|
356
|
-
const ref = useRef<
|
|
370
|
+
const ref = useRef<NitroInputHandle>(null)
|
|
357
371
|
|
|
358
|
-
<
|
|
372
|
+
<NitroInput transition="reflow" ref={ref} mode="number" />
|
|
359
373
|
|
|
360
374
|
ref.current?.focus()
|
|
361
375
|
ref.current?.blur()
|
|
362
|
-
ref.current?.setValue(1234.56) // shows "1,234.56",
|
|
376
|
+
ref.current?.setValue(1234.56) // shows "1,234.56", reflowing from whatever was there
|
|
363
377
|
ref.current?.setText('98,765') // same, from a string in the field's format
|
|
364
378
|
ref.current?.clear()
|
|
365
379
|
ref.current?.getText() // "1,234.56"
|
|
@@ -374,7 +388,7 @@ place. Typing uses **caret matching**: the characters on either side of the
|
|
|
374
388
|
caret keep their identity, so inserting a `9` into `12|34` slides `34` over
|
|
375
389
|
rather than renumbering the columns.
|
|
376
390
|
|
|
377
|
-
##
|
|
391
|
+
## NitroInput props
|
|
378
392
|
|
|
379
393
|
| Prop | Type | Default | Description |
|
|
380
394
|
| --- | --- | --- | --- |
|
|
@@ -402,11 +416,11 @@ rather than renumbering the columns.
|
|
|
402
416
|
| `prefixFontSize` / `suffixFontSize` | `number` | `fontSize` | Their own sizes. |
|
|
403
417
|
| `affixAlign` | `'baseline' \| 'center' \| 'top' \| 'bottom'` | `'baseline'` | How they line up with the text: `top` pins glyph tops, `bottom` the bottom of the ink (a currency code sits on the digits' baseline). |
|
|
404
418
|
| `prefixAlign` / `suffixAlign` | same | `affixAlign` | Per-affix override. |
|
|
405
|
-
| `placeholder` | `string` | `''` | Shown while empty; the first character
|
|
419
|
+
| `placeholder` | `string` | `''` | Shown while empty; the first character reflows it away. `'0'` reads well for amounts. |
|
|
406
420
|
| `placeholderTextColor` | `ColorValue` | platform | Placeholder color. |
|
|
407
|
-
| `
|
|
408
|
-
| `autoWidth` | `boolean \| 'auto'` | `false` | `false` takes no width, so flexbox stretches it like a `TextInput`; `'auto'` infers it from `style
|
|
409
|
-
| `duration` | `number` | `400` | ms of the
|
|
421
|
+
| `transition` | `'none' \| 'reflow'` | `'none'` | `'reflow'` runs the glyph engine, so characters glide, slide and fade as the text changes. |
|
|
422
|
+
| `autoWidth` | `boolean \| 'auto'` | `false`; `'auto'` when reflowing | `false` takes no width, so flexbox stretches it like a `TextInput`; `'auto'` infers it from `style`. |
|
|
423
|
+
| `duration` | `number` | `400` | ms of the reflow; `0` snaps. |
|
|
410
424
|
| `easing` | `'expo' \| 'easeOut' \| 'easeInOut' \| 'linear' \| 'spring'` | `'expo'` | Timing curve. `expo` is Torph's `cubic-bezier(0.19, 1, 0.22, 1)`. |
|
|
411
425
|
| `bounce` | `number` | `0.15` | Overshoot of the `spring` easing (0–1). |
|
|
412
426
|
| `effect` | `'auto' \| 'slide' \| 'fade'` | `'auto'` | `auto`: digits and separators slide through the line box (digits from above, separators from below), other characters fade and scale. |
|
|
@@ -416,7 +430,7 @@ rather than renumbering the columns.
|
|
|
416
430
|
| `color` | `ColorValue` | label color | Text color. |
|
|
417
431
|
| `textAlign` | `'auto' \| 'left' \| 'center' \| 'right'` | `'auto'` | Alignment inside a wider frame. `'auto'` is the start edge of the layout direction, as `TextInput`; `'left'` and `'right'` are absolute. |
|
|
418
432
|
| `lineHeight` | `number` | the font's own | The CSS meaning: the total height a line occupies. Honoured in both directions, including tighter than the font. |
|
|
419
|
-
| `multiline` | `boolean` | `false` | Wraps. Always drawn by the system view and always `'text'` mode; `
|
|
433
|
+
| `multiline` | `boolean` | `false` | Wraps. Always drawn by the system view and always `'text'` mode; `transition="reflow"`, `'number'`, `'mask'` and the affixes are ignored with it, and the return key inserts a line break unless `submitBehavior` says otherwise. |
|
|
420
434
|
| `numberOfLines` / `rows` | `number` | `0` | `multiline`: lines tall before it scrolls; `0` grows with the content. |
|
|
421
435
|
| `textAlignVertical` | `'auto' \| 'top' \| 'center' \| 'bottom'` | `'auto'` | `multiline`: where the text sits in a taller box. |
|
|
422
436
|
| `scrollEnabled` | `boolean` | `true` | `multiline`: scroll once the text outgrows the field; `false` lets a growing field drive its own height. |
|
|
@@ -454,7 +468,7 @@ rather than renumbering the columns.
|
|
|
454
468
|
| `onChange` | `(event) => void` | – | Fired alongside `onChangeText` with the same text; `nativeEvent.eventCount` is the native edit counter, as on `TextInput`. |
|
|
455
469
|
| `onChangeValue` | `(value) => void` | – | `number` mode: the numeric value, `NaN` while empty. A `'worklet'` runs on the UI thread. |
|
|
456
470
|
| `onChangeMask` | `(formatted, extracted, tail, complete) => void` | – | `mask` mode: the formatted text, the characters the user contributed, what is still missing, and whether every mandatory slot is filled. |
|
|
457
|
-
| `signPlacement` | `'beforeAffix' \| 'afterAffix'` | `'beforeAffix'` | Where a negative amount's sign sits relative to `prefix`: `-$1,234.56` or `$-1,234.56`.
|
|
471
|
+
| `signPlacement` | `'beforeAffix' \| 'afterAffix'` | `'beforeAffix'` | Where a negative amount's sign sits relative to `prefix`: `-$1,234.56` or `$-1,234.56`. Reflow only — a plain field's affixes are accessory views outside the text. |
|
|
458
472
|
| `onFocus` / `onBlur` | `(event) => void` | – | Carries `text`, `eventCount` and `target`. |
|
|
459
473
|
| `onSubmitEditing` | `(event) => void` | – | Return key pressed; what happens next is `submitBehavior`. |
|
|
460
474
|
| `onEndEditing` | `(event) => void` | – | Editing finished. |
|
|
@@ -476,10 +490,10 @@ onSubmitEditing={e => search(e.nativeEvent.text)} // as on a TextInput
|
|
|
476
490
|
onSubmitEditing={({ text }) => search(text)} // or just this
|
|
477
491
|
```
|
|
478
492
|
|
|
479
|
-
## How the
|
|
493
|
+
## How the reflow decides what moves
|
|
480
494
|
|
|
481
495
|
Each update pairs the old characters with the new ones (Torph's rules,
|
|
482
|
-
implemented in `cpp/
|
|
496
|
+
implemented in `cpp/ReflowEngine.cpp`):
|
|
483
497
|
|
|
484
498
|
- **Typing** (a caret is known): everything before the caret pairs by
|
|
485
499
|
position from the left, everything after it from the right, so the edit is
|
|
@@ -496,27 +510,338 @@ implemented in `cpp/MorphEngine.cpp`):
|
|
|
496
510
|
|
|
497
511
|
A character that persists eases to its new x. A new digit drops in from above
|
|
498
512
|
(a separator rises from below) through the clipped line box, fading in over the
|
|
499
|
-
first quarter of the
|
|
513
|
+
first quarter of the reflow; a leaving digit drops out the same way, fading over
|
|
500
514
|
the first 45 %. Text characters fade and scale (0.95×) instead. Characters that
|
|
501
515
|
enter or leave ride along with their nearest persisting neighbour, so a word
|
|
502
516
|
that grows or shrinks stays one shape. All of it is Reduce Motion aware.
|
|
503
517
|
|
|
518
|
+
## NitroNumber
|
|
519
|
+
|
|
520
|
+
A number that animates its changes natively, with the same look on iOS
|
|
521
|
+
**and** Android: every digit a wheel that rolls to its new glyph (an odometer /
|
|
522
|
+
ticker), or SwiftUI's `.contentTransition(.numericText())`, or a scramble.
|
|
523
|
+
|
|
524
|
+
- Change the `value` prop and the digits roll natively: per digit, direction
|
|
525
|
+
aware, with easing or spring curves and an optional cascading `stagger`.
|
|
526
|
+
- Formatting on the native side: fraction digits, grouping separator, decimal
|
|
527
|
+
separator, prefix/suffix (with their own font sizes), zero padding, negatives.
|
|
528
|
+
- Columns appear and disappear smoothly (`999 → 1000` slides a new `1` in while
|
|
529
|
+
the layout widens), and the view auto-sizes to its content.
|
|
530
|
+
- `adjustsFontSizeToFit` keeps a fixed box and scales the amount to fit.
|
|
531
|
+
- `loading` shows a text-shaped shimmer skeleton that cross-fades to the value.
|
|
532
|
+
- `reveal` plays the casino "you won" presentation natively: the win-meter
|
|
533
|
+
rollup (with tiers that punch and hold) or slot reels that lock from the left.
|
|
534
|
+
- A currency switch plays as one change: prefix, suffix and separators blur
|
|
535
|
+
across, decimal columns open and close, the digits swap or roll.
|
|
536
|
+
- `animateTo` / `jumpTo` on the Nitro object work from a Reanimated worklet.
|
|
537
|
+
|
|
538
|
+
Guide: **https://ronickg.github.io/react-native-nitro-input/docs/nitro-number**
|
|
539
|
+
|
|
540
|
+
```tsx
|
|
541
|
+
import { NitroNumber } from 'react-native-nitro-input'
|
|
542
|
+
|
|
543
|
+
<NitroNumber
|
|
544
|
+
value={balance}
|
|
545
|
+
fractionDigits={2}
|
|
546
|
+
groupingSeparator=","
|
|
547
|
+
prefix="$"
|
|
548
|
+
fontSize={48}
|
|
549
|
+
fontWeight="700"
|
|
550
|
+
color="#0A84FF"
|
|
551
|
+
easing="spring"
|
|
552
|
+
bounce={0.2}
|
|
553
|
+
stagger={40}
|
|
554
|
+
/>
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
Whenever `value` changes, each digit rolls from its old glyph to its new one in
|
|
558
|
+
the direction of the change. The first value is shown without animation.
|
|
559
|
+
|
|
560
|
+
### The transitions
|
|
561
|
+
|
|
562
|
+
```tsx
|
|
563
|
+
<NitroNumber value={count} transition="numeric" fontSize={48} fontWeight="700" />
|
|
564
|
+
<NitroNumber value={count} transition="scramble" />
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
The roll is the default. The others swap each changed glyph in place, digits
|
|
568
|
+
that don't change staying put, the change cascading from the leftmost changed
|
|
569
|
+
digit to the right (`stagger`); `duration` and `easing` apply to all of them,
|
|
570
|
+
each with its own defaults.
|
|
571
|
+
|
|
572
|
+
- **`numeric`**, after SwiftUI's `.contentTransition(.numericText())`: the
|
|
573
|
+
old glyph softens, shrinks and slides out; the new one slides in from the
|
|
574
|
+
other side, nearly full size and out of focus, and resolves. The glyphs move
|
|
575
|
+
up when the value grows and down when it shrinks (`direction` overrides
|
|
576
|
+
that). The blur is real on all three platforms: a blurred copy of each
|
|
577
|
+
glyph rendered once per font and cross-faded with the sharp one, so a frame
|
|
578
|
+
costs the same as a frame of a roll.
|
|
579
|
+
- **`scramble`**: each changed digit shows a different random digit every
|
|
580
|
+
few frames, never the one it is leaving or arriving at, and locks on its
|
|
581
|
+
target; the lock runs from the left.
|
|
582
|
+
|
|
583
|
+
Two more things happen on a change if you ask for them, with any transition:
|
|
584
|
+
|
|
585
|
+
```tsx
|
|
586
|
+
<NitroNumber value={price} flashUpColor="#16a34a" flashDownColor="#dc2626" popOnChange={0.08} />
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
`flashUpColor` / `flashDownColor` is the change flash of a trading screen:
|
|
590
|
+
every digit whose glyph changes lights up in the up colour when the value grew
|
|
591
|
+
and the down colour when it shrank, stays lit while it moves, and fades back
|
|
592
|
+
over `flashDuration` (600 ms) once it has landed.
|
|
593
|
+
`popOnChange` punches the whole figure on every change, its peak overshoot as
|
|
594
|
+
a fraction of the size, rung out like the reveal's landing pop.
|
|
595
|
+
|
|
596
|
+
### Currency layouts and fitting a width
|
|
597
|
+
|
|
598
|
+
```tsx
|
|
599
|
+
// "$" smaller than the amount, aligned to the top of the digits
|
|
600
|
+
<NitroNumber value={total} prefix="$" prefixFontSize={22} affixAlign="top" fontSize={44} />
|
|
601
|
+
|
|
602
|
+
// currency code after the amount, smaller and pinned to the bottom
|
|
603
|
+
<NitroNumber value={total} suffix=" USD" suffixFontSize={18} suffixAlign="bottom" fractionDigits={2} />
|
|
604
|
+
|
|
605
|
+
// both at once: "$" pinned top, "USD" pinned bottom
|
|
606
|
+
<NitroNumber value={total} prefix="$" prefixAlign="top" suffix=" USD" suffixAlign="bottom" prefixFontSize={22} suffixFontSize={16} />
|
|
607
|
+
|
|
608
|
+
// fit the container without a fixed width: full size until it would overflow, then it shrinks
|
|
609
|
+
<NitroNumber value={total} fontSize={52} adjustsFontSizeToFit style={{ maxWidth: '100%' }} />
|
|
610
|
+
|
|
611
|
+
// fixed box: the box never resizes, the amount shrinks (down to 50%) and grows back to fit
|
|
612
|
+
<NitroNumber
|
|
613
|
+
value={total}
|
|
614
|
+
fontSize={64}
|
|
615
|
+
adjustsFontSizeToFit
|
|
616
|
+
minimumFontScale={0.5}
|
|
617
|
+
textAlign="center"
|
|
618
|
+
style={{ width: 240 }}
|
|
619
|
+
/>
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
A view that sizes itself grows and shrinks from whichever edge its parent
|
|
623
|
+
holds it by (`textAlign="auto"`): at the end of a row it grows to the left, in
|
|
624
|
+
a centred column from its middle.
|
|
625
|
+
|
|
626
|
+
Switching currency is a change like any other: set the new `prefix`, `suffix`,
|
|
627
|
+
separators and `fractionDigits` with the new `value` and it plays as one
|
|
628
|
+
transition. The old mark blurs out as the new one comes into focus, the
|
|
629
|
+
digits keep their place value, decimal columns that go close and new ones open
|
|
630
|
+
(swapping in, or rolling up from blank), and the decimal separator fades with
|
|
631
|
+
them.
|
|
632
|
+
|
|
633
|
+
```tsx
|
|
634
|
+
<NitroNumber
|
|
635
|
+
value={round(usd * c.rate, c.digits)}
|
|
636
|
+
prefix={c.prefix} // "$" → "" → "¥" → "CHF "
|
|
637
|
+
suffix={c.suffix} // "" → " €" …
|
|
638
|
+
groupingSeparator={c.grouping}
|
|
639
|
+
decimalSeparator={c.decimal}
|
|
640
|
+
fractionDigits={c.digits} // 2 → 2 → 0 → 2
|
|
641
|
+
transition="numeric"
|
|
642
|
+
/>
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
### Loading skeleton
|
|
646
|
+
|
|
647
|
+
```tsx
|
|
648
|
+
<NitroNumber value={balance ?? 0} loading={balance === undefined} prefix="$" fractionDigits={2} />
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
While `loading` is true the glyphs keep their color and a slanted, text-wide
|
|
652
|
+
glint (`[color, shimmerColor, color]` at 10/50/90 %) sweeps through them every
|
|
653
|
+
950 ms, seeded with its core at the left edge so it shows immediately. It is
|
|
654
|
+
text-shaped, so the layout is exactly what the real number will occupy. When
|
|
655
|
+
the value arrives, flip `loading` off and set `value` in the same render: the
|
|
656
|
+
glint fades out while the digits roll to the amount.
|
|
657
|
+
|
|
658
|
+
### Jackpot reveal
|
|
659
|
+
|
|
660
|
+
```tsx
|
|
661
|
+
const [reveal, setReveal] = useState(false)
|
|
662
|
+
|
|
663
|
+
<NitroNumber
|
|
664
|
+
value={50000}
|
|
665
|
+
reveal={reveal} // false: hold "$0.00" in the final layout; true: play
|
|
666
|
+
revealStyle="count" // the win-meter rollup, or "spin" for slot reels
|
|
667
|
+
revealMilestones={[1000, 10000, 25000]}
|
|
668
|
+
revealMilestoneHold={400}
|
|
669
|
+
revealDuration={4800} // about a second per tier
|
|
670
|
+
onRevealMilestone={(index, at) => haptics.impact()}
|
|
671
|
+
onRevealEnd={() => setShowNextStep(true)}
|
|
672
|
+
prefix="$" fractionDigits={2} groupingSeparator="," textAlign="center" style={{ width: '100%' }}
|
|
673
|
+
/>
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
`count` opens at 0, smaller, and tallies up like a slot's win counter: it takes
|
|
677
|
+
off at once, runs at a constant rate (the low digits blur), grows as it climbs
|
|
678
|
+
(`revealGrow`) and crawls into the total; digits swap in place and leading
|
|
679
|
+
digits appear as the count reaches them. With `revealMilestones` (the "big win → mega
|
|
680
|
+
win" tiers, numbers in the figure's units) the count runs tier by tier: equal
|
|
681
|
+
time per tier, braking into each milestone, a punch, a pause of
|
|
682
|
+
`revealMilestoneHold` ms, then taking off again. `spin` spins every digit like
|
|
683
|
+
a slot reel and locks the reels one at a time from the left. Both land with a
|
|
684
|
+
pop. `jumpTo(value)` skips a running reveal (tap to slam). Banners, confetti
|
|
685
|
+
and sounds are the app's: the callbacks give you the beats.
|
|
686
|
+
|
|
687
|
+
### Imperative
|
|
688
|
+
|
|
689
|
+
```tsx
|
|
690
|
+
const ref = useRef<NitroNumberHandle>(null)
|
|
691
|
+
|
|
692
|
+
<NitroNumber ref={ref} value={0} />
|
|
693
|
+
|
|
694
|
+
ref.current?.animateTo(42) // rolls, like changing the prop
|
|
695
|
+
ref.current?.jumpTo(41.75) // positions the wheels continuously, no roll (scrubbing)
|
|
696
|
+
ref.current?.revealTo(1234.5) // plays a jackpot reveal
|
|
697
|
+
ref.current?.getValue() // value shown or being rolled towards
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
`jumpTo` positions every wheel from a continuous number (`41.75` shows the units
|
|
701
|
+
wheel three quarters of the way from `1` to `2`), which is what you want when a
|
|
702
|
+
scroll or drag handler drives the number.
|
|
703
|
+
|
|
704
|
+
The Nitro object (`onNativeRef`) can be captured by a Reanimated worklet as it
|
|
705
|
+
is, so the UI thread can drive the figure while JS is busy:
|
|
706
|
+
|
|
707
|
+
```tsx
|
|
708
|
+
const [price, setPrice] = useState<NitroNumberRef>()
|
|
709
|
+
|
|
710
|
+
useFrameCallback((frame) => {
|
|
711
|
+
'worklet'
|
|
712
|
+
if (price && tickDue(frame)) price.animateTo(nextPrice())
|
|
713
|
+
}, true)
|
|
714
|
+
|
|
715
|
+
<NitroNumber value={initial} onNativeRef={setPrice} />
|
|
716
|
+
```
|
|
717
|
+
|
|
718
|
+
Hand the final value back to React when the feed stops (`scheduleOnRN`) so the
|
|
719
|
+
`value` prop matches the screen; posting every tick queues them up while JS is
|
|
720
|
+
busy and replays them afterwards.
|
|
721
|
+
|
|
722
|
+
## NitroNumber props
|
|
723
|
+
|
|
724
|
+
| Prop | Type | Default | Description |
|
|
725
|
+
| --- | --- | --- | --- |
|
|
726
|
+
| `value` | `number` | – | The number to display. Shown with at most 18 digits: `|value| × 10^fractionDigits` is clamped at 10^17, and a JS number carries exact integers only up to 2^53. |
|
|
727
|
+
| `fractionDigits` | `number` | `0` | Digits after the decimal separator. |
|
|
728
|
+
| `minimumIntegerDigits` | `number` | `1` | Zero-pads the integer part. |
|
|
729
|
+
| `groupingSeparator` | `string` | `''` | Inserted every three integer digits. |
|
|
730
|
+
| `decimalSeparator` | `string` | `'.'` | Between integer and fraction digits. |
|
|
731
|
+
| `prefix` / `suffix` | `string` | `''` | Static text around the number. |
|
|
732
|
+
| `duration` | `number` | `500` | Roll duration in ms; `0` snaps. |
|
|
733
|
+
| `easing` | `'linear' \| 'easeIn' \| 'easeOut' \| 'easeInOut' \| 'spring'` | `'easeInOut'` | Roll timing curve. A value that arrives while the wheels are still rolling continues with the ease-out half of the curve, so rapid updates never stall. |
|
|
734
|
+
| `bounce` | `number` | `0.15` | Overshoot of the `spring` easing (0–1). |
|
|
735
|
+
| `stagger` | `number` | `0` | ms between the start of each digit's roll (least significant first), a cascading carry; in the numeric transition it is the span of the whole cascade, spread over the changed digits from the left, default `150`. |
|
|
736
|
+
| `transition` | `'roll' \| 'numeric' \| 'scramble'` | `'roll'` | How a change plays: the odometer roll; the numeric transition (each changed glyph swaps in place, SwiftUI's `numericText`); or a scramble that locks from the left. Each swap style has its own `duration` / `easing` / `stagger` defaults (numeric 480 ms with SwiftUI's own clocks and a 150 ms cascade span, scramble 500 / linear / 60). |
|
|
737
|
+
| `flashUpColor`, `flashDownColor` | `ColorValue` | unset | The change flash: digits whose glyph changes light up in the up colour when the value grew, the down colour when it shrank, stay lit while they move, and fade back over `flashDuration` once they have landed. Unset: no flash. |
|
|
738
|
+
| `flashDuration` | `number` | `600` | ms a change flash takes to fade, once the digit has landed. |
|
|
739
|
+
| `popOnChange` | `number` | `0` | A punch of the whole figure on every change, peak overshoot 0–1, rung out like the reveal's landing pop. |
|
|
740
|
+
| `direction` | `'auto' \| 'up' \| 'down'` | `'auto'` | Roll direction; `auto` follows the sign of the change. |
|
|
741
|
+
| `reveal` | `boolean` | – | `false` holds the opening frame (`$0.00` in the final layout); `true` plays the reveal to `value`. Unset = a normal NitroNumber. |
|
|
742
|
+
| `revealStyle` | `'count' \| 'spin'` | `'count'` | The win-meter rollup, or slot reels locking from the left. |
|
|
743
|
+
| `revealDuration` | `number` | `2200` | ms of the count, or until the last reel locks (holds and the pop come on top). |
|
|
744
|
+
| `revealBounce` | `number` | `0.12` | Peak overshoot of the landing pop and the milestone punches; `0` = none. |
|
|
745
|
+
| `revealGrow` | `number` | `0.2` | `count`: how much smaller the figure opens, growing to full size over the count. |
|
|
746
|
+
| `revealStagger` | `number` | `200` | `spin`: ms between reel stops, shortened to fit the duration. |
|
|
747
|
+
| `revealMilestones` | `number[]` | – | `count`: tiers in the figure's units; the count lands on each, punches, holds, then accelerates again. |
|
|
748
|
+
| `revealMilestoneHold` | `number` | `0` | `count`: ms the count pauses on each milestone. |
|
|
749
|
+
| `onRevealMilestone` | `(index, value) => void` | – | The count reached a milestone. |
|
|
750
|
+
| `onRevealEnd` | `() => void` | – | The reveal landed (pop rung out). |
|
|
751
|
+
| `loading` | `boolean` | `false` | "Shine" glint: a slanted, text-wide band sweeps through the ink; cross-fades on toggle. |
|
|
752
|
+
| `shimmerColor` | `ColorValue` | light neutral | Color of the glint's core (`#D6D9E1`, `#2B2E37` in dark mode). |
|
|
753
|
+
| `shimmerDuration` | `number` | `950` | ms per sweep (linear, repeating). |
|
|
754
|
+
| `fontSize` | `number` | `32` | Font size of the digits in points. |
|
|
755
|
+
| `prefixFontSize` / `suffixFontSize` | `number` | `fontSize` | Smaller (or larger) prefix/suffix, e.g. a currency symbol or code. |
|
|
756
|
+
| `affixAlign` | `'baseline' \| 'center' \| 'top' \| 'bottom'` | `'baseline'` | How prefix/suffix line up with the digits: `top` pins the glyph tops (cap height), `bottom` the bottom of the glyphs' ink (a currency code sits on the digits' baseline, not down where a comma's tail reaches). |
|
|
757
|
+
| `prefixAlign` / `suffixAlign` | same | `affixAlign` | Per-affix override, e.g. `$` pinned top and `USD` pinned bottom. |
|
|
758
|
+
| `adjustsFontSizeToFit` | `boolean` | `false` | Shrink the whole number to fit the view's fixed `width`; the view keeps its full height. |
|
|
759
|
+
| `minimumFontScale` | `number` | `0.5` | Lower bound for `adjustsFontSizeToFit`. |
|
|
760
|
+
| `allowFontScaling` | `boolean` | `false` | Follow the system text size like `Text` (off by default so amounts keep their design size). |
|
|
761
|
+
| `maxFontSizeMultiplier` | `number` | `0` | Cap for `allowFontScaling`; `0` = no cap. |
|
|
762
|
+
| `fontWeight` | `TextStyle['fontWeight']` | `'normal'` | Font weight. |
|
|
763
|
+
| `fontFamily` | `string` | system | Font family, resolved like `Text` (bundled / expo-font fonts work). |
|
|
764
|
+
| `color` | `ColorValue` | label color | Text color. |
|
|
765
|
+
| `textAlign` | `'auto' \| 'left' \| 'center' \| 'right'` | `'auto'` | Alignment inside a wider frame. `'auto'` is the start edge of the layout direction, except in a view that hugs the number: there it is the edge the parent keeps the view to, so a figure at the end of a row grows and shrinks from its right edge. `'left'` and `'right'` are absolute. In a right-to-left app the prefix sits at the right edge and the suffix at the left, and the digits keep reading left to right. |
|
|
766
|
+
| `onNativeRef` | `(ref) => void` | – | Receives the Nitro object on mount. |
|
|
767
|
+
| `style`, `testID`, … | `ViewProps` | – | Regular view props. |
|
|
768
|
+
|
|
769
|
+
The view reports its intrinsic size from native and sizes itself. Give it an
|
|
770
|
+
explicit `width` in `style` plus `textAlign="right"` if you don't want the layout
|
|
771
|
+
to reflow while digits appear (e.g. a counter that grows past `999`).
|
|
772
|
+
|
|
504
773
|
## Accessibility and threading
|
|
505
774
|
|
|
775
|
+
### NitroInput
|
|
776
|
+
|
|
506
777
|
- The system field remains the accessibility element, with the formatted text
|
|
507
778
|
(`$1,234.50 USD` reads as such); VoiceOver / TalkBack, autofill, the paste
|
|
508
779
|
menu and selection all work as in a plain input.
|
|
509
780
|
- Reduce Motion (iOS) and "Remove animations" (Android) snap.
|
|
510
781
|
- The view implements Nitro's `RecyclableView`.
|
|
511
782
|
- Every keystroke is handled on the main thread: the formatter runs, the field
|
|
512
|
-
is updated, the
|
|
783
|
+
is updated, the reflow starts. `onChangeText` reaches JS afterwards; nothing
|
|
513
784
|
the user sees waits for it. A `value` prop carrying a stale
|
|
514
785
|
`mostRecentEventCount` (the user typed since) is ignored, like React
|
|
515
786
|
Native's own `TextInput`.
|
|
516
787
|
|
|
788
|
+
### NitroNumber
|
|
789
|
+
|
|
790
|
+
- VoiceOver / TalkBack read the formatted amount (prefix, sign, grouped digits,
|
|
791
|
+
suffix, e.g. `$1,234.50 USD`), updated whenever the value changes; while
|
|
792
|
+
`loading` the element is announced as loading.
|
|
793
|
+
- Reduce Motion (iOS) and "Remove animations" / animator scale 0 (Android)
|
|
794
|
+
snap to the new value instead of rolling, and freeze the loading glint.
|
|
795
|
+
- The view implements Nitro's `RecyclableView`, so Fabric reuses instances in
|
|
796
|
+
long lists; a recycled view forgets all props and animation state first.
|
|
797
|
+
- Custom fonts resolve like `Text`: on iOS by PostScript or family name from
|
|
798
|
+
`UIAppFonts`, on Android through React Native's font manager (`assets/fonts`,
|
|
799
|
+
`res/font`, or fonts registered by expo-font).
|
|
800
|
+
|
|
801
|
+
#### Performance
|
|
802
|
+
|
|
803
|
+
- A `value` change is delivered by React once; from there the roll runs
|
|
804
|
+
natively (`CADisplayLink` on the main run loop, `ValueAnimator` on the UI
|
|
805
|
+
thread). A busy JS thread delays the *next* value, never the animation in
|
|
806
|
+
flight, the shimmer, or the shrink-to-fit scaling.
|
|
807
|
+
- On iOS a frame never redraws a bitmap: each glyph and wheel is a `CALayer`
|
|
808
|
+
with a pre-rasterized image (a wheel is a clipped strip of the digits), and a
|
|
809
|
+
frame only moves layers, so the render server composites the roll. The
|
|
810
|
+
Core Graphics path is used only while the loading glint is showing. On
|
|
811
|
+
Android a frame is about a dozen `Canvas.drawText` calls through HWUI's glyph
|
|
812
|
+
cache. Scaling is a layer / canvas transform, so no fonts are rebuilt while
|
|
813
|
+
fitting.
|
|
814
|
+
- `jumpTo` / `animateTo` coalesce: only the newest value per main-thread turn
|
|
815
|
+
is applied, so pushing a value every frame into many views never builds a
|
|
816
|
+
backlog of main-thread dispatches.
|
|
817
|
+
- The only JS round trip is auto-sizing: when the digit count changes the view
|
|
818
|
+
reports its new intrinsic size and React applies it. Give the view a fixed
|
|
819
|
+
`width` (recommended for amounts anyway) and nothing depends on JS at all;
|
|
820
|
+
in auto-size mode the view is not clipped, so a late size update never cuts
|
|
821
|
+
a digit off. A size that grows is reported at once; a size that shrinks is
|
|
822
|
+
reported when the roll has finished, so the box never squeezes digits that
|
|
823
|
+
are still on their way out.
|
|
824
|
+
|
|
825
|
+
## How NitroNumber works
|
|
826
|
+
|
|
827
|
+
- All behaviour lives in one shared C++ engine (`cpp/RollingEngine.hpp`): each
|
|
828
|
+
digit is a wheel with a continuous position on a `0–9` strip; the engine
|
|
829
|
+
computes rolls (shortest path in the roll direction, blank↔digit for
|
|
830
|
+
appearing/disappearing wheels), stagger, easing/spring curves, the odometer
|
|
831
|
+
carry rule for `jumpTo`, the loading fade, the shimmer phase, the jackpot
|
|
832
|
+
reveals (count curve, tiers, reels, landing pop), the numeric transition's
|
|
833
|
+
springs and the clocks of a prefix, suffix, separator or decimal change.
|
|
834
|
+
- The Swift view calls the engine directly through Swift/C++ interop; the
|
|
835
|
+
Kotlin view through a 60-line fbjni handle (the only hand-written JNI). Each
|
|
836
|
+
platform only owns fonts, layout, fit-to-width and text drawing, and drives
|
|
837
|
+
the engine from a `CADisplayLink` / `Choreographer` loop.
|
|
838
|
+
- A frame is about a dozen cached glyph draws with Core Graphics / `Canvas`.
|
|
839
|
+
- Props are parsed by Nitro from JSI (no Fabric codegen); the view is a Fabric
|
|
840
|
+
component, so `style`, `opacity`, `transform` and friends work as usual.
|
|
841
|
+
|
|
517
842
|
## Credits
|
|
518
843
|
|
|
519
|
-
The
|
|
844
|
+
The reflow is based on [Torph](https://torph.lochie.me) by
|
|
520
845
|
[Lochie Axon](https://github.com/lochie). Thanks for building it.
|
|
521
846
|
|
|
522
847
|
## License
|
package/android/CMakeLists.txt
CHANGED
|
@@ -8,15 +8,17 @@ set (CMAKE_CXX_STANDARD 20)
|
|
|
8
8
|
# Define C++ library and add all sources
|
|
9
9
|
add_library(${PACKAGE_NAME} SHARED
|
|
10
10
|
src/main/cpp/cpp-adapter.cpp
|
|
11
|
-
src/main/cpp/
|
|
11
|
+
src/main/cpp/JReflowEngine.cpp
|
|
12
12
|
src/main/cpp/JAmountFormatter.cpp
|
|
13
13
|
src/main/cpp/JMaskEngine.cpp
|
|
14
14
|
src/main/cpp/JOutlineGeometry.cpp
|
|
15
15
|
src/main/cpp/JNitroInputWorklets.cpp
|
|
16
|
-
|
|
16
|
+
src/main/cpp/JRollingEngine.cpp
|
|
17
|
+
../cpp/ReflowEngine.cpp
|
|
17
18
|
../cpp/AmountFormatter.cpp
|
|
18
19
|
../cpp/MaskEngine.cpp
|
|
19
20
|
../cpp/OutlineGeometry.cpp
|
|
21
|
+
../cpp/RollingEngine.cpp
|
|
20
22
|
../cpp/worklets/NitroInputWorkletsBridge.cpp
|
|
21
23
|
../cpp/worklets/HybridNitroInputWorklets.cpp
|
|
22
24
|
)
|
|
@@ -35,7 +37,7 @@ include_directories(
|
|
|
35
37
|
# run `transform` / `onChangeText` worklets synchronously on the UI thread.
|
|
36
38
|
find_package(react-native-worklets CONFIG QUIET)
|
|
37
39
|
if(react-native-worklets_FOUND)
|
|
38
|
-
target_compile_definitions(${PACKAGE_NAME} PRIVATE
|
|
40
|
+
target_compile_definitions(${PACKAGE_NAME} PRIVATE NITRO_INPUT_WORKLETS=1)
|
|
39
41
|
target_link_libraries(${PACKAGE_NAME} react-native-worklets::worklets)
|
|
40
42
|
message(STATUS "NitroInput: react-native-worklets found, worklet support enabled")
|
|
41
43
|
else()
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// y, radius, startAngle, sweepAngle - rather than as objects: the view reuses
|
|
10
10
|
// one array, and the geometry is traced into a vector this object keeps (the
|
|
11
11
|
// `std::vector<double>` overload of `OutlineGeometry::outline`), so redrawing
|
|
12
|
-
// the frame allocates nothing on either side, the same trick
|
|
12
|
+
// the frame allocates nothing on either side, the same trick JReflowEngine
|
|
13
13
|
// uses for its glyphs.
|
|
14
14
|
//
|
|
15
15
|
// `gapFor` needs no bridge. It only clamps, and `outline` already treats a
|