react-native-nitro-input 0.3.7 → 0.4.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 +133 -0
- package/README.md +9 -4
- package/android/CMakeLists.txt +1 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputMeasure.kt +52 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +74 -80
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +18 -18
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextView.kt +14 -14
- package/android/src/main/java/com/margelo/nitro/nitroinput/InputFonts.kt +199 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/InputSizing.kt +398 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +112 -333
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +178 -30
- package/cpp/RollingEngine.cpp +68 -5
- package/cpp/RollingEngine.hpp +13 -0
- package/cpp/numberformat/FormatFigure.cpp +134 -0
- package/cpp/numberformat/FormatFigure.hpp +65 -0
- package/cpp/numberformat/HybridNitroNumberFormat.cpp +32 -10
- package/cpp/numberformat/HybridNitroNumberFormat.hpp +9 -1
- package/ios/HybridNitroInputView.swift +69 -75
- package/ios/HybridNitroNumberView.swift +18 -18
- package/ios/HybridNitroTextView.swift +14 -14
- package/ios/InputSizing.swift +534 -0
- package/ios/NitroInputView.swift +102 -198
- package/ios/NitroNumberView.swift +98 -23
- package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +12 -8
- package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
- package/lib/commonjs/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
- package/lib/commonjs/src/NitroInput.js +164 -23
- package/lib/commonjs/src/NitroNumber.js +19 -11
- package/lib/commonjs/src/NitroText.js +6 -6
- package/lib/commonjs/src/NumberFormat.js +20 -0
- package/lib/commonjs/src/formatProps.js +57 -81
- package/lib/commonjs/src/specs/NitroInputMeasure.nitro.js +2 -0
- package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +12 -8
- package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
- package/lib/module/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
- package/lib/module/src/NitroInput.js +165 -24
- package/lib/module/src/NitroNumber.js +20 -12
- package/lib/module/src/NitroText.js +6 -6
- package/lib/module/src/NumberFormat.js +18 -0
- package/lib/module/src/formatProps.js +54 -81
- package/lib/module/src/specs/NitroInputMeasure.nitro.js +1 -0
- package/lib/typescript/src/NitroInput.d.ts +9 -16
- package/lib/typescript/src/NitroNumber.d.ts +25 -7
- package/lib/typescript/src/NumberFormat.d.ts +15 -1
- package/lib/typescript/src/formatProps.d.ts +23 -18
- package/lib/typescript/src/specs/NitroInput.nitro.d.ts +17 -8
- package/lib/typescript/src/specs/NitroInputMeasure.nitro.d.ts +67 -0
- package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +6 -6
- package/lib/typescript/src/specs/NitroText.nitro.d.ts +6 -6
- package/lib/typescript/src/specs/NumberFormat.nitro.d.ts +33 -0
- package/nitro.json +10 -0
- package/nitrogen/generated/android/NitroInput+autolinking.cmake +2 -0
- package/nitrogen/generated/android/NitroInputOnLoad.cpp +16 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputMeasureSpec.cpp +93 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputMeasureSpec.hpp +63 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +76 -40
- package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +24 -16
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +30 -30
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +12 -12
- package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.cpp +30 -30
- package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.hpp +12 -12
- package/nitrogen/generated/android/c++/JNitroInputSize.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroInputSizing.hpp +284 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +44 -24
- package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +18 -18
- package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.cpp +18 -18
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputMeasureSpec.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +32 -8
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +6 -6
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextViewSpec.kt +6 -6
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSize.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSizing.kt +246 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +29 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +11 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.mm +8 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.swift +12 -0
- package/nitrogen/generated/ios/c++/HybridNitroInputMeasureSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroInputMeasureSpecSwift.hpp +112 -0
- package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +56 -32
- package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +24 -24
- package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.hpp +24 -24
- package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +56 -32
- package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +24 -24
- package/nitrogen/generated/ios/c++/views/HybridNitroTextViewComponent.mm +24 -24
- package/nitrogen/generated/ios/swift/HybridNitroInputMeasureSpec.swift +55 -0
- package/nitrogen/generated/ios/swift/HybridNitroInputMeasureSpec_cxx.swift +138 -0
- package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +12 -8
- package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +68 -24
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +6 -6
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +18 -18
- package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec.swift +6 -6
- package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec_cxx.swift +18 -18
- package/nitrogen/generated/ios/swift/NitroInputSize.swift +34 -0
- package/nitrogen/generated/ios/swift/NitroInputSizing.swift +242 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputMeasureSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputMeasureSpec.hpp +66 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +24 -16
- package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +24 -16
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatSpec.hpp +8 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +12 -12
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +12 -12
- package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.cpp +12 -12
- package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.hpp +12 -12
- package/nitrogen/generated/shared/c++/NitroInputSize.hpp +87 -0
- package/nitrogen/generated/shared/c++/NitroInputSizing.hpp +263 -0
- package/nitrogen/generated/shared/c++/NumberFigure.hpp +95 -0
- package/nitrogen/generated/shared/c++/NumberFormatLayout.hpp +112 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +24 -16
- package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +36 -24
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +12 -12
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +18 -18
- package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.cpp +12 -12
- package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.hpp +18 -18
- package/nitrogen/generated/shared/json/NitroInputViewConfig.json +12 -8
- package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
- package/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
- package/package.json +5 -3
- package/src/NitroInput.tsx +201 -64
- package/src/NitroNumber.tsx +54 -25
- package/src/NitroText.tsx +6 -6
- package/src/NumberFormat.ts +22 -0
- package/src/formatProps.ts +59 -99
- package/src/specs/NitroInput.nitro.ts +17 -8
- package/src/specs/NitroInputMeasure.nitro.ts +76 -0
- package/src/specs/NitroNumber.nitro.ts +6 -6
- package/src/specs/NitroText.nitro.ts +6 -6
- package/src/specs/NumberFormat.nitro.ts +35 -0
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"shimmerBaseColor": true,
|
|
38
38
|
"shimmerDirection": true,
|
|
39
39
|
"shimmerDelay": true,
|
|
40
|
-
"
|
|
40
|
+
"textSize": true,
|
|
41
41
|
"prefixFontSize": true,
|
|
42
42
|
"suffixFontSize": true,
|
|
43
43
|
"affixAlign": true,
|
|
44
44
|
"prefixAlign": true,
|
|
45
45
|
"suffixAlign": true,
|
|
46
|
-
"
|
|
46
|
+
"textLetterSpacing": true,
|
|
47
47
|
"prefixSpacing": true,
|
|
48
48
|
"suffixSpacing": true,
|
|
49
49
|
"prefixOffset": true,
|
|
@@ -66,10 +66,10 @@
|
|
|
66
66
|
"minimumFontScale": true,
|
|
67
67
|
"allowFontScaling": true,
|
|
68
68
|
"maxFontSizeMultiplier": true,
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
69
|
+
"textWeight": true,
|
|
70
|
+
"textFamily": true,
|
|
71
|
+
"textColor": true,
|
|
72
|
+
"textAlignment": true,
|
|
73
73
|
"rightToLeft": true,
|
|
74
74
|
"onSizeChange": true,
|
|
75
75
|
"onRevealEnd": true,
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
"directEventTypes": {},
|
|
6
6
|
"validAttributes": {
|
|
7
7
|
"text": true,
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
8
|
+
"textSize": true,
|
|
9
|
+
"textWeight": true,
|
|
10
|
+
"textFamily": true,
|
|
11
|
+
"textColor": true,
|
|
12
|
+
"textLetterSpacing": true,
|
|
13
|
+
"textAlignment": true,
|
|
14
14
|
"rightToLeft": true,
|
|
15
15
|
"duration": true,
|
|
16
16
|
"easing": true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-input",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Native text for React Native, built with Nitro: a text and amount input with native formatting, masks and a Torph-style reflow, and an animated number (odometer, SwiftUI-style numeric text, ticker) whose digits roll or swap natively, with currency layouts and animated currency switches, shrink-to-fit, a loading shimmer and a jackpot reveal.",
|
|
5
5
|
"main": "lib/commonjs/src/index.js",
|
|
6
6
|
"module": "lib/module/src/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"specs": "nitrogen --logLevel=\"debug\"",
|
|
40
40
|
"prepack": "bun run build",
|
|
41
41
|
"test": "jest",
|
|
42
|
-
"test:cpp": "mkdir -p .cache && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/ReflowEngine.cpp cpp/AmountFormatter.cpp cpp/__tests__/ReflowEngineTest.cpp -o .cache/reflow-engine-test && .cache/reflow-engine-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/AmountFormatter.cpp cpp/__tests__/AmountFormatterTest.cpp -o .cache/amount-formatter-test && .cache/amount-formatter-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/AmountFormatter.cpp cpp/MaskEngine.cpp cpp/__tests__/MaskEngineTest.cpp -o .cache/mask-engine-test && .cache/mask-engine-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/AmountFormatter.cpp cpp/MaskEngine.cpp cpp/__tests__/MaskEngineCorpusTest.cpp -o .cache/mask-engine-corpus-test && .cache/mask-engine-corpus-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/OutlineGeometry.cpp cpp/__tests__/OutlineGeometryTest.cpp -o .cache/outline-geometry-test && .cache/outline-geometry-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/RollingEngine.cpp cpp/__tests__/RollingEngineTest.cpp -o .cache/rolling-engine-test && .cache/rolling-engine-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/numberformat/NumberFormatCore.cpp cpp/__tests__/NumberFormatCoreTest.cpp -o .cache/number-format-core-test && .cache/number-format-core-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/numberformat/NumberFormatCore.cpp cpp/numberformat/NumberFormatProbe.cpp cpp/__tests__/NumberFormatProbeTest.cpp -o .cache/number-format-probe-test && .cache/number-format-probe-test",
|
|
42
|
+
"test:cpp": "mkdir -p .cache && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/ReflowEngine.cpp cpp/AmountFormatter.cpp cpp/__tests__/ReflowEngineTest.cpp -o .cache/reflow-engine-test && .cache/reflow-engine-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/AmountFormatter.cpp cpp/__tests__/AmountFormatterTest.cpp -o .cache/amount-formatter-test && .cache/amount-formatter-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/AmountFormatter.cpp cpp/MaskEngine.cpp cpp/__tests__/MaskEngineTest.cpp -o .cache/mask-engine-test && .cache/mask-engine-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/AmountFormatter.cpp cpp/MaskEngine.cpp cpp/__tests__/MaskEngineCorpusTest.cpp -o .cache/mask-engine-corpus-test && .cache/mask-engine-corpus-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/OutlineGeometry.cpp cpp/__tests__/OutlineGeometryTest.cpp -o .cache/outline-geometry-test && .cache/outline-geometry-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/RollingEngine.cpp cpp/__tests__/RollingEngineTest.cpp -o .cache/rolling-engine-test && .cache/rolling-engine-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/numberformat/NumberFormatCore.cpp cpp/numberformat/FormatFigure.cpp cpp/__tests__/NumberFormatCoreTest.cpp -o .cache/number-format-core-test && .cache/number-format-core-test && clang++ -std=c++20 -O1 -Wall -Wextra -Icpp cpp/numberformat/NumberFormatCore.cpp cpp/numberformat/NumberFormatProbe.cpp cpp/__tests__/NumberFormatProbeTest.cpp -o .cache/number-format-probe-test && .cache/number-format-probe-test",
|
|
43
43
|
"test:cpp:sanitize": "mkdir -p .cache && clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer -Icpp cpp/RollingEngine.cpp cpp/__tests__/RollingEngineTest.cpp -o .cache/rolling-engine-sanitize && .cache/rolling-engine-sanitize",
|
|
44
44
|
"release": "release-it"
|
|
45
45
|
},
|
|
@@ -140,10 +140,12 @@
|
|
|
140
140
|
},
|
|
141
141
|
"hooks": {
|
|
142
142
|
"before:init": [
|
|
143
|
+
"node ../../scripts/release/stamp-changelog.mjs --check",
|
|
143
144
|
"bun run typecheck",
|
|
144
145
|
"bun run test",
|
|
145
146
|
"bun run test:cpp"
|
|
146
|
-
]
|
|
147
|
+
],
|
|
148
|
+
"after:bump": "node ../../scripts/release/stamp-changelog.mjs ${version}"
|
|
147
149
|
}
|
|
148
150
|
}
|
|
149
151
|
}
|
package/src/NitroInput.tsx
CHANGED
|
@@ -11,12 +11,14 @@ import {
|
|
|
11
11
|
I18nManager,
|
|
12
12
|
StyleSheet,
|
|
13
13
|
type ColorValue,
|
|
14
|
+
type StyleProp,
|
|
14
15
|
type TextStyle,
|
|
15
16
|
type ViewProps,
|
|
16
17
|
} from 'react-native'
|
|
17
18
|
import {
|
|
18
19
|
callback,
|
|
19
20
|
getHostComponent,
|
|
21
|
+
NitroModules,
|
|
20
22
|
type HybridRef,
|
|
21
23
|
} from 'react-native-nitro-modules'
|
|
22
24
|
import NitroInputViewConfig from '../nitrogen/generated/shared/json/NitroInputViewConfig.json'
|
|
@@ -42,6 +44,7 @@ import type {
|
|
|
42
44
|
NitroInputTextCase,
|
|
43
45
|
NitroInputCharacterMapping,
|
|
44
46
|
} from './specs/NitroInput.nitro'
|
|
47
|
+
import type { NitroInputMeasure, NitroInputSizing } from './specs/NitroInputMeasure.nitro'
|
|
45
48
|
import {
|
|
46
49
|
allocateWorkletId,
|
|
47
50
|
isWorklet,
|
|
@@ -275,7 +278,14 @@ export interface NitroInputKeyPressEvent {
|
|
|
275
278
|
nativeEvent: { key: string; eventCount: number; target: number }
|
|
276
279
|
}
|
|
277
280
|
|
|
278
|
-
export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus' | 'onBlur'> {
|
|
281
|
+
export interface NitroInputProps extends Omit<ViewProps, 'children' | 'onFocus' | 'onBlur' | 'style'> {
|
|
282
|
+
/**
|
|
283
|
+
* As `TextInput`'s: a view style, and the text styles it reads its
|
|
284
|
+
* typography from (`fontSize`, `fontWeight`, `fontFamily`, `color`,
|
|
285
|
+
* `letterSpacing`, `lineHeight`, `textAlign`, `textAlignVertical`). The props
|
|
286
|
+
* of the same name win over it.
|
|
287
|
+
*/
|
|
288
|
+
style?: StyleProp<TextStyle>
|
|
279
289
|
/**
|
|
280
290
|
* The text to show (controlled). The native side formats and shows what the
|
|
281
291
|
* user types on its own; this prop is applied when it changes to something
|
|
@@ -734,6 +744,85 @@ export type NitroInputTransition = 'none' | 'reflow'
|
|
|
734
744
|
* Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
|
|
735
745
|
* it to its content instead, and is on by default when the text reflows.
|
|
736
746
|
*/
|
|
747
|
+
interface Insets {
|
|
748
|
+
left: number
|
|
749
|
+
top: number
|
|
750
|
+
right: number
|
|
751
|
+
bottom: number
|
|
752
|
+
}
|
|
753
|
+
const NO_INSETS: Insets = { left: 0, top: 0, right: 0, bottom: 0 }
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* The style's padding plus border per edge, resolved the way Yoga does: a
|
|
757
|
+
* start / end edge before left / right, then horizontal / vertical, then all.
|
|
758
|
+
* A size measured for the text gets them added, as `TextInput`'s is, so a
|
|
759
|
+
* padded field grows rather than squeezing its text. Percentages are not
|
|
760
|
+
* resolved here (they need the parent's size) and count as 0.
|
|
761
|
+
*/
|
|
762
|
+
function styleInsets(flat: Record<string, unknown> | undefined, rightToLeft: boolean): Insets {
|
|
763
|
+
if (flat == null) return NO_INSETS
|
|
764
|
+
const n = (key: string): number | undefined => {
|
|
765
|
+
const value = flat[key]
|
|
766
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined
|
|
767
|
+
}
|
|
768
|
+
const start = rightToLeft ? 'End' : 'Start'
|
|
769
|
+
const end = rightToLeft ? 'Start' : 'End'
|
|
770
|
+
const insets = {
|
|
771
|
+
left:
|
|
772
|
+
(n(`padding${start}`) ?? n('paddingLeft') ?? n('paddingHorizontal') ?? n('padding') ?? 0) +
|
|
773
|
+
(n(`border${start}Width`) ?? n('borderLeftWidth') ?? n('borderWidth') ?? 0),
|
|
774
|
+
right:
|
|
775
|
+
(n(`padding${end}`) ?? n('paddingRight') ?? n('paddingHorizontal') ?? n('padding') ?? 0) +
|
|
776
|
+
(n(`border${end}Width`) ?? n('borderRightWidth') ?? n('borderWidth') ?? 0),
|
|
777
|
+
top:
|
|
778
|
+
(n('paddingTop') ?? n('paddingVertical') ?? n('padding') ?? 0) + (n('borderTopWidth') ?? n('borderWidth') ?? 0),
|
|
779
|
+
bottom:
|
|
780
|
+
(n('paddingBottom') ?? n('paddingVertical') ?? n('padding') ?? 0) +
|
|
781
|
+
(n('borderBottomWidth') ?? n('borderWidth') ?? 0),
|
|
782
|
+
}
|
|
783
|
+
return insets.left === 0 && insets.right === 0 && insets.top === 0 && insets.bottom === 0 ? NO_INSETS : insets
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
function styleTextAlign(value: TextStyle['textAlign'], rightToLeft: boolean): NitroInputTextAlign | undefined {
|
|
787
|
+
switch (value) {
|
|
788
|
+
case undefined:
|
|
789
|
+
return undefined
|
|
790
|
+
// `justify` has no meaning on one line: the start edge, as on a TextInput.
|
|
791
|
+
case 'start':
|
|
792
|
+
case 'justify':
|
|
793
|
+
return 'auto'
|
|
794
|
+
case 'end':
|
|
795
|
+
return rightToLeft ? 'left' : 'right'
|
|
796
|
+
default:
|
|
797
|
+
return value
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
function styleTextAlignVertical(value: TextStyle['textAlignVertical']): NitroInputTextAlignVertical | undefined {
|
|
802
|
+
return value ?? undefined
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// One per app, made on first use. `null` when the native side has none (an
|
|
806
|
+
// app built against an older version, or a test without native modules): the
|
|
807
|
+
// field then takes its size from the view's first report, as it used to.
|
|
808
|
+
let measurer: NitroInputMeasure | null | undefined
|
|
809
|
+
function measureSizing(sizing: NitroInputSizing): Size | null {
|
|
810
|
+
if (measurer === undefined) {
|
|
811
|
+
try {
|
|
812
|
+
const made = NitroModules.createHybridObject<NitroInputMeasure>('NitroInputMeasure')
|
|
813
|
+
measurer = typeof made?.measure === 'function' ? made : null
|
|
814
|
+
} catch {
|
|
815
|
+
measurer = null
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
if (measurer === null) return null
|
|
819
|
+
try {
|
|
820
|
+
return measurer.measure(sizing)
|
|
821
|
+
} catch {
|
|
822
|
+
return null
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
737
826
|
export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
|
|
738
827
|
function NitroInput(
|
|
739
828
|
{
|
|
@@ -752,7 +841,7 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
|
|
|
752
841
|
signPlacement,
|
|
753
842
|
prefixAlign,
|
|
754
843
|
suffixAlign,
|
|
755
|
-
letterSpacing,
|
|
844
|
+
letterSpacing: letterSpacingProp,
|
|
756
845
|
prefixSpacing,
|
|
757
846
|
suffixSpacing,
|
|
758
847
|
prefixOffset,
|
|
@@ -764,12 +853,12 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
|
|
|
764
853
|
easing,
|
|
765
854
|
bounce,
|
|
766
855
|
effect,
|
|
767
|
-
fontSize,
|
|
768
|
-
lineHeight,
|
|
769
|
-
fontWeight,
|
|
770
|
-
fontFamily,
|
|
771
|
-
color,
|
|
772
|
-
textAlign,
|
|
856
|
+
fontSize: fontSizeProp,
|
|
857
|
+
lineHeight: lineHeightProp,
|
|
858
|
+
fontWeight: fontWeightProp,
|
|
859
|
+
fontFamily: fontFamilyProp,
|
|
860
|
+
color: colorProp,
|
|
861
|
+
textAlign: textAlignProp,
|
|
773
862
|
cursorColor,
|
|
774
863
|
selectionColor,
|
|
775
864
|
caretHidden,
|
|
@@ -808,7 +897,7 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
|
|
|
808
897
|
multiline,
|
|
809
898
|
numberOfLines,
|
|
810
899
|
rows,
|
|
811
|
-
textAlignVertical,
|
|
900
|
+
textAlignVertical: textAlignVerticalProp,
|
|
812
901
|
scrollEnabled,
|
|
813
902
|
autoFocus,
|
|
814
903
|
transition,
|
|
@@ -912,6 +1001,11 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
|
|
|
912
1001
|
if (value != null) textRef.current = value
|
|
913
1002
|
|
|
914
1003
|
const [size, setSize] = useState<Size | null>(null)
|
|
1004
|
+
// The size measured before the view existed (see `measureSizing`), and
|
|
1005
|
+
// whether the view has reported its own since.
|
|
1006
|
+
const seedRef = useRef<Size | null>(null)
|
|
1007
|
+
const seedKeyRef = useRef('')
|
|
1008
|
+
const reportedRef = useRef(false)
|
|
915
1009
|
// Worklets are registered on the UI runtime and referenced by id; a
|
|
916
1010
|
// handler marked 'worklet' runs there instead of on the JS thread.
|
|
917
1011
|
const transformId = useWorkletId(transform, registerTransform)
|
|
@@ -1035,16 +1129,29 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
|
|
|
1035
1129
|
const flat = useMemo(
|
|
1036
1130
|
() =>
|
|
1037
1131
|
StyleSheet.flatten(style) as
|
|
1038
|
-
| { width?: unknown; flex?: unknown; height?: unknown; direction?: unknown }
|
|
1132
|
+
| ({ width?: unknown; flex?: unknown; height?: unknown; direction?: unknown } & TextStyle)
|
|
1039
1133
|
| undefined,
|
|
1040
1134
|
[style]
|
|
1041
1135
|
)
|
|
1136
|
+
// `TextInput` takes its typography from `style`; so does this, under the
|
|
1137
|
+
// props of the same name, which win. (Fabric hands a view its style's keys
|
|
1138
|
+
// as props too; the view's own are named so that none can be one of them -
|
|
1139
|
+
// see PropNameCollisions.test.)
|
|
1140
|
+
const fontSize = fontSizeProp ?? flat?.fontSize
|
|
1141
|
+
const lineHeight = lineHeightProp ?? flat?.lineHeight
|
|
1142
|
+
const fontWeight = fontWeightProp ?? flat?.fontWeight
|
|
1143
|
+
const fontFamily = fontFamilyProp ?? flat?.fontFamily
|
|
1144
|
+
const color = colorProp ?? flat?.color
|
|
1145
|
+
const letterSpacing = letterSpacingProp ?? flat?.letterSpacing
|
|
1146
|
+
const textAlignVertical = textAlignVerticalProp ?? styleTextAlignVertical(flat?.textAlignVertical)
|
|
1042
1147
|
// The layout direction, resolved the way React Native resolves it for its
|
|
1043
1148
|
// own views: the field's `style.direction` if it says, else the app's.
|
|
1044
1149
|
// Fabric does not hand a Hybrid View its resolved direction, so native is
|
|
1045
1150
|
// told outright.
|
|
1046
1151
|
const rightToLeft =
|
|
1047
1152
|
flat?.direction === 'rtl' || (flat?.direction !== 'ltr' && I18nManager.isRTL)
|
|
1153
|
+
const textAlign = textAlignProp ?? styleTextAlign(flat?.textAlign, rightToLeft)
|
|
1154
|
+
const insets = useMemo(() => styleInsets(flat as Record<string, unknown> | undefined, rightToLeft), [flat, rightToLeft])
|
|
1048
1155
|
// `TextInput` stretches to its parent; sizing to content is this
|
|
1049
1156
|
// component's own behaviour, and it is what stops it being a drop-in.
|
|
1050
1157
|
// `NitroInput` turns it off so flexbox gives it the parent's width, the
|
|
@@ -1066,12 +1173,16 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
|
|
|
1066
1173
|
const onSizeChange = useMemo(
|
|
1067
1174
|
() =>
|
|
1068
1175
|
callback((width: number, height: number) => {
|
|
1176
|
+
reportedRef.current = true
|
|
1069
1177
|
if (!measuredRef.current) return
|
|
1070
1178
|
setSize((previous) => {
|
|
1179
|
+
// Until the first report the field shows the seed; a report that
|
|
1180
|
+
// matches it leaves `size` as it is, and costs no commit.
|
|
1181
|
+
const shown = previous ?? seedRef.current
|
|
1071
1182
|
if (!autoWidthRef.current) {
|
|
1072
|
-
return
|
|
1183
|
+
return shown !== null && shown.height === height ? previous : { width: shown?.width ?? width, height }
|
|
1073
1184
|
}
|
|
1074
|
-
return
|
|
1185
|
+
return shown !== null && shown.width === width && shown.height === height
|
|
1075
1186
|
? previous
|
|
1076
1187
|
: { width, height }
|
|
1077
1188
|
})
|
|
@@ -1392,94 +1503,122 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
|
|
|
1392
1503
|
if (resolvedImportance != null) hostViewProps.importantForAccessibility = resolvedImportance
|
|
1393
1504
|
if (resolvedLabelledBy != null) hostViewProps.accessibilityLabelledBy = resolvedLabelledBy
|
|
1394
1505
|
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1506
|
+
// What the field's size follows. Sent to the view as props and, before
|
|
1507
|
+
// the view exists, to `measureSizing`, so the two see the same values.
|
|
1508
|
+
const sizing: NitroInputSizing = {
|
|
1509
|
+
text: value ?? uncontrolledText,
|
|
1510
|
+
mode: resolvedMode,
|
|
1511
|
+
plain: !reflows,
|
|
1512
|
+
multiline: isMultiline,
|
|
1513
|
+
secureTextEntry: secureTextEntry ?? false,
|
|
1514
|
+
maxLength: maxLength ?? 0,
|
|
1515
|
+
fractionDigits: resolvedFractionDigits,
|
|
1516
|
+
maxIntegerDigits: maxIntegerDigits ?? 15,
|
|
1517
|
+
groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? ',',
|
|
1518
|
+
decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.',
|
|
1519
|
+
prefix: resolvedPrefix,
|
|
1520
|
+
suffix: resolvedSuffix,
|
|
1521
|
+
signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix',
|
|
1522
|
+
placeholder: placeholder ?? '',
|
|
1523
|
+
mask: resolvedMode === 'mask' ? (mask ?? '') : '',
|
|
1524
|
+
maskNotations: stableNotations,
|
|
1525
|
+
maskAutocomplete: maskAutocomplete ?? true,
|
|
1526
|
+
maskAutoSkip: maskAutoSkip ?? false,
|
|
1527
|
+
maskAffinityFormats: stableAffinityFormats,
|
|
1528
|
+
maskAffinityStrategy: maskAffinityStrategy ?? 'wholeString',
|
|
1529
|
+
maskTextCase: maskTextCase ?? 'none',
|
|
1530
|
+
maskCharacterMap: stableCharacterMap,
|
|
1531
|
+
maskSlotPlaceholder: maskSlotPlaceholder ?? (keepPlaceholder ? '_' : ''),
|
|
1532
|
+
keepPlaceholder: keepPlaceholder ?? false,
|
|
1533
|
+
textSize: resolvedFontSize,
|
|
1534
|
+
textLineHeight: Math.max(0, lineHeight ?? 0),
|
|
1535
|
+
prefixFontSize: prefixFontSize ?? resolvedFontSize,
|
|
1536
|
+
suffixFontSize: suffixFontSize ?? resolvedFontSize,
|
|
1537
|
+
textWeight: numericWeight,
|
|
1538
|
+
textFamily: fontFamily ?? '',
|
|
1539
|
+
textLetterSpacing: letterSpacing ?? 0,
|
|
1540
|
+
prefixSpacing: prefixSpacing ?? Infinity,
|
|
1541
|
+
suffixSpacing: suffixSpacing ?? Infinity,
|
|
1542
|
+
allowFontScaling: allowFontScaling ?? false,
|
|
1543
|
+
maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0,
|
|
1544
|
+
variant: variant ?? 'none',
|
|
1545
|
+
label: label ?? '',
|
|
1546
|
+
labelBehavior: labelBehavior ?? 'float',
|
|
1547
|
+
labelFontSize: labelFontSize ?? 0,
|
|
1548
|
+
cornerRadius: cornerRadius ?? 8,
|
|
1549
|
+
}
|
|
1550
|
+
// Until the view reports its size, the field lays out at the size it will
|
|
1551
|
+
// report, measured now with the view's own code - as `TextInput` measures
|
|
1552
|
+
// in its shadow node - rather than at its parent's width for the commit
|
|
1553
|
+
// the report takes. Not for a wrapping field (its height needs the width
|
|
1554
|
+
// it will get), a `transform` (a worklet, run on the UI thread) or a
|
|
1555
|
+
// style that sets both dimensions. Measured again only when what it
|
|
1556
|
+
// follows changes.
|
|
1557
|
+
if (!reportedRef.current) {
|
|
1558
|
+
const seedKey = measured && !isMultiline && transformId === 0 ? JSON.stringify(sizing) : ''
|
|
1559
|
+
if (seedKey !== seedKeyRef.current) {
|
|
1560
|
+
seedKeyRef.current = seedKey
|
|
1561
|
+
seedRef.current = seedKey === '' ? null : measureSizing(sizing)
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
const shownSize = size ?? seedRef.current
|
|
1565
|
+
// The size measured for the text, plus the style's padding and border
|
|
1566
|
+
// (Yoga's box includes them; `TextInput`'s measured size gets them too).
|
|
1567
|
+
const autoSize = useMemo(() => {
|
|
1568
|
+
const extraWidth = insets.left + insets.right
|
|
1569
|
+
const extraHeight = insets.top + insets.bottom
|
|
1570
|
+
return shownSize !== null
|
|
1571
|
+
? autoWidth
|
|
1572
|
+
? { width: shownSize.width + extraWidth, height: shownSize.height + extraHeight }
|
|
1573
|
+
: { height: shownSize.height + extraHeight }
|
|
1574
|
+
: { height: resolvedFontSize * 1.25 + extraHeight }
|
|
1575
|
+
}, [shownSize, resolvedFontSize, autoWidth, insets])
|
|
1404
1576
|
|
|
1405
1577
|
return (
|
|
1406
1578
|
<NativeNitroInputView
|
|
1407
1579
|
{...hostViewProps}
|
|
1580
|
+
{...sizing}
|
|
1408
1581
|
ref={hostRef as React.Ref<never>}
|
|
1409
1582
|
style={[autoSize, style]}
|
|
1410
1583
|
hybridRef={hybridRef}
|
|
1411
|
-
text={value ?? uncontrolledText}
|
|
1412
1584
|
// An uncontrolled field's `text` is its initial text: a count of 0 is
|
|
1413
1585
|
// never caught up after the first edit, so native never puts it back.
|
|
1414
1586
|
mostRecentEventCount={value != null ? eventCountRef.current : 0}
|
|
1415
|
-
mode={resolvedMode}
|
|
1416
|
-
plain={!reflows}
|
|
1417
|
-
fractionDigits={resolvedFractionDigits}
|
|
1418
|
-
maxIntegerDigits={maxIntegerDigits ?? 15}
|
|
1419
|
-
groupingSeparator={groupingSeparator ?? derived?.groupingSeparator ?? ','}
|
|
1420
|
-
decimalSeparator={decimalSeparator ?? derived?.decimalSeparator ?? '.'}
|
|
1421
|
-
prefix={resolvedPrefix}
|
|
1422
|
-
suffix={resolvedSuffix}
|
|
1423
|
-
prefixFontSize={prefixFontSize ?? resolvedFontSize}
|
|
1424
|
-
suffixFontSize={suffixFontSize ?? resolvedFontSize}
|
|
1425
|
-
signPlacement={signPlacement ?? derived?.signPlacement ?? 'beforeAffix'}
|
|
1426
1587
|
prefixAlign={prefixAlign ?? resolvedAffixAlign}
|
|
1427
1588
|
suffixAlign={suffixAlign ?? resolvedAffixAlign}
|
|
1428
|
-
letterSpacing={letterSpacing ?? 0}
|
|
1429
|
-
prefixSpacing={prefixSpacing ?? Infinity}
|
|
1430
|
-
suffixSpacing={suffixSpacing ?? Infinity}
|
|
1431
1589
|
prefixOffset={prefixOffset ?? 0}
|
|
1432
1590
|
suffixOffset={suffixOffset ?? 0}
|
|
1433
|
-
placeholder={placeholder ?? ''}
|
|
1434
1591
|
placeholderColor={processedPlaceholderColor}
|
|
1435
1592
|
duration={duration ?? 400}
|
|
1436
1593
|
easing={easing ?? 'expo'}
|
|
1437
1594
|
bounce={bounce ?? 0.15}
|
|
1438
1595
|
effect={effect ?? 'auto'}
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
fontWeight={numericWeight}
|
|
1442
|
-
fontFamily={fontFamily ?? ''}
|
|
1443
|
-
color={processedColor}
|
|
1444
|
-
textAlign={textAlign ?? 'auto'}
|
|
1596
|
+
textColor={processedColor}
|
|
1597
|
+
textAlignment={textAlign ?? 'auto'}
|
|
1445
1598
|
rightToLeft={rightToLeft}
|
|
1446
1599
|
caretColor={processedCursorColor}
|
|
1447
1600
|
selectionColor={processedSelectionColor}
|
|
1448
1601
|
caretHidden={caretHidden ?? false}
|
|
1449
1602
|
adjustsFontSizeToFit={adjustsFontSizeToFit ?? false}
|
|
1450
1603
|
minimumFontScale={minimumFontScale ?? 0.5}
|
|
1451
|
-
allowFontScaling={allowFontScaling ?? false}
|
|
1452
|
-
maxFontSizeMultiplier={maxFontSizeMultiplier ?? 0}
|
|
1453
|
-
variant={variant ?? 'none'}
|
|
1454
|
-
label={label ?? ''}
|
|
1455
|
-
labelBehavior={labelBehavior ?? 'float'}
|
|
1456
1604
|
labelColor={processedLabelColor}
|
|
1457
1605
|
labelFocusedColor={processedLabelFocusedColor}
|
|
1458
|
-
labelFontSize={labelFontSize ?? 0}
|
|
1459
1606
|
strokeColor={processedStrokeColor}
|
|
1460
1607
|
focusedStrokeColor={processedFocusedStrokeColor}
|
|
1461
1608
|
strokeWidth={strokeWidth ?? 1}
|
|
1462
|
-
cornerRadius={cornerRadius ?? 8}
|
|
1463
1609
|
fillColor={processedFillColor}
|
|
1464
|
-
mask={resolvedMode === 'mask' ? (mask ?? '') : ''}
|
|
1465
|
-
maskNotations={stableNotations}
|
|
1466
|
-
maskAutocomplete={maskAutocomplete ?? true}
|
|
1467
|
-
maskAutoSkip={maskAutoSkip ?? false}
|
|
1468
|
-
maskAffinityFormats={stableAffinityFormats}
|
|
1469
|
-
maskAffinityStrategy={maskAffinityStrategy ?? 'wholeString'}
|
|
1470
|
-
maskTextCase={maskTextCase ?? 'none'}
|
|
1471
|
-
maskCharacterMap={stableCharacterMap}
|
|
1472
|
-
maskSlotPlaceholder={maskSlotPlaceholder ?? (keepPlaceholder ? '_' : '')}
|
|
1473
|
-
keepPlaceholder={keepPlaceholder ?? false}
|
|
1474
1610
|
onChangeMask={onChangeMaskCallback}
|
|
1475
1611
|
keyboardType={resolvedKeyboardType}
|
|
1476
1612
|
returnKeyType={resolvedReturnKeyType}
|
|
1477
1613
|
autoCapitalize={autoCapitalize ?? 'sentences'}
|
|
1478
1614
|
autoCorrect={autoCorrect ?? true}
|
|
1479
1615
|
editable={(editable ?? true) && !(readOnly ?? false)}
|
|
1480
|
-
multiline={isMultiline}
|
|
1481
1616
|
numberOfLines={Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0))}
|
|
1482
|
-
|
|
1617
|
+
textVerticalAlignment={textAlignVertical ?? 'auto'}
|
|
1618
|
+
textInsetLeft={insets.left}
|
|
1619
|
+
textInsetTop={insets.top}
|
|
1620
|
+
textInsetRight={insets.right}
|
|
1621
|
+
textInsetBottom={insets.bottom}
|
|
1483
1622
|
scrollEnabled={scrollEnabled ?? true}
|
|
1484
1623
|
autoFocus={autoFocus ?? false}
|
|
1485
1624
|
fieldTestID={viewProps.testID ?? ''}
|
|
@@ -1496,7 +1635,6 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
|
|
|
1496
1635
|
? 'submit'
|
|
1497
1636
|
: 'blurAndSubmit')
|
|
1498
1637
|
}
|
|
1499
|
-
secureTextEntry={secureTextEntry ?? false}
|
|
1500
1638
|
keyboardAppearance={keyboardAppearance ?? 'default'}
|
|
1501
1639
|
textContentType={textContentType ?? autoComplete ?? ''}
|
|
1502
1640
|
enablesReturnKeyAutomatically={enablesReturnKeyAutomatically ?? false}
|
|
@@ -1509,7 +1647,6 @@ export const NitroInput = forwardRef<NitroInputHandle, NitroInputProps>(
|
|
|
1509
1647
|
spellCheck={spellCheck ?? autoCorrect ?? true}
|
|
1510
1648
|
selectionStart={selection?.start ?? -1}
|
|
1511
1649
|
selectionEnd={selection?.end ?? selection?.start ?? -1}
|
|
1512
|
-
maxLength={maxLength ?? 0}
|
|
1513
1650
|
transformWorklet={transformId}
|
|
1514
1651
|
onChangeTextWorklet={onChangeTextId}
|
|
1515
1652
|
onChangeValueWorklet={onChangeValueId}
|
package/src/NitroNumber.tsx
CHANGED
|
@@ -31,7 +31,7 @@ import type {
|
|
|
31
31
|
NitroNumberTextAlign,
|
|
32
32
|
} from './specs/NitroNumber.nitro'
|
|
33
33
|
import { toNumericWeight, toProcessedColor } from './styleHelpers'
|
|
34
|
-
import {
|
|
34
|
+
import { figureOf, formatProps, toNumber, withMinorDigits } from './formatProps'
|
|
35
35
|
import type { NumberFormat } from './NumberFormat'
|
|
36
36
|
|
|
37
37
|
/**
|
|
@@ -53,11 +53,28 @@ export interface NitroNumberProps extends Omit<ViewProps, 'children'> {
|
|
|
53
53
|
/**
|
|
54
54
|
* The number to display. Every change rolls each digit natively to its new
|
|
55
55
|
* glyph, in the direction of the change. The first value is shown instantly.
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
*
|
|
57
|
+
* A `bigint` or a decimal string (`"1234.56"`) is taken as is, with no
|
|
58
|
+
* conversion on your side: money kept as minor units passes straight in
|
|
59
|
+
* with `minorDigits`. With a `format`, it is rounded by the format, in
|
|
60
|
+
* decimal, so it never goes through a double first. The digits themselves
|
|
61
|
+
* animate as a double: exact while `|value| × 10^fractionDigits` stays
|
|
62
|
+
* within 2^53, and at most 18 digits are shown.
|
|
63
|
+
*/
|
|
64
|
+
value: number | bigint | string
|
|
65
|
+
/**
|
|
66
|
+
* The decimal places `value` is counted in: `value={123456n}` with
|
|
67
|
+
* `minorDigits={2}` is 1234.56, cents to dollars without dividing. Applied
|
|
68
|
+
* to a bigint or a decimal string exactly. Default: `0`.
|
|
69
|
+
*/
|
|
70
|
+
minorDigits?: number
|
|
71
|
+
/**
|
|
72
|
+
* Digits shown after the decimal separator. Default: `0`, or with a
|
|
73
|
+
* `format`, what the format shows for each value: its
|
|
74
|
+
* `trailingZeroDisplay`, a minimum below its maximum and significant
|
|
75
|
+
* digits all decide it per value, and the decimal columns roll in and out as
|
|
76
|
+
* the count changes. Set, it holds every value to this many.
|
|
58
77
|
*/
|
|
59
|
-
value: number
|
|
60
|
-
/** Digits shown after the decimal separator. Default: `0`. */
|
|
61
78
|
fractionDigits?: number
|
|
62
79
|
/** Zero-pads the integer part to at least this many digits. Default: `1`. */
|
|
63
80
|
minimumIntegerDigits?: number
|
|
@@ -231,9 +248,10 @@ export interface NitroNumberProps extends Omit<ViewProps, 'children'> {
|
|
|
231
248
|
tabularNums?: boolean
|
|
232
249
|
/**
|
|
233
250
|
* A `NumberFormat` the number follows: its prefix and suffix (the currency
|
|
234
|
-
* where the locale puts it), grouping and decimal separators,
|
|
235
|
-
* digits and
|
|
236
|
-
*
|
|
251
|
+
* where the locale puts it), grouping and decimal separators, minimum
|
|
252
|
+
* integer digits, and per value the digits it prints: rounded with its
|
|
253
|
+
* `roundingMode`, trimmed by its `trailingZeroDisplay`. The figure is what
|
|
254
|
+
* `format.format(value)` shows. The individual props override what it says.
|
|
237
255
|
*/
|
|
238
256
|
format?: NumberFormat
|
|
239
257
|
/**
|
|
@@ -379,6 +397,7 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
|
|
|
379
397
|
function NitroNumber(
|
|
380
398
|
{
|
|
381
399
|
value,
|
|
400
|
+
minorDigits,
|
|
382
401
|
fractionDigits,
|
|
383
402
|
minimumIntegerDigits,
|
|
384
403
|
groupingSeparator,
|
|
@@ -463,8 +482,10 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
|
|
|
463
482
|
latestOnRevealEnd.current = onRevealEnd
|
|
464
483
|
const latestOnRevealMilestone = useRef(onRevealMilestone)
|
|
465
484
|
latestOnRevealMilestone.current = onRevealMilestone
|
|
466
|
-
|
|
467
|
-
|
|
485
|
+
// The value as the format takes it: minor units shifted in, exactly.
|
|
486
|
+
const input = withMinorDigits(value, minorDigits)
|
|
487
|
+
const latestValue = useRef(input)
|
|
488
|
+
latestValue.current = input
|
|
468
489
|
const latestOnAnimationStart = useRef(onAnimationStart)
|
|
469
490
|
latestOnAnimationStart.current = onAnimationStart
|
|
470
491
|
const latestOnAnimationEnd = useRef(onAnimationEnd)
|
|
@@ -523,7 +544,7 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
|
|
|
523
544
|
const onAnimationEndCallback = useMemo(
|
|
524
545
|
() =>
|
|
525
546
|
callback((shown: number) => {
|
|
526
|
-
latestOnAnimationEnd.current?.(compactRef.current ? latestValue.current : shown)
|
|
547
|
+
latestOnAnimationEnd.current?.(compactRef.current ? toNumber(latestValue.current) : shown)
|
|
527
548
|
}),
|
|
528
549
|
[]
|
|
529
550
|
)
|
|
@@ -545,7 +566,8 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
|
|
|
545
566
|
jumpTo: (next) => nativeRef.current?.jumpTo(next),
|
|
546
567
|
animateTo: (next) => nativeRef.current?.animateTo(next),
|
|
547
568
|
revealTo: (next) => nativeRef.current?.revealTo(next),
|
|
548
|
-
getValue: () =>
|
|
569
|
+
getValue: () =>
|
|
570
|
+
compactRef.current ? toNumber(latestValue.current) : nativeRef.current?.value ?? toNumber(latestValue.current),
|
|
549
571
|
get native() {
|
|
550
572
|
return nativeRef.current
|
|
551
573
|
},
|
|
@@ -572,14 +594,21 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
|
|
|
572
594
|
const resolvedFontSize = fontSize ?? 32
|
|
573
595
|
const resolvedAffixAlign = affixAlign ?? 'baseline'
|
|
574
596
|
const derived = format ? formatProps(format) : undefined
|
|
575
|
-
//
|
|
576
|
-
|
|
597
|
+
// What the format shows for this value: the figure rounded its way, in the
|
|
598
|
+
// fraction digits it prints. Compact notation also swaps the suffix: "1.2K"
|
|
599
|
+
// rolls the figure 1.2.
|
|
600
|
+
const figure = useMemo(() => (format ? figureOf(format, input) : undefined), [format, input])
|
|
601
|
+
const compact = derived?.compact ? figure : undefined
|
|
577
602
|
const compactRef = useRef(false)
|
|
578
603
|
compactRef.current = compact !== undefined
|
|
579
604
|
// Which way the value moved, for a compact figure that fell while the value grew (999 → 1K).
|
|
580
|
-
const
|
|
581
|
-
const
|
|
582
|
-
|
|
605
|
+
const numericValue = toNumber(input)
|
|
606
|
+
const previousValue = useRef(numericValue)
|
|
607
|
+
const compactDirection =
|
|
608
|
+
compact && direction === undefined ? (numericValue >= previousValue.current ? 'up' : 'down') : undefined
|
|
609
|
+
previousValue.current = numericValue
|
|
610
|
+
// Without a format the engine rounds the double, as it always has.
|
|
611
|
+
const shownValue = figure ? figure.value : numericValue
|
|
583
612
|
const processedPrefixColor = useMemo(() => toProcessedColor(prefixColor) ?? Infinity, [prefixColor])
|
|
584
613
|
const processedSuffixColor = useMemo(() => toProcessedColor(suffixColor) ?? Infinity, [suffixColor])
|
|
585
614
|
const processedFractionColor = useMemo(() => toProcessedColor(fractionColor) ?? Infinity, [fractionColor])
|
|
@@ -627,8 +656,8 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
|
|
|
627
656
|
{...viewProps}
|
|
628
657
|
style={[autoSize, style]}
|
|
629
658
|
hybridRef={hybridRef}
|
|
630
|
-
value={
|
|
631
|
-
fractionDigits={fractionDigits ??
|
|
659
|
+
value={shownValue}
|
|
660
|
+
fractionDigits={fractionDigits ?? figure?.fractionDigits ?? 0}
|
|
632
661
|
minimumIntegerDigits={minimumIntegerDigits ?? derived?.minimumIntegerDigits ?? 1}
|
|
633
662
|
groupingSeparator={groupingSeparator ?? derived?.groupingSeparator ?? ''}
|
|
634
663
|
decimalSeparator={decimalSeparator ?? derived?.decimalSeparator ?? '.'}
|
|
@@ -664,13 +693,13 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
|
|
|
664
693
|
shimmerBaseColor={processedShimmerBase}
|
|
665
694
|
shimmerDirection={shimmerDirection ?? 'auto'}
|
|
666
695
|
shimmerDelay={shimmerDelay ?? 0}
|
|
667
|
-
|
|
696
|
+
textSize={resolvedFontSize}
|
|
668
697
|
prefixFontSize={prefixFontSize ?? resolvedFontSize}
|
|
669
698
|
suffixFontSize={suffixFontSize ?? resolvedFontSize}
|
|
670
699
|
affixAlign={resolvedAffixAlign}
|
|
671
700
|
prefixAlign={prefixAlign ?? resolvedAffixAlign}
|
|
672
701
|
suffixAlign={suffixAlign ?? resolvedAffixAlign}
|
|
673
|
-
|
|
702
|
+
textLetterSpacing={letterSpacing ?? 0}
|
|
674
703
|
prefixSpacing={prefixSpacing ?? Infinity}
|
|
675
704
|
suffixSpacing={suffixSpacing ?? Infinity}
|
|
676
705
|
prefixOffset={prefixOffset ?? 0}
|
|
@@ -693,10 +722,10 @@ export const NitroNumber = forwardRef<NitroNumberHandle, NitroNumberProps>(
|
|
|
693
722
|
minimumFontScale={minimumFontScale ?? 0.5}
|
|
694
723
|
allowFontScaling={allowFontScaling ?? false}
|
|
695
724
|
maxFontSizeMultiplier={maxFontSizeMultiplier ?? 0}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
725
|
+
textWeight={numericWeight}
|
|
726
|
+
textFamily={fontFamily ?? ''}
|
|
727
|
+
textColor={processedColor}
|
|
728
|
+
textAlignment={textAlign ?? 'auto'}
|
|
700
729
|
rightToLeft={rightToLeft}
|
|
701
730
|
onSizeChange={onSizeChange}
|
|
702
731
|
/>
|