@onekeyfe/react-native-native-list 6.8.0-14 → 6.8.0-16

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.
Files changed (45) hide show
  1. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +18 -4
  2. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +21 -7
  3. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +3 -2
  4. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +8 -1
  5. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +24 -3
  6. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +11 -4
  7. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +84 -9
  8. package/android/src/main/res/values/native_scroll_coordinator_ids.xml +1 -0
  9. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +2 -0
  10. package/docs/SPEC.md +113 -2
  11. package/docs/STYLE_SPEC.md +7 -1
  12. package/ios/NativeListAccessoryStack.swift +22 -0
  13. package/ios/NativeListDataRowRenderer.swift +12 -5
  14. package/ios/NativeListIdentityRenderer.swift +36 -58
  15. package/ios/NativeListLeadingVisual.swift +8 -0
  16. package/ios/NativeListMarketRenderer.swift +6 -2
  17. package/ios/NativeListModels.swift +7 -0
  18. package/ios/NativeListResolvedText.swift +9 -7
  19. package/ios/NativeListSectionHeaderRenderer.swift +9 -43
  20. package/ios/NativeListTextStyles.swift +72 -12
  21. package/ios/RNCNativeListView.swift +124 -20
  22. package/ios/tests/NativeListLifecycleTests.swift +105 -0
  23. package/lib/module/validation.js +21 -10
  24. package/lib/module/web/NativeListWebEngine.js +213 -23
  25. package/lib/module/web/templates/ActivityRowRenderer.js +1 -1
  26. package/lib/module/web/templates/IdentityRowRenderer.js +12 -1
  27. package/lib/module/web/templates/MarketRowRenderer.js +2 -0
  28. package/lib/module/web/templates/MediaTileRowRenderer.js +1 -0
  29. package/lib/module/web/templates/RowElements.js +2 -2
  30. package/lib/module/web/templates/RowText.js +2 -0
  31. package/lib/typescript/src/models.d.ts +15 -1
  32. package/lib/typescript/src/web/NativeListWebEngine.d.ts +8 -1
  33. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +6 -2
  34. package/lib/typescript/src/web/templates/RowVisual.d.ts +1 -1
  35. package/package.json +1 -1
  36. package/src/models.ts +15 -0
  37. package/src/validation.ts +67 -4
  38. package/src/web/NativeListWebEngine.ts +382 -27
  39. package/src/web/templates/ActivityRowRenderer.ts +1 -1
  40. package/src/web/templates/IdentityRowRenderer.ts +23 -1
  41. package/src/web/templates/MarketRowRenderer.ts +2 -0
  42. package/src/web/templates/MediaTileRowRenderer.ts +1 -0
  43. package/src/web/templates/RowElements.ts +3 -2
  44. package/src/web/templates/RowText.ts +6 -0
  45. package/src/web/templates/RowVisual.ts +2 -1
@@ -7,6 +7,8 @@ final class NativeListAccessoryButton: NativeListIconButton {
7
7
  var fixedTextLineHeight: CGFloat?
8
8
  var rowTextOffsetY: CGFloat = 0
9
9
  var helpBindingGeneration = 0
10
+ /// Marks the trailing `drag` accessory that can start a handle-only reorder.
11
+ var isReorderHandle = false
10
12
  private var helpTrackingGeneration = 0
11
13
  override func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
12
14
  helpTrackingGeneration = helpBindingGeneration
@@ -278,6 +280,14 @@ final class NativeListAccessoryStack: UIStackView {
278
280
  }
279
281
  isHidden = arrangedSubviews.allSatisfy { $0.isHidden }
280
282
  }
