react-native-nitro-input 0.1.0 → 0.3.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 +343 -3
- package/NitroInput.podspec +4 -4
- package/README.md +420 -53
- package/android/CMakeLists.txt +9 -3
- package/android/gradle.properties +1 -1
- 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 +223 -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 +21 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatform.kt +209 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +496 -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 +107 -26
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +1881 -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 +60 -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 +1234 -0
- package/cpp/RollingEngine.hpp +475 -0
- package/cpp/SwiftNonCopyable.hpp +22 -0
- package/cpp/numberformat/HybridNitroNumberFormat.cpp +498 -0
- package/cpp/numberformat/HybridNitroNumberFormat.hpp +74 -0
- package/cpp/numberformat/HybridNitroNumberFormatFactory.hpp +11 -0
- package/cpp/numberformat/NumberFormatCore.cpp +629 -0
- package/cpp/numberformat/NumberFormatCore.hpp +154 -0
- package/cpp/numberformat/NumberFormatProbe.cpp +354 -0
- package/cpp/numberformat/NumberFormatProbe.hpp +63 -0
- package/cpp/worklets/NitroInputWorkletsBridge.cpp +3 -3
- package/cpp/worklets/NitroInputWorkletsBridge.hpp +1 -1
- package/ios/{HybridMorphInputView.swift → HybridNitroInputView.swift} +16 -1
- package/ios/HybridNitroNumberFormatPlatform.swift +348 -0
- package/ios/HybridNitroNumberView.swift +458 -0
- package/ios/NitroInputView.swift +148 -64
- package/ios/NitroNumberView.swift +2074 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +61 -0
- package/lib/commonjs/src/NitroInput.js +27 -56
- package/lib/commonjs/src/NitroNumber.js +141 -0
- package/lib/commonjs/src/NumberFormat.js +525 -0
- package/lib/commonjs/src/formatProps.js +48 -0
- package/lib/commonjs/src/index.js +6 -3
- package/lib/commonjs/src/specs/NitroNumber.nitro.js +2 -0
- package/lib/commonjs/src/specs/NumberFormat.nitro.js +2 -0
- package/lib/commonjs/src/styleHelpers.js +36 -0
- package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
- package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +61 -0
- package/lib/module/src/NitroInput.js +18 -47
- package/lib/module/src/NitroNumber.js +102 -0
- package/lib/module/src/NumberFormat.js +521 -0
- package/lib/module/src/formatProps.js +45 -0
- package/lib/module/src/index.js +2 -1
- package/lib/module/src/specs/NitroNumber.nitro.js +1 -0
- package/lib/module/src/specs/NumberFormat.nitro.js +1 -0
- package/lib/module/src/styleHelpers.js +32 -0
- package/lib/typescript/src/NitroInput.d.ts +50 -21
- package/lib/typescript/src/NitroNumber.d.ts +246 -0
- package/lib/typescript/src/NumberFormat.d.ts +47 -0
- package/lib/typescript/src/formatProps.d.ts +21 -0
- package/lib/typescript/src/index.d.ts +5 -2
- package/lib/typescript/src/specs/NitroInput.nitro.d.ts +19 -9
- package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +250 -0
- package/lib/typescript/src/specs/NumberFormat.nitro.d.ts +139 -0
- package/lib/typescript/src/styleHelpers.d.ts +3 -0
- package/nitro.json +26 -0
- package/nitrogen/generated/android/NitroInput+autolinking.cmake +10 -0
- package/nitrogen/generated/android/NitroInputOnLoad.cpp +48 -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++/JHybridNitroInputViewSpec.cpp +45 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +10 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberFormatPlatformSpec.cpp +118 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberFormatPlatformSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +590 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +168 -0
- package/nitrogen/generated/android/c++/JHybridNitroPlatformNumberFormatterSpec.cpp +65 -0
- package/nitrogen/generated/android/c++/JHybridNitroPlatformNumberFormatterSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroNumberAffixAlign.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroNumberDirection.hpp +64 -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++/JNumberFormatCompactDisplay.hpp +58 -0
- package/nitrogen/generated/android/c++/JNumberFormatCurrencyDisplay.hpp +64 -0
- package/nitrogen/generated/android/c++/JNumberFormatCurrencySign.hpp +58 -0
- package/nitrogen/generated/android/c++/JNumberFormatNotation.hpp +64 -0
- package/nitrogen/generated/android/c++/JNumberFormatPlatformOptions.hpp +161 -0
- package/nitrogen/generated/android/c++/JNumberFormatPlatformSymbols.hpp +89 -0
- package/nitrogen/generated/android/c++/JNumberFormatRoundingMode.hpp +79 -0
- package/nitrogen/generated/android/c++/JNumberFormatSignDisplay.hpp +67 -0
- package/nitrogen/generated/android/c++/JNumberFormatStyle.hpp +64 -0
- package/nitrogen/generated/android/c++/JNumberFormatUnitDisplay.hpp +61 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +25 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +329 -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/HybridNitroInputViewSpec.kt +30 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatformSpec.kt +60 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +399 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroPlatformNumberFormatterSpec.kt +62 -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 +25 -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/NumberFormatCompactDisplay.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatCurrencyDisplay.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatCurrencySign.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatNotation.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatPlatformOptions.kt +136 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatPlatformSymbols.kt +91 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatRoundingMode.kt +30 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatSignDisplay.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatStyle.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatUnitDisplay.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 +59 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +311 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +63 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.mm +26 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.swift +24 -0
- package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +30 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberFormatPlatformSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberFormatPlatformSpecSwift.hpp +122 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +474 -0
- package/nitrogen/generated/ios/c++/HybridNitroPlatformNumberFormatterSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroPlatformNumberFormatterSpecSwift.hpp +94 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +30 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +450 -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/HybridNitroInputViewSpec.swift +5 -0
- package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +55 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberFormatPlatformSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberFormatPlatformSpec_cxx.swift +159 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +108 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +1387 -0
- package/nitrogen/generated/ios/swift/HybridNitroPlatformNumberFormatterSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridNitroPlatformNumberFormatterSpec_cxx.swift +155 -0
- package/nitrogen/generated/ios/swift/NitroNumberAffixAlign.swift +48 -0
- package/nitrogen/generated/ios/swift/NitroNumberDirection.swift +48 -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/ios/swift/NumberFormatCompactDisplay.swift +40 -0
- package/nitrogen/generated/ios/swift/NumberFormatCurrencyDisplay.swift +48 -0
- package/nitrogen/generated/ios/swift/NumberFormatCurrencySign.swift +40 -0
- package/nitrogen/generated/ios/swift/NumberFormatNotation.swift +48 -0
- package/nitrogen/generated/ios/swift/NumberFormatPlatformOptions.swift +159 -0
- package/nitrogen/generated/ios/swift/NumberFormatPlatformSymbols.swift +69 -0
- package/nitrogen/generated/ios/swift/NumberFormatRoundingMode.swift +68 -0
- package/nitrogen/generated/ios/swift/NumberFormatSignDisplay.swift +52 -0
- package/nitrogen/generated/ios/swift/NumberFormatStyle.swift +48 -0
- package/nitrogen/generated/ios/swift/NumberFormatUnitDisplay.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +10 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +10 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatFactorySpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatFactorySpec.hpp +70 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatPlatformSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatPlatformSpec.hpp +70 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +127 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +187 -0
- package/nitrogen/generated/shared/c++/HybridNitroPlatformNumberFormatterSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridNitroPlatformNumberFormatterSpec.hpp +65 -0
- package/nitrogen/generated/shared/c++/NitroNumberAffixAlign.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroNumberDirection.hpp +84 -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++/NumberFormatCompactDisplay.hpp +76 -0
- package/nitrogen/generated/shared/c++/NumberFormatCurrencyDisplay.hpp +84 -0
- package/nitrogen/generated/shared/c++/NumberFormatCurrencySign.hpp +76 -0
- package/nitrogen/generated/shared/c++/NumberFormatGrouping.hpp +80 -0
- package/nitrogen/generated/shared/c++/NumberFormatNotation.hpp +84 -0
- package/nitrogen/generated/shared/c++/NumberFormatOptions.hpp +193 -0
- package/nitrogen/generated/shared/c++/NumberFormatPart.hpp +87 -0
- package/nitrogen/generated/shared/c++/NumberFormatPlatformOptions.hpp +176 -0
- package/nitrogen/generated/shared/c++/NumberFormatPlatformSymbols.hpp +115 -0
- package/nitrogen/generated/shared/c++/NumberFormatRoundingMode.hpp +104 -0
- package/nitrogen/generated/shared/c++/NumberFormatRoundingPriority.hpp +80 -0
- package/nitrogen/generated/shared/c++/NumberFormatSignDisplay.hpp +88 -0
- package/nitrogen/generated/shared/c++/NumberFormatStyle.hpp +84 -0
- package/nitrogen/generated/shared/c++/NumberFormatTrailingZeroDisplay.hpp +76 -0
- package/nitrogen/generated/shared/c++/NumberFormatUnitDisplay.hpp +80 -0
- package/nitrogen/generated/shared/c++/ResolvedNumberFormatOptions.hpp +197 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +10 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +15 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +136 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +245 -0
- package/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
- package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +61 -0
- package/package.json +15 -7
- package/src/NitroInput.tsx +79 -67
- package/src/NitroNumber.tsx +531 -0
- package/src/NumberFormat.ts +563 -0
- package/src/formatProps.ts +59 -0
- package/src/index.ts +38 -6
- package/src/specs/NitroInput.nitro.ts +19 -9
- package/src/specs/NitroNumber.nitro.ts +271 -0
- package/src/specs/NumberFormat.nitro.ts +145 -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,36 @@
|
|
|
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
|
+
- **[`NumberFormat`](#numberformat)**: `Intl.NumberFormat`, formatted
|
|
15
|
+
natively. It learns a locale's format once from the platform and formats in
|
|
16
|
+
C++, with Hermes' output and a fraction of its cost.
|
|
17
|
+
|
|
18
|
+
Fabric only (new architecture), React Native ≥ 0.78, Nitro Modules ≥ 0.37.
|
|
19
|
+
|
|
20
|
+
Docs, live demos and benchmarks: **https://ronickg.github.io/react-native-nitro-input/**
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
bun add react-native-nitro-input react-native-nitro-modules
|
|
26
|
+
cd ios && pod install
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
> **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.
|
|
30
|
+
|
|
31
|
+
## NitroInput
|
|
32
|
+
|
|
33
|
+
A native **text input**: a
|
|
5
34
|
system text field (`UITextField` / `EditText`) that owns the keyboard, editing,
|
|
6
35
|
selection, paste and accessibility, with native formatting, native masking and
|
|
7
36
|
an outlined or filled frame with a floating label on top of it.
|
|
@@ -12,9 +41,9 @@ import { NitroInput } from 'react-native-nitro-input'
|
|
|
12
41
|
<NitroInput variant="outlined" label="Email address" keyboardType="email-address" />
|
|
13
42
|
```
|
|
14
43
|
|
|
15
|
-
`
|
|
16
|
-
where
|
|
17
|
-
|
|
44
|
+
`transition="reflow"` animates the characters as they change, for the one case
|
|
45
|
+
where that is the point — an amount. It is not the default, and for an
|
|
46
|
+
ordinary form field you do not want it.
|
|
18
47
|
|
|
19
48
|
- **It is a real input.** Focus, blur, return key, keyboard types,
|
|
20
49
|
auto-capitalisation, max length, selection, the text-input registry, all the
|
|
@@ -31,26 +60,14 @@ and for an ordinary form field you do not want it.
|
|
|
31
60
|
decimals, a currency `prefix` / `suffix`, the caret kept where you typed. No
|
|
32
61
|
JS round trip, so none of the flicker, caret jumps or dropped keystrokes of a
|
|
33
62
|
controlled `TextInput` that formats in `onChangeText`.
|
|
34
|
-
- **Same formatting model as [`
|
|
63
|
+
- **Same formatting model as [`NitroNumber`](#nitronumber)**:
|
|
35
64
|
prefix/suffix at their own font sizes, pinned to the top, bottom, baseline or
|
|
36
65
|
centre of the digits; grouping and decimal separators of your choice.
|
|
37
66
|
- **One C++ engine per concern** drives both platforms — formatting, masking,
|
|
38
|
-
the frame geometry, and (with `
|
|
67
|
+
the frame geometry, and (with `transition="reflow"`) the glyph matching and curves. Swift
|
|
39
68
|
and Kotlin only measure, draw and talk to the keyboard.
|
|
40
|
-
- Fabric only (new architecture), React Native ≥ 0.78, Nitro Modules ≥ 0.37.
|
|
41
69
|
|
|
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
|
|
70
|
+
Guide: **https://ronickg.github.io/react-native-nitro-input/docs/nitro-input**
|
|
54
71
|
|
|
55
72
|
### A text field
|
|
56
73
|
|
|
@@ -66,9 +83,9 @@ cd ios && pod install
|
|
|
66
83
|
```
|
|
67
84
|
|
|
68
85
|
`NitroInput` does not animate its characters: they appear the instant you type
|
|
69
|
-
them, the way a `TextInput` does. Pass `
|
|
70
|
-
|
|
71
|
-
|
|
86
|
+
them, the way a `TextInput` does. Pass `transition="reflow"` to turn the glyph
|
|
87
|
+
engine on — see [An amount field](#an-amount-field-the-reflow), which is where
|
|
88
|
+
it earns itself.
|
|
72
89
|
|
|
73
90
|
### A masked field
|
|
74
91
|
|
|
@@ -160,27 +177,27 @@ content, and `scrollEnabled={false}` hands the height to the content entirely.
|
|
|
160
177
|
`textAlignVertical` says where the text sits in a taller box. A multiline field
|
|
161
178
|
is always drawn by the system view and is always `mode="text"`: the glyph
|
|
162
179
|
engine lays one run out on one baseline, and an amount, a mask and their
|
|
163
|
-
affixes are single-line ideas, so `
|
|
180
|
+
affixes are single-line ideas, so `transition="reflow"`, `mode="number"`, `mode="mask"`,
|
|
164
181
|
`prefix` and `suffix` are ignored alongside it, with one warning each in
|
|
165
182
|
development. Its return key inserts a line break, as a `TextInput`'s does;
|
|
166
183
|
`submitBehavior="blurAndSubmit"` (or `blurOnSubmit`) makes it submit instead.
|
|
167
184
|
|
|
168
|
-
### An amount field (the
|
|
185
|
+
### An amount field (the reflow)
|
|
169
186
|
|
|
170
|
-
This is the one case the
|
|
171
|
-
|
|
172
|
-
arrive.
|
|
187
|
+
This is the one case the reflow is for, so it passes `transition="reflow"`.
|
|
188
|
+
A reflowing field also sizes its box to its content by default
|
|
189
|
+
(`autoWidth="auto"`), so it grows as digits arrive.
|
|
173
190
|
|
|
174
191
|
With the engine running, `mode="text"` fades and scales characters in and out
|
|
175
192
|
(Torph's text morph) while digits and separators slide in `mode="number"`,
|
|
176
193
|
unless you force one style with `effect="slide"` / `effect="fade"`.
|
|
177
194
|
|
|
178
195
|
```tsx
|
|
179
|
-
import {
|
|
196
|
+
import { NitroInput } from 'react-native-nitro-input'
|
|
180
197
|
|
|
181
198
|
const [amount, setAmount] = useState(NaN)
|
|
182
199
|
|
|
183
|
-
<
|
|
200
|
+
<NitroInput transition="reflow"
|
|
184
201
|
mode="number"
|
|
185
202
|
prefix="$"
|
|
186
203
|
prefixFontSize={28}
|
|
@@ -209,34 +226,34 @@ formatted string) and keep the field uncontrolled, or pass `value` to drive it:
|
|
|
209
226
|
```tsx
|
|
210
227
|
const [text, setText] = useState('')
|
|
211
228
|
|
|
212
|
-
<
|
|
229
|
+
<NitroInput transition="reflow" mode="number" value={text} onChangeText={setText} prefix="$" />
|
|
213
230
|
```
|
|
214
231
|
|
|
215
232
|
A `value` that merely echoes `onChangeText` back never fights the user: native
|
|
216
233
|
already shows it. A `value` that differs (a "Max" button, a clamp) is applied
|
|
217
|
-
and
|
|
234
|
+
and reflows in.
|
|
218
235
|
|
|
219
236
|
### Currency layouts
|
|
220
237
|
|
|
221
238
|
```tsx
|
|
222
239
|
// "$" smaller than the amount, aligned to the top of the digits
|
|
223
|
-
<
|
|
240
|
+
<NitroInput transition="reflow" mode="number" prefix="$" prefixFontSize={22} affixAlign="top" fontSize={44} />
|
|
224
241
|
|
|
225
242
|
// currency code after the amount, smaller and sitting on the baseline of the digits' ink
|
|
226
|
-
<
|
|
243
|
+
<NitroInput transition="reflow" mode="number" suffix=" USD" suffixFontSize={18} suffixAlign="bottom" />
|
|
227
244
|
|
|
228
245
|
// European separators: 1.234,56
|
|
229
|
-
<
|
|
246
|
+
<NitroInput transition="reflow" mode="number" groupingSeparator="." decimalSeparator="," />
|
|
230
247
|
|
|
231
248
|
// whole numbers only (no decimal key accepted), at most six digits
|
|
232
|
-
<
|
|
249
|
+
<NitroInput transition="reflow" mode="number" fractionDigits={0} maxIntegerDigits={6} />
|
|
233
250
|
|
|
234
251
|
// a big centred amount that shrinks when it gets long
|
|
235
|
-
<
|
|
252
|
+
<NitroInput transition="reflow" mode="number" fontSize={64} adjustsFontSizeToFit minimumFontScale={0.4} textAlign="center" style={{ width: '100%' }} />
|
|
236
253
|
```
|
|
237
254
|
|
|
238
255
|
In a right-to-left layout the prefix sits at the right edge and the suffix at
|
|
239
|
-
the left, plain or
|
|
256
|
+
the left, plain or reflowed; the digits keep reading left to right.
|
|
240
257
|
|
|
241
258
|
Whatever the keyboard's decimal key produces (`.` or `,`) counts as the
|
|
242
259
|
decimal separator; nobody types a grouping separator on purpose. The rules
|
|
@@ -353,13 +370,13 @@ the worklets UI runtime is handed to native once, the worklet is called with
|
|
|
353
370
|
### Imperative
|
|
354
371
|
|
|
355
372
|
```tsx
|
|
356
|
-
const ref = useRef<
|
|
373
|
+
const ref = useRef<NitroInputHandle>(null)
|
|
357
374
|
|
|
358
|
-
<
|
|
375
|
+
<NitroInput transition="reflow" ref={ref} mode="number" />
|
|
359
376
|
|
|
360
377
|
ref.current?.focus()
|
|
361
378
|
ref.current?.blur()
|
|
362
|
-
ref.current?.setValue(1234.56) // shows "1,234.56",
|
|
379
|
+
ref.current?.setValue(1234.56) // shows "1,234.56", reflowing from whatever was there
|
|
363
380
|
ref.current?.setText('98,765') // same, from a string in the field's format
|
|
364
381
|
ref.current?.clear()
|
|
365
382
|
ref.current?.getText() // "1,234.56"
|
|
@@ -374,7 +391,7 @@ place. Typing uses **caret matching**: the characters on either side of the
|
|
|
374
391
|
caret keep their identity, so inserting a `9` into `12|34` slides `34` over
|
|
375
392
|
rather than renumbering the columns.
|
|
376
393
|
|
|
377
|
-
##
|
|
394
|
+
## NitroInput props
|
|
378
395
|
|
|
379
396
|
| Prop | Type | Default | Description |
|
|
380
397
|
| --- | --- | --- | --- |
|
|
@@ -402,11 +419,15 @@ rather than renumbering the columns.
|
|
|
402
419
|
| `prefixFontSize` / `suffixFontSize` | `number` | `fontSize` | Their own sizes. |
|
|
403
420
|
| `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
421
|
| `prefixAlign` / `suffixAlign` | same | `affixAlign` | Per-affix override. |
|
|
405
|
-
| `
|
|
422
|
+
| `letterSpacing` | number | `0` | Points added after every glyph, like `Text`'s; a smaller affix gets it in proportion to its size. |
|
|
423
|
+
| `prefixSpacing` / `suffixSpacing` | number | the letter spacing | Points between the prefix and the text, and between the text and the suffix. |
|
|
424
|
+
| `prefixOffset` / `suffixOffset` | number | `0` | Points an affix is moved down after its alignment (negative: up). |
|
|
425
|
+
| `format` | `NumberFormat` | none | The amount follows it: prefix and suffix, separators, fraction digits, where the sign goes. Sets `mode="number"`; the individual props override it. |
|
|
426
|
+
| `placeholder` | `string` | `''` | Shown while empty; the first character reflows it away. `'0'` reads well for amounts. |
|
|
406
427
|
| `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
|
|
428
|
+
| `transition` | `'none' \| 'reflow'` | `'none'` | `'reflow'` runs the glyph engine, so characters glide, slide and fade as the text changes. |
|
|
429
|
+
| `autoWidth` | `boolean \| 'auto'` | `false`; `'auto'` when reflowing | `false` takes no width, so flexbox stretches it like a `TextInput`; `'auto'` infers it from `style`. |
|
|
430
|
+
| `duration` | `number` | `400` | ms of the reflow; `0` snaps. |
|
|
410
431
|
| `easing` | `'expo' \| 'easeOut' \| 'easeInOut' \| 'linear' \| 'spring'` | `'expo'` | Timing curve. `expo` is Torph's `cubic-bezier(0.19, 1, 0.22, 1)`. |
|
|
411
432
|
| `bounce` | `number` | `0.15` | Overshoot of the `spring` easing (0–1). |
|
|
412
433
|
| `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 +437,7 @@ rather than renumbering the columns.
|
|
|
416
437
|
| `color` | `ColorValue` | label color | Text color. |
|
|
417
438
|
| `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
439
|
| `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; `
|
|
440
|
+
| `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
441
|
| `numberOfLines` / `rows` | `number` | `0` | `multiline`: lines tall before it scrolls; `0` grows with the content. |
|
|
421
442
|
| `textAlignVertical` | `'auto' \| 'top' \| 'center' \| 'bottom'` | `'auto'` | `multiline`: where the text sits in a taller box. |
|
|
422
443
|
| `scrollEnabled` | `boolean` | `true` | `multiline`: scroll once the text outgrows the field; `false` lets a growing field drive its own height. |
|
|
@@ -454,7 +475,7 @@ rather than renumbering the columns.
|
|
|
454
475
|
| `onChange` | `(event) => void` | – | Fired alongside `onChangeText` with the same text; `nativeEvent.eventCount` is the native edit counter, as on `TextInput`. |
|
|
455
476
|
| `onChangeValue` | `(value) => void` | – | `number` mode: the numeric value, `NaN` while empty. A `'worklet'` runs on the UI thread. |
|
|
456
477
|
| `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`.
|
|
478
|
+
| `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
479
|
| `onFocus` / `onBlur` | `(event) => void` | – | Carries `text`, `eventCount` and `target`. |
|
|
459
480
|
| `onSubmitEditing` | `(event) => void` | – | Return key pressed; what happens next is `submitBehavior`. |
|
|
460
481
|
| `onEndEditing` | `(event) => void` | – | Editing finished. |
|
|
@@ -476,10 +497,10 @@ onSubmitEditing={e => search(e.nativeEvent.text)} // as on a TextInput
|
|
|
476
497
|
onSubmitEditing={({ text }) => search(text)} // or just this
|
|
477
498
|
```
|
|
478
499
|
|
|
479
|
-
## How the
|
|
500
|
+
## How the reflow decides what moves
|
|
480
501
|
|
|
481
502
|
Each update pairs the old characters with the new ones (Torph's rules,
|
|
482
|
-
implemented in `cpp/
|
|
503
|
+
implemented in `cpp/ReflowEngine.cpp`):
|
|
483
504
|
|
|
484
505
|
- **Typing** (a caret is known): everything before the caret pairs by
|
|
485
506
|
position from the left, everything after it from the right, so the edit is
|
|
@@ -496,27 +517,373 @@ implemented in `cpp/MorphEngine.cpp`):
|
|
|
496
517
|
|
|
497
518
|
A character that persists eases to its new x. A new digit drops in from above
|
|
498
519
|
(a separator rises from below) through the clipped line box, fading in over the
|
|
499
|
-
first quarter of the
|
|
520
|
+
first quarter of the reflow; a leaving digit drops out the same way, fading over
|
|
500
521
|
the first 45 %. Text characters fade and scale (0.95×) instead. Characters that
|
|
501
522
|
enter or leave ride along with their nearest persisting neighbour, so a word
|
|
502
523
|
that grows or shrinks stays one shape. All of it is Reduce Motion aware.
|
|
503
524
|
|
|
525
|
+
## NitroNumber
|
|
526
|
+
|
|
527
|
+
A number that animates its changes natively, with the same look on iOS
|
|
528
|
+
**and** Android: every digit a wheel that rolls to its new glyph (an odometer /
|
|
529
|
+
ticker), or SwiftUI's `.contentTransition(.numericText())`, or a scramble.
|
|
530
|
+
|
|
531
|
+
- Change the `value` prop and the digits roll natively: per digit, direction
|
|
532
|
+
aware, with easing or spring curves and an optional cascading `stagger`.
|
|
533
|
+
- Formatting on the native side: fraction digits, grouping separator, decimal
|
|
534
|
+
separator, prefix/suffix (with their own font sizes), zero padding, negatives.
|
|
535
|
+
- Columns appear and disappear smoothly (`999 → 1000` slides a new `1` in while
|
|
536
|
+
the layout widens), and the view auto-sizes to its content.
|
|
537
|
+
- `adjustsFontSizeToFit` keeps a fixed box and scales the amount to fit.
|
|
538
|
+
- `loading` shows a text-shaped shimmer skeleton that cross-fades to the value.
|
|
539
|
+
- `reveal` plays the casino "you won" presentation natively: the win-meter
|
|
540
|
+
rollup (with tiers that punch and hold) or slot reels that lock from the left.
|
|
541
|
+
- A currency switch plays as one change: prefix, suffix and separators blur
|
|
542
|
+
across, decimal columns open and close, the digits swap or roll.
|
|
543
|
+
- `animateTo` / `jumpTo` on the Nitro object work from a Reanimated worklet.
|
|
544
|
+
|
|
545
|
+
Guide: **https://ronickg.github.io/react-native-nitro-input/docs/nitro-number**
|
|
546
|
+
|
|
547
|
+
```tsx
|
|
548
|
+
import { NitroNumber } from 'react-native-nitro-input'
|
|
549
|
+
|
|
550
|
+
<NitroNumber
|
|
551
|
+
value={balance}
|
|
552
|
+
fractionDigits={2}
|
|
553
|
+
groupingSeparator=","
|
|
554
|
+
prefix="$"
|
|
555
|
+
fontSize={48}
|
|
556
|
+
fontWeight="700"
|
|
557
|
+
color="#0A84FF"
|
|
558
|
+
easing="spring"
|
|
559
|
+
bounce={0.2}
|
|
560
|
+
stagger={40}
|
|
561
|
+
/>
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
Whenever `value` changes, each digit rolls from its old glyph to its new one in
|
|
565
|
+
the direction of the change. The first value is shown without animation.
|
|
566
|
+
|
|
567
|
+
### The transitions
|
|
568
|
+
|
|
569
|
+
```tsx
|
|
570
|
+
<NitroNumber value={count} transition="numeric" fontSize={48} fontWeight="700" />
|
|
571
|
+
<NitroNumber value={count} transition="scramble" />
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
The roll is the default. The others swap each changed glyph in place, digits
|
|
575
|
+
that don't change staying put, the change cascading from the leftmost changed
|
|
576
|
+
digit to the right (`stagger`); `duration` and `easing` apply to all of them,
|
|
577
|
+
each with its own defaults.
|
|
578
|
+
|
|
579
|
+
- **`numeric`**, after SwiftUI's `.contentTransition(.numericText())`: the
|
|
580
|
+
old glyph softens, shrinks and slides out; the new one slides in from the
|
|
581
|
+
other side, nearly full size and out of focus, and resolves. The glyphs move
|
|
582
|
+
up when the value grows and down when it shrinks (`direction` overrides
|
|
583
|
+
that). The blur is real on all three platforms: a blurred copy of each
|
|
584
|
+
glyph rendered once per font and cross-faded with the sharp one, so a frame
|
|
585
|
+
costs the same as a frame of a roll.
|
|
586
|
+
- **`scramble`**: each changed digit shows a different random digit every
|
|
587
|
+
few frames, never the one it is leaving or arriving at, and locks on its
|
|
588
|
+
target; the lock runs from the left.
|
|
589
|
+
|
|
590
|
+
Two more things happen on a change if you ask for them, with any transition:
|
|
591
|
+
|
|
592
|
+
```tsx
|
|
593
|
+
<NitroNumber value={price} flashUpColor="#16a34a" flashDownColor="#dc2626" popOnChange={0.08} />
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
`flashUpColor` / `flashDownColor` is the change flash of a trading screen:
|
|
597
|
+
every digit whose glyph changes lights up in the up colour when the value grew
|
|
598
|
+
and the down colour when it shrank, stays lit while it moves, and fades back
|
|
599
|
+
over `flashDuration` (600 ms) once it has landed.
|
|
600
|
+
`popOnChange` punches the whole figure on every change, its peak overshoot as
|
|
601
|
+
a fraction of the size, rung out like the reveal's landing pop.
|
|
602
|
+
|
|
603
|
+
### Currency layouts and fitting a width
|
|
604
|
+
|
|
605
|
+
```tsx
|
|
606
|
+
// "$" smaller than the amount, aligned to the top of the digits
|
|
607
|
+
<NitroNumber value={total} prefix="$" prefixFontSize={22} affixAlign="top" fontSize={44} />
|
|
608
|
+
|
|
609
|
+
// currency code after the amount, smaller and pinned to the bottom
|
|
610
|
+
<NitroNumber value={total} suffix=" USD" suffixFontSize={18} suffixAlign="bottom" fractionDigits={2} />
|
|
611
|
+
|
|
612
|
+
// both at once: "$" pinned top, "USD" pinned bottom
|
|
613
|
+
<NitroNumber value={total} prefix="$" prefixAlign="top" suffix=" USD" suffixAlign="bottom" prefixFontSize={22} suffixFontSize={16} />
|
|
614
|
+
|
|
615
|
+
// fit the container without a fixed width: full size until it would overflow, then it shrinks
|
|
616
|
+
<NitroNumber value={total} fontSize={52} adjustsFontSizeToFit style={{ maxWidth: '100%' }} />
|
|
617
|
+
|
|
618
|
+
// fixed box: the box never resizes, the amount shrinks (down to 50%) and grows back to fit
|
|
619
|
+
<NitroNumber
|
|
620
|
+
value={total}
|
|
621
|
+
fontSize={64}
|
|
622
|
+
adjustsFontSizeToFit
|
|
623
|
+
minimumFontScale={0.5}
|
|
624
|
+
textAlign="center"
|
|
625
|
+
style={{ width: 240 }}
|
|
626
|
+
/>
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
A view that sizes itself grows and shrinks from whichever edge its parent
|
|
630
|
+
holds it by (`textAlign="auto"`): at the end of a row it grows to the left, in
|
|
631
|
+
a centred column from its middle.
|
|
632
|
+
|
|
633
|
+
Switching currency is a change like any other: set the new `prefix`, `suffix`,
|
|
634
|
+
separators and `fractionDigits` with the new `value` and it plays as one
|
|
635
|
+
transition. The old mark blurs out as the new one comes into focus, the
|
|
636
|
+
digits keep their place value, decimal columns that go close and new ones open
|
|
637
|
+
(swapping in, or rolling up from blank), and the decimal separator fades with
|
|
638
|
+
them.
|
|
639
|
+
|
|
640
|
+
```tsx
|
|
641
|
+
<NitroNumber
|
|
642
|
+
value={round(usd * c.rate, c.digits)}
|
|
643
|
+
prefix={c.prefix} // "$" → "" → "¥" → "CHF "
|
|
644
|
+
suffix={c.suffix} // "" → " €" …
|
|
645
|
+
groupingSeparator={c.grouping}
|
|
646
|
+
decimalSeparator={c.decimal}
|
|
647
|
+
fractionDigits={c.digits} // 2 → 2 → 0 → 2
|
|
648
|
+
transition="numeric"
|
|
649
|
+
/>
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
### Loading skeleton
|
|
653
|
+
|
|
654
|
+
```tsx
|
|
655
|
+
<NitroNumber value={balance ?? 0} loading={balance === undefined} prefix="$" fractionDigits={2} />
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
While `loading` is true the glyphs keep their color and a slanted, text-wide
|
|
659
|
+
glint (`[color, shimmerColor, color]` at 10/50/90 %) sweeps through them every
|
|
660
|
+
950 ms, seeded with its core at the left edge so it shows immediately. It is
|
|
661
|
+
text-shaped, so the layout is exactly what the real number will occupy. When
|
|
662
|
+
the value arrives, flip `loading` off and set `value` in the same render: the
|
|
663
|
+
glint fades out while the digits roll to the amount.
|
|
664
|
+
|
|
665
|
+
### Jackpot reveal
|
|
666
|
+
|
|
667
|
+
```tsx
|
|
668
|
+
const [reveal, setReveal] = useState(false)
|
|
669
|
+
|
|
670
|
+
<NitroNumber
|
|
671
|
+
value={50000}
|
|
672
|
+
reveal={reveal} // false: hold "$0.00" in the final layout; true: play
|
|
673
|
+
revealStyle="count" // the win-meter rollup, or "spin" for slot reels
|
|
674
|
+
revealMilestones={[1000, 10000, 25000]}
|
|
675
|
+
revealMilestoneHold={400}
|
|
676
|
+
revealDuration={4800} // about a second per tier
|
|
677
|
+
onRevealMilestone={(index, at) => haptics.impact()}
|
|
678
|
+
onRevealEnd={() => setShowNextStep(true)}
|
|
679
|
+
prefix="$" fractionDigits={2} groupingSeparator="," textAlign="center" style={{ width: '100%' }}
|
|
680
|
+
/>
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
`count` opens at 0, smaller, and tallies up like a slot's win counter: it takes
|
|
684
|
+
off at once, runs at a constant rate (the low digits blur), grows as it climbs
|
|
685
|
+
(`revealGrow`) and crawls into the total; digits swap in place and leading
|
|
686
|
+
digits appear as the count reaches them. With `revealMilestones` (the "big win → mega
|
|
687
|
+
win" tiers, numbers in the figure's units) the count runs tier by tier: equal
|
|
688
|
+
time per tier, braking into each milestone, a punch, a pause of
|
|
689
|
+
`revealMilestoneHold` ms, then taking off again. `spin` spins every digit like
|
|
690
|
+
a slot reel and locks the reels one at a time from the left. Both land with a
|
|
691
|
+
pop. `jumpTo(value)` skips a running reveal (tap to slam). Banners, confetti
|
|
692
|
+
and sounds are the app's: the callbacks give you the beats.
|
|
693
|
+
|
|
694
|
+
### Imperative
|
|
695
|
+
|
|
696
|
+
```tsx
|
|
697
|
+
const ref = useRef<NitroNumberHandle>(null)
|
|
698
|
+
|
|
699
|
+
<NitroNumber ref={ref} value={0} />
|
|
700
|
+
|
|
701
|
+
ref.current?.animateTo(42) // rolls, like changing the prop
|
|
702
|
+
ref.current?.jumpTo(41.75) // positions the wheels continuously, no roll (scrubbing)
|
|
703
|
+
ref.current?.revealTo(1234.5) // plays a jackpot reveal
|
|
704
|
+
ref.current?.getValue() // value shown or being rolled towards
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
`jumpTo` positions every wheel from a continuous number (`41.75` shows the units
|
|
708
|
+
wheel three quarters of the way from `1` to `2`), which is what you want when a
|
|
709
|
+
scroll or drag handler drives the number.
|
|
710
|
+
|
|
711
|
+
The Nitro object (`onNativeRef`) can be captured by a Reanimated worklet as it
|
|
712
|
+
is, so the UI thread can drive the figure while JS is busy:
|
|
713
|
+
|
|
714
|
+
```tsx
|
|
715
|
+
const [price, setPrice] = useState<NitroNumberRef>()
|
|
716
|
+
|
|
717
|
+
useFrameCallback((frame) => {
|
|
718
|
+
'worklet'
|
|
719
|
+
if (price && tickDue(frame)) price.animateTo(nextPrice())
|
|
720
|
+
}, true)
|
|
721
|
+
|
|
722
|
+
<NitroNumber value={initial} onNativeRef={setPrice} />
|
|
723
|
+
```
|
|
724
|
+
|
|
725
|
+
Hand the final value back to React when the feed stops (`scheduleOnRN`) so the
|
|
726
|
+
`value` prop matches the screen; posting every tick queues them up while JS is
|
|
727
|
+
busy and replays them afterwards.
|
|
728
|
+
|
|
729
|
+
## NitroNumber props
|
|
730
|
+
|
|
731
|
+
| Prop | Type | Default | Description |
|
|
732
|
+
| --- | --- | --- | --- |
|
|
733
|
+
| `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. |
|
|
734
|
+
| `fractionDigits` | `number` | `0` | Digits after the decimal separator. |
|
|
735
|
+
| `minimumIntegerDigits` | `number` | `1` | Zero-pads the integer part. |
|
|
736
|
+
| `groupingSeparator` | `string` | `''` | Inserted every three integer digits. |
|
|
737
|
+
| `decimalSeparator` | `string` | `'.'` | Between integer and fraction digits. |
|
|
738
|
+
| `prefix` / `suffix` | `string` | `''` | Static text around the number. |
|
|
739
|
+
| `duration` | `number` | `500` | Roll duration in ms; `0` snaps. |
|
|
740
|
+
| `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. |
|
|
741
|
+
| `bounce` | `number` | `0.15` | Overshoot of the `spring` easing (0–1). |
|
|
742
|
+
| `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`. |
|
|
743
|
+
| `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). |
|
|
744
|
+
| `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. |
|
|
745
|
+
| `flashDuration` | `number` | `600` | ms a change flash takes to fade, once the digit has landed. |
|
|
746
|
+
| `popOnChange` | `number` | `0` | A punch of the whole figure on every change, peak overshoot 0–1, rung out like the reveal's landing pop. |
|
|
747
|
+
| `direction` | `'auto' \| 'up' \| 'down' \| 'shortest'` | `'auto'` | Roll direction; `auto` follows the sign of the change. `shortest` rolls each digit its own shorter way round. |
|
|
748
|
+
| `reveal` | `boolean` | – | `false` holds the opening frame (`$0.00` in the final layout); `true` plays the reveal to `value`. Unset = a normal NitroNumber. |
|
|
749
|
+
| `revealStyle` | `'count' \| 'spin'` | `'count'` | The win-meter rollup, or slot reels locking from the left. |
|
|
750
|
+
| `revealDuration` | `number` | `2200` | ms of the count, or until the last reel locks (holds and the pop come on top). |
|
|
751
|
+
| `revealBounce` | `number` | `0.12` | Peak overshoot of the landing pop and the milestone punches; `0` = none. |
|
|
752
|
+
| `revealGrow` | `number` | `0.2` | `count`: how much smaller the figure opens, growing to full size over the count. |
|
|
753
|
+
| `revealStagger` | `number` | `200` | `spin`: ms between reel stops, shortened to fit the duration. |
|
|
754
|
+
| `revealMilestones` | `number[]` | – | `count`: tiers in the figure's units; the count lands on each, punches, holds, then accelerates again. |
|
|
755
|
+
| `revealMilestoneHold` | `number` | `0` | `count`: ms the count pauses on each milestone. |
|
|
756
|
+
| `onRevealMilestone` | `(index, value) => void` | – | The count reached a milestone. |
|
|
757
|
+
| `onRevealEnd` | `() => void` | – | The reveal landed (pop rung out). |
|
|
758
|
+
| `loading` | `boolean` | `false` | "Shine" glint: a slanted, text-wide band sweeps through the ink; cross-fades on toggle. |
|
|
759
|
+
| `shimmerColor` | `ColorValue` | light neutral | Color of the glint's core (`#D6D9E1`, `#2B2E37` in dark mode). |
|
|
760
|
+
| `shimmerDuration` | `number` | `950` | ms per sweep (linear, repeating). |
|
|
761
|
+
| `fontSize` | `number` | `32` | Font size of the digits in points. |
|
|
762
|
+
| `prefixFontSize` / `suffixFontSize` | `number` | `fontSize` | Smaller (or larger) prefix/suffix, e.g. a currency symbol or code. |
|
|
763
|
+
| `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). |
|
|
764
|
+
| `prefixAlign` / `suffixAlign` | same | `affixAlign` | Per-affix override, e.g. `$` pinned top and `USD` pinned bottom. |
|
|
765
|
+
| `letterSpacing` | number | `0` | Points added after every glyph, like `Text`'s; a smaller affix gets it in proportion to its size. |
|
|
766
|
+
| `prefixSpacing` / `suffixSpacing` | number | the letter spacing | Points between the prefix and the digits, and between the digits and the suffix. |
|
|
767
|
+
| `prefixOffset` / `suffixOffset` | number | `0` | Points an affix is moved down after its alignment (negative: up). |
|
|
768
|
+
| `format` | `NumberFormat` | none | The number follows it: prefix and suffix, separators, fraction and minimum integer digits. The individual props override it. |
|
|
769
|
+
| `tabularNums` | boolean | `true` | `false` lays each digit out at its own width (proportional figures); a changing column eases once from the old digit's width to the new one's. |
|
|
770
|
+
| `adjustsFontSizeToFit` | `boolean` | `false` | Shrink the whole number to fit the view's fixed `width`; the view keeps its full height. |
|
|
771
|
+
| `minimumFontScale` | `number` | `0.5` | Lower bound for `adjustsFontSizeToFit`. |
|
|
772
|
+
| `allowFontScaling` | `boolean` | `false` | Follow the system text size like `Text` (off by default so amounts keep their design size). |
|
|
773
|
+
| `maxFontSizeMultiplier` | `number` | `0` | Cap for `allowFontScaling`; `0` = no cap. |
|
|
774
|
+
| `fontWeight` | `TextStyle['fontWeight']` | `'normal'` | Font weight. |
|
|
775
|
+
| `fontFamily` | `string` | system | Font family, resolved like `Text` (bundled / expo-font fonts work). |
|
|
776
|
+
| `color` | `ColorValue` | label color | Text color. |
|
|
777
|
+
| `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. |
|
|
778
|
+
| `onNativeRef` | `(ref) => void` | – | Receives the Nitro object on mount. |
|
|
779
|
+
| `style`, `testID`, … | `ViewProps` | – | Regular view props. |
|
|
780
|
+
|
|
781
|
+
The view reports its intrinsic size from native and sizes itself. Give it an
|
|
782
|
+
explicit `width` in `style` plus `textAlign="right"` if you don't want the layout
|
|
783
|
+
to reflow while digits appear (e.g. a counter that grows past `999`).
|
|
784
|
+
|
|
504
785
|
## Accessibility and threading
|
|
505
786
|
|
|
787
|
+
### NitroInput
|
|
788
|
+
|
|
506
789
|
- The system field remains the accessibility element, with the formatted text
|
|
507
790
|
(`$1,234.50 USD` reads as such); VoiceOver / TalkBack, autofill, the paste
|
|
508
791
|
menu and selection all work as in a plain input.
|
|
509
792
|
- Reduce Motion (iOS) and "Remove animations" (Android) snap.
|
|
510
793
|
- The view implements Nitro's `RecyclableView`.
|
|
511
794
|
- Every keystroke is handled on the main thread: the formatter runs, the field
|
|
512
|
-
is updated, the
|
|
795
|
+
is updated, the reflow starts. `onChangeText` reaches JS afterwards; nothing
|
|
513
796
|
the user sees waits for it. A `value` prop carrying a stale
|
|
514
797
|
`mostRecentEventCount` (the user typed since) is ignored, like React
|
|
515
798
|
Native's own `TextInput`.
|
|
516
799
|
|
|
800
|
+
### NitroNumber
|
|
801
|
+
|
|
802
|
+
- VoiceOver / TalkBack read the formatted amount (prefix, sign, grouped digits,
|
|
803
|
+
suffix, e.g. `$1,234.50 USD`), updated whenever the value changes; while
|
|
804
|
+
`loading` the element is announced as loading.
|
|
805
|
+
- Reduce Motion (iOS) and "Remove animations" / animator scale 0 (Android)
|
|
806
|
+
snap to the new value instead of rolling, and freeze the loading glint.
|
|
807
|
+
- The view implements Nitro's `RecyclableView`, so Fabric reuses instances in
|
|
808
|
+
long lists; a recycled view forgets all props and animation state first.
|
|
809
|
+
- Custom fonts resolve like `Text`: on iOS by PostScript or family name from
|
|
810
|
+
`UIAppFonts`, on Android through React Native's font manager (`assets/fonts`,
|
|
811
|
+
`res/font`, or fonts registered by expo-font).
|
|
812
|
+
|
|
813
|
+
#### Performance
|
|
814
|
+
|
|
815
|
+
- A `value` change is delivered by React once; from there the roll runs
|
|
816
|
+
natively (`CADisplayLink` on the main run loop, `ValueAnimator` on the UI
|
|
817
|
+
thread). A busy JS thread delays the *next* value, never the animation in
|
|
818
|
+
flight, the shimmer, or the shrink-to-fit scaling.
|
|
819
|
+
- On iOS a frame never redraws a bitmap: each glyph and wheel is a `CALayer`
|
|
820
|
+
with a pre-rasterized image (a wheel is a clipped strip of the digits), and a
|
|
821
|
+
frame only moves layers, so the render server composites the roll. The
|
|
822
|
+
Core Graphics path is used only while the loading glint is showing. On
|
|
823
|
+
Android a frame is about a dozen `Canvas.drawText` calls through HWUI's glyph
|
|
824
|
+
cache. Scaling is a layer / canvas transform, so no fonts are rebuilt while
|
|
825
|
+
fitting.
|
|
826
|
+
- `jumpTo` / `animateTo` coalesce: only the newest value per main-thread turn
|
|
827
|
+
is applied, so pushing a value every frame into many views never builds a
|
|
828
|
+
backlog of main-thread dispatches.
|
|
829
|
+
- The only JS round trip is auto-sizing: when the digit count changes the view
|
|
830
|
+
reports its new intrinsic size and React applies it. Give the view a fixed
|
|
831
|
+
`width` (recommended for amounts anyway) and nothing depends on JS at all;
|
|
832
|
+
in auto-size mode the view is not clipped, so a late size update never cuts
|
|
833
|
+
a digit off. A size that grows is reported at once; a size that shrinks is
|
|
834
|
+
reported when the roll has finished, so the box never squeezes digits that
|
|
835
|
+
are still on their way out.
|
|
836
|
+
|
|
837
|
+
## How NitroNumber works
|
|
838
|
+
|
|
839
|
+
- All behaviour lives in one shared C++ engine (`cpp/RollingEngine.hpp`): each
|
|
840
|
+
digit is a wheel with a continuous position on a `0–9` strip; the engine
|
|
841
|
+
computes rolls (shortest path in the roll direction, blank↔digit for
|
|
842
|
+
appearing/disappearing wheels), stagger, easing/spring curves, the odometer
|
|
843
|
+
carry rule for `jumpTo`, the loading fade, the shimmer phase, the jackpot
|
|
844
|
+
reveals (count curve, tiers, reels, landing pop), the numeric transition's
|
|
845
|
+
springs and the clocks of a prefix, suffix, separator or decimal change.
|
|
846
|
+
- The Swift view calls the engine directly through Swift/C++ interop; the
|
|
847
|
+
Kotlin view through a 60-line fbjni handle (the only hand-written JNI). Each
|
|
848
|
+
platform only owns fonts, layout, fit-to-width and text drawing, and drives
|
|
849
|
+
the engine from a `CADisplayLink` / `Choreographer` loop.
|
|
850
|
+
- A frame is about a dozen cached glyph draws with Core Graphics / `Canvas`.
|
|
851
|
+
- Props are parsed by Nitro from JSI (no Fabric codegen); the view is a Fabric
|
|
852
|
+
component, so `style`, `opacity`, `transform` and friends work as usual.
|
|
853
|
+
|
|
854
|
+
## NumberFormat
|
|
855
|
+
|
|
856
|
+
`Intl.NumberFormat`'s API, formatted natively. The first formatter for a
|
|
857
|
+
locale and currency learns its format from the platform's own formatter
|
|
858
|
+
(Foundation on iOS, ICU on Android, the data Hermes' `Intl` uses); every number
|
|
859
|
+
after that is formatted in C++. It behaves as ECMA-402 specifies (callable
|
|
860
|
+
without `new`, a bound `format`, options read and checked in the specified
|
|
861
|
+
order) and passes test262's `intl402/NumberFormat` suite as far as the
|
|
862
|
+
platform's data goes: 242 of 251 tests on iOS and 244 on Android, where Hermes'
|
|
863
|
+
own `Intl` passes 121 and 101.
|
|
864
|
+
|
|
865
|
+
```ts
|
|
866
|
+
import { NumberFormat, NitroNumber } from 'react-native-nitro-input'
|
|
867
|
+
|
|
868
|
+
const php = new NumberFormat('en-PH', { style: 'currency', currency: 'PHP' })
|
|
869
|
+
php.format(1234.5) // "₱1,234.50"
|
|
870
|
+
php.formatToParts(-12) // on iOS too
|
|
871
|
+
php.formatRange(3, 5) // "₱3.00 – ₱5.00"
|
|
872
|
+
[1, 2].map(php.format) // format is bound
|
|
873
|
+
php.format('12345678901234567890.125') // exact
|
|
874
|
+
|
|
875
|
+
<NitroNumber value={balance} format={php} />
|
|
876
|
+
```
|
|
877
|
+
|
|
878
|
+
Building a formatter takes 9 µs on a Galaxy A22 against Hermes' 3.3 ms, and
|
|
879
|
+
`format()` 2.8 µs against 10 µs. Every option of `Intl.NumberFormatOptions` is
|
|
880
|
+
supported; compact notation, units and currency names are printed by the
|
|
881
|
+
platform formatter (iOS has no long compact form). Full guide:
|
|
882
|
+
https://ronickg.github.io/react-native-nitro-input/docs/number-format
|
|
883
|
+
|
|
517
884
|
## Credits
|
|
518
885
|
|
|
519
|
-
The
|
|
886
|
+
The reflow is based on [Torph](https://torph.lochie.me) by
|
|
520
887
|
[Lochie Axon](https://github.com/lochie). Thanks for building it.
|
|
521
888
|
|
|
522
889
|
## License
|