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
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
package com.margelo.nitro.nitroinput
|
|
2
|
+
|
|
3
|
+
import android.icu.number.LocalizedNumberFormatter
|
|
4
|
+
import android.icu.number.Notation
|
|
5
|
+
import android.icu.number.NumberFormatter
|
|
6
|
+
import android.icu.number.Precision
|
|
7
|
+
import android.icu.number.Scale
|
|
8
|
+
import android.icu.text.CompactDecimalFormat
|
|
9
|
+
import android.icu.text.DecimalFormat
|
|
10
|
+
import android.icu.text.DecimalFormatSymbols
|
|
11
|
+
import android.icu.text.MeasureFormat
|
|
12
|
+
import android.icu.text.NumberFormat
|
|
13
|
+
import android.icu.text.NumberingSystem
|
|
14
|
+
import android.icu.util.Currency
|
|
15
|
+
import android.icu.util.Measure
|
|
16
|
+
import android.icu.util.MeasureUnit
|
|
17
|
+
import android.icu.util.ULocale
|
|
18
|
+
import android.os.Build
|
|
19
|
+
import androidx.annotation.Keep
|
|
20
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
21
|
+
import java.math.BigDecimal
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* ICU's `NumberFormat`, for the C++ `NumberFormat`: C++ learns a locale's
|
|
25
|
+
* format from it once (see NumberFormatProbe) and formats with it only for
|
|
26
|
+
* what C++ does not draw itself (compact and scientific notation, units,
|
|
27
|
+
* currency names). Hermes' `Intl.NumberFormat` uses the same classes on
|
|
28
|
+
* Android, so the two agree.
|
|
29
|
+
*/
|
|
30
|
+
@Keep
|
|
31
|
+
@DoNotStrip
|
|
32
|
+
class HybridNitroNumberFormatPlatform : HybridNitroNumberFormatPlatformSpec() {
|
|
33
|
+
override fun create(options: NumberFormatPlatformOptions): HybridNitroPlatformNumberFormatterSpec =
|
|
34
|
+
HybridNitroPlatformNumberFormatter(options)
|
|
35
|
+
|
|
36
|
+
override fun supportedLocalesOf(locales: Array<String>): Array<String> =
|
|
37
|
+
locales.mapNotNull { NumberFormatLocales.match(it)?.tag }.toTypedArray()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** ECMA-402's lookup matcher over the locales ICU has number data for. */
|
|
41
|
+
internal object NumberFormatLocales {
|
|
42
|
+
private val available: Set<String> by lazy { NumberFormat.getAvailableLocales().map { it.toLanguageTag() }.toSet() }
|
|
43
|
+
|
|
44
|
+
class Match(val tag: String, val locale: ULocale, val numberingSystem: String?)
|
|
45
|
+
|
|
46
|
+
fun match(requested: String): Match? {
|
|
47
|
+
val locale = try {
|
|
48
|
+
ULocale.forLanguageTag(requested.replace('_', '-'))
|
|
49
|
+
} catch (e: Exception) {
|
|
50
|
+
return null
|
|
51
|
+
}
|
|
52
|
+
val numberingSystem = locale.getKeywordValue("numbers")
|
|
53
|
+
var tag = locale.toLanguageTag().substringBefore("-u-").substringBefore("-x-")
|
|
54
|
+
// ICU lists some locales with their script only ("zh-Hant-TW" for zh-TW): try the likely form too.
|
|
55
|
+
if (!available.contains(tag)) {
|
|
56
|
+
val likely = ULocale.addLikelySubtags(ULocale.forLanguageTag(tag)).toLanguageTag()
|
|
57
|
+
if (available.contains(likely)) return Match(tag, ULocale.forLanguageTag(likely), numberingSystem)
|
|
58
|
+
}
|
|
59
|
+
while (tag.isNotEmpty() && tag != "und") {
|
|
60
|
+
if (available.contains(tag)) return Match(tag, ULocale.forLanguageTag(tag), numberingSystem)
|
|
61
|
+
tag = tag.substringBeforeLast('-', "")
|
|
62
|
+
}
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The first requested locale ICU knows, or the device's. */
|
|
67
|
+
fun resolve(requested: Array<String>): Match =
|
|
68
|
+
requested.firstNotNullOfOrNull { match(it) } ?: ULocale.getDefault().let { Match(it.toLanguageTag(), it, null) }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Keep
|
|
72
|
+
@DoNotStrip
|
|
73
|
+
class HybridNitroPlatformNumberFormatter(o: NumberFormatPlatformOptions) : HybridNitroPlatformNumberFormatterSpec() {
|
|
74
|
+
private val format: NumberFormat
|
|
75
|
+
private val unit: MeasureUnit?
|
|
76
|
+
private val measureFormat: MeasureFormat?
|
|
77
|
+
/** `unit: 'percent'`, which MeasureFormat prints without its sign: a percent formatter that does not multiply. */
|
|
78
|
+
private val percentUnit: NumberFormat?
|
|
79
|
+
/**
|
|
80
|
+
* Compact notation with a currency or a percent, or a signDisplay plus:
|
|
81
|
+
* CompactDecimalFormat prints bare numbers ("1.5K" for "$1.5K"). Android 11+
|
|
82
|
+
* has ICU's number formatter, which prints the locale's compact patterns;
|
|
83
|
+
* before it, the compact number goes inside the style's own affixes.
|
|
84
|
+
*/
|
|
85
|
+
private val compact: ((BigDecimal) -> String)?
|
|
86
|
+
override val symbols: NumberFormatPlatformSymbols
|
|
87
|
+
|
|
88
|
+
init {
|
|
89
|
+
val match = NumberFormatLocales.resolve(o.locales)
|
|
90
|
+
val numberingSystem = o.numberingSystem ?: match.numberingSystem
|
|
91
|
+
val locale = if (numberingSystem != null) match.locale.setKeywordValue("numbers", numberingSystem) else match.locale
|
|
92
|
+
val scientific = o.notation == NumberFormatNotation.SCIENTIFIC || o.notation == NumberFormatNotation.ENGINEERING
|
|
93
|
+
val currencyStyle = when (o.currencyDisplay) {
|
|
94
|
+
NumberFormatCurrencyDisplay.CODE -> NumberFormat.ISOCURRENCYSTYLE
|
|
95
|
+
NumberFormatCurrencyDisplay.NAME -> NumberFormat.PLURALCURRENCYSTYLE
|
|
96
|
+
else -> if (o.currencySign == NumberFormatCurrencySign.ACCOUNTING) NumberFormat.ACCOUNTINGCURRENCYSTYLE else NumberFormat.CURRENCYSTYLE
|
|
97
|
+
}
|
|
98
|
+
format = when {
|
|
99
|
+
o.notation == NumberFormatNotation.COMPACT -> CompactDecimalFormat.getInstance(
|
|
100
|
+
locale,
|
|
101
|
+
if (o.compactDisplay == NumberFormatCompactDisplay.LONG) CompactDecimalFormat.CompactStyle.LONG else CompactDecimalFormat.CompactStyle.SHORT,
|
|
102
|
+
)
|
|
103
|
+
scientific -> NumberFormat.getInstance(locale, NumberFormat.SCIENTIFICSTYLE)
|
|
104
|
+
o.style == NumberFormatStyle.PERCENT -> NumberFormat.getInstance(locale, NumberFormat.PERCENTSTYLE)
|
|
105
|
+
o.style == NumberFormatStyle.CURRENCY -> NumberFormat.getInstance(locale, currencyStyle)
|
|
106
|
+
else -> NumberFormat.getInstance(locale, NumberFormat.NUMBERSTYLE)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var currencyShown = ""
|
|
110
|
+
val code = o.currency
|
|
111
|
+
if (o.style == NumberFormatStyle.CURRENCY && code != null) {
|
|
112
|
+
val currency = Currency.getInstance(code)
|
|
113
|
+
format.currency = currency
|
|
114
|
+
val decimal = format as? DecimalFormat
|
|
115
|
+
if (o.currencyDisplay == NumberFormatCurrencyDisplay.NARROWSYMBOL && decimal != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
116
|
+
val narrow = currency.getName(locale, Currency.NARROW_SYMBOL_NAME, null)
|
|
117
|
+
decimal.decimalFormatSymbols = decimal.decimalFormatSymbols.apply { currencySymbol = narrow }
|
|
118
|
+
}
|
|
119
|
+
currencyShown = if (o.currencyDisplay == NumberFormatCurrencyDisplay.CODE) code else decimal?.decimalFormatSymbols?.currencySymbol ?: currency.getSymbol(locale)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
format.isGroupingUsed = o.useGrouping
|
|
123
|
+
format.minimumIntegerDigits = o.minimumIntegerDigits.toInt()
|
|
124
|
+
val decimal = format as? DecimalFormat
|
|
125
|
+
if (o.minimumSignificantDigits > 0 && decimal != null) {
|
|
126
|
+
decimal.setSignificantDigitsUsed(true)
|
|
127
|
+
decimal.minimumSignificantDigits = o.minimumSignificantDigits.toInt()
|
|
128
|
+
decimal.maximumSignificantDigits = o.maximumSignificantDigits.toInt()
|
|
129
|
+
} else {
|
|
130
|
+
format.minimumFractionDigits = o.minimumFractionDigits.toInt()
|
|
131
|
+
format.maximumFractionDigits = o.maximumFractionDigits.toInt()
|
|
132
|
+
}
|
|
133
|
+
if (o.notation == NumberFormatNotation.ENGINEERING && decimal != null) decimal.maximumIntegerDigits = 3
|
|
134
|
+
format.roundingMode = when (o.roundingMode) {
|
|
135
|
+
NumberFormatRoundingMode.CEIL -> BigDecimal.ROUND_CEILING
|
|
136
|
+
NumberFormatRoundingMode.FLOOR -> BigDecimal.ROUND_FLOOR
|
|
137
|
+
NumberFormatRoundingMode.EXPAND -> BigDecimal.ROUND_UP
|
|
138
|
+
NumberFormatRoundingMode.TRUNC -> BigDecimal.ROUND_DOWN
|
|
139
|
+
NumberFormatRoundingMode.HALFTRUNC -> BigDecimal.ROUND_HALF_DOWN
|
|
140
|
+
NumberFormatRoundingMode.HALFEVEN -> BigDecimal.ROUND_HALF_EVEN
|
|
141
|
+
else -> BigDecimal.ROUND_HALF_UP
|
|
142
|
+
}
|
|
143
|
+
if (decimal != null) {
|
|
144
|
+
when (o.signDisplay) {
|
|
145
|
+
NumberFormatSignDisplay.ALWAYS, NumberFormatSignDisplay.EXCEPTZERO ->
|
|
146
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) decimal.isSignAlwaysShown = true
|
|
147
|
+
else decimal.positivePrefix = decimal.decimalFormatSymbols.plusSign + decimal.positivePrefix
|
|
148
|
+
NumberFormatSignDisplay.NEVER -> {
|
|
149
|
+
decimal.negativePrefix = decimal.positivePrefix
|
|
150
|
+
decimal.negativeSuffix = decimal.positiveSuffix
|
|
151
|
+
}
|
|
152
|
+
else -> Unit
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
compact = if (o.notation != NumberFormatNotation.COMPACT) {
|
|
157
|
+
null
|
|
158
|
+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
159
|
+
modernCompact(o, locale)
|
|
160
|
+
} else if (o.style == NumberFormatStyle.CURRENCY || o.style == NumberFormatStyle.PERCENT) {
|
|
161
|
+
// The style's own pattern around the compact number: "$" + "1.5K", "1.2M" + "%".
|
|
162
|
+
val pattern = NumberFormat.getInstance(locale, if (o.style == NumberFormatStyle.PERCENT) NumberFormat.PERCENTSTYLE else currencyStyle) as DecimalFormat
|
|
163
|
+
if (o.style == NumberFormatStyle.CURRENCY && code != null) pattern.currency = Currency.getInstance(code)
|
|
164
|
+
val plus = o.signDisplay == NumberFormatSignDisplay.ALWAYS || o.signDisplay == NumberFormatSignDisplay.EXCEPTZERO
|
|
165
|
+
val positivePrefix = (if (plus) pattern.decimalFormatSymbols.plusSign.toString() else "") + pattern.positivePrefix
|
|
166
|
+
val scale = if (o.style == NumberFormatStyle.PERCENT) 100 else 1
|
|
167
|
+
val number = format
|
|
168
|
+
{ value ->
|
|
169
|
+
val body = number.format(value.abs().multiply(BigDecimal(scale)))
|
|
170
|
+
if (value.signum() < 0) pattern.negativePrefix + body + pattern.negativeSuffix else positivePrefix + body + pattern.positiveSuffix
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
null
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (o.style == NumberFormatStyle.UNIT && o.unit == "percent") {
|
|
177
|
+
percentUnit = (NumberFormat.getInstance(locale, NumberFormat.PERCENTSTYLE) as DecimalFormat).also { p ->
|
|
178
|
+
p.multiplier = 1
|
|
179
|
+
p.isGroupingUsed = format.isGroupingUsed
|
|
180
|
+
p.minimumIntegerDigits = format.minimumIntegerDigits
|
|
181
|
+
p.minimumFractionDigits = format.minimumFractionDigits
|
|
182
|
+
p.maximumFractionDigits = format.maximumFractionDigits
|
|
183
|
+
p.roundingMode = format.roundingMode
|
|
184
|
+
if (decimal != null && decimal.areSignificantDigitsUsed()) {
|
|
185
|
+
p.setSignificantDigitsUsed(true)
|
|
186
|
+
p.minimumSignificantDigits = decimal.minimumSignificantDigits
|
|
187
|
+
p.maximumSignificantDigits = decimal.maximumSignificantDigits
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
percentUnit = null
|
|
192
|
+
}
|
|
193
|
+
if (o.style == NumberFormatStyle.UNIT && percentUnit == null) {
|
|
194
|
+
val id = o.unit ?: throw IllegalArgumentException("NumberFormat: a unit is required with style 'unit'.")
|
|
195
|
+
unit = MeasureUnit.getAvailable().firstOrNull { it.subtype == id }
|
|
196
|
+
// A compound unit ("acre-per-day") is built from its identifier (Android 11+).
|
|
197
|
+
?: (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) try { MeasureUnit.forIdentifier(id) } catch (e: Exception) { null } else null)
|
|
198
|
+
?: throw IllegalArgumentException("NumberFormat: unknown unit '$id'.")
|
|
199
|
+
val width = when (o.unitDisplay) {
|
|
200
|
+
NumberFormatUnitDisplay.LONG -> MeasureFormat.FormatWidth.WIDE
|
|
201
|
+
NumberFormatUnitDisplay.NARROW -> MeasureFormat.FormatWidth.NARROW
|
|
202
|
+
else -> MeasureFormat.FormatWidth.SHORT
|
|
203
|
+
}
|
|
204
|
+
measureFormat = MeasureFormat.getInstance(locale, width, format)
|
|
205
|
+
} else {
|
|
206
|
+
unit = null
|
|
207
|
+
measureFormat = null
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
val dfs = decimal?.decimalFormatSymbols ?: DecimalFormatSymbols.getInstance(locale)
|
|
211
|
+
val modern = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
|
|
212
|
+
symbols = NumberFormatPlatformSymbols(
|
|
213
|
+
locale = match.tag,
|
|
214
|
+
numberingSystem = NumberingSystem.getInstance(locale).name,
|
|
215
|
+
minusSign = if (modern) dfs.minusSignString else dfs.minusSign.toString(),
|
|
216
|
+
plusSign = if (modern) dfs.plusSignString else dfs.plusSign.toString(),
|
|
217
|
+
percentSign = if (modern) dfs.percentString else dfs.percent.toString(),
|
|
218
|
+
currency = currencyShown,
|
|
219
|
+
nan = dfs.naN,
|
|
220
|
+
infinity = dfs.infinity,
|
|
221
|
+
exponentSeparator = dfs.exponentSeparator,
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
@Synchronized
|
|
226
|
+
override fun format(value: Double): String {
|
|
227
|
+
compact?.let { if (value.isFinite()) return it(BigDecimal(value)) }
|
|
228
|
+
percentUnit?.let { return it.format(value) }
|
|
229
|
+
val measure = measureFormat
|
|
230
|
+
return if (measure != null) measure.format(Measure(value, unit)) else format.format(value)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
@Synchronized
|
|
234
|
+
override fun formatDecimal(value: String): String {
|
|
235
|
+
if (value == "NaN") return format(Double.NaN)
|
|
236
|
+
if (value.endsWith("Infinity")) return format(if (value.startsWith("-")) Double.NEGATIVE_INFINITY else Double.POSITIVE_INFINITY)
|
|
237
|
+
val number = BigDecimal(value)
|
|
238
|
+
compact?.let { return it(number) }
|
|
239
|
+
percentUnit?.let { return it.format(number) }
|
|
240
|
+
val measure = measureFormat
|
|
241
|
+
return if (measure != null) measure.format(Measure(number, unit)) else format.format(number)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
private companion object {
|
|
245
|
+
/** ICU's number formatter (Android 11+): compact currency, percent and signs as CLDR writes them. */
|
|
246
|
+
@androidx.annotation.RequiresApi(Build.VERSION_CODES.R)
|
|
247
|
+
fun modernCompact(o: NumberFormatPlatformOptions, locale: ULocale): (BigDecimal) -> String {
|
|
248
|
+
var f: LocalizedNumberFormatter = NumberFormatter.withLocale(locale)
|
|
249
|
+
.notation(if (o.compactDisplay == NumberFormatCompactDisplay.LONG) Notation.compactLong() else Notation.compactShort())
|
|
250
|
+
// Compact numbers group from five digits ("9876", "12,345"): ECMA-402's
|
|
251
|
+
// default for compact notation is "min2", which is what this receives as true.
|
|
252
|
+
.grouping(if (o.useGrouping) NumberFormatter.GroupingStrategy.MIN2 else NumberFormatter.GroupingStrategy.OFF)
|
|
253
|
+
f = if (o.minimumSignificantDigits > 0) {
|
|
254
|
+
f.precision(Precision.minMaxSignificantDigits(o.minimumSignificantDigits.toInt(), o.maximumSignificantDigits.toInt()))
|
|
255
|
+
} else {
|
|
256
|
+
f.precision(Precision.minMaxFraction(o.minimumFractionDigits.toInt(), o.maximumFractionDigits.toInt()))
|
|
257
|
+
}
|
|
258
|
+
val code = o.currency
|
|
259
|
+
if (o.style == NumberFormatStyle.CURRENCY && code != null) {
|
|
260
|
+
f = f.unit(Currency.getInstance(code)).unitWidth(
|
|
261
|
+
when (o.currencyDisplay) {
|
|
262
|
+
NumberFormatCurrencyDisplay.CODE -> NumberFormatter.UnitWidth.ISO_CODE
|
|
263
|
+
NumberFormatCurrencyDisplay.NAME -> NumberFormatter.UnitWidth.FULL_NAME
|
|
264
|
+
NumberFormatCurrencyDisplay.NARROWSYMBOL -> NumberFormatter.UnitWidth.NARROW
|
|
265
|
+
else -> NumberFormatter.UnitWidth.SHORT
|
|
266
|
+
}
|
|
267
|
+
)
|
|
268
|
+
} else if (o.style == NumberFormatStyle.PERCENT) {
|
|
269
|
+
f = f.unit(MeasureUnit.PERCENT).scale(Scale.powerOfTen(2))
|
|
270
|
+
}
|
|
271
|
+
val accounting = o.currencySign == NumberFormatCurrencySign.ACCOUNTING
|
|
272
|
+
f = f.sign(
|
|
273
|
+
when (o.signDisplay) {
|
|
274
|
+
NumberFormatSignDisplay.ALWAYS -> if (accounting) NumberFormatter.SignDisplay.ACCOUNTING_ALWAYS else NumberFormatter.SignDisplay.ALWAYS
|
|
275
|
+
NumberFormatSignDisplay.EXCEPTZERO -> if (accounting) NumberFormatter.SignDisplay.ACCOUNTING_EXCEPT_ZERO else NumberFormatter.SignDisplay.EXCEPT_ZERO
|
|
276
|
+
NumberFormatSignDisplay.NEVER -> NumberFormatter.SignDisplay.NEVER
|
|
277
|
+
else -> if (accounting) NumberFormatter.SignDisplay.ACCOUNTING else NumberFormatter.SignDisplay.AUTO
|
|
278
|
+
}
|
|
279
|
+
)
|
|
280
|
+
val formatter = f
|
|
281
|
+
return { value -> formatter.format(value).toString() }
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
@@ -52,6 +52,8 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
52
52
|
}
|
|
53
53
|
rollingView.onRevealEnd = { onRevealEnd?.invoke() }
|
|
54
54
|
rollingView.onRevealMilestone = { index, milestone -> onRevealMilestone?.invoke(index.toDouble(), milestone) }
|
|
55
|
+
rollingView.onAnimationStart = { onAnimationStart?.invoke() }
|
|
56
|
+
rollingView.onAnimationEnd = { value -> onAnimationEnd?.invoke(value) }
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
// region Props
|
|
@@ -129,6 +131,16 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
129
131
|
set(v) { field = v; markConfigDirty() }
|
|
130
132
|
override var shimmerDuration: Double? = null
|
|
131
133
|
set(v) { field = v; markConfigDirty() }
|
|
134
|
+
override var shimmerAngle: Double? = null
|
|
135
|
+
set(v) { field = v; markConfigDirty() }
|
|
136
|
+
override var shimmerWidth: Double? = null
|
|
137
|
+
set(v) { field = v; markConfigDirty() }
|
|
138
|
+
override var shimmerBaseColor: Double? = null
|
|
139
|
+
set(v) { field = v; markConfigDirty() }
|
|
140
|
+
override var shimmerDirection: NitroNumberShimmerDirection? = null
|
|
141
|
+
set(v) { field = v; markConfigDirty() }
|
|
142
|
+
override var shimmerDelay: Double? = null
|
|
143
|
+
set(v) { field = v; markConfigDirty() }
|
|
132
144
|
override var fontSize: Double? = null
|
|
133
145
|
set(v) { field = v; markConfigDirty() }
|
|
134
146
|
override var prefixFontSize: Double? = null
|
|
@@ -141,6 +153,46 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
141
153
|
set(v) { field = v; markConfigDirty() }
|
|
142
154
|
override var suffixAlign: NitroNumberAffixAlign? = null
|
|
143
155
|
set(v) { field = v; markConfigDirty() }
|
|
156
|
+
override var letterSpacing: Double? = null
|
|
157
|
+
set(v) { field = v; markConfigDirty() }
|
|
158
|
+
override var prefixSpacing: Double? = null
|
|
159
|
+
set(v) { field = v; markConfigDirty() }
|
|
160
|
+
override var suffixSpacing: Double? = null
|
|
161
|
+
set(v) { field = v; markConfigDirty() }
|
|
162
|
+
override var prefixOffset: Double? = null
|
|
163
|
+
set(v) { field = v; markConfigDirty() }
|
|
164
|
+
override var suffixOffset: Double? = null
|
|
165
|
+
set(v) { field = v; markConfigDirty() }
|
|
166
|
+
override var tabularNums: Boolean? = null
|
|
167
|
+
set(v) { field = v; markConfigDirty() }
|
|
168
|
+
override var signDisplay: NitroNumberSignDisplay? = null
|
|
169
|
+
set(v) { field = v; markConfigDirty() }
|
|
170
|
+
override var plusSign: String? = null
|
|
171
|
+
set(v) { field = v; markConfigDirty() }
|
|
172
|
+
override var minusSign: String? = null
|
|
173
|
+
set(v) { field = v; markConfigDirty() }
|
|
174
|
+
override var digitGlyphs: Array<String>? = null
|
|
175
|
+
set(v) { field = v; markConfigDirty() }
|
|
176
|
+
override var groupingSizes: DoubleArray? = null
|
|
177
|
+
set(v) { field = v; markConfigDirty() }
|
|
178
|
+
override var digitMax: DoubleArray? = null
|
|
179
|
+
set(v) { field = v; markConfigDirty() }
|
|
180
|
+
override var continuous: Boolean? = null
|
|
181
|
+
set(v) { field = v; markConfigDirty() }
|
|
182
|
+
override var prefixColor: Double? = null
|
|
183
|
+
set(v) { field = v; markConfigDirty() }
|
|
184
|
+
override var suffixColor: Double? = null
|
|
185
|
+
set(v) { field = v; markConfigDirty() }
|
|
186
|
+
override var fractionColor: Double? = null
|
|
187
|
+
set(v) { field = v; markConfigDirty() }
|
|
188
|
+
override var fractionFontSize: Double? = null
|
|
189
|
+
set(v) { field = v; markConfigDirty() }
|
|
190
|
+
override var fractionAlign: NitroNumberAffixAlign? = null
|
|
191
|
+
set(v) { field = v; markConfigDirty() }
|
|
192
|
+
override var respectReduceMotion: Boolean? = null
|
|
193
|
+
set(v) { field = v; markConfigDirty() }
|
|
194
|
+
override var onAnimationStart: (() -> Unit)? = null
|
|
195
|
+
override var onAnimationEnd: ((value: Double) -> Unit)? = null
|
|
144
196
|
override var adjustsFontSizeToFit: Boolean? = null
|
|
145
197
|
set(v) { field = v; markConfigDirty() }
|
|
146
198
|
override var minimumFontScale: Double? = null
|
|
@@ -303,12 +355,38 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
303
355
|
loading = null
|
|
304
356
|
shimmerColor = null
|
|
305
357
|
shimmerDuration = null
|
|
358
|
+
shimmerAngle = null
|
|
359
|
+
shimmerWidth = null
|
|
360
|
+
shimmerBaseColor = null
|
|
361
|
+
shimmerDirection = null
|
|
362
|
+
shimmerDelay = null
|
|
306
363
|
fontSize = null
|
|
307
364
|
prefixFontSize = null
|
|
308
365
|
suffixFontSize = null
|
|
309
366
|
affixAlign = null
|
|
310
367
|
prefixAlign = null
|
|
311
368
|
suffixAlign = null
|
|
369
|
+
letterSpacing = null
|
|
370
|
+
prefixSpacing = null
|
|
371
|
+
suffixSpacing = null
|
|
372
|
+
prefixOffset = null
|
|
373
|
+
suffixOffset = null
|
|
374
|
+
tabularNums = null
|
|
375
|
+
signDisplay = null
|
|
376
|
+
plusSign = null
|
|
377
|
+
minusSign = null
|
|
378
|
+
digitGlyphs = null
|
|
379
|
+
groupingSizes = null
|
|
380
|
+
digitMax = null
|
|
381
|
+
continuous = null
|
|
382
|
+
prefixColor = null
|
|
383
|
+
suffixColor = null
|
|
384
|
+
fractionColor = null
|
|
385
|
+
fractionFontSize = null
|
|
386
|
+
fractionAlign = null
|
|
387
|
+
respectReduceMotion = null
|
|
388
|
+
onAnimationStart = null
|
|
389
|
+
onAnimationEnd = null
|
|
312
390
|
adjustsFontSizeToFit = null
|
|
313
391
|
minimumFontScale = null
|
|
314
392
|
allowFontScaling = null
|
|
@@ -377,6 +455,18 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
377
455
|
color = color?.let { colorFromARGB(it) },
|
|
378
456
|
prefixAlign = mapAffixAlign(prefixAlign ?: affixAlign),
|
|
379
457
|
suffixAlign = mapAffixAlign(suffixAlign ?: affixAlign),
|
|
458
|
+
letterSpacing = (letterSpacing ?: 0.0).takeIf { it.isFinite() }?.toFloat() ?: 0f,
|
|
459
|
+
prefixSpacing = prefixSpacing?.takeIf { it.isFinite() }?.toFloat(),
|
|
460
|
+
suffixSpacing = suffixSpacing?.takeIf { it.isFinite() }?.toFloat(),
|
|
461
|
+
prefixOffset = (prefixOffset ?: 0.0).takeIf { it.isFinite() }?.toFloat() ?: 0f,
|
|
462
|
+
suffixOffset = (suffixOffset ?: 0.0).takeIf { it.isFinite() }?.toFloat() ?: 0f,
|
|
463
|
+
tabularNums = tabularNums ?: true,
|
|
464
|
+
prefixColor = prefixColor?.let { colorFromARGB(it) },
|
|
465
|
+
suffixColor = suffixColor?.let { colorFromARGB(it) },
|
|
466
|
+
fractionColor = fractionColor?.let { colorFromARGB(it) },
|
|
467
|
+
fractionFontSize = fractionFontSize?.takeIf { it.isFinite() && it > 0 }?.toFloat(),
|
|
468
|
+
fractionAlign = mapAffixAlign(fractionAlign),
|
|
469
|
+
digitGlyphs = digitGlyphs?.toList() ?: emptyList(),
|
|
380
470
|
adjustsFontSizeToFit = adjustsFontSizeToFit ?: false,
|
|
381
471
|
minimumFontScale = (minimumFontScale ?: 0.5).coerceIn(0.05, 1.0).toFloat(),
|
|
382
472
|
allowFontScaling = allowFontScaling ?: false,
|
|
@@ -389,6 +479,17 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
389
479
|
decimalSeparator = decimalSeparator ?: ".",
|
|
390
480
|
prefix = prefix ?: "",
|
|
391
481
|
suffix = suffix ?: "",
|
|
482
|
+
signDisplay = when (signDisplay) {
|
|
483
|
+
NitroNumberSignDisplay.ALWAYS -> 1
|
|
484
|
+
NitroNumberSignDisplay.EXCEPTZERO -> 2
|
|
485
|
+
NitroNumberSignDisplay.NEGATIVE -> 3
|
|
486
|
+
NitroNumberSignDisplay.NEVER -> 4
|
|
487
|
+
NitroNumberSignDisplay.AUTO, null -> 0
|
|
488
|
+
},
|
|
489
|
+
plusSign = plusSign?.takeIf { it.isNotEmpty() } ?: "+",
|
|
490
|
+
minusSign = minusSign?.takeIf { it.isNotEmpty() } ?: "-",
|
|
491
|
+
groupingSizes = groupingSizes?.map { if (it.isFinite()) Math.max(0, Math.rint(it).toInt()) else 0 } ?: emptyList(),
|
|
492
|
+
digitMax = digitMax?.map { if (it.isFinite()) Math.rint(it).toInt() else 9 } ?: emptyList(),
|
|
392
493
|
)
|
|
393
494
|
rollingView.timing = NitroNumberView.Timing(
|
|
394
495
|
transition = when (transition) {
|
|
@@ -410,6 +511,7 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
410
511
|
direction = when (rollDirection) {
|
|
411
512
|
NitroNumberDirection.UP -> NitroNumberView.Direction.UP
|
|
412
513
|
NitroNumberDirection.DOWN -> NitroNumberView.Direction.DOWN
|
|
514
|
+
NitroNumberDirection.SHORTEST -> NitroNumberView.Direction.SHORTEST
|
|
413
515
|
NitroNumberDirection.AUTO, null -> NitroNumberView.Direction.AUTO
|
|
414
516
|
},
|
|
415
517
|
revealDurationMs = Math.max(0.0, revealDuration ?: 2200.0).toLong(),
|
|
@@ -421,11 +523,22 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
421
523
|
},
|
|
422
524
|
revealStaggerMs = Math.max(0.0, revealStagger ?: 200.0).toLong(),
|
|
423
525
|
revealMilestoneHoldMs = Math.max(0.0, revealMilestoneHold ?: 0.0).toLong(),
|
|
526
|
+
continuous = continuous ?: false,
|
|
527
|
+
respectReduceMotion = respectReduceMotion ?: true,
|
|
424
528
|
)
|
|
425
529
|
rollingView.revealMilestones = revealMilestones ?: DoubleArray(0)
|
|
426
530
|
rollingView.shimmer = NitroNumberView.Shimmer(
|
|
427
531
|
color = shimmerColor?.let { colorFromARGB(it) },
|
|
428
532
|
durationMs = Math.max(200.0, shimmerDuration ?: 950.0).toLong(),
|
|
533
|
+
angle = (shimmerAngle?.takeIf { it.isFinite() } ?: 31.0).toFloat(),
|
|
534
|
+
width = (shimmerWidth?.takeIf { it.isFinite() && it > 0 } ?: 1.0).toFloat(),
|
|
535
|
+
baseColor = shimmerBaseColor?.let { colorFromARGB(it) },
|
|
536
|
+
leftToRight = when (shimmerDirection) {
|
|
537
|
+
NitroNumberShimmerDirection.LTR -> true
|
|
538
|
+
NitroNumberShimmerDirection.RTL -> false
|
|
539
|
+
else -> null
|
|
540
|
+
},
|
|
541
|
+
delayMs = Math.max(0.0, shimmerDelay?.takeIf { it.isFinite() } ?: 0.0).toLong(),
|
|
429
542
|
)
|
|
430
543
|
rollingView.flash = NitroNumberView.Flash(
|
|
431
544
|
upColor = flashUpColor?.let { colorFromARGB(it) },
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
package com.margelo.nitro.nitroinput
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Keep
|
|
4
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Measures a NitroText line on the JS thread, the way [NitroTextView] lays it
|
|
8
|
+
* out ([NitroTextFonts]): every code point's advance plus the letter spacing,
|
|
9
|
+
* in dp.
|
|
10
|
+
*
|
|
11
|
+
* Mirrors `HybridNitroTextMeasure` in `HybridNitroTextView.swift` on iOS.
|
|
12
|
+
*/
|
|
13
|
+
@Keep
|
|
14
|
+
@DoNotStrip
|
|
15
|
+
class HybridNitroTextMeasure : HybridNitroTextMeasureSpec() {
|
|
16
|
+
override fun measure(text: String, fontSize: Double, fontWeight: Double, fontFamily: String, letterSpacing: Double): Double {
|
|
17
|
+
val entry = NitroTextFonts.entry(fontSize, fontWeight, fontFamily)
|
|
18
|
+
val density = NitroTextFonts.density
|
|
19
|
+
val spacingPx = (if (letterSpacing.isFinite()) letterSpacing else 0.0).toFloat() * density
|
|
20
|
+
return (NitroTextFonts.width(text, entry, spacingPx) / density).toDouble()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
override fun lineHeight(fontSize: Double, fontWeight: Double, fontFamily: String): Double =
|
|
24
|
+
(NitroTextFonts.entry(fontSize, fontWeight, fontFamily).lineHeight / NitroTextFonts.density).toDouble()
|
|
25
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
package com.margelo.nitro.nitroinput
|
|
2
|
+
|
|
3
|
+
import android.graphics.Color
|
|
4
|
+
import android.os.Handler
|
|
5
|
+
import android.os.Looper
|
|
6
|
+
import android.view.View
|
|
7
|
+
import androidx.annotation.Keep
|
|
8
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
9
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
10
|
+
import com.margelo.nitro.views.RecyclableView
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Nitro glue between NitroText's props and [NitroTextView]: the props land
|
|
14
|
+
* one by one and are applied together once Nitro says the update is done.
|
|
15
|
+
*
|
|
16
|
+
* Mirrors `HybridNitroTextView.swift` on iOS.
|
|
17
|
+
*/
|
|
18
|
+
@Keep
|
|
19
|
+
@DoNotStrip
|
|
20
|
+
class HybridNitroTextView(private val context: ThemedReactContext) : HybridNitroTextViewSpec(), RecyclableView {
|
|
21
|
+
private val mainHandler = Handler(Looper.getMainLooper())
|
|
22
|
+
private val textView = NitroTextView(context)
|
|
23
|
+
|
|
24
|
+
override val view: View
|
|
25
|
+
get() = textView
|
|
26
|
+
|
|
27
|
+
override var text: String = ""
|
|
28
|
+
// Unset unless the element set it: the wrapper sends only those.
|
|
29
|
+
override var fontSize: Double? = null
|
|
30
|
+
override var fontWeight: Double? = null
|
|
31
|
+
override var fontFamily: String? = null
|
|
32
|
+
override var color: Double? = null
|
|
33
|
+
override var letterSpacing: Double? = null
|
|
34
|
+
override var textAlign: NitroNumberTextAlign? = null
|
|
35
|
+
override var rightToLeft: Boolean? = null
|
|
36
|
+
override var duration: Double? = null
|
|
37
|
+
override var easing: NitroInputEasing? = null
|
|
38
|
+
override var bounce: Double? = null
|
|
39
|
+
override var effect: NitroInputEffect? = null
|
|
40
|
+
override var respectReduceMotion: Boolean? = null
|
|
41
|
+
override var loading: Boolean? = null
|
|
42
|
+
override var shimmerColor: Double? = null
|
|
43
|
+
override var shimmerDuration: Double? = null
|
|
44
|
+
override var shimmerAngle: Double? = null
|
|
45
|
+
override var shimmerWidth: Double? = null
|
|
46
|
+
override var shimmerBaseColor: Double? = null
|
|
47
|
+
override var shimmerDirection: NitroNumberShimmerDirection? = null
|
|
48
|
+
override var shimmerDelay: Double? = null
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Every prop of an update is set before this runs: apply them in one go
|
|
52
|
+
* (the style first, so the text is laid out in its font).
|
|
53
|
+
*/
|
|
54
|
+
override fun afterUpdate() {
|
|
55
|
+
onMain { apply() }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private fun apply() {
|
|
59
|
+
textView.style = NitroTextView.Style(
|
|
60
|
+
fontSize = fontSize?.takeIf { it.isFinite() && it > 0 } ?: 17.0,
|
|
61
|
+
fontWeight = fontWeight?.takeIf { it.isFinite() } ?: 400.0,
|
|
62
|
+
fontFamily = fontFamily ?: "",
|
|
63
|
+
color = color?.let(::colorFromARGB),
|
|
64
|
+
letterSpacing = (letterSpacing?.takeIf { it.isFinite() } ?: 0.0).toFloat(),
|
|
65
|
+
textAlign = when (textAlign) {
|
|
66
|
+
NitroNumberTextAlign.LEFT -> NitroNumberView.Alignment.LEFT
|
|
67
|
+
NitroNumberTextAlign.CENTER -> NitroNumberView.Alignment.CENTER
|
|
68
|
+
NitroNumberTextAlign.RIGHT -> NitroNumberView.Alignment.RIGHT
|
|
69
|
+
else -> NitroNumberView.Alignment.AUTO
|
|
70
|
+
},
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
textView.timing = NitroTextView.Timing(
|
|
74
|
+
durationSeconds = Math.max(0.0, (duration?.takeIf { it.isFinite() } ?: 400.0) / 1000.0),
|
|
75
|
+
easing = when (easing) {
|
|
76
|
+
NitroInputEasing.EASEOUT -> 1
|
|
77
|
+
NitroInputEasing.EASEINOUT -> 2
|
|
78
|
+
NitroInputEasing.LINEAR -> 3
|
|
79
|
+
NitroInputEasing.SPRING -> 4
|
|
80
|
+
else -> 0
|
|
81
|
+
},
|
|
82
|
+
bounce = bounce?.takeIf { it.isFinite() } ?: 0.15,
|
|
83
|
+
effect = when (effect) {
|
|
84
|
+
NitroInputEffect.SLIDE -> 1
|
|
85
|
+
NitroInputEffect.FADE -> 2
|
|
86
|
+
else -> 0
|
|
87
|
+
},
|
|
88
|
+
respectReduceMotion = respectReduceMotion ?: true,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
textView.shimmer = NitroNumberView.Shimmer(
|
|
92
|
+
color = shimmerColor?.let(::colorFromARGB),
|
|
93
|
+
durationMs = Math.max(200.0, shimmerDuration?.takeIf { it.isFinite() } ?: 950.0).toLong(),
|
|
94
|
+
angle = (shimmerAngle?.takeIf { it.isFinite() } ?: 31.0).toFloat(),
|
|
95
|
+
width = (shimmerWidth?.takeIf { it.isFinite() && it > 0 } ?: 1.0).toFloat(),
|
|
96
|
+
baseColor = shimmerBaseColor?.let(::colorFromARGB),
|
|
97
|
+
leftToRight = when (shimmerDirection) {
|
|
98
|
+
NitroNumberShimmerDirection.LTR -> true
|
|
99
|
+
NitroNumberShimmerDirection.RTL -> false
|
|
100
|
+
else -> null
|
|
101
|
+
},
|
|
102
|
+
delayMs = Math.max(0.0, shimmerDelay?.takeIf { it.isFinite() } ?: 0.0).toLong(),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
textView.rightToLeft = rightToLeft ?: false
|
|
106
|
+
textView.text = text
|
|
107
|
+
textView.loading = loading ?: false
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Fabric dropped the view: stop its frame loop (a recycled one is reset next). */
|
|
111
|
+
override fun onDropView() {
|
|
112
|
+
onMain { textView.stopFrames() }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Fabric is about to reuse this view for another element. */
|
|
116
|
+
override fun prepareForRecycle() {
|
|
117
|
+
// The next element's props arrive as a first mount's do, only the ones it set.
|
|
118
|
+
text = ""
|
|
119
|
+
fontSize = null; fontWeight = null; fontFamily = null; color = null; letterSpacing = null
|
|
120
|
+
textAlign = null; rightToLeft = null
|
|
121
|
+
duration = null; easing = null; bounce = null; effect = null; respectReduceMotion = null
|
|
122
|
+
loading = null
|
|
123
|
+
shimmerColor = null; shimmerDuration = null; shimmerAngle = null; shimmerWidth = null
|
|
124
|
+
shimmerBaseColor = null; shimmerDirection = null; shimmerDelay = null
|
|
125
|
+
onMain { textView.resetForRecycle() }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
override val memorySize: Long
|
|
129
|
+
get() = 8L * 1024
|
|
130
|
+
|
|
131
|
+
private fun onMain(block: () -> Unit) {
|
|
132
|
+
if (Looper.myLooper() == Looper.getMainLooper()) block() else mainHandler.post(block)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private fun colorFromARGB(value: Double): Int? {
|
|
136
|
+
if (!value.isFinite()) return null
|
|
137
|
+
val bits = value.toLong().toInt()
|
|
138
|
+
return Color.argb((bits ushr 24) and 0xff, (bits ushr 16) and 0xff, (bits ushr 8) and 0xff, bits and 0xff)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -7,6 +7,7 @@ import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
|
7
7
|
import com.facebook.react.uimanager.ViewManager
|
|
8
8
|
import com.margelo.nitro.nitroinput.views.HybridNitroInputViewManager
|
|
9
9
|
import com.margelo.nitro.nitroinput.views.HybridNitroNumberViewManager
|
|
10
|
+
import com.margelo.nitro.nitroinput.views.HybridNitroTextViewManager
|
|
10
11
|
|
|
11
12
|
class NitroInputPackage : BaseReactPackage() {
|
|
12
13
|
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
|
|
@@ -14,7 +15,7 @@ class NitroInputPackage : BaseReactPackage() {
|
|
|
14
15
|
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider { HashMap() }
|
|
15
16
|
|
|
16
17
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
17
|
-
return listOf(HybridNitroInputViewManager(), HybridNitroNumberViewManager())
|
|
18
|
+
return listOf(HybridNitroInputViewManager(), HybridNitroNumberViewManager(), HybridNitroTextViewManager())
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
companion object {
|