react-native-nitro-input 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +43 -1
- package/android/CMakeLists.txt +4 -0
- package/android/gradle.properties +1 -1
- package/android/src/main/cpp/JRollingEngine.cpp +3 -2
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +20 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatform.kt +209 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +25 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +69 -10
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +164 -24
- package/android/src/main/java/com/margelo/nitro/nitroinput/RollingEngine.kt +2 -1
- package/cpp/RollingEngine.cpp +12 -2
- package/cpp/RollingEngine.hpp +8 -1
- 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 +348 -0
- package/ios/HybridNitroNumberView.swift +19 -0
- package/ios/NitroInputView.swift +79 -19
- package/ios/NitroNumberView.swift +171 -31
- package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -0
- package/lib/commonjs/src/NitroInput.js +8 -6
- package/lib/commonjs/src/NitroNumber.js +4 -2
- package/lib/commonjs/src/NumberFormat.js +525 -0
- package/lib/commonjs/src/formatProps.js +48 -0
- package/lib/commonjs/src/index.js +3 -1
- 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 +6 -0
- package/lib/module/src/NitroInput.js +8 -6
- package/lib/module/src/NitroNumber.js +4 -2
- package/lib/module/src/NumberFormat.js +521 -0
- package/lib/module/src/formatProps.js +45 -0
- package/lib/module/src/index.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 +36 -1
- package/lib/typescript/src/NumberFormat.d.ts +47 -0
- package/lib/typescript/src/formatProps.d.ts +21 -0
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/specs/NitroInput.nitro.d.ts +10 -0
- package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +13 -1
- package/lib/typescript/src/specs/NumberFormat.nitro.d.ts +139 -0
- package/nitro.json +16 -0
- package/nitrogen/generated/android/NitroInput+autolinking.cmake +6 -0
- package/nitrogen/generated/android/NitroInputOnLoad.cpp +28 -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 +54 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +12 -0
- package/nitrogen/generated/android/c++/JHybridNitroPlatformNumberFormatterSpec.cpp +65 -0
- package/nitrogen/generated/android/c++/JHybridNitroPlatformNumberFormatterSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroNumberDirection.hpp +3 -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 +30 -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 +36 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroPlatformNumberFormatterSpec.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberDirection.kt +2 -1
- 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/ios/NitroInput-Swift-Cxx-Bridge.cpp +34 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +63 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +40 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.mm +18 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.swift +12 -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 +42 -0
- package/nitrogen/generated/ios/c++/HybridNitroPlatformNumberFormatterSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroPlatformNumberFormatterSpecSwift.hpp +94 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +30 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +36 -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 +6 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +144 -0
- package/nitrogen/generated/ios/swift/HybridNitroPlatformNumberFormatterSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridNitroPlatformNumberFormatterSpec_cxx.swift +155 -0
- package/nitrogen/generated/ios/swift/NitroNumberDirection.swift +4 -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 +12 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +12 -0
- package/nitrogen/generated/shared/c++/HybridNitroPlatformNumberFormatterSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridNitroPlatformNumberFormatterSpec.hpp +65 -0
- package/nitrogen/generated/shared/c++/NitroNumberDirection.hpp +4 -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 +12 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +18 -0
- package/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
- package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -0
- package/package.json +2 -2
- package/src/NitroInput.tsx +42 -7
- package/src/NitroNumber.tsx +57 -7
- package/src/NumberFormat.ts +563 -0
- package/src/formatProps.ts +59 -0
- package/src/index.ts +18 -0
- package/src/specs/NitroInput.nitro.ts +10 -0
- package/src/specs/NitroNumber.nitro.ts +13 -1
- package/src/specs/NumberFormat.nitro.ts +145 -0
|
@@ -50,6 +50,16 @@ final class NitroNumberView: UIView {
|
|
|
50
50
|
var color: UIColor = .label
|
|
51
51
|
var prefixAlign: AffixAlign = .baseline
|
|
52
52
|
var suffixAlign: AffixAlign = .baseline
|
|
53
|
+
/// Points added after every glyph, as `Text`'s letterSpacing; an affix gets it in proportion to its size.
|
|
54
|
+
var letterSpacing: CGFloat = 0
|
|
55
|
+
/// Points between the prefix and the digits, and between the digits and the suffix, in place of the letter spacing there.
|
|
56
|
+
var prefixSpacing: CGFloat? = nil
|
|
57
|
+
var suffixSpacing: CGFloat? = nil
|
|
58
|
+
/// Points an affix is moved down (negative: up) after its alignment.
|
|
59
|
+
var prefixOffset: CGFloat = 0
|
|
60
|
+
var suffixOffset: CGFloat = 0
|
|
61
|
+
/// Every digit as wide as the widest (tabular figures, the default), or each at its own width.
|
|
62
|
+
var tabularNums: Bool = true
|
|
53
63
|
var adjustsFontSizeToFit: Bool = false
|
|
54
64
|
var minimumFontScale: CGFloat = 0.5
|
|
55
65
|
var allowFontScaling: Bool = false
|
|
@@ -61,7 +71,7 @@ final class NitroNumberView: UIView {
|
|
|
61
71
|
}
|
|
62
72
|
|
|
63
73
|
enum Direction: Int32 {
|
|
64
|
-
case auto = 0, up = 1, down = 2
|
|
74
|
+
case auto = 0, up = 1, down = 2, shortest = 3
|
|
65
75
|
}
|
|
66
76
|
|
|
67
77
|
struct Timing: Equatable {
|
|
@@ -318,12 +328,24 @@ final class NitroNumberView: UIView {
|
|
|
318
328
|
let color: UIColor
|
|
319
329
|
let prefixAlign: AffixAlign
|
|
320
330
|
let suffixAlign: AffixAlign
|
|
331
|
+
/// Letter spacing after a digit / prefix / suffix glyph, and the spacing at the affix seams (nil: the letter spacing), scaled with the fonts.
|
|
332
|
+
let digitSpacing: CGFloat
|
|
333
|
+
let prefixLetterSpacing: CGFloat
|
|
334
|
+
let suffixLetterSpacing: CGFloat
|
|
335
|
+
let prefixSeam: CGFloat?
|
|
336
|
+
let suffixSeam: CGFloat?
|
|
337
|
+
let prefixOffset: CGFloat
|
|
338
|
+
let suffixOffset: CGFloat
|
|
321
339
|
/// Height of the line box (the digit font's line height).
|
|
322
340
|
let lineHeight: CGFloat
|
|
323
341
|
/// The numeric transition's blur radius at full blur, in line heights.
|
|
324
342
|
let numericBlur: CGFloat = NitroNumberView.numericBlur
|
|
325
343
|
/// Width of the widest digit glyph.
|
|
326
344
|
private(set) var digitWidth: CGFloat = 0
|
|
345
|
+
/// Each digit at its own advance instead of the widest's (`tabularNums={false}`).
|
|
346
|
+
let proportional: Bool
|
|
347
|
+
/// The advance of each digit 0…9.
|
|
348
|
+
private(set) var digitWidths: [CGFloat] = []
|
|
327
349
|
// Keyed by a value type rather than a concatenated string: a lookup on the
|
|
328
350
|
// frame path must not allocate.
|
|
329
351
|
private var glyphCache: [GlyphKey: NSAttributedString] = [:]
|
|
@@ -367,7 +389,7 @@ final class NitroNumberView: UIView {
|
|
|
367
389
|
private let colorKey: UInt32
|
|
368
390
|
private func fontTag(_ role: GlyphRole) -> String {
|
|
369
391
|
let font = self.font(for: role)
|
|
370
|
-
return "\(font.fontName)|\(font.pointSize)"
|
|
392
|
+
return "\(font.fontName)|\(font.pointSize)\(proportional ? "|p" : "")"
|
|
371
393
|
}
|
|
372
394
|
/// Pixel density the glyph images are rendered at.
|
|
373
395
|
let renderScale: CGFloat
|
|
@@ -378,17 +400,26 @@ final class NitroNumberView: UIView {
|
|
|
378
400
|
// The view's own display, not the main screen's (deprecated, and absent on visionOS).
|
|
379
401
|
renderScale = max(1, traits.displayScale)
|
|
380
402
|
let scale = NitroNumberView.systemFontMultiplier(t)
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
403
|
+
proportional = !t.tabularNums
|
|
404
|
+
digit = NitroNumberView.makeFont(size: t.fontSize * scale, weight: t.fontWeight, family: t.fontFamily, tabular: t.tabularNums)
|
|
405
|
+
prefix = NitroNumberView.makeFont(size: (t.prefixFontSize ?? t.fontSize) * scale, weight: t.fontWeight, family: t.fontFamily, tabular: t.tabularNums)
|
|
406
|
+
suffix = NitroNumberView.makeFont(size: (t.suffixFontSize ?? t.fontSize) * scale, weight: t.fontWeight, family: t.fontFamily, tabular: t.tabularNums)
|
|
384
407
|
color = t.color.resolvedColor(with: traits)
|
|
385
408
|
var r: CGFloat = 0, g: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0
|
|
386
409
|
color.getRed(&r, green: &g, blue: &b, alpha: &a)
|
|
387
410
|
colorKey = (UInt32(max(0, min(1, a)) * 255) << 24) | (UInt32(max(0, min(1, r)) * 255) << 16) | (UInt32(max(0, min(1, g)) * 255) << 8) | UInt32(max(0, min(1, b)) * 255)
|
|
388
411
|
prefixAlign = t.prefixAlign
|
|
389
412
|
suffixAlign = t.suffixAlign
|
|
413
|
+
digitSpacing = t.letterSpacing * scale
|
|
414
|
+
prefixLetterSpacing = t.letterSpacing * scale * (prefix.pointSize / digit.pointSize)
|
|
415
|
+
suffixLetterSpacing = t.letterSpacing * scale * (suffix.pointSize / digit.pointSize)
|
|
416
|
+
prefixSeam = t.prefixSpacing.map { $0 * scale }
|
|
417
|
+
suffixSeam = t.suffixSpacing.map { $0 * scale }
|
|
418
|
+
prefixOffset = t.prefixOffset * scale
|
|
419
|
+
suffixOffset = t.suffixOffset * scale
|
|
390
420
|
lineHeight = ceil(digit.lineHeight)
|
|
391
|
-
|
|
421
|
+
digitWidths = (0...9).map { width(of: String($0), role: .digit) }
|
|
422
|
+
digitWidth = digitWidths.max() ?? 0
|
|
392
423
|
}
|
|
393
424
|
|
|
394
425
|
func font(for role: GlyphRole) -> UIFont {
|
|
@@ -623,6 +654,19 @@ final class NitroNumberView: UIView {
|
|
|
623
654
|
/// Top of the glyph's line box for `role` drawing `text`, given the top of the digit line box.
|
|
624
655
|
func top(for role: GlyphRole, text: String, lineTop: CGFloat) -> CGFloat {
|
|
625
656
|
guard role != .digit else { return lineTop }
|
|
657
|
+
return alignedTop(for: role, text: text, lineTop: lineTop) + (role == .prefix ? prefixOffset : suffixOffset)
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/// Letter spacing after a glyph of `role`.
|
|
661
|
+
func spacing(for role: GlyphRole) -> CGFloat {
|
|
662
|
+
switch role {
|
|
663
|
+
case .digit: return digitSpacing
|
|
664
|
+
case .prefix: return prefixLetterSpacing
|
|
665
|
+
case .suffix: return suffixLetterSpacing
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
private func alignedTop(for role: GlyphRole, text: String, lineTop: CGFloat) -> CGFloat {
|
|
626
670
|
let f = font(for: role)
|
|
627
671
|
switch role == .prefix ? prefixAlign : suffixAlign {
|
|
628
672
|
case .baseline:
|
|
@@ -893,6 +937,7 @@ final class NitroNumberView: UIView {
|
|
|
893
937
|
shimmer = Shimmer()
|
|
894
938
|
alignment = .auto
|
|
895
939
|
revealMilestones = []
|
|
940
|
+
cellWidths.removeAll()
|
|
896
941
|
// `onIntrinsicSizeChange`, `onRevealEnd` and `onRevealMilestone` are the
|
|
897
942
|
// hybrid's wiring, not the element's props: they stay across recycling
|
|
898
943
|
// (the hybrid clears its own callback props).
|
|
@@ -1026,6 +1071,7 @@ final class NitroNumberView: UIView {
|
|
|
1026
1071
|
|
|
1027
1072
|
private func rebuildFonts() {
|
|
1028
1073
|
fonts = FontSet(typography, traits: traitCollection)
|
|
1074
|
+
cellWidths.removeAll()
|
|
1029
1075
|
contentLayer.contentsScale = fonts.renderScale
|
|
1030
1076
|
fontScale = 1
|
|
1031
1077
|
// Every cached glyph image belongs to the old font set.
|
|
@@ -1079,7 +1125,7 @@ final class NitroNumberView: UIView {
|
|
|
1079
1125
|
return multiplier
|
|
1080
1126
|
}
|
|
1081
1127
|
|
|
1082
|
-
private static func makeFont(size: CGFloat, weight: CGFloat, family: String
|
|
1128
|
+
private static func makeFont(size: CGFloat, weight: CGFloat, family: String?, tabular: Bool) -> UIFont {
|
|
1083
1129
|
let uiWeight = uiWeight(weight)
|
|
1084
1130
|
let traits: [UIFontDescriptor.TraitKey: Any] = [.weight: uiWeight]
|
|
1085
1131
|
var base: UIFont
|
|
@@ -1094,12 +1140,14 @@ final class NitroNumberView: UIView {
|
|
|
1094
1140
|
} else {
|
|
1095
1141
|
base = UIFont.systemFont(ofSize: size, weight: uiWeight)
|
|
1096
1142
|
}
|
|
1097
|
-
// Tabular (monospaced) digits so every column has the same width
|
|
1143
|
+
// Tabular (monospaced) digits so every column has the same width, or the
|
|
1144
|
+
// font's proportional ones when each digit is laid out at its own width.
|
|
1145
|
+
let selector = tabular ? kMonospacedNumbersSelector : kProportionalNumbersSelector
|
|
1098
1146
|
let feature: [UIFontDescriptor.FeatureKey: Int]
|
|
1099
1147
|
if #available(iOS 15.0, *) {
|
|
1100
|
-
feature = [.type: kNumberSpacingType, .selector:
|
|
1148
|
+
feature = [.type: kNumberSpacingType, .selector: selector]
|
|
1101
1149
|
} else {
|
|
1102
|
-
feature = [.featureIdentifier: kNumberSpacingType, .typeIdentifier:
|
|
1150
|
+
feature = [.featureIdentifier: kNumberSpacingType, .typeIdentifier: selector]
|
|
1103
1151
|
}
|
|
1104
1152
|
let descriptor = base.fontDescriptor.addingAttributes([.featureSettings: [feature]])
|
|
1105
1153
|
return UIFont(descriptor: descriptor, size: size)
|
|
@@ -1135,6 +1183,9 @@ final class NitroNumberView: UIView {
|
|
|
1135
1183
|
var slot = -1
|
|
1136
1184
|
var fromText: String?
|
|
1137
1185
|
var anchor = 1
|
|
1186
|
+
/// Space after the cell (letter spacing, or an affix seam), scaled with it; not part of the glyph's box.
|
|
1187
|
+
var gap: CGFloat = 0
|
|
1188
|
+
var advance: CGFloat { width + gap }
|
|
1138
1189
|
}
|
|
1139
1190
|
|
|
1140
1191
|
/// Pulls the engine's wheels into `wheelBuffer`.
|
|
@@ -1204,7 +1255,8 @@ final class NitroNumberView: UIView {
|
|
|
1204
1255
|
while power >= 0 {
|
|
1205
1256
|
let wheel = wheels[power]
|
|
1206
1257
|
if wheel.width > 0 {
|
|
1207
|
-
|
|
1258
|
+
let advance = digitAdvance(wheel, power: power, fonts: fonts, settled: !animated)
|
|
1259
|
+
elements.append(Element(kind: .wheel(power), width: advance * CGFloat(wheel.width), fullWidth: advance, factor: wheel.width))
|
|
1208
1260
|
}
|
|
1209
1261
|
if power > fd, (power - fd) % 3 == 0 {
|
|
1210
1262
|
addGlyph(format.groupingSeparator, role: .digit, factor: wheel.width, slot: Self.groupingText, anchor: 0)
|
|
@@ -1221,6 +1273,82 @@ final class NitroNumberView: UIView {
|
|
|
1221
1273
|
} else {
|
|
1222
1274
|
addGlyph(affixes.suffixInk, role: .suffix, factor: 1, slot: Self.suffixText, anchor: -1)
|
|
1223
1275
|
}
|
|
1276
|
+
applySpacing(to: &elements, fonts: fonts)
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
/// A wheel's cell width at full size: the widest digit's with tabular
|
|
1280
|
+
/// figures; otherwise its target digit's, eased there once from where the
|
|
1281
|
+
/// column was on the wheel's own progress. Following the digits a wheel
|
|
1282
|
+
/// rolled past made every column pulse as a narrow 1 went by. Settled, and
|
|
1283
|
+
/// throughout a reveal (whose layout is the target's from the first frame),
|
|
1284
|
+
/// it is the target digit's.
|
|
1285
|
+
private func digitAdvance(_ wheel: Engine.Wheel, power: Int, fonts: FontSet, settled: Bool) -> CGFloat {
|
|
1286
|
+
guard fonts.proportional else { return fonts.digitWidth }
|
|
1287
|
+
let widths = fonts.digitWidths
|
|
1288
|
+
let digit = max(0, min(9, Int(engine.targetDigit(Int32(power)))))
|
|
1289
|
+
let goal = widths[digit]
|
|
1290
|
+
if settled || engine.isRevealing() { return goal }
|
|
1291
|
+
var cell = cellWidths[power] ?? CellWidth()
|
|
1292
|
+
if cell.digit != digit || wheel.progress < cell.progress {
|
|
1293
|
+
// Interrupted mid-change, it carries on from what it showed; from rest,
|
|
1294
|
+
// from the digit the wheel is leaving.
|
|
1295
|
+
cell.from = cell.digit >= 0 && cell.progress < 1 ? cell.shown : restingWidth(wheel, widths: widths, goal: goal)
|
|
1296
|
+
cell.digit = digit
|
|
1297
|
+
}
|
|
1298
|
+
cell.progress = wheel.progress
|
|
1299
|
+
cell.shown = cell.from + (goal - cell.from) * CGFloat(max(0, min(1, wheel.progress)))
|
|
1300
|
+
cellWidths[power] = cell
|
|
1301
|
+
return cell.shown
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
/// The width of the digit a wheel shows at the start of a change (blank takes the target's).
|
|
1305
|
+
private func restingWidth(_ wheel: Engine.Wheel, widths: [CGFloat], goal: CGFloat) -> CGFloat {
|
|
1306
|
+
let glyph: Int
|
|
1307
|
+
if wheel.blend < 1 {
|
|
1308
|
+
glyph = Int(wheel.fromGlyph)
|
|
1309
|
+
} else {
|
|
1310
|
+
glyph = Int((wheel.linear ? wheel.position : Self.wrap10(wheel.position)).rounded())
|
|
1311
|
+
}
|
|
1312
|
+
return glyph >= 0 ? widths[glyph % 10] : goal
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
/// A proportional column's width through a change, by place value.
|
|
1316
|
+
private struct CellWidth {
|
|
1317
|
+
var from: CGFloat = 0
|
|
1318
|
+
var shown: CGFloat = 0
|
|
1319
|
+
var digit = -1
|
|
1320
|
+
var progress: Double = 1
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
private var cellWidths: [Int: CellWidth] = [:]
|
|
1324
|
+
|
|
1325
|
+
/// Letter spacing after every cell, and the affix seams: the space between
|
|
1326
|
+
/// the prefix and the digits and between the digits and the suffix.
|
|
1327
|
+
private func applySpacing(to elements: inout [Element], fonts: FontSet) {
|
|
1328
|
+
guard fonts.digitSpacing != 0 || fonts.prefixSeam != nil || fonts.suffixSeam != nil else { return }
|
|
1329
|
+
func role(_ e: Element) -> GlyphRole {
|
|
1330
|
+
if case .glyph(_, let r) = e.kind { return r }
|
|
1331
|
+
return .digit
|
|
1332
|
+
}
|
|
1333
|
+
for i in elements.indices {
|
|
1334
|
+
elements[i].gap = fonts.spacing(for: role(elements[i])) * CGFloat(elements[i].factor)
|
|
1335
|
+
}
|
|
1336
|
+
// The seam is the gap at the affix's edge that faces the digits (the far side in RTL).
|
|
1337
|
+
let rtl = isRTL
|
|
1338
|
+
if let seam = fonts.prefixSeam {
|
|
1339
|
+
if !rtl, let last = elements.lastIndex(where: { role($0) == .prefix }) {
|
|
1340
|
+
elements[last].gap = seam
|
|
1341
|
+
} else if rtl, let first = elements.firstIndex(where: { role($0) == .prefix }), first > 0 {
|
|
1342
|
+
elements[first - 1].gap = seam
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
if let seam = fonts.suffixSeam {
|
|
1346
|
+
if !rtl, let first = elements.firstIndex(where: { role($0) == .suffix }), first > 0 {
|
|
1347
|
+
elements[first - 1].gap = seam
|
|
1348
|
+
} else if rtl, let last = elements.lastIndex(where: { role($0) == .suffix }) {
|
|
1349
|
+
elements[last].gap = seam
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1224
1352
|
}
|
|
1225
1353
|
|
|
1226
1354
|
/// The layout direction this view is in. The hybrid sets
|
|
@@ -1297,10 +1425,10 @@ final class NitroNumberView: UIView {
|
|
|
1297
1425
|
let count = Int(engine.settledPowerCount())
|
|
1298
1426
|
settledWheels.removeAll(keepingCapacity: true)
|
|
1299
1427
|
for _ in 0..<count {
|
|
1300
|
-
settledWheels.append(Engine.Wheel(position: 0, width: 1, linear: false, blankZero: false, fromGlyph: -1, toGlyph: -1, blend: 1, fromAbove: true, focus: 1, grow: 1, blurOut: 1, flash: 0, flashUp: true))
|
|
1428
|
+
settledWheels.append(Engine.Wheel(position: 0, width: 1, linear: false, blankZero: false, fromGlyph: -1, toGlyph: -1, blend: 1, fromAbove: true, focus: 1, grow: 1, blurOut: 1, flash: 0, flashUp: true, progress: 1))
|
|
1301
1429
|
}
|
|
1302
1430
|
buildElements(into: &settledBuffer, wheels: settledWheels, signFactor: engine.settledNegative() ? 1 : 0, animated: false)
|
|
1303
|
-
return settledBuffer.reduce(CGFloat(0)) { $0 + $1.
|
|
1431
|
+
return settledBuffer.reduce(CGFloat(0)) { $0 + $1.advance }
|
|
1304
1432
|
}
|
|
1305
1433
|
|
|
1306
1434
|
/// Formats the target the way it is displayed, for VoiceOver.
|
|
@@ -1321,11 +1449,17 @@ final class NitroNumberView: UIView {
|
|
|
1321
1449
|
return (engine.settledNegative() ? "-" : "") + format.prefix + digits + format.suffix
|
|
1322
1450
|
}
|
|
1323
1451
|
|
|
1452
|
+
/// An `accessibilityLabel` the app set, which VoiceOver reads instead of the figure.
|
|
1453
|
+
private var explicitAccessibilityLabel: String?
|
|
1454
|
+
|
|
1324
1455
|
// VoiceOver reads the settled figure when it asks for it, so a value update
|
|
1325
1456
|
// (which can come every frame) formats nothing.
|
|
1326
1457
|
override var accessibilityLabel: String? {
|
|
1327
|
-
get {
|
|
1328
|
-
|
|
1458
|
+
get {
|
|
1459
|
+
if let explicit = explicitAccessibilityLabel, !explicit.isEmpty { return explicit }
|
|
1460
|
+
return engine.hasShownValue() ? accessibleText() : nil
|
|
1461
|
+
}
|
|
1462
|
+
set { explicitAccessibilityLabel = newValue }
|
|
1329
1463
|
}
|
|
1330
1464
|
|
|
1331
1465
|
override var accessibilityValue: String? {
|
|
@@ -1401,7 +1535,7 @@ final class NitroNumberView: UIView {
|
|
|
1401
1535
|
buildElements(into: &elementBuffer, wheels: wheelBuffer, signFactor: engine.signFactor())
|
|
1402
1536
|
let wheels = wheelBuffer
|
|
1403
1537
|
let elements = elementBuffer
|
|
1404
|
-
let total = elements.reduce(CGFloat(0)) { $0 + $1.
|
|
1538
|
+
let total = elements.reduce(CGFloat(0)) { $0 + $1.advance }
|
|
1405
1539
|
updateFontScale(contentWidth: total)
|
|
1406
1540
|
let placement = contentPlacement(total: total, lineHeight: fonts.lineHeight)
|
|
1407
1541
|
|
|
@@ -1421,7 +1555,12 @@ final class NitroNumberView: UIView {
|
|
|
1421
1555
|
// still opening or closing is not cut to its width (the glyph read as a
|
|
1422
1556
|
// sliver of its right edge, a ")" of a 0 rolling past); the glyph
|
|
1423
1557
|
// overhangs, faded (`openingOpacity`). Vertically it is the roll's window.
|
|
1424
|
-
|
|
1558
|
+
var mask = CGRect(x: x + element.width - element.fullWidth, y: 0, width: element.fullWidth, height: fonts.lineHeight)
|
|
1559
|
+
if case .wheel = element.kind {
|
|
1560
|
+
// A digit column is the widest digit wide, centred on the digit's own
|
|
1561
|
+
// cell (with tabular figures the two are the same, right-aligned).
|
|
1562
|
+
mask = CGRect(x: x + element.width - (element.fullWidth + fonts.digitWidth) / 2, y: 0, width: fonts.digitWidth, height: fonts.lineHeight)
|
|
1563
|
+
}
|
|
1425
1564
|
if slot.frame != mask {
|
|
1426
1565
|
slot.layer.frame = mask
|
|
1427
1566
|
slot.overlay?.frame = frame
|
|
@@ -1455,7 +1594,7 @@ final class NitroNumberView: UIView {
|
|
|
1455
1594
|
slots[i].overlay = overlay
|
|
1456
1595
|
slots[i].swap = swap
|
|
1457
1596
|
}
|
|
1458
|
-
layoutSwap(swap, wheel: wheel, fonts: fonts, cellWidth: element.width, tint: tint, flash: CGFloat(wheel.flash))
|
|
1597
|
+
layoutSwap(swap, wheel: wheel, fonts: fonts, cellWidth: element.width, advance: element.fullWidth, tint: tint, flash: CGFloat(wheel.flash))
|
|
1459
1598
|
} else if let swap = slot.swap, !swap.hidden {
|
|
1460
1599
|
for layer in swap.all { layer.isHidden = true }
|
|
1461
1600
|
swap.hidden = true
|
|
@@ -1468,7 +1607,7 @@ final class NitroNumberView: UIView {
|
|
|
1468
1607
|
// Linear strips run from -1 (blank) to 9; a roll can be any real, so wrap it onto 0..<10.
|
|
1469
1608
|
let position = wheel.linear ? wheel.position : Self.wrap10(wheel.position)
|
|
1470
1609
|
let stripFrame = CGRect(
|
|
1471
|
-
x:
|
|
1610
|
+
x: 0,
|
|
1472
1611
|
y: -(position + 1) * fonts.lineHeight,
|
|
1473
1612
|
width: strip.bounds.width,
|
|
1474
1613
|
height: strip.bounds.height
|
|
@@ -1495,7 +1634,7 @@ final class NitroNumberView: UIView {
|
|
|
1495
1634
|
slots[i].textSwap = swap
|
|
1496
1635
|
}
|
|
1497
1636
|
layoutTextSwap(swap, element: element, from: from, to: text, role: role, fonts: fonts)
|
|
1498
|
-
x += element.
|
|
1637
|
+
x += element.advance
|
|
1499
1638
|
continue
|
|
1500
1639
|
}
|
|
1501
1640
|
if slot.layer.isHidden { slot.layer.isHidden = false }
|
|
@@ -1520,7 +1659,7 @@ final class NitroNumberView: UIView {
|
|
|
1520
1659
|
slots[i].innerFrame = imageFrame
|
|
1521
1660
|
}
|
|
1522
1661
|
}
|
|
1523
|
-
x += element.
|
|
1662
|
+
x += element.advance
|
|
1524
1663
|
}
|
|
1525
1664
|
}
|
|
1526
1665
|
|
|
@@ -1545,15 +1684,15 @@ final class NitroNumberView: UIView {
|
|
|
1545
1684
|
/// cross-faded with its blurred image as it goes out of, or comes into,
|
|
1546
1685
|
/// focus. With a change flash on (`tint`), the same two again in the tint
|
|
1547
1686
|
/// at `flash` of their opacity, over them: the ink mixed towards the tint.
|
|
1548
|
-
private func layoutSwap(_ swap: SwapLayers, wheel: Engine.Wheel, fonts: FontSet, cellWidth: CGFloat, tint: UIColor?, flash: CGFloat) {
|
|
1687
|
+
private func layoutSwap(_ swap: SwapLayers, wheel: Engine.Wheel, fonts: FontSet, cellWidth: CGFloat, advance: CGFloat, tint: UIColor?, flash: CGFloat) {
|
|
1549
1688
|
// The position clock overshoots 1 (a spring); only the offsets follow it there.
|
|
1550
1689
|
let b = CGFloat(wheel.blend)
|
|
1551
1690
|
let g = max(0, min(1, CGFloat(wheel.grow)))
|
|
1552
1691
|
let f = max(0, min(1, CGFloat(wheel.focus)))
|
|
1553
1692
|
let d: CGFloat = wheel.fromAbove ? 1 : -1
|
|
1554
1693
|
let offset = fonts.lineHeight * Self.numericOffset
|
|
1555
|
-
// The digit
|
|
1556
|
-
let center = CGPoint(x: cellWidth -
|
|
1694
|
+
// The digit sits right-aligned in its cell (the cell shrinks and grows from the left).
|
|
1695
|
+
let center = CGPoint(x: cellWidth - advance / 2, y: fonts.lineHeight / 2)
|
|
1557
1696
|
let outGlyph = Int(wheel.fromGlyph)
|
|
1558
1697
|
let outCenter = CGPoint(x: center.x, y: center.y + d * offset * b)
|
|
1559
1698
|
let outScale = 1 - (1 - Self.numericScale) * g
|
|
@@ -1796,7 +1935,7 @@ final class NitroNumberView: UIView {
|
|
|
1796
1935
|
buildElements(into: &elementBuffer, wheels: wheelBuffer, signFactor: engine.signFactor())
|
|
1797
1936
|
let wheels = wheelBuffer
|
|
1798
1937
|
let elements = elementBuffer
|
|
1799
|
-
let total = elements.reduce(CGFloat(0)) { $0 + $1.
|
|
1938
|
+
let total = elements.reduce(CGFloat(0)) { $0 + $1.advance }
|
|
1800
1939
|
updateFontScale(contentWidth: total)
|
|
1801
1940
|
let placement = contentPlacement(total: total, lineHeight: fonts.lineHeight)
|
|
1802
1941
|
|
|
@@ -1814,11 +1953,11 @@ final class NitroNumberView: UIView {
|
|
|
1814
1953
|
for element in elements {
|
|
1815
1954
|
switch element.kind {
|
|
1816
1955
|
case .wheel(let index):
|
|
1817
|
-
drawWheel(wheels[index], fonts: fonts, x: x, width: element.width, ctx: ctx)
|
|
1956
|
+
drawWheel(wheels[index], fonts: fonts, x: x, width: element.width, advance: element.fullWidth, ctx: ctx)
|
|
1818
1957
|
case .glyph(let text, let role):
|
|
1819
1958
|
drawGlyph(text, role: role, fonts: fonts, x: x, width: element.width, fullWidth: element.fullWidth, alpha: element.factor, ctx: ctx)
|
|
1820
1959
|
}
|
|
1821
|
-
x += element.
|
|
1960
|
+
x += element.advance
|
|
1822
1961
|
}
|
|
1823
1962
|
if dim > 0 {
|
|
1824
1963
|
drawShimmer(contentWidth: total, dim: dim, ctx: ctx)
|
|
@@ -1865,12 +2004,14 @@ final class NitroNumberView: UIView {
|
|
|
1865
2004
|
ctx.restoreGState()
|
|
1866
2005
|
}
|
|
1867
2006
|
|
|
1868
|
-
private func drawWheel(_ wheel: Engine.Wheel, fonts: FontSet, x: CGFloat, width: CGFloat, ctx: CGContext) {
|
|
2007
|
+
private func drawWheel(_ wheel: Engine.Wheel, fonts: FontSet, x: CGFloat, width: CGFloat, advance: CGFloat, ctx: CGContext) {
|
|
1869
2008
|
guard width > 0 else { return }
|
|
1870
2009
|
let lineHeight = fonts.lineHeight
|
|
2010
|
+
// The digit column, the widest digit wide, centred on the digit's own cell.
|
|
2011
|
+
let columnLeft = x + width - (advance + fonts.digitWidth) / 2
|
|
1871
2012
|
ctx.saveGState()
|
|
1872
2013
|
// The roll's window, the whole digit wide (see `renderLayers`).
|
|
1873
|
-
ctx.clip(to: CGRect(x:
|
|
2014
|
+
ctx.clip(to: CGRect(x: columnLeft, y: 0, width: fonts.digitWidth, height: lineHeight))
|
|
1874
2015
|
ctx.setAlpha(CGFloat(Self.openingOpacity(wheel.width)))
|
|
1875
2016
|
if wheel.blend < 1 || wheel.focus < 1 || wheel.grow < 1 {
|
|
1876
2017
|
// The numeric transition under the glint: the pair, without the blur.
|
|
@@ -1878,7 +2019,7 @@ final class NitroNumberView: UIView {
|
|
|
1878
2019
|
let g = max(0, min(1, CGFloat(wheel.grow)))
|
|
1879
2020
|
let d: CGFloat = wheel.fromAbove ? 1 : -1
|
|
1880
2021
|
let offset = lineHeight * Self.numericOffset
|
|
1881
|
-
let cx =
|
|
2022
|
+
let cx = columnLeft + fonts.digitWidth / 2
|
|
1882
2023
|
let pair: [(glyph: Int, dy: CGFloat, scale: CGFloat, alpha: CGFloat)] = [
|
|
1883
2024
|
(Int(wheel.fromGlyph), d * offset * b, 1 - (1 - Self.numericScale) * g, 1 - g),
|
|
1884
2025
|
(Int(wheel.toGlyph), -d * offset * (1 - b), Self.numericScale + (1 - Self.numericScale) * g, g),
|
|
@@ -1898,7 +2039,6 @@ final class NitroNumberView: UIView {
|
|
|
1898
2039
|
let base = wheel.position.rounded(.down)
|
|
1899
2040
|
let fraction = CGFloat(wheel.position - base)
|
|
1900
2041
|
let index = Int(base)
|
|
1901
|
-
let columnLeft = x + width - fonts.digitWidth
|
|
1902
2042
|
if let text = digitText(at: index, in: wheel), let image = fonts.image(text, role: .digit) {
|
|
1903
2043
|
image.draw(at: CGPoint(x: columnLeft + (fonts.digitWidth - fonts.width(of: text, role: .digit)) / 2, y: -fraction * lineHeight))
|
|
1904
2044
|
}
|
|
@@ -34,6 +34,11 @@
|
|
|
34
34
|
"signPlacement": true,
|
|
35
35
|
"prefixAlign": true,
|
|
36
36
|
"suffixAlign": true,
|
|
37
|
+
"letterSpacing": true,
|
|
38
|
+
"prefixSpacing": true,
|
|
39
|
+
"suffixSpacing": true,
|
|
40
|
+
"prefixOffset": true,
|
|
41
|
+
"suffixOffset": true,
|
|
37
42
|
"placeholder": true,
|
|
38
43
|
"placeholderColor": true,
|
|
39
44
|
"duration": true,
|
|
@@ -38,6 +38,12 @@
|
|
|
38
38
|
"affixAlign": true,
|
|
39
39
|
"prefixAlign": true,
|
|
40
40
|
"suffixAlign": true,
|
|
41
|
+
"letterSpacing": true,
|
|
42
|
+
"prefixSpacing": true,
|
|
43
|
+
"suffixSpacing": true,
|
|
44
|
+
"prefixOffset": true,
|
|
45
|
+
"suffixOffset": true,
|
|
46
|
+
"tabularNums": true,
|
|
41
47
|
"adjustsFontSizeToFit": true,
|
|
42
48
|
"minimumFontScale": true,
|
|
43
49
|
"allowFontScaling": true,
|
|
@@ -43,6 +43,7 @@ const react_native_nitro_modules_1 = require("react-native-nitro-modules");
|
|
|
43
43
|
const NitroInputViewConfig_json_1 = __importDefault(require("../nitrogen/generated/shared/json/NitroInputViewConfig.json"));
|
|
44
44
|
const worklets_1 = require("./worklets");
|
|
45
45
|
const styleHelpers_1 = require("./styleHelpers");
|
|
46
|
+
const formatProps_1 = require("./formatProps");
|
|
46
47
|
const textInputRegistry = (() => {
|
|
47
48
|
try {
|
|
48
49
|
// The registry has no public surface: `TextInput.State` exposes the focus
|
|
@@ -175,7 +176,7 @@ function warnIncompatible(what) {
|
|
|
175
176
|
* Like a `TextInput`, it takes its width from its parent; `autoWidth` sizes
|
|
176
177
|
* it to its content instead, and is on by default when the text reflows.
|
|
177
178
|
*/
|
|
178
|
-
exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, placeholder, placeholderTextColor, duration, easing, bounce, effect, fontSize, lineHeight, fontWeight, fontFamily, color, textAlign, cursorColor, selectionColor, caretHidden, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, variant, label, labelBehavior, labelColor, labelFocusedColor, labelFontSize, strokeColor, focusedStrokeColor, strokeWidth, cornerRadius, fillColor, keyboardType, inputMode, enterKeyHint, mask, maskNotations, maskAutocomplete, maskAutoSkip, returnKeyType, autoCapitalize, autoCorrect, editable, multiline, numberOfLines, rows, textAlignVertical, scrollEnabled, autoFocus, transition, autoWidth: autoWidthProp, submitBehavior, blurOnSubmit, secureTextEntry, keyboardAppearance, textContentType, autoComplete, enablesReturnKeyAutomatically, showSoftInputOnFocus, selectTextOnFocus, clearTextOnFocus, contextMenuHidden, spellCheck, readOnly, selection, onEndEditing, onSelectionChange, onKeyPress, maxLength, transform, onChangeText, onChange, onChangeValue, onChangeMask, onFocus, onBlur, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
|
|
179
|
+
exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaultValue, mode, fractionDigits, maxIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, prefixFontSize, suffixFontSize, affixAlign, signPlacement, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, format, placeholder, placeholderTextColor, duration, easing, bounce, effect, fontSize, lineHeight, fontWeight, fontFamily, color, textAlign, cursorColor, selectionColor, caretHidden, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, variant, label, labelBehavior, labelColor, labelFocusedColor, labelFontSize, strokeColor, focusedStrokeColor, strokeWidth, cornerRadius, fillColor, keyboardType, inputMode, enterKeyHint, mask, maskNotations, maskAutocomplete, maskAutoSkip, returnKeyType, autoCapitalize, autoCorrect, editable, multiline, numberOfLines, rows, textAlignVertical, scrollEnabled, autoFocus, transition, autoWidth: autoWidthProp, submitBehavior, blurOnSubmit, secureTextEntry, keyboardAppearance, textContentType, autoComplete, enablesReturnKeyAutomatically, showSoftInputOnFocus, selectTextOnFocus, clearTextOnFocus, contextMenuHidden, spellCheck, readOnly, selection, onEndEditing, onSelectionChange, onKeyPress, maxLength, transform, onChangeText, onChange, onChangeValue, onChangeMask, onFocus, onBlur, onSubmitEditing, onNativeRef, style, ...viewProps }, ref) {
|
|
179
180
|
const nativeRef = (0, react_1.useRef)(null);
|
|
180
181
|
// What React Native's registry stores for this field. The React host
|
|
181
182
|
// instance when there is one (iOS), otherwise a stable per-instance token:
|
|
@@ -467,13 +468,14 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
|
|
|
467
468
|
if (suffix)
|
|
468
469
|
warnIncompatible('suffix');
|
|
469
470
|
}
|
|
470
|
-
const
|
|
471
|
+
const derived = format ? (0, formatProps_1.formatProps)(format) : undefined;
|
|
472
|
+
const resolvedMode = isMultiline ? 'text' : (mode ?? (derived ? 'number' : 'text'));
|
|
471
473
|
const reflows = !isMultiline && transition === 'reflow';
|
|
472
474
|
// The affixes are accessory views beside one line of text; a wrapping text
|
|
473
475
|
// view has no slot for them, so they go with the mode rather than being
|
|
474
476
|
// half-drawn on one platform and not the other.
|
|
475
|
-
const resolvedPrefix = isMultiline ? '' : (prefix ?? '');
|
|
476
|
-
const resolvedSuffix = isMultiline ? '' : (suffix ?? '');
|
|
477
|
+
const resolvedPrefix = isMultiline ? '' : (prefix ?? derived?.prefix ?? '');
|
|
478
|
+
const resolvedSuffix = isMultiline ? '' : (suffix ?? derived?.suffix ?? '');
|
|
477
479
|
// A new `maskNotations` literal each render must not re-set the native
|
|
478
480
|
// prop, so it is keyed on its contents. Always an array (empty = none):
|
|
479
481
|
// removing the prop would reach native as `null`, which Nitro's array
|
|
@@ -482,7 +484,7 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
|
|
|
482
484
|
const stableNotations = (0, react_1.useMemo)(() => (notationsKey !== '' && maskNotations ? [...maskNotations] : EMPTY_NOTATIONS),
|
|
483
485
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
484
486
|
[notationsKey]);
|
|
485
|
-
const resolvedFractionDigits = fractionDigits ?? 2;
|
|
487
|
+
const resolvedFractionDigits = fractionDigits ?? derived?.fractionDigits ?? 2;
|
|
486
488
|
const resolvedKeyboardType = keyboardType ??
|
|
487
489
|
(inputMode != null
|
|
488
490
|
? INPUT_MODE_TO_KEYBOARD[inputMode]
|
|
@@ -544,7 +546,7 @@ exports.NitroInput = (0, react_1.forwardRef)(function NitroInput({ value, defaul
|
|
|
544
546
|
? { width: size.width, height: size.height }
|
|
545
547
|
: { height: size.height }
|
|
546
548
|
: { height: resolvedFontSize * 1.25 }, [size, resolvedFontSize, autoWidth]);
|
|
547
|
-
return (react_1.default.createElement(exports.NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? initialText, mostRecentEventCount: eventCountRef.current, mode: resolvedMode, plain: !reflows, fractionDigits: resolvedFractionDigits, maxIntegerDigits: maxIntegerDigits ?? 15, groupingSeparator: groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, placeholder: placeholder ?? '', placeholderColor: processedPlaceholderColor, duration: duration ?? 400, easing: easing ?? 'expo', bounce: bounce ?? 0.15, effect: effect ?? 'auto', fontSize: resolvedFontSize, lineHeight: Math.max(0, lineHeight ?? 0), fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, caretColor: processedCursorColor, selectionColor: processedSelectionColor, caretHidden: caretHidden ?? false, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, variant: variant ?? 'none', label: label ?? '', labelBehavior: labelBehavior ?? 'float', labelColor: processedLabelColor, labelFocusedColor: processedLabelFocusedColor, labelFontSize: labelFontSize ?? 0, strokeColor: processedStrokeColor, focusedStrokeColor: processedFocusedStrokeColor, strokeWidth: strokeWidth ?? 1, cornerRadius: cornerRadius ?? 8, fillColor: processedFillColor, mask: resolvedMode === 'mask' ? (mask ?? '') : '', maskNotations: stableNotations, maskAutocomplete: maskAutocomplete ?? true, maskAutoSkip: maskAutoSkip ?? false, onChangeMask: onChangeMaskCallback, keyboardType: resolvedKeyboardType, returnKeyType: resolvedReturnKeyType, autoCapitalize: autoCapitalize ?? 'sentences', autoCorrect: autoCorrect ?? true, editable: (editable ?? true) && !(readOnly ?? false), multiline: isMultiline, numberOfLines: Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0)), textAlignVertical: textAlignVertical ?? 'auto', scrollEnabled: scrollEnabled ?? true, autoFocus: autoFocus ?? false, fieldTestID: viewProps.testID ?? '', fieldAccessibilityLabel: resolvedAccessibilityLabel ?? '', submitBehavior: submitBehavior ??
|
|
549
|
+
return (react_1.default.createElement(exports.NativeNitroInputView, { ...hostViewProps, ref: hostRef, style: [autoSize, style], hybridRef: hybridRef, text: value ?? initialText, mostRecentEventCount: eventCountRef.current, mode: resolvedMode, plain: !reflows, fractionDigits: resolvedFractionDigits, maxIntegerDigits: maxIntegerDigits ?? 15, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? ',', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: resolvedPrefix, suffix: resolvedSuffix, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, signPlacement: signPlacement ?? derived?.signPlacement ?? 'beforeAffix', prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, placeholder: placeholder ?? '', placeholderColor: processedPlaceholderColor, duration: duration ?? 400, easing: easing ?? 'expo', bounce: bounce ?? 0.15, effect: effect ?? 'auto', fontSize: resolvedFontSize, lineHeight: Math.max(0, lineHeight ?? 0), fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, caretColor: processedCursorColor, selectionColor: processedSelectionColor, caretHidden: caretHidden ?? false, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, variant: variant ?? 'none', label: label ?? '', labelBehavior: labelBehavior ?? 'float', labelColor: processedLabelColor, labelFocusedColor: processedLabelFocusedColor, labelFontSize: labelFontSize ?? 0, strokeColor: processedStrokeColor, focusedStrokeColor: processedFocusedStrokeColor, strokeWidth: strokeWidth ?? 1, cornerRadius: cornerRadius ?? 8, fillColor: processedFillColor, mask: resolvedMode === 'mask' ? (mask ?? '') : '', maskNotations: stableNotations, maskAutocomplete: maskAutocomplete ?? true, maskAutoSkip: maskAutoSkip ?? false, onChangeMask: onChangeMaskCallback, keyboardType: resolvedKeyboardType, returnKeyType: resolvedReturnKeyType, autoCapitalize: autoCapitalize ?? 'sentences', autoCorrect: autoCorrect ?? true, editable: (editable ?? true) && !(readOnly ?? false), multiline: isMultiline, numberOfLines: Math.max(0, Math.trunc(numberOfLines ?? rows ?? 0)), textAlignVertical: textAlignVertical ?? 'auto', scrollEnabled: scrollEnabled ?? true, autoFocus: autoFocus ?? false, fieldTestID: viewProps.testID ?? '', fieldAccessibilityLabel: resolvedAccessibilityLabel ?? '', submitBehavior: submitBehavior ??
|
|
548
550
|
// As `TextInput` resolves the legacy `blurOnSubmit`: a multiline
|
|
549
551
|
// field's return key inserts a line break unless told to blur.
|
|
550
552
|
(multiline
|
|
@@ -42,6 +42,7 @@ const react_native_1 = require("react-native");
|
|
|
42
42
|
const react_native_nitro_modules_1 = require("react-native-nitro-modules");
|
|
43
43
|
const NitroNumberViewConfig_json_1 = __importDefault(require("../nitrogen/generated/shared/json/NitroNumberViewConfig.json"));
|
|
44
44
|
const styleHelpers_1 = require("./styleHelpers");
|
|
45
|
+
const formatProps_1 = require("./formatProps");
|
|
45
46
|
/**
|
|
46
47
|
* The raw Nitro host component. Prefer {@link NitroNumber}, which adds
|
|
47
48
|
* auto-sizing, color/weight conversion and a convenient handle.
|
|
@@ -63,7 +64,7 @@ const TRANSITION_DEFAULTS = {
|
|
|
63
64
|
* The view sizes itself to its content unless you pass an explicit `width` /
|
|
64
65
|
* `height` in `style`.
|
|
65
66
|
*/
|
|
66
|
-
exports.NitroNumber = (0, react_1.forwardRef)(function NitroNumber({ value, fractionDigits, minimumIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, transition, flashUpColor, flashDownColor, flashDuration, popOnChange, duration, easing, bounce, stagger, direction, reveal, revealStyle, revealDuration, revealBounce, revealGrow, revealStagger, revealMilestones, revealMilestoneHold, onRevealEnd, onRevealMilestone, loading, shimmerColor, shimmerDuration, fontSize, prefixFontSize, suffixFontSize, affixAlign, prefixAlign, suffixAlign, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, fontWeight, fontFamily, color, textAlign, onNativeRef, style, ...viewProps }, ref) {
|
|
67
|
+
exports.NitroNumber = (0, react_1.forwardRef)(function NitroNumber({ value, fractionDigits, minimumIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, transition, flashUpColor, flashDownColor, flashDuration, popOnChange, duration, easing, bounce, stagger, direction, reveal, revealStyle, revealDuration, revealBounce, revealGrow, revealStagger, revealMilestones, revealMilestoneHold, onRevealEnd, onRevealMilestone, loading, shimmerColor, shimmerDuration, fontSize, prefixFontSize, suffixFontSize, affixAlign, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, tabularNums, format, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, fontWeight, fontFamily, color, textAlign, onNativeRef, style, ...viewProps }, ref) {
|
|
67
68
|
const nativeRef = (0, react_1.useRef)(null);
|
|
68
69
|
const latestOnNativeRef = (0, react_1.useRef)(onNativeRef);
|
|
69
70
|
latestOnNativeRef.current = onNativeRef;
|
|
@@ -127,6 +128,7 @@ exports.NitroNumber = (0, react_1.forwardRef)(function NitroNumber({ value, frac
|
|
|
127
128
|
const numericWeight = (0, styleHelpers_1.toNumericWeight)(fontWeight) ?? 400;
|
|
128
129
|
const resolvedFontSize = fontSize ?? 32;
|
|
129
130
|
const resolvedAffixAlign = affixAlign ?? 'baseline';
|
|
131
|
+
const derived = format ? (0, formatProps_1.formatProps)(format) : undefined;
|
|
130
132
|
const autoSize = (0, react_1.useMemo)(() => size !== null
|
|
131
133
|
? { width: size.width, height: size.height }
|
|
132
134
|
: { height: (fontSize ?? 32) * 1.25 }, [size, fontSize]);
|
|
@@ -135,5 +137,5 @@ exports.NitroNumber = (0, react_1.forwardRef)(function NitroNumber({ value, frac
|
|
|
135
137
|
// does not hand a Hybrid View its resolved direction, so native is told.
|
|
136
138
|
const layoutDirection = (0, react_1.useMemo)(() => react_native_1.StyleSheet.flatten(style)?.direction, [style]);
|
|
137
139
|
const rightToLeft = layoutDirection === 'rtl' || (layoutDirection !== 'ltr' && react_native_1.I18nManager.isRTL);
|
|
138
|
-
return (react_1.default.createElement(exports.NativeNitroNumberView, { ...viewProps, style: [autoSize, style], hybridRef: hybridRef, value: value, fractionDigits: fractionDigits ?? 0, minimumIntegerDigits: minimumIntegerDigits ?? 1, groupingSeparator: groupingSeparator ?? '', decimalSeparator: decimalSeparator ?? '.', prefix: prefix ?? '', suffix: suffix ?? '', transition: transition ?? 'roll', flashUpColor: processedFlashUp, flashDownColor: processedFlashDown, flashDuration: flashDuration ?? 600, popOnChange: popOnChange ?? 0, duration: duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration, easing: easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing, bounce: bounce ?? 0.15, stagger: stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger, rollDirection: direction ?? 'auto', revealState: reveal === undefined ? 0 : reveal ? 2 : 1, revealStyle: revealStyle ?? 'count', revealDuration: revealDuration ?? 2200, revealBounce: revealBounce ?? 0.12, revealGrow: revealGrow ?? 0.2, revealStagger: revealStagger ?? 200, revealMilestones: stableMilestones, revealMilestoneHold: revealMilestoneHold ?? 0, onRevealEnd: onRevealEndCallback, onRevealMilestone: onRevealMilestoneCallback, loading: loading ?? false, shimmerColor: processedShimmerColor, shimmerDuration: shimmerDuration ?? 950, fontSize: resolvedFontSize, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, affixAlign: resolvedAffixAlign, prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, onSizeChange: onSizeChange }));
|
|
140
|
+
return (react_1.default.createElement(exports.NativeNitroNumberView, { ...viewProps, style: [autoSize, style], hybridRef: hybridRef, value: value, fractionDigits: fractionDigits ?? derived?.fractionDigits ?? 0, minimumIntegerDigits: minimumIntegerDigits ?? derived?.minimumIntegerDigits ?? 1, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? '', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: prefix ?? derived?.prefix ?? '', suffix: suffix ?? derived?.suffix ?? '', transition: transition ?? 'roll', flashUpColor: processedFlashUp, flashDownColor: processedFlashDown, flashDuration: flashDuration ?? 600, popOnChange: popOnChange ?? 0, duration: duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration, easing: easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing, bounce: bounce ?? 0.15, stagger: stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger, rollDirection: direction ?? 'auto', revealState: reveal === undefined ? 0 : reveal ? 2 : 1, revealStyle: revealStyle ?? 'count', revealDuration: revealDuration ?? 2200, revealBounce: revealBounce ?? 0.12, revealGrow: revealGrow ?? 0.2, revealStagger: revealStagger ?? 200, revealMilestones: stableMilestones, revealMilestoneHold: revealMilestoneHold ?? 0, onRevealEnd: onRevealEndCallback, onRevealMilestone: onRevealMilestoneCallback, loading: loading ?? false, shimmerColor: processedShimmerColor, shimmerDuration: shimmerDuration ?? 950, fontSize: resolvedFontSize, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, affixAlign: resolvedAffixAlign, prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, tabularNums: tabularNums ?? true, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, onSizeChange: onSizeChange }));
|
|
139
141
|
});
|