@onekeyfe/react-native-native-list 6.8.0-3 → 6.8.0-30

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 (62) hide show
  1. package/android/build.gradle +3 -0
  2. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +18 -4
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +12 -1
  4. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +166 -36
  5. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +3 -2
  6. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +8 -1
  7. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +6 -3
  8. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +21 -4
  9. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +24 -3
  10. package/android/src/main/java/com/onekey/nativelist/NativeListRowUpdates.kt +34 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +11 -4
  12. package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentLayout.kt +71 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentsView.kt +126 -0
  14. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +84 -9
  15. package/android/src/main/res/values/native_scroll_coordinator_ids.xml +1 -0
  16. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentitySubtitleBindingTest.kt +177 -0
  17. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +2 -0
  18. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListTitleSegmentLayoutTest.kt +130 -0
  19. package/docs/ROW_TEMPLATES.md +8 -1
  20. package/docs/SPEC.md +312 -5
  21. package/docs/STYLE_SPEC.md +7 -1
  22. package/ios/NativeListAccessoryStack.swift +22 -0
  23. package/ios/NativeListActivityDetailsView.swift +45 -1
  24. package/ios/NativeListDataRowRenderer.swift +12 -5
  25. package/ios/NativeListIdentityRenderer.swift +145 -66
  26. package/ios/NativeListLeadingVisual.swift +8 -0
  27. package/ios/NativeListMarketRenderer.swift +6 -2
  28. package/ios/NativeListModels.swift +7 -0
  29. package/ios/NativeListResolvedText.swift +9 -7
  30. package/ios/NativeListSectionHeaderRenderer.swift +9 -43
  31. package/ios/NativeListTextStyles.swift +72 -12
  32. package/ios/NativeListTitleSegmentLayout.swift +72 -0
  33. package/ios/NativeListTitleSegmentsLabel.swift +92 -0
  34. package/ios/RNCNativeListView.swift +203 -45
  35. package/ios/tests/NativeListActivityPresentationTests.swift +137 -0
  36. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +155 -0
  37. package/ios/tests/NativeListLifecycleTests.swift +298 -24
  38. package/ios/tests/NativeListMediaVisibilityTests.swift +2 -1
  39. package/lib/module/models.js +2 -0
  40. package/lib/module/validation.js +96 -13
  41. package/lib/module/web/NativeListWebEngine.js +427 -100
  42. package/lib/module/web/templates/ActivityRowRenderer.js +1 -1
  43. package/lib/module/web/templates/IdentityRowRenderer.js +134 -3
  44. package/lib/module/web/templates/MarketRowRenderer.js +2 -0
  45. package/lib/module/web/templates/MediaTileRowRenderer.js +1 -0
  46. package/lib/module/web/templates/RowElements.js +2 -2
  47. package/lib/module/web/templates/RowText.js +2 -0
  48. package/lib/typescript/src/models.d.ts +35 -1
  49. package/lib/typescript/src/web/NativeListWebEngine.d.ts +17 -2
  50. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +6 -2
  51. package/lib/typescript/src/web/templates/RowVisual.d.ts +1 -1
  52. package/package.json +1 -1
  53. package/src/models.ts +38 -0
  54. package/src/validation.ts +196 -6
  55. package/src/web/NativeListWebEngine.ts +671 -112
  56. package/src/web/templates/ActivityRowRenderer.ts +1 -1
  57. package/src/web/templates/IdentityRowRenderer.ts +208 -3
  58. package/src/web/templates/MarketRowRenderer.ts +2 -0
  59. package/src/web/templates/MediaTileRowRenderer.ts +1 -0
  60. package/src/web/templates/RowElements.ts +3 -2
  61. package/src/web/templates/RowText.ts +6 -0
  62. package/src/web/templates/RowVisual.ts +2 -1