283
+ func explicitTextStyle(for view: UIView, style: [String: Any]) -> [String: Any]? {
284
+ switch semanticValueButtons.firstIndex(where: { $0 === view }) {
285
+ case 0: return style.dictionary("value")
286
+ case 1: return style.dictionary("valueSecondary")
287
+ default: return nil
288
+ }
289
+ }
290
+
281
291
  func updateSelection(
282
292
  _ item: NativeListItem,
283
293
  checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
@@ -339,6 +349,7 @@ final class NativeListAccessoryStack: UIStackView {
339
349
  button.isHidden = true
340
350
  button.isEnabled = true
341
351
  button.isUserInteractionEnabled = true
352
+ button.isReorderHandle = false
342
353
  button.alpha = 1
343
354
  button.accessibilityIdentifier = nil
344
355
  button.accessibilityLabel = nil
@@ -440,10 +451,15 @@ final class NativeListAccessoryStack: UIStackView {
440
451
  case "drag":
441
452
  var icon = accessory
442
453
  icon["name"] = "DragOutline"
454
+ // ListItem draws the handle as a medium tertiary IconButton (38-point frame).
455
+ icon["buttonStyle"] = "tertiary"
443
456
  if icon["tintColor"] == nil {
444
457
  icon["tintColor"] = theme?["iconSubdued"] as? String ?? "#8D8D8D"
445
458
  }
446
459
  showAccessoryIcon(textIndex, icon)
460
+ if accessoryButtons.indices.contains(textIndex) {
461
+ accessoryButtons[textIndex].isReorderHandle = true
462
+ }
447
463
  textIndex += 1
448
464
  case "icon":
449
465
  var icon = accessory
@@ -690,6 +706,8 @@ final class NativeListAccessoryStack: UIStackView {
690
706
  button.layer.cornerRadius = size / 2
691
707
  }
692
708
  if isAccountIcon { contentGap = 5 }
709
+ // A leading tertiary button's m=-7 also pulls the text column 7 points closer.
710
+ if isTertiary && index == 0 && contentGap == nil { contentGap = 5 }
693
711
  button.accessibilityIdentifier = data["testID"] as? String
694
712
  button.accessibilityLabel = data["accessibilityLabel"] as? String
695
713
  if !isDrillIn, !data.string("actionKey").isEmpty {
@@ -789,6 +807,7 @@ final class NativeListAccessoryStack: UIStackView {
789
807
  var attributes: [NSAttributedString.Key: Any] = [:]
790
808
  applyStyledFont(attributed, style, fallback: baseFont)
791
809
  if style["color"] != nil { attributes[.foregroundColor] = color }
810
+ if style["letterSpacing"] != nil { attributes[.kern] = CGFloat(style.double("letterSpacing")) }
792
811
  if style["alignment"] != nil || style["lineHeight"] != nil || style["lines"] != nil
793
812
  || style["truncate"] != nil
794
813
  {
@@ -833,6 +852,9 @@ final class NativeListAccessoryStack: UIStackView {
833
852
  range: range)
834
853
  }
835
854
  }
855
+ if let tabular = style["tabularNumbers"] as? Bool {
856
+ NativeListTextStyles.applyDigitSpacing(attributed, tabular: tabular, fallback: font)
857
+ }
836
858
  button.setAttributedTitle(attributed, for: .normal)
837
859
  }
838
860
 
@@ -397,13 +397,13 @@ private final class NativeListTableColumnView: UIStackView {
397
397
  let primaryStyle = style.dictionary("columns") ?? [:]
398
398
  let secondaryStyle = style.dictionary("columnSecondary") ?? [:]
399
399
  func font(_ textStyle: [String: Any], size: CGFloat, weight: NativeListFontWeight) -> UIFont {
400
- guard textStyle["fontSize"] != nil || textStyle["fontWeight"] != nil else {
401
- return nativeListFont(ofSize: size, weight: weight, fonts: fonts)
402
- }
403
- return nativeListFont(
400
+ let baseFont = nativeListFont(
404
401
  ofSize: CGFloat(textStyle.double("fontSize", default: Double(size))),
405
402
  weight: NativeListTextStyles.marketFontWeight(
406
403
  textStyle.string("fontWeight"), fallback: weight), fonts: fonts)
404
+ return (textStyle["tabularNumbers"] as? Bool).map {
405
+ NativeListTextStyles.digitSpacingFont(baseFont, tabular: $0)
406
+ } ?? baseFont
407
407
  }
408
408
  func color(_ textStyle: [String: Any], _ fallback: UIColor) -> UIColor {
409
409
  (textStyle["color"] as? String).map { UIColor(nativeListHex: $0, fallback: fallback) }
@@ -443,6 +443,10 @@ private final class NativeListTableColumnView: UIStackView {
443
443
  .font: primaryFont,
444
444
  .foregroundColor: color(primaryStyle, textColor(column.string("tone"), theme: theme)),
445
445
  ])
446
+ if primaryStyle["letterSpacing"] != nil {
447
+ attributed.addAttribute(.kern, value: CGFloat(primaryStyle.double("letterSpacing")),
448
+ range: NSRange(location: 0, length: attributed.length))
449
+ }
446
450
  attributed.setAttributedString(nativeListDataSegments(attributed, column.dictionaries("textSegments")))
447
451
  let primaryLength = attributed.length
448
452
  // Every badge run is the legacy " text " pill: both lead spaces sit inside the badge
@@ -451,7 +455,7 @@ private final class NativeListTableColumnView: UIStackView {
451
455
  // rows add no kern and stay byte-identical to legacy.
452
456
  if style["titleBadgeGap"] != nil, !badges.isEmpty, primaryLength > 0 {
453
457
  attributed.addAttribute(
454
- .kern, value: CGFloat(style.double("titleBadgeGap")),
458
+ .kern, value: CGFloat(style.double("titleBadgeGap") + primaryStyle.double("letterSpacing")),
455
459
  range: (attributed.string as NSString).rangeOfComposedCharacterSequence(
456
460
  at: primaryLength - 1))
457
461
  }
@@ -482,6 +486,9 @@ private final class NativeListTableColumnView: UIStackView {
482
486
  secondaryStyle,
483
487
  textColor(column.string("secondaryTone", default: "secondary"), theme: theme)),
484
488
  ]
489
+ if secondaryStyle["letterSpacing"] != nil {
490
+ attributes[.kern] = CGFloat(secondaryStyle.double("letterSpacing"))
491
+ }
485
492
  attributes.merge(paragraph(secondaryStyle, font: secondaryFont, spacing: nil)) { $1 }
486
493
  attributed.append(NSAttributedString(string: "\n", attributes: attributes))
487
494
  attributed.append(nativeListDataSegments(
@@ -40,8 +40,9 @@ final class NativeListIdentityCell: NativeListRendererCell {
40
40
  } else if descriptors.count == 2,
41
41
  descriptors[0].string("kind") == "icon",
42
42
  descriptors[0].string("name") == "PencilOutline",
43
- descriptors[1].string("kind") == "icon",
44
- descriptors[1].string("name") == "DragOutline"
43
+ (descriptors[1].string("kind") == "icon"
44
+ && descriptors[1].string("name") == "DragOutline")
45
+ || descriptors[1].string("kind") == "drag"
45
46
  {
46
47
  stack.axis = .horizontal
47
48
  stack.alignment = .center
@@ -49,6 +50,10 @@ final class NativeListIdentityCell: NativeListRendererCell {
49
50
  stack.spacing = 10
50
51
  }
51
52
  }
53
+ private static func collapsesTrailing(_ item: NativeListItem, descriptors: [[String: Any]]) -> Bool {
54
+ descriptors.isEmpty && item.data.bool("collapseEmptyTrailing")
55
+ }
56
+
52
57
  override class func measure(
53
58
  _ item: NativeListItem, width: CGFloat, theme: [String: Any]?, layout: String,
54
59
  fonts: NativeListFontFamilies
@@ -70,11 +75,12 @@ final class NativeListIdentityCell: NativeListRendererCell {
70
75
  trailing.bind(
71
76
  item, descriptors: accessories, theme: theme, style: style,
72
77
  defaultSpacing: trailing.spacing, checkboxState: { _, _, fallback in fallback }, fonts: fonts)
73
- trailing.isHidden = false
74
- let trailingSize = trailing.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
78
+ let collapsed = collapsesTrailing(item, descriptors: accessories)
79
+ let trailingSize = collapsed ? .zero
80
+ : trailing.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
75
81
  let rightInset = style["horizontalPadding"] != nil
76
82
  ? horizontalPadding : trailing.endInset ?? horizontalPadding
77
- let contentGap = trailing.contentGap ?? 12
83
+ let contentGap = collapsed ? 0 : trailing.contentGap ?? 12
78
84
  let textWidth = max(1,
79
85
  width - horizontalPadding - rightInset - imageWidth - leadingGap
80
86
  - trailingSize.width - contentGap)
@@ -286,10 +292,11 @@ final class NativeListIdentityCell: NativeListRendererCell {
286
292
  leadingWidth.constant = 40
287
293
  leadingHeight.constant = 40
288
294
  visual.glyphSize = 18
295
+ let leadingDescriptor = item.data.dictionary("leading")
289
296
  visual.bitmapBorderWidth =
290
- item.data.dictionary("leading")?.string("borderColor").isEmpty == false
291
- && item.data.dictionary("leading")?.string("borderStyle") != "dashed"
292
- ? 1 : 0
297
+ leadingDescriptor?.string("borderColor").isEmpty == false
298
+ && leadingDescriptor?.string("borderStyle") != "dashed"
299
+ ? nativeListBorderWidth(leadingDescriptor?["borderWidth"]) : 0
293
300
  fallbackLabel.attributedText = nil
294
301
  fallbackLabel.font = nativeListFont(ofSize: 13, weight: .bold, fonts: fonts)
295
302
  trailingStack.reset()
@@ -623,13 +630,13 @@ final class NativeListIdentityCell: NativeListRendererCell {
623
630
  leadingActionButton.alpha = leadingActionButton.isEnabled ? 1 : 0.4
624
631
  leadingActionKey = leadingAction.string("actionKey")
625
632
  root.addArrangedSubview(leadingActionButton)
626
- // ListItem.IconButton is a medium tertiary button: its 36-point frame
627
- // carries m=-7. The collection already contributes ListItem's outer
628
- // mx=8, so move the frame 7 points into that inset and reduce only the
629
- // following gap by 7. This preserves the source button, avatar and text
630
- // positions without shrinking the 24-point SVG glyph or its hit target.
631
- leftInset = 5
632
- root.setCustomSpacing(5, after: leadingActionButton)
633
+ // ListItem.IconButton is a medium tertiary button: p=6 plus a 1-point
634
+ // border makes a 38-point frame with m=-7, so its glyph sits exactly on
635
+ // a 24-point slot at the 12-point padding and the avatar starts at 48.
636
+ // This 36-point frame centers the same glyph with a 6-point inset and
637
+ // 6-point following gap, keeping the 24-point SVG and its hit target.
638
+ leftInset = 6
639
+ root.setCustomSpacing(6, after: leadingActionButton)
633
640
  }
634
641
  addLeading(item.data.dictionary("leading"), key: item.key)
635
642
  // OneKey patch: custom network initials match LetterAvatar size 32.
@@ -796,7 +803,7 @@ final class NativeListIdentityCell: NativeListRendererCell {
796
803
  defaultSpacing: trailingStack.spacing, checkboxState: checkboxState, fonts: fonts)
797
804
  // Legacy kept the (possibly empty) trailing stack arranged, so the text column always
798
805
  // ends 12 points before the trailing edge inset.
799
- trailingStack.isHidden = false
806
+ trailingStack.isHidden = Self.collapsesTrailing(item, descriptors: accessories)
800
807
  if let gap = trailingStack.contentGap { root.setCustomSpacing(gap, after: mainStack) }
801
808
  if let inset = trailingStack.endInset { rightInset = -inset }
802
809
  if accessories.count == 1,
@@ -829,51 +836,22 @@ final class NativeListIdentityCell: NativeListRendererCell {
829
836
  default: return nativeListColor(theme, "primaryText", "#202020")
830
837
  }
831
838
  }
832
- private func selectorTabularFont(_ font: UIFont) -> UIFont {
833
- var settings =
834
- font.fontDescriptor.fontAttributes[.featureSettings] as? [[UIFontDescriptor.FeatureKey: Int]]
835
- ?? []
836
- settings.removeAll { $0[.type] == kNumberSpacingType }
837
- settings.append([.type: kNumberSpacingType, .selector: kMonospacedNumbersSelector])
838
- return UIFont(
839
- descriptor: font.fontDescriptor.addingAttributes([.featureSettings: settings]),
840
- size: font.pointSize)
841
- }
842
- private func selectorTabularText(_ original: NSAttributedString) -> NSAttributedString {
843
- let result = NSMutableAttributedString(attributedString: original)
844
- // OneKey patch: body typography explicitly supplies letterSpacing=0 in Tamagui.
845
- result.addAttribute(.kern, value: 0, range: NSRange(location: 0, length: result.length))
846
- original.enumerateAttribute(.font, in: NSRange(location: 0, length: original.length)) {
847
- value, range, _ in
848
- if let font = value as? UIFont {
849
- result.addAttribute(.font, value: self.selectorTabularFont(font), range: range)
850
- }
851
- }
852
- return result
853
- }
854
839
  private func applySelectorTypography(_ item: NativeListItem) {
855
- guard
856
- ["accountSelector", "networkSelector", "walletSidebar"].contains(
857
- item.data.string("presentation"))
858
- else { return }
859
- func visit(_ view: UIView) {
860
- if let button = view as? UIButton {
861
- if let original = button.attributedTitle(for: .normal) {
862
- selectorTypographyRestorers.append { button.setAttributedTitle(original, for: .normal) }
863
- button.setAttributedTitle(selectorTabularText(original), for: .normal)
864
- }
865
- } else if let label = view as? UILabel, let font = label.font {
866
- let original = label.attributedText
867
- selectorTypographyRestorers.append {
868
- label.font = font
869
- label.attributedText = original
870
- }
871
- label.font = selectorTabularFont(font)
872
- if let original { label.attributedText = selectorTabularText(original) }
840
+ guard ["accountSelector", "networkSelector", "walletSidebar"].contains(
841
+ item.data.string("presentation")
842
+ ) else { return }
843
+ let style = item.data.dictionary("style") ?? [:]
844
+ selectorTypographyRestorers = NativeListTextStyles.applySelectorDefaults(in: contentView) { view in
845
+ if view === titleLabel { return style.dictionary("title") }
846
+ if view === subtitleLabel || semanticSubtitleLabels.contains(where: { $0 === view }) {
847
+ return style.dictionary("subtitle")
848
+ }
849
+ if view === tertiaryLabel { return style.dictionary("tertiary") }
850
+ if view === badgeLabel || semanticBadgeLabels.contains(where: { $0 === view }) {
851
+ return style.dictionary("badge")
873
852
  }
874
- for child in view.subviews { visit(child) }
853
+ return trailingStack.explicitTextStyle(for: view, style: style)
875
854
  }
876
- visit(contentView)
877
855
  }
878
856
  private func setLineHeight(
879
857
  _ label: UILabel,
@@ -2,6 +2,14 @@ import UIKit
2
2
 
3
3
  // Bounded visual primitive: three source slots, two optional overlays. It knows
4
4
  // visual descriptors and request lifetimes, never row types or business keys.
5
+ /// A leading visual's solid border width: `borderWidth` when valid, else 1 point.
6
+ func nativeListBorderWidth(_ value: Any?) -> CGFloat {
7
+ guard let width = (value as? NSNumber)?.doubleValue, width.isFinite, width > 0, width <= 4 else {
8
+ return 1
9
+ }
10
+ return CGFloat(width)
11
+ }
12
+
5
13
  final class NativeListLeadingVisual: UIView {
6
14
  var fonts = NativeListFontFamilies()
7
15
  var glyphSize: CGFloat = 18
@@ -188,7 +188,7 @@ final class NativeListMarketCell: NativeListRendererCell {
188
188
  button.titleEdgeInsets = .zero
189
189
  }
190
190
  private func textLayoutStyle(_ style: [String: Any]) -> [String: Any] {
191
- style.filter { ["lines", "truncate", "verticalAlignment", "offsetY"].contains($0.key) }
191
+ style.filter { ["lines", "truncate", "verticalAlignment", "offsetY", "letterSpacing", "tabularNumbers"].contains($0.key) }
192
192
  }
193
193
  override func accessibilityText(_ item: NativeListItem) -> String {
194
194
  if let label = item.data["accessibilityLabel"] as? String { return label }
@@ -603,6 +603,9 @@ final class NativeListMarketCell: NativeListRendererCell {
603
603
  // The explicit text-only line box must not cover an adjacent icon.
604
604
  if hasIcon { button.marketLineHeight = nil }
605
605
  }
606
+ if let badgeStyle {
607
+ NativeListTextStyles.applyStyledButton(button, textLayoutStyle(badgeStyle), fonts: fonts)
608
+ }
606
609
  button.tintColor = foreground
607
610
  button.backgroundColor = UIColor(
608
611
  nativeListHex: badge.string("backgroundColor", default: ""),
@@ -631,7 +634,8 @@ final class NativeListMarketCell: NativeListRendererCell {
631
634
  // let height = button.heightAnchor.constraint(equalToConstant: 18)
632
635
  let height = button.heightAnchor.constraint(
633
636
  equalToConstant: CGFloat(badgeStyle?.double("height", default: 18) ?? 18))
634
- let textWidth = (text as NSString).size(withAttributes: [.font: badgeFont]).width
637
+ let textWidth = button.attributedTitle(for: .normal)?.size().width
638
+ ?? (text as NSString).size(withAttributes: [.font: badgeFont]).width
635
639
  let scale = max(1, traitCollection.displayScale)
636
640
  let roundedTextWidth = badgeStyle == nil ? ceil(textWidth) : ceil(textWidth * scale) / scale
637
641
  let extraWidth =
@@ -104,6 +104,8 @@ struct NativeListConfig {
104
104
  let rowPressToggles: Bool
105
105
  var selectedKeys: Set<String>
106
106
  let reorderable: Bool
107
+ /// `handle` starts a reorder only from a long press on a trailing `drag` accessory.
108
+ let reorderFromHandleOnly: Bool
107
109
  let pullToRefresh: Bool
108
110
  let refreshTriggerDistance: CGFloat?
109
111
  var refreshing: Bool
@@ -139,6 +141,10 @@ struct NativeListConfig {
139
141
  let selectedKeys = Set(selection?["selectedKeys"] as? [String] ?? [])
140
142
  guard selectedKeys.isSubset(of: keys) else { throw NativeListModelError.unknownSelectionKey }
141
143
  let capabilities = root["capabilities"] as? [String: Any]
144
+ let reorderActivation = capabilities?["reorderActivation"]
145
+ if let reorderActivation, !["row", "handle"].contains(reorderActivation as? String ?? "") {
146
+ throw NativeListModelError.invalidSnapshot
147
+ }
142
148
  let sectionIndex = capabilities?["sectionIndex"] as? [String: Any]
143
149
  let footer = try (root["fixedFooter"] as? [String: Any]).map(NativeListItem.init)
144
150
  let transition = root["structuralTransition"] as? [String: Any]
@@ -196,6 +202,7 @@ struct NativeListConfig {
196
202
  rowPressToggles: selection?["rowPressToggles"] as? Bool ?? false,
197
203
  selectedKeys: selectedKeys,
198
204
  reorderable: capabilities?["reorderable"] as? Bool ?? false,
205
+ reorderFromHandleOnly: reorderActivation as? String == "handle",
199
206
  pullToRefresh: capabilities?["pullToRefresh"] as? Bool ?? false,
200
207
  refreshTriggerDistance: (capabilities?["refreshTriggerDistance"] as? Double)
201
208
  .flatMap { $0.isFinite && $0 > 0 ? CGFloat($0) : nil },
@@ -13,7 +13,8 @@ struct NativeListResolvedText {
13
13
  let offsetY: CGFloat
14
14
  let explicitLineHeight: Bool
15
15
  let explicitTruncation: Bool
16
- let tabular: Bool
16
+ let digitSpacing: Bool?
17
+ let letterSpacing: CGFloat?
17
18
  /// Keep the label's break mode in the attributed paragraph (legacy plain-text labels kept
18
19
  /// their tail ellipsis; attributed paragraphs otherwise default to word wrapping).
19
20
  let preservesBreakMode: Bool
@@ -24,7 +25,8 @@ struct NativeListResolvedText {
24
25
  tabular: Bool = false, preservesBreakMode: Bool = false, fonts: NativeListFontFamilies
25
26
  ) {
26
27
  let style = style ?? [:]
27
- self.tabular = tabular
28
+ digitSpacing = (style["tabularNumbers"] as? Bool) ?? (tabular ? true : nil)
29
+ letterSpacing = style["letterSpacing"].map { _ in CGFloat(style.double("letterSpacing")) }
28
30
  self.preservesBreakMode = preservesBreakMode
29
31
  let requestedLines = style.int("lines", default: lines)
30
32
  self.lines = requestedLines == 0 ? 0 : min(3, max(1, requestedLines))
@@ -39,10 +41,9 @@ struct NativeListResolvedText {
39
41
  default: resolvedWeight = weight
40
42
  }
41
43
  let resolvedSize = CGFloat(style.double("fontSize", default: Double(size)))
42
- font =
43
- tabular
44
- ? nativeListTabularFont(ofSize: resolvedSize, weight: resolvedWeight, fonts: fonts)
45
- : nativeListFont(ofSize: resolvedSize, weight: resolvedWeight, fonts: fonts)
44
+ let baseFont = nativeListFont(ofSize: resolvedSize, weight: resolvedWeight, fonts: fonts)
45
+ font = digitSpacing.map { NativeListTextStyles.digitSpacingFont(baseFont, tabular: $0) }
46
+ ?? baseFont
46
47
  self.color =
47
48
  (style["color"] as? String).map { UIColor(nativeListHex: $0, fallback: color) } ?? color
48
49
  self.lineHeight = CGFloat(style.double("lineHeight", default: Double(lineHeight)))
@@ -85,6 +86,7 @@ struct NativeListResolvedText {
85
86
  var attributes: [NSAttributedString.Key: Any] = [
86
87
  .font: font, .foregroundColor: color, .paragraphStyle: paragraph,
87
88
  ]
89
+ if let letterSpacing { attributes[.kern] = letterSpacing }
88
90
  if explicitLineHeight {
89
91
  attributes[.baselineOffset] = max(0, (lineHeight - font.lineHeight) / 2)
90
92
  }
@@ -128,7 +130,7 @@ struct NativeListResolvedText {
128
130
  guard !text.isEmpty else { return 0 }
129
131
  let width = max(1, width)
130
132
  let key =
131
- "\(width)|\(lines)|\(lineHeight)|\(explicitLineHeight)|\(explicitTruncation)|\(breakMode.rawValue)|\(preservesBreakMode)|\(font.fontName)|\(font.pointSize)|\(tabular)|\(text)"
133
+ "\(width)|\(lines)|\(lineHeight)|\(explicitLineHeight)|\(explicitTruncation)|\(breakMode.rawValue)|\(preservesBreakMode)|\(font.fontName)|\(font.pointSize)|\(String(describing: digitSpacing))|\(String(describing: letterSpacing))|\(text)"
132
134
  as NSString
133
135
  if let cached = Self.heightCache.object(forKey: key) { return CGFloat(cached.doubleValue) }
134
136
  let label = Thread.isMainThread ? Self.sizingLabel : NativeListTextLabel()
@@ -784,50 +784,16 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
784
784
  )
785
785
  }
786
786
  }
787
- private func selectorTabularFont(_ font: UIFont) -> UIFont {
788
- var settings =
789
- font.fontDescriptor.fontAttributes[.featureSettings] as? [[UIFontDescriptor.FeatureKey: Int]]
790
- ?? []
791
- settings.removeAll { $0[.type] == kNumberSpacingType }
792
- settings.append([.type: kNumberSpacingType, .selector: kMonospacedNumbersSelector])
793
- return UIFont(
794
- descriptor: font.fontDescriptor.addingAttributes([.featureSettings: settings]),
795
- size: font.pointSize)
796
- }
797
- private func selectorTabularText(_ original: NSAttributedString) -> NSAttributedString {
798
- let result = NSMutableAttributedString(attributedString: original)
799
- // OneKey patch: body typography explicitly supplies letterSpacing=0 in Tamagui.
800
- result.addAttribute(.kern, value: 0, range: NSRange(location: 0, length: result.length))
801
- original.enumerateAttribute(.font, in: NSRange(location: 0, length: original.length)) {
802
- value, range, _ in
803
- if let font = value as? UIFont {
804
- result.addAttribute(.font, value: self.selectorTabularFont(font), range: range)
805
- }
806
- }
807
- return result
808
- }
809
787
  private func applySelectorTypography(_ item: NativeListItem) {
810
- guard
811
- ["accountSelector", "networkSelector", "walletSidebar"].contains(
812
- item.data.string("presentation"))
813
- else { return }
814
- func visit(_ view: UIView) {
815
- if let button = view as? UIButton {
816
- if let original = button.attributedTitle(for: .normal) {
817
- selectorTypographyRestorers.append { button.setAttributedTitle(original, for: .normal) }
818
- button.setAttributedTitle(selectorTabularText(original), for: .normal)
819
- }
820
- } else if let label = view as? UILabel, let font = label.font {
821
- let original = label.attributedText
822
- selectorTypographyRestorers.append {
823
- label.font = font
824
- label.attributedText = original
825
- }
826
- label.font = selectorTabularFont(font)
827
- if let original { label.attributedText = selectorTabularText(original) }
828
- }
829
- for child in view.subviews { visit(child) }
788
+ guard ["accountSelector", "networkSelector", "walletSidebar"].contains(
789
+ item.data.string("presentation")
790
+ ) else { return }
791
+ let style = item.data.dictionary("style") ?? [:]
792
+ selectorTypographyRestorers = NativeListTextStyles.applySelectorDefaults(in: contentView) { view in
793
+ if view === titleLabel { return style.dictionary("title") }
794
+ if view === subtitleLabel { return style.dictionary("subtitle") }
795
+ if view === accessoryButtons[0] { return style.dictionary("value") }
796
+ return nil
830
797
  }
831
- visit(contentView)
832
798
  }
833
799
  }
@@ -56,7 +56,12 @@ enum NativeListTextStyles {
56
56
  }
57
57
  var attributes: [NSAttributedString.Key: Any] = [:]
58
58
  applyStyledFont(attributed, style, fallback: baseFont, fonts: fonts)
59
+ if let tabular = style["tabularNumbers"] as? Bool {
60
+ applyDigitSpacing(attributed, tabular: tabular, fallback: font)
61
+ }
59
62
  if style["color"] != nil { attributes[.foregroundColor] = color }
63
+ // An explicit 0 still sets kern, which disables pair kerning like React Native.
64
+ if style["letterSpacing"] != nil { attributes[.kern] = CGFloat(style.double("letterSpacing")) }
60
65
  if style["alignment"] != nil || style["lines"] != nil || style["truncate"] != nil
61
66
  || style["lineHeight"] != nil
62
67
  {
@@ -121,7 +126,11 @@ enum NativeListTextStyles {
121
126
  }
122
127
  var attributes: [NSAttributedString.Key: Any] = [:]
123
128
  applyStyledFont(attributed, style, fallback: baseFont, fonts: fonts)
129
+ if let tabular = style["tabularNumbers"] as? Bool {
130
+ applyDigitSpacing(attributed, tabular: tabular, fallback: font)
131
+ }
124
132
  if style["color"] != nil { attributes[.foregroundColor] = color }
133
+ if style["letterSpacing"] != nil { attributes[.kern] = CGFloat(style.double("letterSpacing")) }
125
134
  if style["alignment"] != nil || style["lineHeight"] != nil || style["lines"] != nil
126
135
  || style["truncate"] != nil
127
136
  {
@@ -202,33 +211,84 @@ enum NativeListTextStyles {
202
211
  }
203
212
  }
204
213
 
205
- /// Legacy selector/warning typography: monospaced digits and zero kerning on the label.
214
+ /// Legacy selector/warning defaults: monospaced digits and zero tracking.
206
215
  static func applyTabularDigits(_ label: UILabel) {
207
216
  guard let font = label.font else { return }
208
- label.font = tabularDigitsFont(font)
209
- guard let original = label.attributedText else { return }
217
+ label.font = digitSpacingFont(font, tabular: true)
218
+ if let original = label.attributedText {
219
+ label.attributedText = selectorText(original, explicit: nil, fallback: font)
220
+ }
221
+ }
222
+
223
+ static func selectorText(
224
+ _ original: NSAttributedString, explicit: [String: Any]?, fallback: UIFont
225
+ ) -> NSAttributedString {
210
226
  let result = NSMutableAttributedString(attributedString: original)
211
- let range = NSRange(location: 0, length: result.length)
212
- result.addAttribute(.kern, value: 0, range: range)
213
- original.enumerateAttribute(.font, in: range) { value, range, _ in
214
- if let font = value as? UIFont {
215
- result.addAttribute(.font, value: tabularDigitsFont(font), range: range)
216
- }
227
+ if explicit?["letterSpacing"] == nil {
228
+ result.addAttribute(.kern, value: 0, range: NSRange(location: 0, length: result.length))
229
+ }
230
+ if explicit?["tabularNumbers"] == nil {
231
+ applyDigitSpacing(result, tabular: true, fallback: fallback)
232
+ }
233
+ return result
234
+ }
235
+
236
+ /// Apply the feature to each run without changing its weight or size.
237
+ static func applyDigitSpacing(
238
+ _ text: NSMutableAttributedString, tabular: Bool, fallback: UIFont
239
+ ) {
240
+ let range = NSRange(location: 0, length: text.length)
241
+ var runs: [(NSRange, UIFont)] = []
242
+ text.enumerateAttribute(.font, in: range) { value, run, _ in
243
+ runs.append((run, (value as? UIFont) ?? fallback))
244
+ }
245
+ for (run, font) in runs {
246
+ text.addAttribute(.font, value: digitSpacingFont(font, tabular: tabular), range: run)
217
247
  }
218
- label.attributedText = result
219
248
  }
220
249
 
221
- static func tabularDigitsFont(_ font: UIFont) -> UIFont {
250
+ static func digitSpacingFont(_ font: UIFont, tabular: Bool) -> UIFont {
222
251
  var settings =
223
252
  font.fontDescriptor.fontAttributes[.featureSettings] as? [[UIFontDescriptor.FeatureKey: Int]]
224
253
  ?? []
225
254
  settings.removeAll { $0[.type] == kNumberSpacingType }
226
- settings.append([.type: kNumberSpacingType, .selector: kMonospacedNumbersSelector])
255
+ settings.append([
256
+ .type: kNumberSpacingType,
257
+ .selector: tabular ? kMonospacedNumbersSelector : kProportionalNumbersSelector,
258
+ ])
227
259
  return UIFont(
228
260
  descriptor: font.fontDescriptor.addingAttributes([.featureSettings: settings]),
229
261
  size: font.pointSize)
230
262
  }
231
263
 
264
+ static func applySelectorDefaults(
265
+ in root: UIView, explicitStyle: (UIView) -> [String: Any]?
266
+ ) -> [() -> Void] {
267
+ var restorers: [() -> Void] = []
268
+ func visit(_ view: UIView, inherited: [String: Any]? = nil) {
269
+ let style = explicitStyle(view) ?? inherited
270
+ if let button = view as? UIButton,
271
+ let original = button.attributedTitle(for: .normal),
272
+ let font = button.titleLabel?.font {
273
+ restorers.append { button.setAttributedTitle(original, for: .normal) }
274
+ button.setAttributedTitle(selectorText(original, explicit: style, fallback: font), for: .normal)
275
+ } else if let label = view as? UILabel, let font = label.font {
276
+ let original = label.attributedText
277
+ restorers.append {
278
+ label.font = font
279
+ label.attributedText = original
280
+ }
281
+ if style?["tabularNumbers"] == nil { label.font = digitSpacingFont(font, tabular: true) }
282
+ if let original {
283
+ label.attributedText = selectorText(original, explicit: style, fallback: font)
284
+ }
285
+ }
286
+ for child in view.subviews { visit(child, inherited: style) }
287
+ }
288
+ visit(root)
289
+ return restorers
290
+ }
291
+
232
292
  static func marketTextAlignment(_ value: String, direction: UIUserInterfaceLayoutDirection)
233
293
  -> NSTextAlignment
234
294
  {