react-native-nitro-input 0.2.0 → 0.3.1
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 +87 -0
- package/README.md +132 -2
- package/android/CMakeLists.txt +4 -0
- package/android/gradle.properties +1 -1
- package/android/src/main/cpp/JReflowEngine.cpp +32 -0
- package/android/src/main/cpp/JReflowEngine.hpp +13 -0
- package/android/src/main/cpp/JRollingEngine.cpp +43 -2
- package/android/src/main/cpp/JRollingEngine.hpp +9 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +20 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatform.kt +284 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +113 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextMeasure.kt +25 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextView.kt +140 -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 +69 -10
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +522 -130
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroTextView.kt +868 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/ReflowEngine.kt +21 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/RollingEngine.kt +14 -2
- package/cpp/RollingEngine.cpp +102 -8
- package/cpp/RollingEngine.hpp +44 -3
- 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/ios/HybridNitroInputView.swift +15 -0
- package/ios/HybridNitroNumberFormatPlatform.swift +426 -0
- package/ios/HybridNitroNumberView.swift +101 -1
- package/ios/HybridNitroTextView.swift +134 -0
- package/ios/NitroInputView.swift +79 -19
- package/ios/NitroNumberView.swift +520 -147
- package/ios/NitroTextView.swift +583 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +26 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
- package/lib/commonjs/src/NitroInput.js +8 -6
- package/lib/commonjs/src/NitroNumber.js +54 -3
- package/lib/commonjs/src/NitroText.js +138 -0
- package/lib/commonjs/src/NitroTime.js +65 -0
- package/lib/commonjs/src/NumberFormat.js +525 -0
- package/lib/commonjs/src/formatProps.js +108 -0
- package/lib/commonjs/src/index.js +8 -1
- package/lib/commonjs/src/specs/NitroText.nitro.js +2 -0
- package/lib/commonjs/src/specs/NumberFormat.nitro.js +2 -0
- package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
- package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +26 -0
- package/lib/module/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
- package/lib/module/src/NitroInput.js +8 -6
- package/lib/module/src/NitroNumber.js +54 -3
- package/lib/module/src/NitroText.js +98 -0
- package/lib/module/src/NitroTime.js +29 -0
- package/lib/module/src/NumberFormat.js +521 -0
- package/lib/module/src/formatProps.js +104 -0
- package/lib/module/src/index.js +3 -0
- package/lib/module/src/specs/NitroText.nitro.js +1 -0
- package/lib/module/src/specs/NumberFormat.nitro.js +1 -0
- package/lib/typescript/src/NitroInput.d.ts +22 -0
- package/lib/typescript/src/NitroNumber.d.ts +115 -2
- package/lib/typescript/src/NitroText.d.ts +67 -0
- package/lib/typescript/src/NitroTime.d.ts +19 -0
- package/lib/typescript/src/NumberFormat.d.ts +47 -0
- package/lib/typescript/src/formatProps.d.ts +47 -0
- package/lib/typescript/src/index.d.ts +6 -1
- package/lib/typescript/src/specs/NitroInput.nitro.d.ts +10 -0
- package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +80 -1
- package/lib/typescript/src/specs/NitroText.nitro.d.ts +60 -0
- package/lib/typescript/src/specs/NumberFormat.nitro.d.ts +139 -0
- package/nitro.json +36 -0
- package/nitrogen/generated/android/NitroInput+autolinking.cmake +12 -0
- package/nitrogen/generated/android/NitroInputOnLoad.cpp +62 -0
- 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 +297 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +52 -0
- package/nitrogen/generated/android/c++/JHybridNitroPlatformNumberFormatterSpec.cpp +65 -0
- package/nitrogen/generated/android/c++/JHybridNitroPlatformNumberFormatterSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JHybridNitroTextMeasureSpec.cpp +58 -0
- package/nitrogen/generated/android/c++/JHybridNitroTextMeasureSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.cpp +253 -0
- package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.hpp +104 -0
- package/nitrogen/generated/android/c++/JNitroNumberDirection.hpp +3 -0
- package/nitrogen/generated/android/c++/JNitroNumberShimmerDirection.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroNumberSignDisplay.hpp +67 -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 +130 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.cpp +174 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.hpp +54 -0
- 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 +172 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroPlatformNumberFormatterSpec.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextMeasureSpec.kt +60 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextViewSpec.kt +179 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberDirection.kt +2 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberShimmerDirection.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberSignDisplay.kt +26 -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/HybridNitroTextViewManager.kt +96 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroTextViewStateUpdater.kt +23 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +68 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +184 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +56 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.mm +34 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.swift +36 -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.hpp +188 -0
- package/nitrogen/generated/ios/c++/HybridNitroPlatformNumberFormatterSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroPlatformNumberFormatterSpecSwift.hpp +94 -0
- package/nitrogen/generated/ios/c++/HybridNitroTextMeasureSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroTextMeasureSpecSwift.hpp +90 -0
- package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.hpp +233 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +30 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +156 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroTextViewComponent.mm +264 -0
- 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 +26 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +658 -21
- package/nitrogen/generated/ios/swift/HybridNitroPlatformNumberFormatterSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridNitroPlatformNumberFormatterSpec_cxx.swift +155 -0
- package/nitrogen/generated/ios/swift/HybridNitroTextMeasureSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridNitroTextMeasureSpec_cxx.swift +150 -0
- package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec.swift +75 -0
- package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec_cxx.swift +608 -0
- package/nitrogen/generated/ios/swift/NitroNumberDirection.swift +4 -0
- package/nitrogen/generated/ios/swift/NitroNumberShimmerDirection.swift +44 -0
- package/nitrogen/generated/ios/swift/NitroNumberSignDisplay.swift +52 -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 +52 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +58 -0
- package/nitrogen/generated/shared/c++/HybridNitroPlatformNumberFormatterSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridNitroPlatformNumberFormatterSpec.hpp +65 -0
- package/nitrogen/generated/shared/c++/HybridNitroTextMeasureSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridNitroTextMeasureSpec.hpp +63 -0
- package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.cpp +62 -0
- package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.hpp +115 -0
- package/nitrogen/generated/shared/c++/NitroNumberDirection.hpp +4 -0
- package/nitrogen/generated/shared/c++/NitroNumberShimmerDirection.hpp +80 -0
- package/nitrogen/generated/shared/c++/NitroNumberSignDisplay.hpp +88 -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 +52 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +80 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.cpp +74 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.hpp +149 -0
- package/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
- package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +26 -0
- package/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
- package/package.json +2 -2
- package/src/NitroInput.tsx +42 -7
- package/src/NitroNumber.tsx +236 -12
- package/src/NitroText.tsx +166 -0
- package/src/NitroTime.tsx +68 -0
- package/src/NumberFormat.ts +563 -0
- package/src/formatProps.ts +149 -0
- package/src/index.ts +23 -0
- package/src/specs/NitroInput.nitro.ts +10 -0
- package/src/specs/NitroNumber.nitro.ts +82 -1
- package/src/specs/NitroText.nitro.ts +65 -0
- package/src/specs/NumberFormat.nitro.ts +145 -0
|
@@ -34,6 +34,11 @@
|
|
|
34
34
|
"signPlacement": true,
|
|
35
35
|
"prefixAlign": true,
|
|
36
36
|
"suffixAlign": true,
|
|
37
|
+
"letterSpacing": true,
|
|
38
|
+
"prefixSpacing": true,
|
|
39
|
+
"suffixSpacing": true,
|
|
40
|
+
"prefixOffset": true,
|
|
41
|
+
"suffixOffset": true,
|
|
37
42
|
"placeholder": true,
|
|
38
43
|
"placeholderColor": true,
|
|
39
44
|
"duration": true,
|
|
@@ -32,12 +32,36 @@
|
|
|
32
32
|
"loading": true,
|
|
33
33
|
"shimmerColor": true,
|
|
34
34
|
"shimmerDuration": true,
|
|
35
|
+
"shimmerAngle": true,
|
|
36
|
+
"shimmerWidth": true,
|
|
37
|
+
"shimmerBaseColor": true,
|
|
38
|
+
"shimmerDirection": true,
|
|
39
|
+
"shimmerDelay": true,
|
|
35
40
|
"fontSize": true,
|
|
36
41
|
"prefixFontSize": true,
|
|
37
42
|
"suffixFontSize": true,
|
|
38
43
|
"affixAlign": true,
|
|
39
44
|
"prefixAlign": true,
|
|
40
45
|
"suffixAlign": true,
|
|
46
|
+
"letterSpacing": true,
|
|
47
|
+
"prefixSpacing": true,
|
|
48
|
+
"suffixSpacing": true,
|
|
49
|
+
"prefixOffset": true,
|
|
50
|
+
"suffixOffset": true,
|
|
51
|
+
"tabularNums": true,
|
|
52
|
+
"signDisplay": true,
|
|
53
|
+
"plusSign": true,
|
|
54
|
+
"minusSign": true,
|
|
55
|
+
"digitGlyphs": true,
|
|
56
|
+
"groupingSizes": true,
|
|
57
|
+
"digitMax": true,
|
|
58
|
+
"continuous": true,
|
|
59
|
+
"prefixColor": true,
|
|
60
|
+
"suffixColor": true,
|
|
61
|
+
"fractionColor": true,
|
|
62
|
+
"fractionFontSize": true,
|
|
63
|
+
"fractionAlign": true,
|
|
64
|
+
"respectReduceMotion": true,
|
|
41
65
|
"adjustsFontSizeToFit": true,
|
|
42
66
|
"minimumFontScale": true,
|
|
43
67
|
"allowFontScaling": true,
|
|
@@ -50,6 +74,8 @@
|
|
|
50
74
|
"onSizeChange": true,
|
|
51
75
|
"onRevealEnd": true,
|
|
52
76
|
"onRevealMilestone": true,
|
|
77
|
+
"onAnimationStart": true,
|
|
78
|
+
"onAnimationEnd": true,
|
|
53
79
|
"hybridRef": true
|
|
54
80
|
}
|
|
55
81
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"uiViewClassName": "NitroTextView",
|
|
3
|
+
"supportsRawText": false,
|
|
4
|
+
"bubblingEventTypes": {},
|
|
5
|
+
"directEventTypes": {},
|
|
6
|
+
"validAttributes": {
|
|
7
|
+
"text": true,
|
|
8
|
+
"fontSize": true,
|
|
9
|
+
"fontWeight": true,
|
|
10
|
+
"fontFamily": true,
|
|
11
|
+
"color": true,
|
|
12
|
+
"letterSpacing": true,
|
|
13
|
+
"textAlign": true,
|
|
14
|
+
"rightToLeft": true,
|
|
15
|
+
"duration": true,
|
|
16
|
+
"easing": true,
|
|
17
|
+
"bounce": true,
|
|
18
|
+
"effect": true,
|
|
19
|
+
"respectReduceMotion": true,
|
|
20
|
+
"loading": true,
|
|
21
|
+
"shimmerColor": true,
|
|
22
|
+
"shimmerDuration": true,
|
|
23
|
+
"shimmerAngle": true,
|
|
24
|
+
"shimmerWidth": true,
|
|
25
|
+
"shimmerBaseColor": true,
|
|
26
|
+
"shimmerDirection": true,
|
|
27
|
+
"shimmerDelay": true,
|
|
28
|
+
"hybridRef": true
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -4,6 +4,7 @@ import { callback, getHostComponent, } from 'react-native-nitro-modules';
|
|
|
4
4
|
import NitroInputViewConfig from '../nitrogen/generated/shared/json/NitroInputViewConfig.json';
|
|
5
5
|
import { allocateWorkletId, isWorklet, registerFocusChange, registerKeyPress, registerSelectionChange, registerTextEvent, registerCallback, registerTransform, unregisterWorklet, } from './worklets';
|
|
6
6
|
import { toNumericWeight, toProcessedColor } from './styleHelpers';
|
|
7
|
+
import { formatProps } from './formatProps';
|
|
7
8
|
const textInputRegistry = (() => {
|
|
8
9
|
try {
|
|
9
10
|
// The registry has no public surface: `TextInput.State` exposes the focus
|
|
@@ -136,7 +137,7 @@ function warnIncompatible(what) {
|
|
|
136
137
|
* Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
|
|
137
138
|
* it to its content instead, and is on by default when the text reflows.
|
|
138
139
|
*/
|
|
139
|
-
export const NitroInput = forwardRef(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, placeholder, placeholderTextColor, duration, easing, bounce, effect, fontSize, lineHeight, fontWeight, fontFamily, color, textAlign, cursorColor, selectionColor, caretHidden, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, variant, label, labelBehavior, labelColor, labelFocusedColor, labelFontSize, strokeColor, focusedStrokeColor, strokeWidth, cornerRadius, fillColor, keyboardType, inputMode, enterKeyHint, mask, maskNotations, maskAutocomplete, maskAutoSkip, returnKeyType, autoCapitalize, autoCorrect, editable, multiline, numberOfLines, rows, textAlignVertical, scrollEnabled, autoFocus, transition, autoWidth: autoWidthProp, submitBehavior, blurOnSubmit, secureTextEntry, keyboardAppearance, textContentType, autoComplete, enablesReturnKeyAutomatically, showSoftInputOnFocus, selectTextOnFocus, clearTextOnFocus, contextMenuHidden, spellCheck, readOnly, selection, onEndEditing, onSelectionChange, onKeyPress, maxLength, transform, onChangeText, onChange, onChangeValue, onChangeMask, onFocus, onBlur, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
|
|
140
|
+
export const NitroInput = forwardRef(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, format, placeholder, placeholderTextColor, duration, easing, bounce, effect, fontSize, lineHeight, fontWeight, fontFamily, color, textAlign, cursorColor, selectionColor, caretHidden, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, variant, label, labelBehavior, labelColor, labelFocusedColor, labelFontSize, strokeColor, focusedStrokeColor, strokeWidth, cornerRadius, fillColor, keyboardType, inputMode, enterKeyHint, mask, maskNotations, maskAutocomplete, maskAutoSkip, returnKeyType, autoCapitalize, autoCorrect, editable, multiline, numberOfLines, rows, textAlignVertical, scrollEnabled, autoFocus, transition, autoWidth: autoWidthProp, submitBehavior, blurOnSubmit, secureTextEntry, keyboardAppearance, textContentType, autoComplete, enablesReturnKeyAutomatically, showSoftInputOnFocus, selectTextOnFocus, clearTextOnFocus, contextMenuHidden, spellCheck, readOnly, selection, onEndEditing, onSelectionChange, onKeyPress, maxLength, transform, onChangeText, onChange, onChangeValue, onChangeMask, onFocus, onBlur, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
|
|
140
141
|
const nativeRef = useRef(null);
|
|
141
142
|
// What React Native's registry stores for this field. The React host
|
|
142
143
|
// instance when there is one (iOS), otherwise a stable per-instance token:
|
|
@@ -428,13 +429,14 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
|
|
|
428
429
|
if (suffix)
|
|
429
430
|
warnIncompatible('suffix');
|
|
430
431
|
}
|
|
431
|
-
const
|
|
432
|
+
const derived = format ? formatProps(format) : undefined;
|
|
433
|
+
const resolvedMode = isMultiline ? 'text' : (mode ?? (derived ? 'number' : 'text'));
|
|
432
434
|
const reflows = !isMultiline && transition === 'reflow';
|
|
433
435
|
// The affixes are accessory views beside one line of text; a wrapping text
|
|
434
436
|
// view has no slot for them, so they go with the mode rather than being
|
|
435
437
|
// half-drawn on one platform and not the other.
|
|
436
|
-
const resolvedPrefix = isMultiline ? '' : (prefix ?? '');
|
|
437
|
-
const resolvedSuffix = isMultiline ? '' : (suffix ?? '');
|
|
438
|
+
const resolvedPrefix = isMultiline ? '' : (prefix ?? derived?.prefix ?? '');
|
|
439
|
+
const resolvedSuffix = isMultiline ? '' : (suffix ?? derived?.suffix ?? '');
|
|
438
440
|
// A new `maskNotations` literal each render must not re-set the native
|
|
439
441
|
// prop, so it is keyed on its contents. Always an array (empty = none):
|
|
440
442
|
// removing the prop would reach native as `null`, which Nitro's array
|
|
@@ -443,7 +445,7 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
|
|
|
443
445
|
const stableNotations = useMemo(() => (notationsKey !== '' && maskNotations ? [...maskNotations] : EMPTY_NOTATIONS),
|
|
444
446
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
445
447
|
[notationsKey]);
|
|
446
|
-
const resolvedFractionDigits = fractionDigits ?? 2;
|
|
448
|
+
const resolvedFractionDigits = fractionDigits ?? derived?.fractionDigits ?? 2;
|
|
447
449
|
const resolvedKeyboardType = keyboardType ??
|
|
448
450
|
(inputMode != null
|
|
449
451
|
? INPUT_MODE_TO_KEYBOARD[inputMode]
|
|
@@ -505,7 +507,7 @@ export const NitroInput = forwardRef(function NitroInput({ value, defaultValue,
|
|
|
505
507
|
? { width: size.width, height: size.height }
|
|
506
508
|
: { height: size.height }
|
|
507
509
|
: { height: resolvedFontSize * 1.25 }, [size, resolvedFontSize, autoWidth]);
|
|
508
|
-
return (React.createElement(NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? initialText, mostRecentEventCount: eventCountRef.current, mode: resolvedMode, plain: !reflows, fractionDigits: resolvedFractionDigits, maxIntegerDigits: maxIntegerDigits ?? 15, groupingSeparator: groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, placeholder: placeholder ?? '', placeholderColor: processedPlaceholderColor, duration: duration ?? 400, easing: easing ?? 'expo', bounce: bounce ?? 0.15, effect: effect ?? 'auto', fontSize: resolvedFontSize, lineHeight: Math.max(0, lineHeight ?? 0), fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, caretColor: processedCursorColor, selectionColor: processedSelectionColor, caretHidden: caretHidden ?? false, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, variant: variant ?? 'none', label: label ?? '', labelBehavior: labelBehavior ?? 'float', labelColor: processedLabelColor, labelFocusedColor: processedLabelFocusedColor, labelFontSize: labelFontSize ?? 0, strokeColor: processedStrokeColor, focusedStrokeColor: processedFocusedStrokeColor, strokeWidth: strokeWidth ?? 1, cornerRadius: cornerRadius ?? 8, fillColor: processedFillColor, mask: resolvedMode === 'mask' ? (mask ?? '') : '', maskNotations: stableNotations, maskAutocomplete: maskAutocomplete ?? true, maskAutoSkip: maskAutoSkip ?? false, onChangeMask: onChangeMaskCallback, keyboardType: resolvedKeyboardType, returnKeyType: resolvedReturnKeyType, autoCapitalize: autoCapitalize ?? 'sentences', autoCorrect: autoCorrect ?? true, editable: (editable ?? true) && !(readOnly ?? false), multiline: isMultiline, numberOfLines: Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0)), textAlignVertical: textAlignVertical ?? 'auto', scrollEnabled: scrollEnabled ?? true, autoFocus: autoFocus ?? false, fieldTestID: viewProps.testID ?? '', fieldAccessibilityLabel: resolvedAccessibilityLabel ?? '', submitBehavior: submitBehavior ??
|
|
510
|
+
return (React.createElement(NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? initialText, mostRecentEventCount: eventCountRef.current, mode: resolvedMode, plain: !reflows, fractionDigits: resolvedFractionDigits, maxIntegerDigits: maxIntegerDigits ?? 15, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, placeholder: placeholder ?? '', placeholderColor: processedPlaceholderColor, duration: duration ?? 400, easing: easing ?? 'expo', bounce: bounce ?? 0.15, effect: effect ?? 'auto', fontSize: resolvedFontSize, lineHeight: Math.max(0, lineHeight ?? 0), fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, caretColor: processedCursorColor, selectionColor: processedSelectionColor, caretHidden: caretHidden ?? false, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, variant: variant ?? 'none', label: label ?? '', labelBehavior: labelBehavior ?? 'float', labelColor: processedLabelColor, labelFocusedColor: processedLabelFocusedColor, labelFontSize: labelFontSize ?? 0, strokeColor: processedStrokeColor, focusedStrokeColor: processedFocusedStrokeColor, strokeWidth: strokeWidth ?? 1, cornerRadius: cornerRadius ?? 8, fillColor: processedFillColor, mask: resolvedMode === 'mask' ? (mask ?? '') : '', maskNotations: stableNotations, maskAutocomplete: maskAutocomplete ?? true, maskAutoSkip: maskAutoSkip ?? false, onChangeMask: onChangeMaskCallback, keyboardType: resolvedKeyboardType, returnKeyType: resolvedReturnKeyType, autoCapitalize: autoCapitalize ?? 'sentences', autoCorrect: autoCorrect ?? true, editable: (editable ?? true) && !(readOnly ?? false), multiline: isMultiline, numberOfLines: Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0)), textAlignVertical: textAlignVertical ?? 'auto', scrollEnabled: scrollEnabled ?? true, autoFocus: autoFocus ?? false, fieldTestID: viewProps.testID ?? '', fieldAccessibilityLabel: resolvedAccessibilityLabel ?? '', submitBehavior: submitBehavior ??
|
|
509
511
|
// As `TextInput` resolves the legacy `blurOnSubmit`: a multiline
|
|
510
512
|
// field's return key inserts a line break unless told to blur.
|
|
511
513
|
(multiline
|
|
@@ -3,11 +3,14 @@ import { I18nManager, StyleSheet, } from 'react-native';
|
|
|
3
3
|
import { callback, getHostComponent, } from 'react-native-nitro-modules';
|
|
4
4
|
import NitroNumberViewConfig from '../nitrogen/generated/shared/json/NitroNumberViewConfig.json';
|
|
5
5
|
import { toNumericWeight, toProcessedColor } from './styleHelpers';
|
|
6
|
+
import { compactParts, formatProps } from './formatProps';
|
|
6
7
|
/**
|
|
7
8
|
* The raw Nitro host component. Prefer {@link NitroNumber}, which adds
|
|
8
9
|
* auto-sizing, color/weight conversion and a convenient handle.
|
|
9
10
|
*/
|
|
10
11
|
export const NativeNitroNumberView = getHostComponent('NitroNumberView', () => NitroNumberViewConfig);
|
|
12
|
+
const EMPTY = [];
|
|
13
|
+
const EMPTY_STRINGS = [];
|
|
11
14
|
/** Each transition's own timing, used when the props leave it unsaid. */
|
|
12
15
|
const TRANSITION_DEFAULTS = {
|
|
13
16
|
roll: { duration: 500, easing: 'easeInOut', stagger: 0 },
|
|
@@ -24,7 +27,7 @@ const TRANSITION_DEFAULTS = {
|
|
|
24
27
|
* The view sizes itself to its content unless you pass an explicit `width` /
|
|
25
28
|
* `height` in `style`.
|
|
26
29
|
*/
|
|
27
|
-
export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigits, minimumIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, transition, flashUpColor, flashDownColor, flashDuration, popOnChange, duration, easing, bounce, stagger, direction, reveal, revealStyle, revealDuration, revealBounce, revealGrow, revealStagger, revealMilestones, revealMilestoneHold, onRevealEnd, onRevealMilestone, loading, shimmerColor, shimmerDuration, fontSize, prefixFontSize, suffixFontSize, affixAlign, prefixAlign, suffixAlign, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, fontWeight, fontFamily, color, textAlign, onNativeRef, style, ...viewProps }, ref) {
|
|
30
|
+
export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigits, minimumIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, transition, flashUpColor, flashDownColor, flashDuration, popOnChange, duration, easing, bounce, stagger, direction, reveal, revealStyle, revealDuration, revealBounce, revealGrow, revealStagger, revealMilestones, revealMilestoneHold, onRevealEnd, onRevealMilestone, loading, shimmerColor, shimmerDuration, shimmerAngle, shimmerWidth, shimmerBaseColor, shimmerDirection, shimmerDelay, fontSize, prefixFontSize, suffixFontSize, affixAlign, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, tabularNums, format, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, fontWeight, fontFamily, color, textAlign, signDisplay, plusSign, minusSign, prefixColor, suffixColor, fractionColor, fractionFontSize, fractionAlign, digitGlyphs, groupingSizes, digits, continuous, animated, respectReduceMotion, onAnimationStart, onAnimationEnd, onNativeRef, style, ...viewProps }, ref) {
|
|
28
31
|
const nativeRef = useRef(null);
|
|
29
32
|
const latestOnNativeRef = useRef(onNativeRef);
|
|
30
33
|
latestOnNativeRef.current = onNativeRef;
|
|
@@ -34,6 +37,10 @@ export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigi
|
|
|
34
37
|
latestOnRevealMilestone.current = onRevealMilestone;
|
|
35
38
|
const latestValue = useRef(value);
|
|
36
39
|
latestValue.current = value;
|
|
40
|
+
const latestOnAnimationStart = useRef(onAnimationStart);
|
|
41
|
+
latestOnAnimationStart.current = onAnimationStart;
|
|
42
|
+
const latestOnAnimationEnd = useRef(onAnimationEnd);
|
|
43
|
+
latestOnAnimationEnd.current = onAnimationEnd;
|
|
37
44
|
const [size, setSize] = useState(null);
|
|
38
45
|
// Nitro callbacks must be wrapped with `callback()` and the wrapper object
|
|
39
46
|
// has to be referentially stable, otherwise every render re-sets the prop.
|
|
@@ -56,6 +63,13 @@ export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigi
|
|
|
56
63
|
const onRevealMilestoneCallback = useMemo(() => callback((index, milestone) => {
|
|
57
64
|
latestOnRevealMilestone.current?.(index, milestone);
|
|
58
65
|
}), []);
|
|
66
|
+
const onAnimationStartCallback = useMemo(() => callback(() => {
|
|
67
|
+
latestOnAnimationStart.current?.();
|
|
68
|
+
}), []);
|
|
69
|
+
// The figure a compact format rolls is not the value (1.2 for 1,234): report the value.
|
|
70
|
+
const onAnimationEndCallback = useMemo(() => callback((shown) => {
|
|
71
|
+
latestOnAnimationEnd.current?.(compactRef.current ? latestValue.current : shown);
|
|
72
|
+
}), []);
|
|
59
73
|
// A new array literal each render must not re-set the native prop. Always an
|
|
60
74
|
// array (empty = no tiers): removing the prop would reach native as `null`,
|
|
61
75
|
// which Nitro's array parser rejects ("Value is null, expected an Object").
|
|
@@ -69,7 +83,7 @@ export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigi
|
|
|
69
83
|
jumpTo: (next) => nativeRef.current?.jumpTo(next),
|
|
70
84
|
animateTo: (next) => nativeRef.current?.animateTo(next),
|
|
71
85
|
revealTo: (next) => nativeRef.current?.revealTo(next),
|
|
72
|
-
getValue: () => nativeRef.current?.value ?? latestValue.current,
|
|
86
|
+
getValue: () => (compactRef.current ? latestValue.current : nativeRef.current?.value ?? latestValue.current),
|
|
73
87
|
get native() {
|
|
74
88
|
return nativeRef.current;
|
|
75
89
|
},
|
|
@@ -83,11 +97,48 @@ export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigi
|
|
|
83
97
|
// render and had the whole configuration re-applied on every value change.
|
|
84
98
|
const processedColor = useMemo(() => toProcessedColor(color) ?? Infinity, [color]);
|
|
85
99
|
const processedShimmerColor = useMemo(() => toProcessedColor(shimmerColor) ?? Infinity, [shimmerColor]);
|
|
100
|
+
const processedShimmerBase = useMemo(() => toProcessedColor(shimmerBaseColor) ?? Infinity, [shimmerBaseColor]);
|
|
86
101
|
const processedFlashUp = useMemo(() => toProcessedColor(flashUpColor) ?? Infinity, [flashUpColor]);
|
|
87
102
|
const processedFlashDown = useMemo(() => toProcessedColor(flashDownColor) ?? Infinity, [flashDownColor]);
|
|
88
103
|
const numericWeight = toNumericWeight(fontWeight) ?? 400;
|
|
89
104
|
const resolvedFontSize = fontSize ?? 32;
|
|
90
105
|
const resolvedAffixAlign = affixAlign ?? 'baseline';
|
|
106
|
+
const derived = format ? formatProps(format) : undefined;
|
|
107
|
+
// Compact notation: "1.2K" rolls the figure 1.2 and swaps the suffix.
|
|
108
|
+
const compact = format && derived?.compact ? compactParts(format, value) : undefined;
|
|
109
|
+
const compactRef = useRef(false);
|
|
110
|
+
compactRef.current = compact !== undefined;
|
|
111
|
+
// Which way the value moved, for a compact figure that fell while the value grew (999 → 1K).
|
|
112
|
+
const previousValue = useRef(value);
|
|
113
|
+
const compactDirection = compact && direction === undefined ? (value >= previousValue.current ? 'up' : 'down') : undefined;
|
|
114
|
+
previousValue.current = value;
|
|
115
|
+
const processedPrefixColor = useMemo(() => toProcessedColor(prefixColor) ?? Infinity, [prefixColor]);
|
|
116
|
+
const processedSuffixColor = useMemo(() => toProcessedColor(suffixColor) ?? Infinity, [suffixColor]);
|
|
117
|
+
const processedFractionColor = useMemo(() => toProcessedColor(fractionColor) ?? Infinity, [fractionColor]);
|
|
118
|
+
// Arrays reach native only when their contents change.
|
|
119
|
+
const digitMaxKey = digits ? JSON.stringify(digits) : '';
|
|
120
|
+
const digitMax = useMemo(() => {
|
|
121
|
+
if (!digits)
|
|
122
|
+
return EMPTY;
|
|
123
|
+
const out = [];
|
|
124
|
+
for (const [position, spec] of Object.entries(digits)) {
|
|
125
|
+
const index = Number(position);
|
|
126
|
+
if (!Number.isInteger(index) || index < 0 || index >= 20)
|
|
127
|
+
continue;
|
|
128
|
+
while (out.length <= index)
|
|
129
|
+
out.push(9);
|
|
130
|
+
out[index] = spec.max;
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
134
|
+
}, [digitMaxKey]);
|
|
135
|
+
const glyphs = digitGlyphs ?? derived?.digitGlyphs ?? EMPTY_STRINGS;
|
|
136
|
+
const glyphsKey = glyphs.join('|');
|
|
137
|
+
const stableGlyphs = useMemo(() => glyphs, [glyphsKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
138
|
+
const groups = groupingSizes ?? derived?.groupingSizes ?? EMPTY;
|
|
139
|
+
const groupsKey = groups.join(',');
|
|
140
|
+
const stableGroups = useMemo(() => groups, [groupsKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
141
|
+
const still = animated === false;
|
|
91
142
|
const autoSize = useMemo(() => size !== null
|
|
92
143
|
? { width: size.width, height: size.height }
|
|
93
144
|
: { height: (fontSize ?? 32) * 1.25 }, [size, fontSize]);
|
|
@@ -96,5 +147,5 @@ export const NitroNumber = forwardRef(function NitroNumber({ value, fractionDigi
|
|
|
96
147
|
// does not hand a Hybrid View its resolved direction, so native is told.
|
|
97
148
|
const layoutDirection = useMemo(() => StyleSheet.flatten(style)?.direction, [style]);
|
|
98
149
|
const rightToLeft = layoutDirection === 'rtl' || (layoutDirection !== 'ltr' && I18nManager.isRTL);
|
|
99
|
-
return (React.createElement(NativeNitroNumberView, { ...viewProps, style: [autoSize, style], hybridRef: hybridRef, value: value, fractionDigits: fractionDigits ?? 0, minimumIntegerDigits: minimumIntegerDigits ?? 1, groupingSeparator: groupingSeparator ?? '', decimalSeparator: decimalSeparator ?? '.', prefix: prefix ?? '', suffix: suffix ?? '', transition: transition ?? 'roll', flashUpColor: processedFlashUp, flashDownColor: processedFlashDown, flashDuration: flashDuration ?? 600, popOnChange: popOnChange ?? 0, duration: duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration, easing: easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing, bounce: bounce ?? 0.15, stagger: stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger, rollDirection: direction ?? 'auto', revealState: reveal === undefined ? 0 : reveal ? 2 : 1, revealStyle: revealStyle ?? 'count', revealDuration: revealDuration ?? 2200, revealBounce: revealBounce ?? 0.12, revealGrow: revealGrow ?? 0.2, revealStagger: revealStagger ?? 200, revealMilestones: stableMilestones, revealMilestoneHold: revealMilestoneHold ?? 0, onRevealEnd: onRevealEndCallback, onRevealMilestone: onRevealMilestoneCallback, loading: loading ?? false, shimmerColor: processedShimmerColor, shimmerDuration: shimmerDuration ?? 950, fontSize: resolvedFontSize, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, affixAlign: resolvedAffixAlign, prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, onSizeChange: onSizeChange }));
|
|
150
|
+
return (React.createElement(NativeNitroNumberView, { ...viewProps, style: [autoSize, style], hybridRef: hybridRef, value: compact ? compact.value : value, fractionDigits: fractionDigits ?? compact?.fractionDigits ?? derived?.fractionDigits ?? 0, minimumIntegerDigits: minimumIntegerDigits ?? derived?.minimumIntegerDigits ?? 1, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? '', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: prefix ?? compact?.prefix ?? derived?.prefix ?? '', suffix: suffix ?? compact?.suffix ?? derived?.suffix ?? '', transition: transition ?? 'roll', flashUpColor: processedFlashUp, flashDownColor: processedFlashDown, flashDuration: flashDuration ?? 600, popOnChange: popOnChange ?? 0, duration: still ? 0 : duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration, easing: easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing, bounce: bounce ?? 0.15, stagger: stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger, rollDirection: direction ?? compactDirection ?? 'auto', revealState: reveal === undefined ? 0 : reveal ? 2 : 1, revealStyle: revealStyle ?? 'count', revealDuration: still ? 0 : revealDuration ?? 2200, revealBounce: revealBounce ?? 0.12, revealGrow: revealGrow ?? 0.2, revealStagger: revealStagger ?? 200, revealMilestones: stableMilestones, revealMilestoneHold: revealMilestoneHold ?? 0, onRevealEnd: onRevealEndCallback, onRevealMilestone: onRevealMilestoneCallback, onAnimationStart: onAnimationStartCallback, onAnimationEnd: onAnimationEndCallback, loading: loading ?? false, shimmerColor: processedShimmerColor, shimmerDuration: shimmerDuration ?? 950, shimmerAngle: shimmerAngle ?? 31, shimmerWidth: shimmerWidth ?? 1, shimmerBaseColor: processedShimmerBase, shimmerDirection: shimmerDirection ?? 'auto', shimmerDelay: shimmerDelay ?? 0, fontSize: resolvedFontSize, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, affixAlign: resolvedAffixAlign, prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, tabularNums: tabularNums ?? true, signDisplay: signDisplay ?? derived?.signDisplay ?? 'auto', plusSign: plusSign ?? derived?.plusSign ?? '+', minusSign: minusSign ?? derived?.minusSign ?? '-', digitGlyphs: stableGlyphs, groupingSizes: stableGroups, digitMax: digitMax, continuous: continuous ?? false, prefixColor: processedPrefixColor, suffixColor: processedSuffixColor, fractionColor: processedFractionColor, fractionFontSize: fractionFontSize ?? Infinity, fractionAlign: fractionAlign ?? 'baseline', respectReduceMotion: respectReduceMotion ?? true, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, onSizeChange: onSizeChange }));
|
|
100
151
|
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { I18nManager, PixelRatio, StyleSheet, } from 'react-native';
|
|
3
|
+
import { getHostComponent, NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
import NitroTextViewConfig from '../nitrogen/generated/shared/json/NitroTextViewConfig.json';
|
|
5
|
+
import { toNumericWeight, toProcessedColor } from './styleHelpers';
|
|
6
|
+
/** The raw Nitro host component behind {@link NitroText}. */
|
|
7
|
+
export const NativeNitroTextView = getHostComponent('NitroTextView', () => NitroTextViewConfig);
|
|
8
|
+
let measurer = null;
|
|
9
|
+
function measure() {
|
|
10
|
+
measurer ??= NitroModules.createHybridObject('NitroTextMeasure');
|
|
11
|
+
return measurer;
|
|
12
|
+
}
|
|
13
|
+
const lineHeights = new Map();
|
|
14
|
+
/**
|
|
15
|
+
* A single line of text that morphs to the next, natively, as Torph does on
|
|
16
|
+
* the web: the characters the two share glide to their new places, digits
|
|
17
|
+
* matched by place ("$1,204" → "$1,318" rolls the hundreds and tens), and the
|
|
18
|
+
* rest fade out and in ("Sign in" → "Signing in…"). At rest it is one line
|
|
19
|
+
* drawn in one pass, like a label: no text field, no layer per character.
|
|
20
|
+
* It sizes itself to its text in the render that mounts it (a native
|
|
21
|
+
* measurement, synchronously); a `width` in `style` overrides it.
|
|
22
|
+
*
|
|
23
|
+
* Only the props that were set go to the native view, as
|
|
24
|
+
* react-native-plain-text does: every prop that crosses is converted and
|
|
25
|
+
* stored per view in the commit, and the native side holds the defaults.
|
|
26
|
+
*/
|
|
27
|
+
export function NitroText({ children, fontSize, fontWeight, fontFamily, color, letterSpacing, textAlign, allowFontScaling, maxFontSizeMultiplier, duration, easing, bounce, effect, respectReduceMotion, loading, shimmerColor, shimmerDuration, shimmerAngle, shimmerWidth, shimmerBaseColor, shimmerDirection, shimmerDelay, style, ...viewProps }) {
|
|
28
|
+
const text = typeof children === 'string' ? children : String(children);
|
|
29
|
+
const scale = allowFontScaling
|
|
30
|
+
? maxFontSizeMultiplier && maxFontSizeMultiplier > 0
|
|
31
|
+
? Math.min(PixelRatio.getFontScale(), maxFontSizeMultiplier)
|
|
32
|
+
: PixelRatio.getFontScale()
|
|
33
|
+
: 1;
|
|
34
|
+
const size = (fontSize ?? 17) * scale;
|
|
35
|
+
const weight = fontWeight === undefined ? 400 : toNumericWeight(fontWeight) ?? 400;
|
|
36
|
+
const family = fontFamily ?? '';
|
|
37
|
+
const spacing = letterSpacing ?? 0;
|
|
38
|
+
const width = useMemo(() => measure().measure(text, size, weight, family, spacing), [text, size, weight, family, spacing]);
|
|
39
|
+
const fontKey = `${size}|${weight}|${family}`;
|
|
40
|
+
let height = lineHeights.get(fontKey);
|
|
41
|
+
if (height === undefined) {
|
|
42
|
+
height = measure().lineHeight(size, weight, family);
|
|
43
|
+
lineHeights.set(fontKey, height);
|
|
44
|
+
}
|
|
45
|
+
const native = viewProps;
|
|
46
|
+
native.text = text;
|
|
47
|
+
native.style = style == null ? { width: Math.ceil(width), height } : [{ width: Math.ceil(width), height }, style];
|
|
48
|
+
if (size !== 17)
|
|
49
|
+
native.fontSize = size;
|
|
50
|
+
if (weight !== 400)
|
|
51
|
+
native.fontWeight = weight;
|
|
52
|
+
if (family !== '')
|
|
53
|
+
native.fontFamily = family;
|
|
54
|
+
if (spacing !== 0)
|
|
55
|
+
native.letterSpacing = spacing;
|
|
56
|
+
const processedColor = toProcessedColor(color);
|
|
57
|
+
if (processedColor !== undefined)
|
|
58
|
+
native.color = processedColor;
|
|
59
|
+
if (textAlign !== undefined)
|
|
60
|
+
native.textAlign = textAlign;
|
|
61
|
+
if (duration !== undefined)
|
|
62
|
+
native.duration = duration;
|
|
63
|
+
if (easing !== undefined)
|
|
64
|
+
native.easing = easing;
|
|
65
|
+
if (bounce !== undefined)
|
|
66
|
+
native.bounce = bounce;
|
|
67
|
+
if (effect !== undefined)
|
|
68
|
+
native.effect = effect;
|
|
69
|
+
if (respectReduceMotion !== undefined)
|
|
70
|
+
native.respectReduceMotion = respectReduceMotion;
|
|
71
|
+
if (loading !== undefined)
|
|
72
|
+
native.loading = loading;
|
|
73
|
+
const processedShimmerColor = toProcessedColor(shimmerColor);
|
|
74
|
+
if (processedShimmerColor !== undefined)
|
|
75
|
+
native.shimmerColor = processedShimmerColor;
|
|
76
|
+
if (shimmerDuration !== undefined)
|
|
77
|
+
native.shimmerDuration = shimmerDuration;
|
|
78
|
+
if (shimmerAngle !== undefined)
|
|
79
|
+
native.shimmerAngle = shimmerAngle;
|
|
80
|
+
if (shimmerWidth !== undefined)
|
|
81
|
+
native.shimmerWidth = shimmerWidth;
|
|
82
|
+
const processedShimmerBaseColor = toProcessedColor(shimmerBaseColor);
|
|
83
|
+
if (processedShimmerBaseColor !== undefined)
|
|
84
|
+
native.shimmerBaseColor = processedShimmerBaseColor;
|
|
85
|
+
if (shimmerDirection !== undefined)
|
|
86
|
+
native.shimmerDirection = shimmerDirection;
|
|
87
|
+
if (shimmerDelay !== undefined)
|
|
88
|
+
native.shimmerDelay = shimmerDelay;
|
|
89
|
+
// The start edge follows the layout direction, the app's unless the style sets one.
|
|
90
|
+
const direction = style == null ? undefined : StyleSheet.flatten(style).direction;
|
|
91
|
+
if (direction === 'rtl' || (direction !== 'ltr' && I18nManager.isRTL))
|
|
92
|
+
native.rightToLeft = true;
|
|
93
|
+
// The native view is the accessibility element, labelled with its text and
|
|
94
|
+
// announced as text. A label from outside takes over, on this view.
|
|
95
|
+
if (native.accessibilityLabel != null && native.accessible === undefined)
|
|
96
|
+
native.accessible = true;
|
|
97
|
+
return React.createElement(NativeNitroTextView, { ...native });
|
|
98
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { NitroNumber } from './NitroNumber';
|
|
3
|
+
const LAYOUT = {
|
|
4
|
+
'm:ss': { hours: false, digits: 3 },
|
|
5
|
+
'mm:ss': { hours: false, digits: 4 },
|
|
6
|
+
'h:mm:ss': { hours: true, digits: 5 },
|
|
7
|
+
'hh:mm:ss': { hours: true, digits: 6 },
|
|
8
|
+
};
|
|
9
|
+
// The tens of seconds, and of minutes when hours are shown, wrap after 5.
|
|
10
|
+
const SECONDS = { 1: { max: 5 } };
|
|
11
|
+
const MINUTES_AND_SECONDS = { 1: { max: 5 }, 3: { max: 5 } };
|
|
12
|
+
// One separator before the seconds: 125:00 is 125 minutes, not 1:25:00.
|
|
13
|
+
const MINUTES_ONLY = [2, 0];
|
|
14
|
+
const PAIRS = [2];
|
|
15
|
+
/**
|
|
16
|
+
* A clock, a timer or a countdown: `NitroNumber` with the time as its figure
|
|
17
|
+
* (12:34:56 is 123456), grouped in pairs, and the tens of seconds and minutes
|
|
18
|
+
* wrapping after 5, so 0:59 → 1:00 turns them one step, as a clock's wheels
|
|
19
|
+
* do, instead of rolling back through 4, 3, 2, 1.
|
|
20
|
+
*/
|
|
21
|
+
export const NitroTime = forwardRef(function NitroTime({ seconds, timeFormat = 'm:ss', separator = ':', ...props }, ref) {
|
|
22
|
+
const layout = LAYOUT[timeFormat];
|
|
23
|
+
const total = Math.max(0, Math.floor(Number.isFinite(seconds) ? seconds : 0));
|
|
24
|
+
const s = total % 60;
|
|
25
|
+
const value = layout.hours
|
|
26
|
+
? Math.floor(total / 3600) * 10000 + (Math.floor(total / 60) % 60) * 100 + s
|
|
27
|
+
: Math.floor(total / 60) * 100 + s;
|
|
28
|
+
return (React.createElement(NitroNumber, { ref: ref, value: value, minimumIntegerDigits: layout.digits, groupingSeparator: separator, groupingSizes: layout.hours ? PAIRS : MINUTES_ONLY, digits: layout.hours ? MINUTES_AND_SECONDS : SECONDS, ...props }));
|
|
29
|
+
});
|