@@ -9,6 +9,9 @@ final class NativeListActivityDetailsView: UIStackView {
9
9
  private let identity = UIStackView()
10
10
  private let titleLine = UIStackView()
11
11
  private let title = NativeListTextLabel()
12
+ // Absorbs the title line's slack so the title keeps its intrinsic width and the
13
+ // badges follow the text (OK-67497), matching the identity title row (OK-66041).
14
+ private let titleLineFiller = NativeListTitleLineFiller()
12
15
  private let descriptionLabel = NativeListTextLabel()
13
16
  private let status = NativeListTextLabel()
14
17
  private let amounts = UIStackView()
@@ -32,6 +35,9 @@ final class NativeListActivityDetailsView: UIStackView {
32
35
  identity.axis = .vertical; identity.alignment = .fill
33
36
  titleLine.axis = .horizontal; titleLine.alignment = .center; titleLine.spacing = 4
34
37
  titleLine.addArrangedSubview(title)
38
+ titleLine.addArrangedSubview(titleLineFiller)
39
+ titleLineFiller.setContentHuggingPriority(UILayoutPriority(1), for: .horizontal)
40
+ titleLineFiller.setContentCompressionResistancePriority(UILayoutPriority(1), for: .horizontal)
35
41
  [titleLine, descriptionLabel, status].forEach(identity.addArrangedSubview)
36
42
  amounts.axis = .vertical; amounts.alignment = .fill; amounts.spacing = 2
37
43
  fee.axis = .vertical; fee.alignment = .trailing
@@ -47,6 +53,11 @@ final class NativeListActivityDetailsView: UIStackView {
47
53
  title.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
48
54
  identity.setContentHuggingPriority(.defaultLow, for: .horizontal)
49
55
  amounts.setContentHuggingPriority(.defaultHigh, for: .horizontal)
56
+ // Stacked fee text hugs, or the fee column takes the row's slack the same
57
+ // way an unpinned amount column does. Required table widths still win.
58
+ [feeLabel, feePrimary, feeSecondary].forEach {
59
+ $0.setContentHuggingPriority(.defaultHigh, for: .horizontal)
60
+ }
50
61
  }
51
62
  required init(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
52
63
 
@@ -215,10 +226,12 @@ final class NativeListActivityDetailsView: UIStackView {
215
226
  ).bind(label)
216
227
  label.backgroundColor = tint.withAlphaComponent(0.1)
217
228
  label.layer.cornerRadius = 4; label.clipsToBounds = true
229
+ label.setContentHuggingPriority(.required, for: .horizontal)
218
230
  label.setContentCompressionResistancePriority(.required, for: .horizontal)
219
- titleLine.addArrangedSubview(label)
231
+ titleLine.insertArrangedSubview(label, at: titleLine.arrangedSubviews.count - 1)
220
232
  return label
221
233
  }
234
+ settleTitleLineFillerSpacing()
222
235
  let descriptors = data.dictionaries("amounts")
223
236
  while amountViews.count > descriptors.count {
224
237
  let view = amountViews.removeLast(); view.recycle(); amounts.removeArrangedSubview(view); view.removeFromSuperview()
@@ -269,6 +282,19 @@ final class NativeListActivityDetailsView: UIStackView {
269
282
  actions.arrangedSubviews.filter { !($0 is UIButton) }.forEach { actions.removeArrangedSubview($0); $0.removeFromSuperview() }
270
283
  actions.addArrangedSubview(spacer)
271
284
  }
285
+ /// The filler only packs the title while badges follow it. Without badges it is
286
+ /// hidden so the title keeps the whole line and its `alignment` (center/end) still
287
+ /// applies, exactly as before badges existed. With badges, the stack's spacing
288
+ /// before the filler would shave `titleBadgeGap` off the title, so that gap is zero.
289
+ private func settleTitleLineFillerSpacing() {
290
+ titleLineFiller.isHidden = badgeViews.isEmpty
291
+ // With badges the filler, not the title, takes the column's leftover width.
292
+ // Without badges the title has to be free to span the line so center/end
293
+ // alignment still applies.
294
+ title.setContentHuggingPriority(badgeViews.isEmpty ? .defaultLow : .defaultHigh, for: .horizontal)
295
+ if let last = badgeViews.last { titleLine.setCustomSpacing(0, after: last) }
296
+ }
297
+
272
298
  @objc private func descriptionPressed() { onAction?(descriptionKey, descriptionLabel, "description", 0) }
273
299
  @objc private func actionPressed(_ button: UIButton) {
274
300
  guard button.tag < actionKeys.count else { return }
@@ -280,6 +306,15 @@ final class NativeListActivityDetailsView: UIStackView {
280
306
  }
281
307
  }
282
308
 
309
+ /// Horizontal spacer with intrinsic width 0. Hugging and compression are 1, so
310
+ /// once the title line is as wide as the identity column the leftover width
311
+ /// lands here, after the badge (OK-67497).
312
+ private final class NativeListTitleLineFiller: UIView {
313
+ override var intrinsicContentSize: CGSize {
314
+ CGSize(width: 0, height: UIView.noIntrinsicMetric)
315
+ }
316
+ }
317
+
283
318
  private func nativeListActivityTone(_ tone: String, theme: [String: Any]?) -> UIColor {
284
319
  switch tone {
285
320
  case "positive", "success": return nativeListColor(theme, "positive", "#218358")
@@ -301,6 +336,15 @@ private final class NativeListActivityAmountView: UIStackView {
301
336
  super.init(frame: frame)
302
337
  axis = .horizontal; alignment = .center; spacing = 6
303
338
  labels.axis = .vertical; labels.alignment = .fill
339
+ // Stacked amounts stay at their text width (Android WRAP_CONTENT). The
340
+ // identity column then receives the leftover row width, which is what
341
+ // measure() already assumes. Table columns ignore this: their required
342
+ // widths win (OK-67497). Hugging stays below the labels' compression
343
+ // resistance (750): all amount labels share the column width, so a short
344
+ // label must never squeeze a longer one.
345
+ [primary, secondary].forEach {
346
+ $0.setContentHuggingPriority(UILayoutPriority(749), for: .horizontal)
347
+ }
304
348
  [primary, secondary].forEach(labels.addArrangedSubview)
305
349
  [visual, labels].forEach(addArrangedSubview)
306
350
  NSLayoutConstraint.activate([visual.widthAnchor.constraint(equalToConstant: 20), visual.heightAnchor.constraint(equalToConstant: 20)])
@@ -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,17 @@ final class NativeListIdentityCell: NativeListRendererCell {
49
50
  stack.spacing = 10
50
51
  }
51
52
  }
53
+ private class func showsTitleRuns(_ item: NativeListItem) -> Bool {
54
+ nativeListShowsTitleRuns(
55
+ presentation: item.data.string("presentation"),
56
+ runCount: item.data.dictionaries("titleSegments").count,
57
+ matchCount: item.data.dictionaries("titleMatch").count)
58
+ }
59
+
60
+ private static func collapsesTrailing(_ item: NativeListItem, descriptors: [[String: Any]]) -> Bool {
61
+ descriptors.isEmpty && item.data.bool("collapseEmptyTrailing")
62
+ }
63
+
52
64
  override class func measure(
53
65
  _ item: NativeListItem, width: CGFloat, theme: [String: Any]?, layout: String,
54
66
  fonts: NativeListFontFamilies
@@ -70,18 +82,23 @@ final class NativeListIdentityCell: NativeListRendererCell {
70
82
  trailing.bind(
71
83
  item, descriptors: accessories, theme: theme, style: style,
72
84
  defaultSpacing: trailing.spacing, checkboxState: { _, _, fallback in fallback }, fonts: fonts)
73
- trailing.isHidden = false
74
- let trailingSize = trailing.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
85
+ let collapsed = collapsesTrailing(item, descriptors: accessories)
86
+ let trailingSize = collapsed ? .zero
87
+ : trailing.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
75
88
  let rightInset = style["horizontalPadding"] != nil
76
89
  ? horizontalPadding : trailing.endInset ?? horizontalPadding
77
- let contentGap = trailing.contentGap ?? 12
90
+ let contentGap = collapsed ? 0 : trailing.contentGap ?? 12
78
91
  let textWidth = max(1,
79
92
  width - horizontalPadding - rightInset - imageWidth - leadingGap
80
93
  - trailingSize.width - contentGap)
94
+ // Runs are one line whatever `style.title.lines` asks for.
95
+ let showsRuns = showsTitleRuns(item)
96
+ var titleStyle = style.dictionary("title")
97
+ if showsRuns { titleStyle?.removeValue(forKey: "lines") }
81
98
  let title = NativeListResolvedText(
82
- item.data.string("title"), style: style.dictionary("title"), size: 16,
99
+ item.data.string("title"), style: titleStyle, size: 16,
83
100
  weight: .medium, color: .black, lineHeight: 24,
84
- lines: item.data.int("titleLines", default: 1), fonts: fonts)
101
+ lines: showsRuns ? 1 : item.data.int("titleLines", default: 1), fonts: fonts)
85
102
  let subtitle = NativeListResolvedText(
86
103
  item.data.string("subtitle"), style: style.dictionary("subtitle"), size: 14,
87
104
  color: .black, lineHeight: 20,
@@ -94,7 +111,13 @@ final class NativeListIdentityCell: NativeListRendererCell {
94
111
  let titleImageSize = CGFloat(item.data.dictionary("titleImage")?.dictionary("image")?.double("width") ?? 0)
95
112
  let titleImageWidth = titleImageSize > 0
96
113
  ? titleImageSize + 4 + (item.data.dictionary("titleIcon") == nil ? 0 : 24) : 0
97
- let textHeight = max(titleImageSize, title.measure(width: max(1, textWidth - titleImageWidth)))
114
+ // The leading glyph and its gap come out of the title's width as well.
115
+ let titleLeadingIconWidth = nativeListTitleLeadingIconWidth(
116
+ presentation: item.data.string("presentation"),
117
+ hasIcon: item.data.dictionary("titleLeadingIcon") != nil)
118
+ let textHeight = max(
119
+ titleImageSize,
120
+ title.measure(width: max(1, textWidth - titleImageWidth - titleLeadingIconWidth)))
98
121
  + subtitle.measure(width: textWidth)
99
122
  + tertiary.measure(width: textWidth)
100
123
  + (item.data.string("subtitle").isEmpty ? 0 : CGFloat(style.double("lineGap", default: 0)))
@@ -110,6 +133,12 @@ final class NativeListIdentityCell: NativeListRendererCell {
110
133
  private let titleRowStack = UIStackView()
111
134
  private let titleLabel = NativeListTextLabel()
112
135
  private let titleIconView = NativeListIconImageView()
136
+ private let titleLeadingIconView = NativeListIconImageView()
137
+ private let titleSegmentsLabel = NativeListTitleSegmentsLabel()
138
+ // Runs, when shown, take the title's place in the title row.
139
+ private var visibleTitleView: UIView {
140
+ titleSegmentsLabel.isHidden ? titleLabel : titleSegmentsLabel
141
+ }
113
142
  private var titleImageSlot: NativeListImageSlot?
114
143
  private var titleImageConstraints: [NSLayoutConstraint] = []
115
144
  // Absorbs the title row's slack so the title keeps its intrinsic width and the
@@ -170,7 +199,9 @@ final class NativeListIdentityCell: NativeListRendererCell {
170
199
  mainStack.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
171
200
  titleRowStack.axis = .horizontal
172
201
  titleRowStack.alignment = .center
202
+ titleRowStack.addArrangedSubview(titleLeadingIconView)
173
203
  titleRowStack.addArrangedSubview(titleLabel)
204
+ titleRowStack.addArrangedSubview(titleSegmentsLabel)
174
205
  titleRowStack.addArrangedSubview(titleIconView)
175
206
  titleRowStack.addArrangedSubview(badgeLabel)
176
207
  titleRowStack.addArrangedSubview(titleRowFiller)
@@ -185,6 +216,18 @@ final class NativeListIdentityCell: NativeListRendererCell {
185
216
  ])
186
217
  titleIconView.contentMode = .scaleAspectFit
187
218
  titleIconView.setContentHuggingPriority(.required, for: .horizontal)
219
+ titleLeadingIconView.translatesAutoresizingMaskIntoConstraints = false
220
+ let leadingIconWidth = titleLeadingIconView.widthAnchor.constraint(equalToConstant: 16)
221
+ leadingIconWidth.priority = UILayoutPriority(999)
222
+ NSLayoutConstraint.activate([
223
+ leadingIconWidth,
224
+ titleLeadingIconView.heightAnchor.constraint(equalToConstant: 16),
225
+ ])
226
+ titleLeadingIconView.contentMode = .scaleAspectFit
227
+ titleLeadingIconView.setContentHuggingPriority(.required, for: .horizontal)
228
+ titleLeadingIconView.setContentCompressionResistancePriority(.required, for: .horizontal)
229
+ titleLeadingIconView.isHidden = true
230
+ titleSegmentsLabel.isHidden = true
188
231
  [titleRowStack, subtitleLabel, tertiaryLabel].forEach(mainStack.addArrangedSubview)
189
232
  visual.translatesAutoresizingMaskIntoConstraints = false
190
233
  leadingWidth = visual.widthAnchor.constraint(equalToConstant: 40)
@@ -249,6 +292,15 @@ final class NativeListIdentityCell: NativeListRendererCell {
249
292
  titleIconView.isHidden = true
250
293
  titleIconView.accessibilityLabel = nil
251
294
  titleIconView.isAccessibilityElement = false
295
+ titleLeadingIconView.image = nil
296
+ titleLeadingIconView.isHidden = true
297
+ titleLeadingIconView.accessibilityLabel = nil
298
+ titleLeadingIconView.isAccessibilityElement = false
299
+ titleSegmentsLabel.isHidden = true
300
+ titleSegmentsLabel.reset()
301
+ titleRowFiller.isHidden = false
302
+ titleSegmentsLabel.setContentHuggingPriority(.defaultLow, for: .horizontal)
303
+ titleSegmentsLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
252
304
  titleImageSlot?.view.isHidden = true
253
305
  titleImageSlot?.view.accessibilityLabel = nil
254
306
  titleImageSlot?.view.isAccessibilityElement = false
@@ -286,10 +338,11 @@ final class NativeListIdentityCell: NativeListRendererCell {
286
338
  leadingWidth.constant = 40
287
339
  leadingHeight.constant = 40
288
340
  visual.glyphSize = 18
341
+ let leadingDescriptor = item.data.dictionary("leading")
289
342
  visual.bitmapBorderWidth =
290
- item.data.dictionary("leading")?.string("borderColor").isEmpty == false
291
- && item.data.dictionary("leading")?.string("borderStyle") != "dashed"
292
- ? 1 : 0
343
+ leadingDescriptor?.string("borderColor").isEmpty == false
344
+ && leadingDescriptor?.string("borderStyle") != "dashed"
345
+ ? nativeListBorderWidth(leadingDescriptor?["borderWidth"]) : 0
293
346
  fallbackLabel.attributedText = nil
294
347
  fallbackLabel.font = nativeListFont(ofSize: 13, weight: .bold, fonts: fonts)
295
348
  trailingStack.reset()
@@ -310,7 +363,7 @@ final class NativeListIdentityCell: NativeListRendererCell {
310
363
  let label = titleIcon.string("accessibilityLabel")
311
364
  titleIconView.accessibilityLabel = label.isEmpty ? nil : label
312
365
  titleIconView.isAccessibilityElement = !label.isEmpty
313
- titleRowStack.setCustomSpacing(4, after: titleLabel)
366
+ titleRowStack.setCustomSpacing(4, after: visibleTitleView)
314
367
  // A long title truncates ahead of the 20pt glyph (Android caps the title
315
368
  // at row width minus accessories, Web shrinks the title first); with the
316
369
  // title at `.required` the icon's 999 width constraint collapsed to 0.
@@ -342,7 +395,7 @@ final class NativeListIdentityCell: NativeListRendererCell {
342
395
  ]
343
396
  titleImageConstraints.forEach { $0.priority = UILayoutPriority(999) }
344
397
  NSLayoutConstraint.activate(titleImageConstraints)
345
- titleRowStack.setCustomSpacing(4, after: titleIconView.isHidden ? titleLabel : titleIconView)
398
+ titleRowStack.setCustomSpacing(4, after: titleIconView.isHidden ? visibleTitleView : titleIconView)
346
399
  titleLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
347
400
  slot.bind(image, key: "\(item.key):titleImage", placeholder: "#00000000")
348
401
  } else {
@@ -385,7 +438,7 @@ final class NativeListIdentityCell: NativeListRendererCell {
385
438
  titleRowStack.setCustomSpacing(
386
439
  CGFloat(style.double("titleBadgeGap")),
387
440
  after: titleImageSlot?.view.isHidden == false ? titleImageSlot!.view
388
- : titleIconView.isHidden ? titleLabel : titleIconView)
441
+ : titleIconView.isHidden ? visibleTitleView : titleIconView)
389
442
  }
390
443
  }
391
444
  if style["trailingGap"] != nil { trailingStack.spacing = CGFloat(style.double("trailingGap")) }
@@ -399,6 +452,7 @@ final class NativeListIdentityCell: NativeListRendererCell {
399
452
  labels.forEach { NativeListTextStyles.applyStyledText($0, text, fonts: fonts) }
400
453
  }
401
454
  }
455
+ if !titleSegmentsLabel.isHidden { bindTitleRuns(item, theme: theme, style: style) }
402
456
  contentInsets = UIEdgeInsets(
403
457
  top: topInset, left: leftInset, bottom: -bottomInset, right: -rightInset)
404
458
  if root.axis == .horizontal {
@@ -464,6 +518,8 @@ final class NativeListIdentityCell: NativeListRendererCell {
464
518
  }
465
519
  override func recycleContent() {
466
520
  visual.recycle()
521
+ titleSegmentsLabel.reset()
522
+ titleLeadingIconView.image = nil
467
523
  titleImageSlot?.recycle()
468
524
  titleImageSlot?.view.isHidden = true
469
525
  titleImageSlot?.view.accessibilityLabel = nil
@@ -512,6 +568,32 @@ final class NativeListIdentityCell: NativeListRendererCell {
512
568
  visual.bind(
513
569
  descriptor, style: image, key: key, theme: currentTheme, isUnread: false, fonts: fonts)
514
570
  }
571
+ // Runs take the title's font, size and color unless they set their own tone
572
+ // or weight; the title label holds the final style by now.
573
+ private func bindTitleRuns(_ item: NativeListItem, theme: [String: Any]?, style: [String: Any]) {
574
+ let baseFont = titleLabel.font ?? nativeListFont(ofSize: 16, weight: .medium, fonts: fonts)
575
+ let baseColor = titleLabel.textColor ?? nativeListColor(theme, "primaryText", "#202020")
576
+ let runs = item.data.dictionaries("titleSegments").map { segment in
577
+ let weight = segment.string("fontWeight")
578
+ let tone = segment.string("tone")
579
+ return NativeListTitleSegmentsLabel.Run(
580
+ text: nativeListTitleRunText(segment.string("text")),
581
+ font: weight.isEmpty
582
+ ? baseFont
583
+ : nativeListFont(
584
+ ofSize: baseFont.pointSize, weight: weight == "medium" ? .medium : .regular, fonts: fonts),
585
+ color: tone == "secondary"
586
+ ? nativeListColor(theme, "secondaryText", "#646464")
587
+ : tone == "primary" ? nativeListColor(theme, "primaryText", "#202020") : baseColor,
588
+ shrink: segment.bool("shrink"),
589
+ maxWidthRatio: (segment["maxWidthRatio"] as? NSNumber).map { CGFloat(truncating: $0) })
590
+ }
591
+ titleSegmentsLabel.lineHeight = CGFloat(
592
+ style.dictionary("title")?.double("lineHeight", default: 24) ?? 24)
593
+ titleSegmentsLabel.offsetY = CGFloat(
594
+ style.dictionary("title")?.double("offsetY", default: 0) ?? 0)
595
+ titleSegmentsLabel.configure(runs, spokenText: item.data.string("title"))
596
+ }
515
597
  private func bindIdentity(
516
598
  _ item: NativeListItem,
517
599
  theme: [String: Any]?,
@@ -623,13 +705,13 @@ final class NativeListIdentityCell: NativeListRendererCell {
623
705
  leadingActionButton.alpha = leadingActionButton.isEnabled ? 1 : 0.4
624
706
  leadingActionKey = leadingAction.string("actionKey")
625
707
  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)
708
+ // ListItem.IconButton is a medium tertiary button: p=6 plus a 1-point
709
+ // border makes a 38-point frame with m=-7, so its glyph sits exactly on
710
+ // a 24-point slot at the 12-point padding and the avatar starts at 48.
711
+ // This 36-point frame centers the same glyph with a 6-point inset and
712
+ // 6-point following gap, keeping the 24-point SVG and its hit target.
713
+ leftInset = 6
714
+ root.setCustomSpacing(6, after: leadingActionButton)
633
715
  }
634
716
  addLeading(item.data.dictionary("leading"), key: item.key)
635
717
  // OneKey patch: custom network initials match LetterAvatar size 32.
@@ -643,10 +725,36 @@ final class NativeListIdentityCell: NativeListRendererCell {
643
725
  }
644
726
  root.addArrangedSubview(mainStack)
645
727
  show(titleLabel, item.data.string("title"), lines: item.data.int("titleLines", default: 1))
728
+ // Runs replace the drawn title except where `title` itself is highlighted;
729
+ // their content is bound once the title style is final.
730
+ if Self.showsTitleRuns(item) {
731
+ titleLabel.isHidden = true
732
+ titleSegmentsLabel.isHidden = false
733
+ // The runs fill what the title row leaves, so a ratio is a share of it.
734
+ titleRowFiller.isHidden = true
735
+ titleSegmentsLabel.setContentHuggingPriority(UILayoutPriority(1), for: .horizontal)
736
+ }
737
+ if nativeListAllowsTitleDecorations(presentation: item.data.string("presentation")),
738
+ let icon = item.data.dictionary("titleLeadingIcon")
739
+ {
740
+ titleLeadingIconView.bindIcon(icon.string("name"))
741
+ titleLeadingIconView.tintColor = UIColor(
742
+ nativeListHex: icon.string("tintColor",
743
+ default: theme?["iconSubdued"] as? String ?? "#8D8D8D"),
744
+ fallback: .gray)
745
+ titleLeadingIconView.isHidden = false
746
+ let label = icon.string("accessibilityLabel")
747
+ titleLeadingIconView.accessibilityLabel = label.isEmpty ? nil : label
748
+ titleLeadingIconView.isAccessibilityElement = !label.isEmpty
749
+ titleRowStack.setCustomSpacing(6, after: titleLeadingIconView)
750
+ // As beside `titleIcon`: a plain title left at `.required` collapses the
751
+ // glyph's 999 width constraint instead of truncating.
752
+ titleLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
753
+ }
646
754
  let titleSuffixes = item.data.dictionaries("titleSuffixes")
647
755
  if !titleSuffixes.isEmpty {
648
- titleLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
649
- let minimumTitleWidth = titleLabel.widthAnchor.constraint(greaterThanOrEqualToConstant: 80)
756
+ visibleTitleView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
757
+ let minimumTitleWidth = visibleTitleView.widthAnchor.constraint(greaterThanOrEqualToConstant: 80)
650
758
  minimumTitleWidth.priority = UILayoutPriority(751)
651
759
  minimumTitleWidth.isActive = true
652
760
  selectorConstraints.append(minimumTitleWidth)
@@ -796,7 +904,7 @@ final class NativeListIdentityCell: NativeListRendererCell {
796
904
  defaultSpacing: trailingStack.spacing, checkboxState: checkboxState, fonts: fonts)
797
905
  // Legacy kept the (possibly empty) trailing stack arranged, so the text column always
798
906
  // ends 12 points before the trailing edge inset.
799
- trailingStack.isHidden = false
907
+ trailingStack.isHidden = Self.collapsesTrailing(item, descriptors: accessories)
800
908
  if let gap = trailingStack.contentGap { root.setCustomSpacing(gap, after: mainStack) }
801
909
  if let inset = trailingStack.endInset { rightInset = -inset }
802
910
  if accessories.count == 1,
@@ -829,51 +937,22 @@ final class NativeListIdentityCell: NativeListRendererCell {
829
937
  default: return nativeListColor(theme, "primaryText", "#202020")
830
938
  }
831
939
  }
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
940
  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) }
941
+ guard ["accountSelector", "networkSelector", "walletSidebar"].contains(
942
+ item.data.string("presentation")
943
+ ) else { return }
944
+ let style = item.data.dictionary("style") ?? [:]
945
+ selectorTypographyRestorers = NativeListTextStyles.applySelectorDefaults(in: contentView) { view in
946
+ if view === titleLabel { return style.dictionary("title") }
947
+ if view === subtitleLabel || semanticSubtitleLabels.contains(where: { $0 === view }) {
948
+ return style.dictionary("subtitle")
949
+ }
950
+ if view === tertiaryLabel { return style.dictionary("tertiary") }
951
+ if view === badgeLabel || semanticBadgeLabels.contains(where: { $0 === view }) {
952
+ return style.dictionary("badge")
873
953
  }
874
- for child in view.subviews { visit(child) }
954
+ return trailingStack.explicitTextStyle(for: view, style: style)
875
955
  }
876
- visit(contentView)
877
956
  }
878
957
  private func setLineHeight(
879
958
  _ 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()