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,426 @@
|
|
|
1
|
+
//
|
|
2
|
+
// HybridNitroNumberFormatPlatform.swift
|
|
3
|
+
// NitroInput
|
|
4
|
+
//
|
|
5
|
+
// Foundation's `NumberFormatter`, for the C++ `NumberFormat`: C++ learns a
|
|
6
|
+
// locale's format from it once (see NumberFormatProbe) and formats with it
|
|
7
|
+
// only for what C++ does not draw itself (compact and scientific notation,
|
|
8
|
+
// currency names). Hermes' `Intl.NumberFormat` uses the same formatter on
|
|
9
|
+
// iOS, so the two agree.
|
|
10
|
+
//
|
|
11
|
+
|
|
12
|
+
import Foundation
|
|
13
|
+
import NitroModules
|
|
14
|
+
|
|
15
|
+
final class HybridNitroNumberFormatPlatform: HybridNitroNumberFormatPlatformSpec {
|
|
16
|
+
func create(options: NumberFormatPlatformOptions) throws -> any HybridNitroPlatformNumberFormatterSpec {
|
|
17
|
+
return try HybridNitroPlatformNumberFormatter(options: options)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
func supportedLocalesOf(locales: [String]) throws -> [String] {
|
|
21
|
+
return locales.compactMap { NumberFormatLocales.match($0)?.tag }
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// ECMA-402's lookup matcher over the locales Foundation has data for.
|
|
26
|
+
enum NumberFormatLocales {
|
|
27
|
+
private static let available = Set(Locale.availableIdentifiers)
|
|
28
|
+
|
|
29
|
+
struct Match {
|
|
30
|
+
/// The matched locale as a BCP 47 tag, without extensions ("de-DE").
|
|
31
|
+
let tag: String
|
|
32
|
+
/// Foundation's identifier for it ("de_DE").
|
|
33
|
+
let identifier: String
|
|
34
|
+
/// The numbering system asked for with `-u-nu-`, if any.
|
|
35
|
+
let numberingSystem: String?
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static func match(_ requested: String) -> Match? {
|
|
39
|
+
let lowered = requested.replacingOccurrences(of: "_", with: "-").lowercased()
|
|
40
|
+
// "de-DE-u-nu-latn": the base tag and the numbering system of its Unicode extension.
|
|
41
|
+
var base = lowered
|
|
42
|
+
var numberingSystem: String?
|
|
43
|
+
if let range = lowered.range(of: "-u-") {
|
|
44
|
+
base = String(lowered[..<range.lowerBound])
|
|
45
|
+
let keys = lowered[range.upperBound...].split(separator: "-")
|
|
46
|
+
if let nu = keys.firstIndex(of: "nu"), nu + 1 < keys.endIndex { numberingSystem = String(keys[nu + 1]) }
|
|
47
|
+
}
|
|
48
|
+
// Canonical case: language lower, script title, region upper ("zh-hant-tw" → zh_Hant_TW).
|
|
49
|
+
var subtags = base.split(separator: "-").enumerated().map { index, tag -> String in
|
|
50
|
+
let tag = String(tag)
|
|
51
|
+
if index == 0 { return tag }
|
|
52
|
+
if tag.count == 4 { return tag.prefix(1).uppercased() + tag.dropFirst() }
|
|
53
|
+
if tag.count == 2 || (tag.count == 3 && tag.allSatisfy(\.isNumber)) { return tag.uppercased() }
|
|
54
|
+
return tag
|
|
55
|
+
}
|
|
56
|
+
// Foundation lists some locales with their script only ("zh_Hant_TW" for zh-TW): try the full form too.
|
|
57
|
+
if #available(iOS 16.0, *), subtags.count > 1 {
|
|
58
|
+
let maximal = Locale.Language(identifier: subtags.joined(separator: "-")).maximalIdentifier.replacingOccurrences(of: "-", with: "_")
|
|
59
|
+
if !available.contains(subtags.joined(separator: "_")), available.contains(maximal) {
|
|
60
|
+
return Match(tag: subtags.joined(separator: "-"), identifier: maximal, numberingSystem: numberingSystem)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
while !subtags.isEmpty {
|
|
64
|
+
let identifier = subtags.joined(separator: "_")
|
|
65
|
+
if available.contains(identifier) {
|
|
66
|
+
return Match(tag: subtags.joined(separator: "-"), identifier: identifier, numberingSystem: numberingSystem)
|
|
67
|
+
}
|
|
68
|
+
subtags.removeLast()
|
|
69
|
+
}
|
|
70
|
+
return nil
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// The first requested locale Foundation knows, or the device's.
|
|
74
|
+
static func resolve(_ requested: [String]) -> Match {
|
|
75
|
+
for tag in requested {
|
|
76
|
+
if let match = match(tag) { return match }
|
|
77
|
+
}
|
|
78
|
+
let current = Locale.current.identifier
|
|
79
|
+
let base = current.split(separator: "@").first.map(String.init) ?? current
|
|
80
|
+
return Match(tag: base.replacingOccurrences(of: "_", with: "-"), identifier: base, numberingSystem: nil)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
final class HybridNitroPlatformNumberFormatter: HybridNitroPlatformNumberFormatterSpec {
|
|
85
|
+
private let formatter = NumberFormatter()
|
|
86
|
+
/// Compact notation, which `NumberFormatter` does not have (iOS 16+).
|
|
87
|
+
private var compact: ((Double) -> String)?
|
|
88
|
+
/// Units, through `MeasurementFormatter` with this formatter for the number.
|
|
89
|
+
private var measure: ((Double) -> String)?
|
|
90
|
+
let symbols: NumberFormatPlatformSymbols
|
|
91
|
+
|
|
92
|
+
init(options o: NumberFormatPlatformOptions) throws {
|
|
93
|
+
let match = NumberFormatLocales.resolve(o.locales)
|
|
94
|
+
// Foundation knows numbering systems only in lower case, and one it does not
|
|
95
|
+
// know leaves the formatter without symbols; Intl ignores those, so drop it.
|
|
96
|
+
var numberingSystem = (o.numberingSystem ?? match.numberingSystem)?.lowercased()
|
|
97
|
+
// The currency goes into the locale too: Foundation otherwise takes some
|
|
98
|
+
// patterns (accounting in tr_TR) from the locale's own currency.
|
|
99
|
+
func makeLocale() -> Locale {
|
|
100
|
+
var keywords: [String] = []
|
|
101
|
+
if o.style == .currency, let code = o.currency { keywords.append("currency=\(code)") }
|
|
102
|
+
if let numberingSystem { keywords.append("numbers=\(numberingSystem)") }
|
|
103
|
+
return Locale(identifier: keywords.isEmpty ? match.identifier : "\(match.identifier)@\(keywords.joined(separator: ";"))")
|
|
104
|
+
}
|
|
105
|
+
var locale = makeLocale()
|
|
106
|
+
formatter.locale = locale
|
|
107
|
+
if numberingSystem != nil, (formatter.minusSign as String?) == nil {
|
|
108
|
+
numberingSystem = nil
|
|
109
|
+
locale = makeLocale()
|
|
110
|
+
formatter.locale = locale
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
var currencyShown = ""
|
|
114
|
+
switch o.style {
|
|
115
|
+
case .decimal:
|
|
116
|
+
formatter.numberStyle = .decimal
|
|
117
|
+
case .percent:
|
|
118
|
+
formatter.numberStyle = .percent
|
|
119
|
+
case .currency:
|
|
120
|
+
switch o.currencyDisplay {
|
|
121
|
+
case .code:
|
|
122
|
+
formatter.numberStyle = .currencyISOCode
|
|
123
|
+
case .name:
|
|
124
|
+
formatter.numberStyle = .currencyPlural
|
|
125
|
+
default:
|
|
126
|
+
formatter.numberStyle = o.currencySign == .accounting ? .currencyAccounting : .currency
|
|
127
|
+
}
|
|
128
|
+
formatter.currencyCode = o.currency ?? "USD"
|
|
129
|
+
if o.currencyDisplay == .narrowsymbol, let narrow = Self.narrowSymbol(o.currency ?? "USD", locale: locale) {
|
|
130
|
+
formatter.currencySymbol = narrow
|
|
131
|
+
}
|
|
132
|
+
currencyShown = (o.currencyDisplay == .code ? formatter.internationalCurrencySymbol as String? : formatter.currencySymbol as String?) ?? (o.currency ?? "")
|
|
133
|
+
case .unit:
|
|
134
|
+
formatter.numberStyle = .decimal
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
switch o.notation {
|
|
138
|
+
case .scientific, .engineering:
|
|
139
|
+
formatter.numberStyle = .scientific
|
|
140
|
+
case .compact, .standard:
|
|
141
|
+
break
|
|
142
|
+
}
|
|
143
|
+
formatter.usesGroupingSeparator = o.useGrouping
|
|
144
|
+
formatter.minimumIntegerDigits = Int(o.minimumIntegerDigits)
|
|
145
|
+
if o.minimumSignificantDigits > 0 {
|
|
146
|
+
formatter.usesSignificantDigits = true
|
|
147
|
+
formatter.minimumSignificantDigits = Int(o.minimumSignificantDigits)
|
|
148
|
+
formatter.maximumSignificantDigits = Int(o.maximumSignificantDigits)
|
|
149
|
+
} else {
|
|
150
|
+
formatter.minimumFractionDigits = Int(o.minimumFractionDigits)
|
|
151
|
+
formatter.maximumFractionDigits = Int(o.maximumFractionDigits)
|
|
152
|
+
}
|
|
153
|
+
formatter.roundingMode = Self.roundingMode(o.roundingMode)
|
|
154
|
+
switch o.signDisplay {
|
|
155
|
+
case .always, .exceptzero:
|
|
156
|
+
formatter.positivePrefix = ((formatter.plusSign as String?) ?? "+") + ((formatter.positivePrefix as String?) ?? "")
|
|
157
|
+
case .never:
|
|
158
|
+
formatter.negativePrefix = formatter.positivePrefix
|
|
159
|
+
formatter.negativeSuffix = formatter.positiveSuffix
|
|
160
|
+
case .auto, .negative:
|
|
161
|
+
break
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if o.notation == .compact, #available(iOS 16.0, *) {
|
|
165
|
+
// Before iOS 18 Foundation has no compact currency style: the currency
|
|
166
|
+
// formatter's own affixes go around the compact number ("$" + "1.5K").
|
|
167
|
+
let affixes = o.style == .currency
|
|
168
|
+
? CompactAffixes(
|
|
169
|
+
positivePrefix: formatter.positivePrefix ?? "", positiveSuffix: formatter.positiveSuffix ?? "",
|
|
170
|
+
negativePrefix: formatter.negativePrefix ?? "-", negativeSuffix: formatter.negativeSuffix ?? "")
|
|
171
|
+
: nil
|
|
172
|
+
compact = Self.compactStyle(o, locale: locale, currencyAffixes: affixes)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if o.style == .unit, let unit = o.unit {
|
|
176
|
+
measure = try Self.unitFormatter(unit, display: o.unitDisplay, locale: locale, number: formatter)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
symbols = NumberFormatPlatformSymbols(
|
|
180
|
+
locale: match.tag,
|
|
181
|
+
numberingSystem: Self.numberingSystem(of: locale),
|
|
182
|
+
minusSign: (formatter.minusSign as String?) ?? "-",
|
|
183
|
+
plusSign: (formatter.plusSign as String?) ?? "+",
|
|
184
|
+
percentSign: (formatter.percentSymbol as String?) ?? "%",
|
|
185
|
+
currency: currencyShown,
|
|
186
|
+
nan: (formatter.notANumberSymbol as String?) ?? "NaN",
|
|
187
|
+
infinity: (formatter.positiveInfinitySymbol as String?) ?? "∞",
|
|
188
|
+
exponentSeparator: (formatter.exponentSymbol as String?) ?? "E"
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/// Compact notation in the style the options ask for: a decimal style
|
|
193
|
+
/// alone dropped the currency ("950" for "$950"), the percent sign and a
|
|
194
|
+
/// signDisplay's plus. Foundation has a compact currency and percent style
|
|
195
|
+
/// of its own, which prints the locale's compact currency patterns.
|
|
196
|
+
/// A currency pattern's text around the number, for compact currency before iOS 18.
|
|
197
|
+
private struct CompactAffixes {
|
|
198
|
+
let positivePrefix: String
|
|
199
|
+
let positiveSuffix: String
|
|
200
|
+
let negativePrefix: String
|
|
201
|
+
let negativeSuffix: String
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
@available(iOS 16.0, *)
|
|
205
|
+
private static func compactStyle(_ o: NumberFormatPlatformOptions, locale: Locale, currencyAffixes: CompactAffixes?) -> (Double) -> String {
|
|
206
|
+
let grouping: NumberFormatStyleConfiguration.Grouping = o.useGrouping ? .automatic : .never
|
|
207
|
+
let precision: NumberFormatStyleConfiguration.Precision = o.minimumSignificantDigits > 0
|
|
208
|
+
? .significantDigits(Int(o.minimumSignificantDigits)...Int(o.maximumSignificantDigits))
|
|
209
|
+
: .fractionLength(Int(o.minimumFractionDigits)...Int(o.maximumFractionDigits))
|
|
210
|
+
let sign: NumberFormatStyleConfiguration.SignDisplayStrategy
|
|
211
|
+
switch o.signDisplay {
|
|
212
|
+
case .always: sign = .always(includingZero: true)
|
|
213
|
+
case .exceptzero: sign = .always(includingZero: false)
|
|
214
|
+
case .never: sign = .never
|
|
215
|
+
default: sign = .automatic
|
|
216
|
+
}
|
|
217
|
+
if o.style == .currency, let code = o.currency, #available(iOS 18.0, *) {
|
|
218
|
+
let presentation: CurrencyFormatStyleConfiguration.Presentation
|
|
219
|
+
switch o.currencyDisplay {
|
|
220
|
+
case .code: presentation = .isoCode
|
|
221
|
+
case .name: presentation = .fullName
|
|
222
|
+
case .narrowsymbol: presentation = .narrow
|
|
223
|
+
default: presentation = .standard
|
|
224
|
+
}
|
|
225
|
+
let currencySign: CurrencyFormatStyleConfiguration.SignDisplayStrategy
|
|
226
|
+
switch o.signDisplay {
|
|
227
|
+
case .always: currencySign = .always(showZero: true)
|
|
228
|
+
case .exceptzero: currencySign = .always(showZero: false)
|
|
229
|
+
case .never: currencySign = .never
|
|
230
|
+
default: currencySign = o.currencySign == .accounting ? .accounting : .automatic
|
|
231
|
+
}
|
|
232
|
+
let style = FloatingPointFormatStyle<Double>.Currency(code: code, locale: locale)
|
|
233
|
+
.notation(.compactName)
|
|
234
|
+
.grouping(grouping)
|
|
235
|
+
.precision(precision)
|
|
236
|
+
.presentation(presentation)
|
|
237
|
+
.sign(strategy: currencySign)
|
|
238
|
+
return { style.format($0) }
|
|
239
|
+
}
|
|
240
|
+
if o.style == .percent {
|
|
241
|
+
let style = FloatingPointFormatStyle<Double>.Percent(locale: locale)
|
|
242
|
+
.notation(.compactName)
|
|
243
|
+
.grouping(grouping)
|
|
244
|
+
.precision(precision)
|
|
245
|
+
.sign(strategy: sign)
|
|
246
|
+
return { style.format($0) }
|
|
247
|
+
}
|
|
248
|
+
if let affixes = currencyAffixes {
|
|
249
|
+
// The sign is the currency pattern's (its prefixes carry signDisplay's plus).
|
|
250
|
+
let number = FloatingPointFormatStyle<Double>(locale: locale)
|
|
251
|
+
.notation(.compactName)
|
|
252
|
+
.grouping(grouping)
|
|
253
|
+
.precision(precision)
|
|
254
|
+
.sign(strategy: .never)
|
|
255
|
+
return { value in
|
|
256
|
+
let negative = value < 0 || (value == 0 && value.sign == .minus)
|
|
257
|
+
let body = number.format(value)
|
|
258
|
+
return negative
|
|
259
|
+
? affixes.negativePrefix + body + affixes.negativeSuffix
|
|
260
|
+
: affixes.positivePrefix + body + affixes.positiveSuffix
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
let style = FloatingPointFormatStyle<Double>(locale: locale)
|
|
264
|
+
.notation(.compactName)
|
|
265
|
+
.grouping(grouping)
|
|
266
|
+
.precision(precision)
|
|
267
|
+
.sign(strategy: sign)
|
|
268
|
+
return { style.format($0) }
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
func format(value: Double) throws -> String {
|
|
272
|
+
if let measure { return measure(value) }
|
|
273
|
+
if let compact { return compact(value) }
|
|
274
|
+
return formatter.string(from: NSNumber(value: value)) ?? ""
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
func formatDecimal(value: String) throws -> String {
|
|
278
|
+
if value.hasSuffix("Infinity") || value == "NaN" {
|
|
279
|
+
return try format(value: value == "NaN" ? .nan : value.hasPrefix("-") ? -.infinity : .infinity)
|
|
280
|
+
}
|
|
281
|
+
if compact != nil || measure != nil { return try format(value: Double(value) ?? .nan) }
|
|
282
|
+
let number = NSDecimalNumber(string: value, locale: Locale(identifier: "en_US_POSIX"))
|
|
283
|
+
return formatter.string(from: number) ?? ""
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/// ECMA-402's sanctioned units as Foundation units.
|
|
287
|
+
private static func dimension(_ unit: String) -> Dimension? {
|
|
288
|
+
switch unit {
|
|
289
|
+
case "acre": return UnitArea.acres
|
|
290
|
+
case "hectare": return UnitArea.hectares
|
|
291
|
+
case "bit": return UnitInformationStorage.bits
|
|
292
|
+
case "byte": return UnitInformationStorage.bytes
|
|
293
|
+
case "kilobit": return UnitInformationStorage.kilobits
|
|
294
|
+
case "kilobyte": return UnitInformationStorage.kilobytes
|
|
295
|
+
case "megabit": return UnitInformationStorage.megabits
|
|
296
|
+
case "megabyte": return UnitInformationStorage.megabytes
|
|
297
|
+
case "gigabit": return UnitInformationStorage.gigabits
|
|
298
|
+
case "gigabyte": return UnitInformationStorage.gigabytes
|
|
299
|
+
case "terabit": return UnitInformationStorage.terabits
|
|
300
|
+
case "terabyte": return UnitInformationStorage.terabytes
|
|
301
|
+
case "petabyte": return UnitInformationStorage.petabytes
|
|
302
|
+
case "celsius": return UnitTemperature.celsius
|
|
303
|
+
case "fahrenheit": return UnitTemperature.fahrenheit
|
|
304
|
+
case "centimeter": return UnitLength.centimeters
|
|
305
|
+
case "foot": return UnitLength.feet
|
|
306
|
+
case "inch": return UnitLength.inches
|
|
307
|
+
case "kilometer": return UnitLength.kilometers
|
|
308
|
+
case "meter": return UnitLength.meters
|
|
309
|
+
case "mile": return UnitLength.miles
|
|
310
|
+
case "mile-scandinavian": return UnitLength.scandinavianMiles
|
|
311
|
+
case "millimeter": return UnitLength.millimeters
|
|
312
|
+
case "yard": return UnitLength.yards
|
|
313
|
+
case "degree": return UnitAngle.degrees
|
|
314
|
+
case "fluid-ounce": return UnitVolume.fluidOunces
|
|
315
|
+
case "gallon": return UnitVolume.gallons
|
|
316
|
+
case "liter": return UnitVolume.liters
|
|
317
|
+
case "milliliter": return UnitVolume.milliliters
|
|
318
|
+
case "gram": return UnitMass.grams
|
|
319
|
+
case "kilogram": return UnitMass.kilograms
|
|
320
|
+
case "ounce": return UnitMass.ounces
|
|
321
|
+
case "pound": return UnitMass.pounds
|
|
322
|
+
case "stone": return UnitMass.stones
|
|
323
|
+
case "hour": return UnitDuration.hours
|
|
324
|
+
case "minute": return UnitDuration.minutes
|
|
325
|
+
case "second": return UnitDuration.seconds
|
|
326
|
+
case "millisecond": return UnitDuration.milliseconds
|
|
327
|
+
case "microsecond": return UnitDuration.microseconds
|
|
328
|
+
case "nanosecond": return UnitDuration.nanoseconds
|
|
329
|
+
case "kilometer-per-hour": return UnitSpeed.kilometersPerHour
|
|
330
|
+
case "meter-per-second": return UnitSpeed.metersPerSecond
|
|
331
|
+
case "mile-per-hour": return UnitSpeed.milesPerHour
|
|
332
|
+
case "mile-per-gallon": return UnitFuelEfficiency.milesPerGallon
|
|
333
|
+
case "liter-per-kilometer": return nil
|
|
334
|
+
default: return nil
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/// A unit formatter: Foundation's for the units it has; days to years and
|
|
339
|
+
/// other compound units through DateComponentsFormatter or "x/y".
|
|
340
|
+
private static func unitFormatter(_ unit: String, display: NumberFormatUnitDisplay, locale: Locale, number: NumberFormatter) throws -> (Double) -> String {
|
|
341
|
+
if unit == "percent" {
|
|
342
|
+
let percent = number.copy() as! NumberFormatter
|
|
343
|
+
percent.numberStyle = .percent
|
|
344
|
+
percent.multiplier = 1
|
|
345
|
+
percent.minimumFractionDigits = number.minimumFractionDigits
|
|
346
|
+
percent.maximumFractionDigits = number.maximumFractionDigits
|
|
347
|
+
return { percent.string(from: NSNumber(value: $0)) ?? "" }
|
|
348
|
+
}
|
|
349
|
+
let formatter = MeasurementFormatter()
|
|
350
|
+
formatter.locale = locale
|
|
351
|
+
formatter.unitOptions = .providedUnit
|
|
352
|
+
formatter.numberFormatter = number
|
|
353
|
+
formatter.unitStyle = display == .long ? .long : display == .narrow ? .short : .medium
|
|
354
|
+
if let dimension = dimension(unit) {
|
|
355
|
+
return { (value: Double) -> String in
|
|
356
|
+
let measurement: Measurement<Dimension> = Measurement(value: value, unit: dimension)
|
|
357
|
+
return formatter.string(from: measurement)
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
let durations: [String: NSCalendar.Unit] = ["day": .day, "week": .weekOfMonth, "month": .month, "year": .year]
|
|
361
|
+
if let calendarUnit = durations[unit] {
|
|
362
|
+
let components = DateComponentsFormatter()
|
|
363
|
+
components.allowedUnits = [calendarUnit]
|
|
364
|
+
components.unitsStyle = display == .long ? .full : display == .narrow ? .abbreviated : .short
|
|
365
|
+
var calendar = Calendar(identifier: .gregorian)
|
|
366
|
+
calendar.locale = locale
|
|
367
|
+
components.calendar = calendar
|
|
368
|
+
return { value in
|
|
369
|
+
var parts = DateComponents()
|
|
370
|
+
let whole = Int(value.rounded(.towardZero))
|
|
371
|
+
switch calendarUnit {
|
|
372
|
+
case .day: parts.day = whole
|
|
373
|
+
case .weekOfMonth: parts.weekOfMonth = whole
|
|
374
|
+
case .month: parts.month = whole
|
|
375
|
+
default: parts.year = whole
|
|
376
|
+
}
|
|
377
|
+
return value == value.rounded(.towardZero) ? (components.string(from: parts) ?? "") : "\(number.string(from: NSNumber(value: value)) ?? "") \(unit)"
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if let per = unit.range(of: "-per-") {
|
|
381
|
+
let first = String(unit[..<per.lowerBound])
|
|
382
|
+
let second = String(unit[per.upperBound...])
|
|
383
|
+
// "x-per-y" as "x/y", with Foundation's symbol for y where it has one.
|
|
384
|
+
let head = try unitFormatter(first, display: display, locale: locale, number: number)
|
|
385
|
+
var suffix = second
|
|
386
|
+
if let b = dimension(second) {
|
|
387
|
+
let symbols = MeasurementFormatter()
|
|
388
|
+
symbols.locale = locale
|
|
389
|
+
symbols.unitStyle = .short
|
|
390
|
+
let unitB: Unit = b
|
|
391
|
+
suffix = symbols.string(from: unitB)
|
|
392
|
+
}
|
|
393
|
+
return { (value: Double) -> String in head(value) + "/" + suffix }
|
|
394
|
+
}
|
|
395
|
+
throw RuntimeError.error(withMessage: "NumberFormat: the unit '\(unit)' is not available on iOS.")
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
private static func roundingMode(_ mode: NumberFormatRoundingMode) -> NumberFormatter.RoundingMode {
|
|
399
|
+
switch mode {
|
|
400
|
+
case .ceil: return .ceiling
|
|
401
|
+
case .floor: return .floor
|
|
402
|
+
case .expand: return .up
|
|
403
|
+
case .trunc: return .down
|
|
404
|
+
case .halftrunc: return .halfDown
|
|
405
|
+
case .halfeven: return .halfEven
|
|
406
|
+
case .halfexpand, .halfceil, .halffloor: return .halfUp
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
private static func numberingSystem(of locale: Locale) -> String {
|
|
411
|
+
if #available(iOS 16.0, *) { return locale.numberingSystem.identifier }
|
|
412
|
+
return "latn"
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/// The currency's narrow symbol ("$" for CA$), read off a formatted zero.
|
|
416
|
+
private static func narrowSymbol(_ code: String, locale: Locale) -> String? {
|
|
417
|
+
guard #available(iOS 16.0, *) else { return nil }
|
|
418
|
+
let text = Decimal(0).formatted(.currency(code: code).locale(locale).presentation(.narrow))
|
|
419
|
+
let symbol = text.unicodeScalars.filter { scalar in
|
|
420
|
+
!CharacterSet.decimalDigits.contains(scalar) && !CharacterSet.whitespaces.contains(scalar) && !CharacterSet.punctuationCharacters.contains(scalar)
|
|
421
|
+
&& !(0x200E...0x200F).contains(scalar.value) && scalar.value != 0x061C
|
|
422
|
+
}
|
|
423
|
+
let result = String(String.UnicodeScalarView(symbol))
|
|
424
|
+
return result.isEmpty ? nil : result
|
|
425
|
+
}
|
|
426
|
+
}
|
|
@@ -32,6 +32,12 @@ final class HybridNitroNumberView: HybridNitroNumberViewSpec, RecyclableView {
|
|
|
32
32
|
rollingView.onRevealMilestone = { [weak self] index, milestone in
|
|
33
33
|
self?.onRevealMilestone?(Double(index), milestone)
|
|
34
34
|
}
|
|
35
|
+
rollingView.onAnimationStart = { [weak self] in
|
|
36
|
+
self?.onAnimationStart?()
|
|
37
|
+
}
|
|
38
|
+
rollingView.onAnimationEnd = { [weak self] value in
|
|
39
|
+
self?.onAnimationEnd?(value)
|
|
40
|
+
}
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
// MARK: - Props
|
|
@@ -79,12 +85,38 @@ final class HybridNitroNumberView: HybridNitroNumberViewSpec, RecyclableView {
|
|
|
79
85
|
var loading: Bool? { didSet { markConfigDirty() } }
|
|
80
86
|
var shimmerColor: Double? { didSet { markConfigDirty() } }
|
|
81
87
|
var shimmerDuration: Double? { didSet { markConfigDirty() } }
|
|
88
|
+
var shimmerAngle: Double? { didSet { markConfigDirty() } }
|
|
89
|
+
var shimmerWidth: Double? { didSet { markConfigDirty() } }
|
|
90
|
+
var shimmerBaseColor: Double? { didSet { markConfigDirty() } }
|
|
91
|
+
var shimmerDirection: NitroNumberShimmerDirection? { didSet { markConfigDirty() } }
|
|
92
|
+
var shimmerDelay: Double? { didSet { markConfigDirty() } }
|
|
82
93
|
var fontSize: Double? { didSet { markConfigDirty() } }
|
|
83
94
|
var prefixFontSize: Double? { didSet { markConfigDirty() } }
|
|
84
95
|
var suffixFontSize: Double? { didSet { markConfigDirty() } }
|
|
85
96
|
var affixAlign: NitroNumberAffixAlign? { didSet { markConfigDirty() } }
|
|
86
97
|
var prefixAlign: NitroNumberAffixAlign? { didSet { markConfigDirty() } }
|
|
87
98
|
var suffixAlign: NitroNumberAffixAlign? { didSet { markConfigDirty() } }
|
|
99
|
+
var letterSpacing: Double? { didSet { markConfigDirty() } }
|
|
100
|
+
var prefixSpacing: Double? { didSet { markConfigDirty() } }
|
|
101
|
+
var suffixSpacing: Double? { didSet { markConfigDirty() } }
|
|
102
|
+
var prefixOffset: Double? { didSet { markConfigDirty() } }
|
|
103
|
+
var suffixOffset: Double? { didSet { markConfigDirty() } }
|
|
104
|
+
var tabularNums: Bool? { didSet { markConfigDirty() } }
|
|
105
|
+
var signDisplay: NitroNumberSignDisplay? { didSet { markConfigDirty() } }
|
|
106
|
+
var plusSign: String? { didSet { markConfigDirty() } }
|
|
107
|
+
var minusSign: String? { didSet { markConfigDirty() } }
|
|
108
|
+
var digitGlyphs: [String]? { didSet { markConfigDirty() } }
|
|
109
|
+
var groupingSizes: [Double]? { didSet { markConfigDirty() } }
|
|
110
|
+
var digitMax: [Double]? { didSet { markConfigDirty() } }
|
|
111
|
+
var continuous: Bool? { didSet { markConfigDirty() } }
|
|
112
|
+
var prefixColor: Double? { didSet { markConfigDirty() } }
|
|
113
|
+
var suffixColor: Double? { didSet { markConfigDirty() } }
|
|
114
|
+
var fractionColor: Double? { didSet { markConfigDirty() } }
|
|
115
|
+
var fractionFontSize: Double? { didSet { markConfigDirty() } }
|
|
116
|
+
var fractionAlign: NitroNumberAffixAlign? { didSet { markConfigDirty() } }
|
|
117
|
+
var respectReduceMotion: Bool? { didSet { markConfigDirty() } }
|
|
118
|
+
var onAnimationStart: (() -> Void)?
|
|
119
|
+
var onAnimationEnd: ((Double) -> Void)?
|
|
88
120
|
var adjustsFontSizeToFit: Bool? { didSet { markConfigDirty() } }
|
|
89
121
|
var minimumFontScale: Double? { didSet { markConfigDirty() } }
|
|
90
122
|
var allowFontScaling: Bool? { didSet { markConfigDirty() } }
|
|
@@ -219,12 +251,38 @@ final class HybridNitroNumberView: HybridNitroNumberViewSpec, RecyclableView {
|
|
|
219
251
|
loading = nil
|
|
220
252
|
shimmerColor = nil
|
|
221
253
|
shimmerDuration = nil
|
|
254
|
+
shimmerAngle = nil
|
|
255
|
+
shimmerWidth = nil
|
|
256
|
+
shimmerBaseColor = nil
|
|
257
|
+
shimmerDirection = nil
|
|
258
|
+
shimmerDelay = nil
|
|
222
259
|
fontSize = nil
|
|
223
260
|
prefixFontSize = nil
|
|
224
261
|
suffixFontSize = nil
|
|
225
262
|
affixAlign = nil
|
|
226
263
|
prefixAlign = nil
|
|
227
264
|
suffixAlign = nil
|
|
265
|
+
letterSpacing = nil
|
|
266
|
+
prefixSpacing = nil
|
|
267
|
+
suffixSpacing = nil
|
|
268
|
+
prefixOffset = nil
|
|
269
|
+
suffixOffset = nil
|
|
270
|
+
tabularNums = nil
|
|
271
|
+
signDisplay = nil
|
|
272
|
+
plusSign = nil
|
|
273
|
+
minusSign = nil
|
|
274
|
+
digitGlyphs = nil
|
|
275
|
+
groupingSizes = nil
|
|
276
|
+
digitMax = nil
|
|
277
|
+
continuous = nil
|
|
278
|
+
prefixColor = nil
|
|
279
|
+
suffixColor = nil
|
|
280
|
+
fractionColor = nil
|
|
281
|
+
fractionFontSize = nil
|
|
282
|
+
fractionAlign = nil
|
|
283
|
+
respectReduceMotion = nil
|
|
284
|
+
onAnimationStart = nil
|
|
285
|
+
onAnimationEnd = nil
|
|
228
286
|
adjustsFontSizeToFit = nil
|
|
229
287
|
minimumFontScale = nil
|
|
230
288
|
allowFontScaling = nil
|
|
@@ -294,6 +352,11 @@ final class HybridNitroNumberView: HybridNitroNumberViewSpec, RecyclableView {
|
|
|
294
352
|
format.decimalSeparator = decimalSeparator ?? "."
|
|
295
353
|
format.prefix = prefix ?? ""
|
|
296
354
|
format.suffix = suffix ?? ""
|
|
355
|
+
format.signDisplay = Self.mapSignDisplay(signDisplay)
|
|
356
|
+
format.plusSign = (plusSign?.isEmpty ?? true) ? "+" : plusSign!
|
|
357
|
+
format.minusSign = (minusSign?.isEmpty ?? true) ? "-" : minusSign!
|
|
358
|
+
format.groupingSizes = (groupingSizes ?? []).map { $0.isFinite ? max(0, Int($0.rounded())) : 0 }
|
|
359
|
+
format.digitMax = (digitMax ?? []).map { $0.isFinite ? Int($0.rounded()) : 9 }
|
|
297
360
|
|
|
298
361
|
var typography = NitroNumberView.Typography()
|
|
299
362
|
typography.fontSize = CGFloat(fontSize ?? 32)
|
|
@@ -305,6 +368,18 @@ final class HybridNitroNumberView: HybridNitroNumberViewSpec, RecyclableView {
|
|
|
305
368
|
let sharedAlign = Self.mapAffixAlign(affixAlign)
|
|
306
369
|
typography.prefixAlign = prefixAlign.map { Self.mapAffixAlign($0) } ?? sharedAlign
|
|
307
370
|
typography.suffixAlign = suffixAlign.map { Self.mapAffixAlign($0) } ?? sharedAlign
|
|
371
|
+
typography.letterSpacing = CGFloat((letterSpacing ?? 0).isFinite ? letterSpacing ?? 0 : 0)
|
|
372
|
+
typography.prefixSpacing = prefixSpacing.flatMap { $0.isFinite ? CGFloat($0) : nil }
|
|
373
|
+
typography.suffixSpacing = suffixSpacing.flatMap { $0.isFinite ? CGFloat($0) : nil }
|
|
374
|
+
typography.prefixOffset = CGFloat((prefixOffset ?? 0).isFinite ? prefixOffset ?? 0 : 0)
|
|
375
|
+
typography.suffixOffset = CGFloat((suffixOffset ?? 0).isFinite ? suffixOffset ?? 0 : 0)
|
|
376
|
+
typography.tabularNums = tabularNums ?? true
|
|
377
|
+
typography.prefixColor = prefixColor.flatMap(Self.optionalColor(fromARGB:))
|
|
378
|
+
typography.suffixColor = suffixColor.flatMap(Self.optionalColor(fromARGB:))
|
|
379
|
+
typography.fractionColor = fractionColor.flatMap(Self.optionalColor(fromARGB:))
|
|
380
|
+
typography.fractionFontSize = fractionFontSize.flatMap { $0.isFinite && $0 > 0 ? CGFloat($0) : nil }
|
|
381
|
+
typography.fractionAlign = Self.mapAffixAlign(fractionAlign)
|
|
382
|
+
typography.digitGlyphs = digitGlyphs ?? []
|
|
308
383
|
typography.adjustsFontSizeToFit = adjustsFontSizeToFit ?? false
|
|
309
384
|
typography.minimumFontScale = CGFloat(min(1, max(0.05, minimumFontScale ?? 0.5)))
|
|
310
385
|
typography.allowFontScaling = allowFontScaling ?? false
|
|
@@ -324,10 +399,21 @@ final class HybridNitroNumberView: HybridNitroNumberViewSpec, RecyclableView {
|
|
|
324
399
|
timing.revealStyle = revealStyle == .spin ? .spin : .count
|
|
325
400
|
timing.revealStagger = max(0, (revealStagger ?? 200) / 1000)
|
|
326
401
|
timing.revealMilestoneHold = max(0, (revealMilestoneHold ?? 0) / 1000)
|
|
402
|
+
timing.continuous = continuous ?? false
|
|
403
|
+
timing.respectReduceMotion = respectReduceMotion ?? true
|
|
327
404
|
|
|
328
405
|
var shimmer = NitroNumberView.Shimmer()
|
|
329
|
-
shimmer.color = shimmerColor.
|
|
406
|
+
shimmer.color = shimmerColor.flatMap(Self.optionalColor(fromARGB:))
|
|
330
407
|
shimmer.duration = max(0.2, (shimmerDuration ?? 950) / 1000)
|
|
408
|
+
shimmer.angle = CGFloat(shimmerAngle.flatMap { $0.isFinite ? $0 : nil } ?? 31)
|
|
409
|
+
shimmer.width = CGFloat(shimmerWidth.flatMap { $0.isFinite && $0 > 0 ? $0 : nil } ?? 1)
|
|
410
|
+
shimmer.baseColor = shimmerBaseColor.flatMap(Self.optionalColor(fromARGB:))
|
|
411
|
+
switch shimmerDirection {
|
|
412
|
+
case .ltr: shimmer.leftToRight = true
|
|
413
|
+
case .rtl: shimmer.leftToRight = false
|
|
414
|
+
default: shimmer.leftToRight = nil
|
|
415
|
+
}
|
|
416
|
+
shimmer.delay = max(0, (shimmerDelay.flatMap { $0.isFinite ? $0 : nil } ?? 0) / 1000)
|
|
331
417
|
|
|
332
418
|
var flash = NitroNumberView.Flash()
|
|
333
419
|
flash.upColor = flashUpColor.flatMap(Self.optionalColor(fromARGB:))
|
|
@@ -411,10 +497,24 @@ final class HybridNitroNumberView: HybridNitroNumberViewSpec, RecyclableView {
|
|
|
411
497
|
case .auto: return .auto
|
|
412
498
|
case .up: return .up
|
|
413
499
|
case .down: return .down
|
|
500
|
+
case .shortest: return .shortest
|
|
414
501
|
default: return .auto
|
|
415
502
|
}
|
|
416
503
|
}
|
|
417
504
|
|
|
505
|
+
/// `Engine.setSignDisplay`'s modes.
|
|
506
|
+
private static func mapSignDisplay(_ mode: NitroNumberSignDisplay?) -> Int32 {
|
|
507
|
+
guard let mode else { return 0 }
|
|
508
|
+
switch mode {
|
|
509
|
+
case .auto: return 0
|
|
510
|
+
case .always: return 1
|
|
511
|
+
case .exceptzero: return 2
|
|
512
|
+
case .negative: return 3
|
|
513
|
+
case .never: return 4
|
|
514
|
+
default: return 0
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
418
518
|
private static func mapAffixAlign(_ align: NitroNumberAffixAlign?) -> NitroNumberView.AffixAlign {
|
|
419
519
|
guard let align else { return .baseline }
|
|
420
520
|
switch align {
|