@onekeyfe/react-native-native-list 3.0.158 → 3.0.159

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 (199) hide show
  1. package/README.md +21 -5
  2. package/android/build.gradle +7 -0
  3. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +20 -0
  4. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +711 -0
  5. package/android/src/main/java/com/onekey/nativelist/NativeListActionRenderer.kt +169 -0
  6. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +179 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +264 -0
  8. package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +20 -6
  9. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +53 -0
  10. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +487 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListEndAlignment.kt +5 -0
  12. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +820 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListImageSlot.kt +147 -0
  14. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +453 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +997 -0
  16. package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +268 -0
  17. package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +243 -0
  18. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +232 -0
  19. package/android/src/main/java/com/onekey/nativelist/NativeListMetricCardRenderer.kt +551 -0
  20. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +27 -1
  21. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +475 -0
  22. package/android/src/main/java/com/onekey/nativelist/NativeListRailRenderer.kt +143 -0
  23. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +42 -0
  24. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +415 -0
  25. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +163 -0
  26. package/android/src/main/java/com/onekey/nativelist/NativeListRowHost.kt +70 -0
  27. package/android/src/main/java/com/onekey/nativelist/NativeListScrollPositionTracker.kt +59 -0
  28. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +763 -0
  29. package/android/src/main/java/com/onekey/nativelist/NativeListSystemRenderer.kt +464 -0
  30. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +25 -0
  31. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +432 -124
  32. package/android/src/main/java/com/onekey/nativelist/NativeListWalletGroupRenderer.kt +407 -0
  33. package/android/src/main/res/values/native_scroll_coordinator_ids.xml +5 -0
  34. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListEndAlignmentTest.kt +34 -0
  35. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListScrollPositionTrackerTest.kt +44 -0
  36. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListSelectorBackgroundColorTest.kt +34 -0
  37. package/docs/DESIGN.md +520 -9
  38. package/docs/MIGRATION_BASELINE.md +117 -0
  39. package/docs/ROW_TEMPLATES.md +404 -0
  40. package/docs/SPEC.md +621 -0
  41. package/docs/STYLE_SPEC.md +988 -0
  42. package/docs/images/list-capabilities.svg +39 -0
  43. package/docs/images/row-action.svg +17 -0
  44. package/docs/images/row-activity.svg +24 -0
  45. package/docs/images/row-data.svg +24 -0
  46. package/docs/images/row-identity.svg +25 -0
  47. package/docs/images/row-market.svg +23 -0
  48. package/docs/images/row-media-tile.svg +26 -0
  49. package/docs/images/row-message.svg +20 -0
  50. package/docs/images/row-metric-card.svg +33 -0
  51. package/docs/images/row-rail.svg +18 -0
  52. package/docs/images/row-section-header.svg +19 -0
  53. package/docs/images/row-style-regions.svg +30 -0
  54. package/docs/images/row-system.svg +30 -0
  55. package/docs/images/row-wallet-group.svg +26 -0
  56. package/ios/HybridNativeList.swift +30 -0
  57. package/ios/NativeListAccessoryStack.swift +680 -0
  58. package/ios/NativeListActionRenderer.swift +108 -0
  59. package/ios/NativeListActivityDetailsView.swift +291 -0
  60. package/ios/NativeListActivityRenderer.swift +201 -0
  61. package/ios/NativeListDataRowRenderer.swift +444 -0
  62. package/ios/NativeListIdentityRenderer.swift +685 -0
  63. package/ios/NativeListImageSlot.swift +140 -0
  64. package/ios/NativeListLeadingVisual.swift +372 -0
  65. package/ios/NativeListMarketRenderer.swift +698 -0
  66. package/ios/NativeListMediaPreviewSlot.swift +259 -0
  67. package/ios/NativeListMediaTileRenderer.swift +190 -0
  68. package/ios/NativeListMessageRenderer.swift +168 -0
  69. package/ios/NativeListMetricCardRenderer.swift +420 -0
  70. package/ios/NativeListModels.swift +36 -1
  71. package/ios/NativeListRailRenderer.swift +152 -0
  72. package/ios/NativeListRendererCell.swift +311 -0
  73. package/ios/NativeListRendererRegistry.swift +50 -0
  74. package/ios/NativeListResolvedText.swift +130 -0
  75. package/ios/NativeListRowHost.swift +63 -0
  76. package/ios/NativeListScrollPositionTracker.swift +30 -0
  77. package/ios/NativeListSectionHeaderRenderer.swift +734 -0
  78. package/ios/NativeListSystemRenderer.swift +568 -0
  79. package/ios/NativeListTextLabel.swift +42 -0
  80. package/ios/NativeListTextStyles.swift +236 -0
  81. package/ios/NativeListWalletGroupRenderer.swift +255 -0
  82. package/ios/RNCNativeListView.swift +282 -184
  83. package/ios/tests/NativeListActivityPresentationTests.swift +97 -0
  84. package/ios/tests/NativeListLifecycleTests.swift +241 -0
  85. package/ios/tests/NativeListMediaVisibilityTests.swift +109 -0
  86. package/ios/tests/NativeListScrollPositionTrackerTests.swift +25 -0
  87. package/lib/module/NativeList.js +56 -3
  88. package/lib/module/NativeList.web.js +5 -0
  89. package/lib/module/models.js +54 -0
  90. package/lib/module/validation.js +386 -28
  91. package/lib/module/web/NativeListWebEngine.js +148 -936
  92. package/lib/module/web/templates/ActionRowRenderer.js +97 -0
  93. package/lib/module/web/templates/ActivityRowRenderer.js +95 -0
  94. package/lib/module/web/templates/DataRowRenderer.js +145 -0
  95. package/lib/module/web/templates/IdentityRowRenderer.js +289 -0
  96. package/lib/module/web/templates/MarketRowRenderer.js +310 -0
  97. package/lib/module/web/templates/MediaTileRowRenderer.js +132 -0
  98. package/lib/module/web/templates/MessageRowRenderer.js +165 -0
  99. package/lib/module/web/templates/MetricCardRowRenderer.js +172 -0
  100. package/lib/module/web/templates/RailRowRenderer.js +98 -0
  101. package/lib/module/web/templates/RowContainerStyle.js +100 -0
  102. package/lib/module/web/templates/RowElements.js +93 -0
  103. package/lib/module/web/templates/RowRendererRegistry.js +70 -0
  104. package/lib/module/web/templates/RowText.js +121 -0
  105. package/lib/module/web/templates/RowVisual.js +43 -0
  106. package/lib/module/web/templates/SectionHeaderRowRenderer.js +146 -0
  107. package/lib/module/web/templates/SystemRowRenderer.js +161 -0
  108. package/lib/module/web/templates/WalletGroupRowRenderer.js +96 -0
  109. package/lib/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
  110. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +39 -3
  111. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +6 -0
  112. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +15 -0
  113. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/Func_void_bool.kt +78 -0
  114. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +26 -0
  115. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListManager.kt +24 -9
  116. package/lib/nitrogen/generated/android/nativelistOnLoad.cpp +2 -0
  117. package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.cpp +8 -0
  118. package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.hpp +37 -0
  119. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +23 -2
  120. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +32 -0
  121. package/lib/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
  122. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +3 -0
  123. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +54 -0
  124. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +6 -0
  125. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +8 -2
  126. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +6 -0
  127. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +11 -2
  128. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +3 -0
  129. package/lib/typescript/src/NativeList.nitro.d.ts +3 -0
  130. package/lib/typescript/src/NativeList.types.d.ts +14 -1
  131. package/lib/typescript/src/models.d.ts +199 -18
  132. package/lib/typescript/src/web/NativeListWebEngine.d.ts +18 -16
  133. package/lib/typescript/src/web/templates/ActionRowRenderer.d.ts +15 -0
  134. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +15 -0
  135. package/lib/typescript/src/web/templates/DataRowRenderer.d.ts +15 -0
  136. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +16 -0
  137. package/lib/typescript/src/web/templates/MarketRowRenderer.d.ts +30 -0
  138. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +15 -0
  139. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +44 -0
  140. package/lib/typescript/src/web/templates/MetricCardRowRenderer.d.ts +15 -0
  141. package/lib/typescript/src/web/templates/RailRowRenderer.d.ts +28 -0
  142. package/lib/typescript/src/web/templates/RowContainerStyle.d.ts +9 -0
  143. package/lib/typescript/src/web/templates/RowElements.d.ts +38 -0
  144. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +83 -0
  145. package/lib/typescript/src/web/templates/RowText.d.ts +9 -0
  146. package/lib/typescript/src/web/templates/RowVisual.d.ts +20 -0
  147. package/lib/typescript/src/web/templates/SectionHeaderRowRenderer.d.ts +15 -0
  148. package/lib/typescript/src/web/templates/SystemRowRenderer.d.ts +16 -0
  149. package/lib/typescript/src/web/templates/WalletGroupRowRenderer.d.ts +20 -0
  150. package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
  151. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +39 -3
  152. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +6 -0
  153. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +15 -0
  154. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/Func_void_bool.kt +78 -0
  155. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +26 -0
  156. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListManager.kt +24 -9
  157. package/nitrogen/generated/android/nativelistOnLoad.cpp +2 -0
  158. package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.cpp +8 -0
  159. package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.hpp +37 -0
  160. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +23 -2
  161. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +32 -0
  162. package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
  163. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +3 -0
  164. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +54 -0
  165. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +6 -0
  166. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +8 -2
  167. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +6 -0
  168. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +11 -2
  169. package/nitrogen/generated/shared/json/NativeListConfig.json +3 -0
  170. package/package.json +7 -6
  171. package/react-native-native-list.podspec +6 -0
  172. package/scripts/enable-container-slots.mjs +58 -0
  173. package/scripts/enable-container-slots.test.mjs +58 -0
  174. package/src/NativeList.nitro.ts +3 -0
  175. package/src/NativeList.tsx +84 -2
  176. package/src/NativeList.types.ts +14 -1
  177. package/src/NativeList.web.tsx +5 -0
  178. package/src/models.ts +320 -20
  179. package/src/validation.ts +641 -49
  180. package/src/web/NativeListWebEngine.ts +361 -1932
  181. package/src/web/templates/ActionRowRenderer.ts +123 -0
  182. package/src/web/templates/ActivityRowRenderer.ts +159 -0
  183. package/src/web/templates/DataRowRenderer.ts +212 -0
  184. package/src/web/templates/IdentityRowRenderer.ts +527 -0
  185. package/src/web/templates/MarketRowRenderer.ts +467 -0
  186. package/src/web/templates/MediaTileRowRenderer.ts +182 -0
  187. package/src/web/templates/MessageRowRenderer.ts +306 -0
  188. package/src/web/templates/MetricCardRowRenderer.ts +337 -0
  189. package/src/web/templates/RailRowRenderer.ts +136 -0
  190. package/src/web/templates/RowContainerStyle.ts +131 -0
  191. package/src/web/templates/RowElements.ts +160 -0
  192. package/src/web/templates/RowRendererRegistry.ts +111 -0
  193. package/src/web/templates/RowText.ts +181 -0
  194. package/src/web/templates/RowVisual.ts +115 -0
  195. package/src/web/templates/SectionHeaderRowRenderer.ts +243 -0
  196. package/src/web/templates/SystemRowRenderer.ts +282 -0
  197. package/src/web/templates/WalletGroupRowRenderer.ts +131 -0
  198. package/android/src/main/java/com/onekey/nativelist/NativeListRowView.kt +0 -4538
  199. package/ios/NativeListCell.swift +0 -4300
@@ -0,0 +1,734 @@
1
+ import UIKit
2
+
3
+ final class NativeListDottedUnderlineLabel: NativeListTextLabel {
4
+ var showsDottedUnderline = false {
5
+ didSet { setNeedsLayout() }
6
+ }
7
+
8
+ // OneKey patch: migrated section titles include the source 3-point underline box.
9
+ var reservesDottedUnderlineSpace = false {
10
+ didSet {
11
+ invalidateIntrinsicContentSize()
12
+ setNeedsLayout()
13
+ setNeedsDisplay()
14
+ }
15
+ }
16
+
17
+ override var intrinsicContentSize: CGSize {
18
+ var size = super.intrinsicContentSize
19
+ if reservesDottedUnderlineSpace && showsDottedUnderline { size.height += 3 }
20
+ return size
21
+ }
22
+
23
+ override func drawText(in rect: CGRect) {
24
+ let textRect =
25
+ reservesDottedUnderlineSpace && showsDottedUnderline
26
+ ? CGRect(x: rect.minX, y: rect.minY, width: rect.width, height: max(0, rect.height - 3))
27
+ : rect
28
+ super.drawText(in: textRect)
29
+ }
30
+
31
+ var dottedUnderlineColor: UIColor = .clear {
32
+ didSet {
33
+ dottedUnderlineLayer.strokeColor = dottedUnderlineColor.cgColor
34
+ setNeedsLayout()
35
+ }
36
+ }
37
+
38
+ var dottedUnderlineVerticalOffset: CGFloat = 0 {
39
+ didSet { setNeedsLayout() }
40
+ }
41
+
42
+ private let dottedUnderlineLayer = CAShapeLayer()
43
+
44
+ override init(frame: CGRect) {
45
+ super.init(frame: frame)
46
+ dottedUnderlineLayer.fillColor = UIColor.clear.cgColor
47
+ dottedUnderlineLayer.lineWidth = 1.5
48
+ dottedUnderlineLayer.lineCap = .round
49
+ dottedUnderlineLayer.lineDashPattern = [0, 4]
50
+ layer.addSublayer(dottedUnderlineLayer)
51
+ }
52
+
53
+ required init?(coder: NSCoder) {
54
+ fatalError("init(coder:) has not been implemented")
55
+ }
56
+
57
+ override func layoutSubviews() {
58
+ super.layoutSubviews()
59
+ CATransaction.begin()
60
+ CATransaction.setDisableActions(true)
61
+ defer { CATransaction.commit() }
62
+ guard showsDottedUnderline, let attributedText else {
63
+ dottedUnderlineLayer.path = nil
64
+ dottedUnderlineLayer.isHidden = true
65
+ return
66
+ }
67
+ let textWidth = ceil(
68
+ attributedText.boundingRect(
69
+ with: CGSize(width: CGFloat.greatestFiniteMagnitude, height: 24),
70
+ options: [.usesLineFragmentOrigin, .usesFontLeading],
71
+ context: nil
72
+ ).width)
73
+ dottedUnderlineLayer.frame = CGRect(
74
+ x: 0,
75
+ y: 0,
76
+ width: bounds.width,
77
+ height: bounds.height + 2 + dottedUnderlineVerticalOffset
78
+ )
79
+ // OneKey patch: explicit header underline occupies the reserved final two points.
80
+ // let y = bounds.height + 1 + dottedUnderlineVerticalOffset
81
+ let y =
82
+ reservesDottedUnderlineSpace
83
+ ? bounds.height - 1 : bounds.height + 1 + dottedUnderlineVerticalOffset
84
+ let path = UIBezierPath()
85
+ path.move(to: CGPoint(x: 1, y: y))
86
+ path.addLine(to: CGPoint(x: max(1, textWidth - 1), y: y))
87
+ dottedUnderlineLayer.path = path.cgPath
88
+ dottedUnderlineLayer.isHidden = false
89
+ }
90
+ }
91
+
92
+ final class NativeListSectionHeaderCell: NativeListRendererCell {
93
+ override class func appliesSizePreset(_ item: NativeListItem) -> Bool {
94
+ !["summary", "gallery"].contains(item.data.string("variant"))
95
+ }
96
+ override class func measure(
97
+ _ item: NativeListItem, width: CGFloat, theme: [String: Any]?, layout: String
98
+ ) -> CGFloat? {
99
+ if layout == "table" { return 28 }
100
+ if item.data.string("presentation") == "networkSelector" { return 47 }
101
+ if item.data.string("variant") == "history" {
102
+ return item.data.bool("titleLoading") ? 20 : 16
103
+ }
104
+ if item.data.string("variant") == "summary" { return 68 }
105
+ if item.data.string("variant") == "gallery" { return 32 }
106
+ if item.data.dictionary("checkbox") != nil { return 56 }
107
+ return layout == "linear" ? 30 : 36
108
+ }
109
+ override var defaultCornerRadius: CGFloat { isHighlighted ? 12 : 0 }
110
+ private let mainStack = UIStackView()
111
+ private let titleRowStack = UIStackView()
112
+ private let titleLabel = NativeListDottedUnderlineLabel()
113
+ private let titleSpinner = UIActivityIndicatorView(style: .medium)
114
+ private let subtitleLabel = NativeListTextLabel()
115
+ private let trailingStack = UIStackView()
116
+ private let accessoryButtons = [NativeListAccessoryButton(type: .system)]
117
+ private let checkboxControl = NativeListAccessoryStack(frame: .zero)
118
+ private let headerTitleIconImageView = UIImageView()
119
+ private let headerValueIconImageView = UIImageView()
120
+ private var accessoryActions: [(String, NativeSelectionTarget?)] = []
121
+ private var currentItem: NativeListItem?
122
+ private var currentTheme: [String: Any]?
123
+ private var leftInset: CGFloat = 12
124
+ private var rightInset: CGFloat = -12
125
+ private var topInset: CGFloat = 8
126
+ private var bottomInset: CGFloat = -8
127
+ private var selectorConstraints: [NSLayoutConstraint] = []
128
+ private var selectorTypographyRestorers: [() -> Void] = []
129
+ private lazy var selectorTitleTap = UITapGestureRecognizer(
130
+ target: self, action: #selector(titlePressed))
131
+ override init(frame: CGRect) {
132
+ super.init(frame: frame)
133
+ root.axis = .horizontal
134
+ root.alignment = .center
135
+ root.spacing = 12
136
+ titleSpinner.translatesAutoresizingMaskIntoConstraints = false
137
+ titleSpinner.isAccessibilityElement = false
138
+ NSLayoutConstraint.activate([
139
+ titleSpinner.widthAnchor.constraint(equalToConstant: 20),
140
+ titleSpinner.heightAnchor.constraint(equalToConstant: 20),
141
+ ])
142
+ mainStack.axis = .vertical
143
+ mainStack.alignment = .fill
144
+ mainStack.spacing = 2
145
+ mainStack.setContentHuggingPriority(UILayoutPriority(1), for: .horizontal)
146
+ mainStack.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
147
+ titleRowStack.axis = .horizontal
148
+ titleRowStack.alignment = .center
149
+ titleRowStack.spacing = 8
150
+ titleRowStack.addArrangedSubview(titleLabel)
151
+ mainStack.addArrangedSubview(titleRowStack)
152
+ mainStack.addArrangedSubview(subtitleLabel)
153
+ titleLabel.setContentHuggingPriority(.defaultLow, for: .horizontal)
154
+ titleLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
155
+ trailingStack.axis = .vertical
156
+ trailingStack.alignment = .trailing
157
+ trailingStack.spacing = 2
158
+ trailingStack.setContentHuggingPriority(.required, for: .horizontal)
159
+ trailingStack.setContentCompressionResistancePriority(.required, for: .horizontal)
160
+ trailingStack.addArrangedSubview(accessoryButtons[0])
161
+ trailingStack.addArrangedSubview(checkboxControl)
162
+ accessoryButtons[0].addTarget(self, action: #selector(valuePressed), for: .touchUpInside)
163
+ for icon in [headerTitleIconImageView, headerValueIconImageView] {
164
+ icon.translatesAutoresizingMaskIntoConstraints = false
165
+ icon.contentMode = .scaleAspectFit
166
+ NSLayoutConstraint.activate([
167
+ icon.widthAnchor.constraint(equalToConstant: 12),
168
+ icon.heightAnchor.constraint(equalToConstant: 12),
169
+ ])
170
+ }
171
+ checkboxControl.onAction = { [weak self] key, view, slot, target in
172
+ self?.emitAction(key, from: view, source: "trailingAccessory", slot: slot, target: target)
173
+ }
174
+ }
175
+ required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
176
+ override func bindContent(
177
+ _ item: NativeListItem, theme: [String: Any]?, layout: String,
178
+ checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
179
+ ) {
180
+ selectorTypographyRestorers.reversed().forEach { $0() }
181
+ selectorTypographyRestorers = []
182
+ currentItem = item
183
+ currentTheme = theme
184
+ titleSpinner.stopAnimating()
185
+ NSLayoutConstraint.deactivate(selectorConstraints)
186
+ selectorConstraints = []
187
+ root.arrangedSubviews.forEach {
188
+ root.removeArrangedSubview($0)
189
+ $0.removeFromSuperview()
190
+ }
191
+ for icon in [headerTitleIconImageView, headerValueIconImageView] {
192
+ if let parent = icon.superview as? UIStackView { parent.removeArrangedSubview(icon) }
193
+ icon.removeFromSuperview()
194
+ icon.image = nil
195
+ icon.isHidden = true
196
+ }
197
+ titleLabel.removeGestureRecognizer(selectorTitleTap)
198
+ titleLabel.isUserInteractionEnabled = false
199
+ titleLabel.showsDottedUnderline = false
200
+ titleLabel.reservesDottedUnderlineSpace = false
201
+ titleLabel.dottedUnderlineVerticalOffset = 0
202
+ for label in [titleLabel, subtitleLabel] {
203
+ label.attributedText = nil
204
+ label.text = nil
205
+ label.isHidden = true
206
+ label.numberOfLines = 1
207
+ label.lineBreakMode = .byTruncatingTail
208
+ label.textAlignment = .natural
209
+ label.rowOffsetY = 0
210
+ label.rowVerticalAlignment = nil
211
+ }
212
+ titleLabel.setContentHuggingPriority(.defaultLow, for: .horizontal)
213
+ subtitleLabel.font = nativeListFont(ofSize: 14)
214
+ subtitleLabel.textColor = nativeListColor(theme, "secondaryText", "#646464")
215
+ mainStack.alignment = .fill
216
+ mainStack.spacing = 2
217
+ titleRowStack.spacing = 8
218
+ trailingStack.axis = .vertical
219
+ trailingStack.alignment = .trailing
220
+ trailingStack.spacing = 2
221
+ let value = accessoryButtons[0]
222
+ value.setTitle(nil, for: .normal)
223
+ value.setAttributedTitle(nil, for: .normal)
224
+ value.titleLabel?.font = nativeListFont(ofSize: 16, weight: .medium)
225
+ value.titleLabel?.numberOfLines = 1
226
+ value.titleLabel?.lineBreakMode = .byTruncatingTail
227
+ value.contentHorizontalAlignment = .center
228
+ value.contentVerticalAlignment = .center
229
+ value.rowTextOffsetY = 0
230
+ value.marketLineHeight = nil
231
+ value.selectorSummaryLineHeight = nil
232
+ value.isHidden = true
233
+ value.accessibilityIdentifier = nil
234
+ value.setTitleColor(nativeListColor(theme, "primaryText", "#202020"), for: .normal)
235
+ accessoryActions = []
236
+ checkboxControl.reset()
237
+ checkboxControl.isHidden = true
238
+ leftInset = layout == "table" ? 16 : 12
239
+ rightInset = -leftInset
240
+ topInset = 8
241
+ bottomInset = -8
242
+ bindSectionHeader(item, theme: theme, layout: layout, checkboxState)
243
+ let style = item.data.dictionary("style") ?? [:]
244
+ if style["horizontalPadding"] != nil {
245
+ leftInset = CGFloat(style.double("horizontalPadding"))
246
+ rightInset = -leftInset
247
+ }
248
+ if style["verticalPadding"] != nil {
249
+ topInset = CGFloat(style.double("verticalPadding"))
250
+ bottomInset = -topInset
251
+ }
252
+ if style["lineGap"] != nil { mainStack.spacing = CGFloat(style.double("lineGap")) }
253
+ if style["trailingGap"] != nil { trailingStack.spacing = CGFloat(style.double("trailingGap")) }
254
+ applyTextStyle(item)
255
+ titleSpinner.color = titleLabel.textColor
256
+ updateTitleSpinner()
257
+ contentInsets = UIEdgeInsets(
258
+ top: topInset, left: leftInset, bottom: -bottomInset, right: -rightInset)
259
+ root.alignment =
260
+ style.dictionary("container")?.string("contentVerticalAlignment") == "top"
261
+ ? .top
262
+ : style.dictionary("container")?.string("contentVerticalAlignment") == "bottom"
263
+ ? .bottom : .center
264
+ applySelectorTypography(item)
265
+ // Legacy measured the value after selector typography (tabular digits, kern 0).
266
+ if item.data.string("presentation") == "networkSelector", item.hasExplicitHeight,
267
+ item.data.dictionary("checkbox") != nil, !item.data.string("value").isEmpty
268
+ {
269
+ let width = trailingStack.widthAnchor.constraint(
270
+ equalToConstant: accessoryButtons[0].intrinsicContentSize.width + 12 + 20)
271
+ width.isActive = true
272
+ selectorConstraints.append(width)
273
+ }
274
+ }
275
+ private func applyTextStyle(_ item: NativeListItem) {
276
+ let style = item.data.dictionary("style") ?? [:]
277
+ if let title = style.dictionary("title") {
278
+ NativeListTextStyles.applyStyledText(titleLabel, title)
279
+ }
280
+ if let subtitle = style.dictionary("subtitle") {
281
+ NativeListTextStyles.applyStyledText(subtitleLabel, subtitle)
282
+ }
283
+ if let value = style.dictionary("value") {
284
+ NativeListTextStyles.applyStyledButton(accessoryButtons[0], value)
285
+ }
286
+ }
287
+ override func bindSelectionContent(
288
+ _ item: NativeListItem,
289
+ checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
290
+ ) {
291
+ currentItem = item
292
+ checkboxControl.updateSelection(item, checkboxState: checkboxState)
293
+ if item.data.string("variant") == "summary" {
294
+ selectorTypographyRestorers.reversed().forEach { $0() }
295
+ selectorTypographyRestorers = []
296
+ updateSummaryText(item)
297
+ applyValueSegments(
298
+ item.data.dictionaries("valueSegments"), to: accessoryButtons[0], theme: currentTheme)
299
+ applyTextStyle(item)
300
+ applySelectorTypography(item)
301
+ }
302
+ }
303
+ private func bindCheckbox(
304
+ _ item: NativeListItem, _ descriptor: [String: Any],
305
+ _ checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
306
+ ) {
307
+ checkboxControl.bind(
308
+ item, descriptors: [descriptor], theme: currentTheme, style: [:], checkboxState: checkboxState
309
+ )
310
+ }
311
+ override func recycleContent() {
312
+ checkboxControl.reset()
313
+ currentItem = nil
314
+ titleSpinner.stopAnimating()
315
+ }
316
+ override func didMoveToWindow() {
317
+ super.didMoveToWindow()
318
+ updateTitleSpinner()
319
+ }
320
+ private func updateTitleSpinner() {
321
+ if window != nil, currentItem?.data.bool("titleLoading") == true {
322
+ titleSpinner.startAnimating()
323
+ } else {
324
+ titleSpinner.stopAnimating()
325
+ }
326
+ }
327
+ @objc private func titlePressed() {
328
+ if let item = currentItem {
329
+ emitAction(item.data.string("titleActionKey"), from: titleLabel, source: "leadingAction")
330
+ }
331
+ }
332
+ @objc private func valuePressed() {
333
+ if let action = accessoryActions.first {
334
+ emitAction(
335
+ action.0, from: accessoryButtons[0], source: "trailingAccessory", slot: 0, target: action.1)
336
+ }
337
+ }
338
+ private func show(_ label: UILabel, _ text: String, lines: Int) {
339
+ label.text = text
340
+ label.numberOfLines = lines
341
+ label.isHidden = text.isEmpty
342
+ }
343
+ private func bindSectionHeader(
344
+ _ item: NativeListItem,
345
+ theme: [String: Any]?,
346
+ layout: String,
347
+ _ checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
348
+ ) {
349
+ if item.data.bool("titleLoading") {
350
+ root.addArrangedSubview(titleSpinner)
351
+ root.setCustomSpacing(8, after: titleSpinner)
352
+ }
353
+ root.addArrangedSubview(mainStack)
354
+ let variant = item.data.string("variant")
355
+ // OneKey patch: title help is a separate target from checkbox and value actions.
356
+ if !item.data.string("titleActionKey").isEmpty {
357
+ titleLabel.isUserInteractionEnabled = true
358
+ titleLabel.addGestureRecognizer(selectorTitleTap)
359
+ titleLabel.setContentHuggingPriority(.required, for: .horizontal)
360
+ }
361
+ let isSummary = variant == "summary"
362
+ let isGallery = variant == "gallery"
363
+ let isTable = layout == "table"
364
+ let isNetworkSelector = item.data.string("presentation") == "networkSelector"
365
+ let isExplicitNetworkHeader = isNetworkSelector && item.hasExplicitHeight
366
+ if isExplicitNetworkHeader {
367
+ // OneKey patch: the flexible title consumes spare space before trailing totals.
368
+ trailingStack.setContentHuggingPriority(.required, for: .horizontal)
369
+ trailingStack.setContentCompressionResistancePriority(.required, for: .horizontal)
370
+ }
371
+ titleLabel.reservesDottedUnderlineSpace =
372
+ isExplicitNetworkHeader && !item.data.string("titleActionKey").isEmpty
373
+ let isHistory = variant == "history"
374
+ let headerWeight: NativeListFontWeight =
375
+ isSummary
376
+ ? .medium
377
+ : isExplicitNetworkHeader
378
+ && (item.data.dictionary("checkbox") != nil || item.data.string("titleActionKey").isEmpty)
379
+ ? .semibold
380
+ : isNetworkSelector
381
+ ? .medium
382
+ : isGallery || layout == "sectioned" ? .semibold : .regular
383
+ titleLabel.font = nativeListFont(
384
+ ofSize: isGallery ? 18 : isSummary ? 16 : isTable ? 11 : isHistory ? 12 : 14,
385
+ weight: isHistory ? .semibold : headerWeight
386
+ )
387
+ titleLabel.textColor = nativeListColor(
388
+ theme,
389
+ isSummary || isGallery ? "primaryText" : "secondaryText",
390
+ isSummary || isGallery ? "#202020" : "#646464"
391
+ )
392
+ show(titleLabel, item.data.string("title"), lines: 1)
393
+ if isNetworkSelector {
394
+ titleLabel.showsDottedUnderline =
395
+ !isExplicitNetworkHeader || !item.data.string("titleActionKey").isEmpty
396
+ titleLabel.dottedUnderlineVerticalOffset = isExplicitNetworkHeader ? 1 : 2
397
+ titleLabel.dottedUnderlineColor = nativeListColor(
398
+ theme,
399
+ "secondaryText",
400
+ "#646464"
401
+ )
402
+ leftInset = 12
403
+ rightInset = -12
404
+ let isAlphabet = isExplicitNetworkHeader && item.data.string("titleActionKey").isEmpty
405
+ topInset = isAlphabet ? 8 : 12
406
+ bottomInset = isAlphabet ? -8 : isExplicitNetworkHeader ? -12 : -15
407
+ setLineHeight(titleLabel, text: item.data.string("title"), lineHeight: 20)
408
+ } else if isHistory {
409
+ leftInset = 0
410
+ rightInset = 0
411
+ topInset = 0
412
+ bottomInset = 0
413
+ setLineHeight(
414
+ titleLabel,
415
+ text: item.data.string("title").uppercased(),
416
+ lineHeight: 16,
417
+ letterSpacing: 0.8
418
+ )
419
+ } else if !isTable && !isGallery && !isSummary {
420
+ setLineHeight(titleLabel, text: item.data.string("title"), lineHeight: 20)
421
+ if layout == "linear" {
422
+ // TokenManager's section title is a plain body label with mt=10,
423
+ // unlike the reusable 36-point SectionHeader used by sectioned lists.
424
+ titleLabel.font = nativeListFont(ofSize: 14)
425
+ topInset = 10
426
+ bottomInset = 0
427
+ }
428
+ }
429
+ if isTable {
430
+ mainStack.alignment = .leading
431
+ titleRowStack.spacing = 4
432
+ titleLabel.setContentHuggingPriority(.required, for: .horizontal)
433
+ setLineHeight(titleLabel, text: item.data.string("title"), lineHeight: 14)
434
+ topInset = 12
435
+ bottomInset = -2
436
+ if let icon = item.data.dictionary("titleIcon") {
437
+ headerTitleIconImageView.image = nativeListIcon(named: icon.string("name"))
438
+ headerTitleIconImageView.tintColor = UIColor(
439
+ nativeListHex: icon.string("tintColor", default: "#646464"),
440
+ fallback: .darkGray
441
+ )
442
+ headerTitleIconImageView.isHidden = false
443
+ titleRowStack.insertArrangedSubview(headerTitleIconImageView, at: 1)
444
+ if icon.string("name") != "ChevronGrabberVerOutline" {
445
+ titleLabel.textColor = nativeListColor(theme, "primaryText", "#202020")
446
+ setLineHeight(titleLabel, text: item.data.string("title"), lineHeight: 14)
447
+ }
448
+ }
449
+ }
450
+ if isGallery {
451
+ setLineHeight(titleLabel, text: item.data.string("title"), lineHeight: 24)
452
+ topInset = 0
453
+ bottomInset = -8
454
+ }
455
+ show(subtitleLabel, item.data.string("subtitle"), lines: 1)
456
+ if isSummary {
457
+ titleLabel.showsDottedUnderline = true
458
+ titleLabel.dottedUnderlineColor = nativeListColor(
459
+ theme,
460
+ "secondaryText",
461
+ "#646464"
462
+ )
463
+ root.addArrangedSubview(trailingStack)
464
+ // The surrounding Stack contributes mt=16/pb=12 while its XStack uses
465
+ // px=20/py=8. The collection's 8-point inset supplies the outer 8 points
466
+ // of horizontal padding, so the cell supplies the remaining 12.
467
+ leftInset = 12
468
+ rightInset = -12
469
+ topInset = 24
470
+ bottomInset = -20
471
+ setLineHeight(titleLabel, text: item.data.string("title"), lineHeight: 24)
472
+ accessoryButtons[0].accessibilityIdentifier = item.data["valueActionTestID"] as? String
473
+ let valueActionKey = item.data.string("valueActionKey")
474
+ let action: (String, NativeSelectionTarget?)? =
475
+ valueActionKey.isEmpty
476
+ ? nil
477
+ : (valueActionKey, nil)
478
+ showAccessory(
479
+ 0,
480
+ item.data.string("value"),
481
+ action: action,
482
+ color: nativeListColor(theme, "secondaryText", "#646464")
483
+ )
484
+ accessoryButtons[0].titleLabel?.font = nativeListFont(
485
+ ofSize: 16, weight: isExplicitNetworkHeader ? .medium : .regular)
486
+ setButtonLine(
487
+ accessoryButtons[0],
488
+ text: item.data.string("value"),
489
+ font: nativeListFont(ofSize: 16, weight: isExplicitNetworkHeader ? .medium : .regular),
490
+ color: nativeListColor(theme, "secondaryText", "#646464"),
491
+ lineHeight: 24
492
+ )
493
+ } else if !isGallery && !isHistory {
494
+ root.addArrangedSubview(trailingStack)
495
+ showAccessory(0, item.data.string("value"))
496
+ if isTable {
497
+ trailingStack.axis = .horizontal
498
+ trailingStack.alignment = .center
499
+ trailingStack.spacing = 4
500
+ accessoryButtons[0].titleLabel?.font = nativeListFont(ofSize: 11)
501
+ accessoryButtons[0].setTitleColor(
502
+ nativeListColor(theme, "secondaryText", "#646464"),
503
+ for: .normal
504
+ )
505
+ if let icon = item.data.dictionary("valueIcon") {
506
+ headerValueIconImageView.image = nativeListIcon(named: icon.string("name"))
507
+ headerValueIconImageView.tintColor = UIColor(
508
+ nativeListHex: icon.string("tintColor", default: "#646464"),
509
+ fallback: .darkGray
510
+ )
511
+ headerValueIconImageView.isHidden = false
512
+ trailingStack.addArrangedSubview(headerValueIconImageView)
513
+ if icon.string("name") != "ChevronGrabberVerOutline" {
514
+ accessoryButtons[0].setTitleColor(
515
+ nativeListColor(theme, "primaryText", "#202020"),
516
+ for: .normal
517
+ )
518
+ }
519
+ }
520
+ }
521
+ if let checkbox = item.data.dictionary("checkbox") {
522
+ bindCheckbox(item, checkbox, checkboxState)
523
+ }
524
+ if item.data.dictionary("checkbox") != nil && !item.data.string("value").isEmpty {
525
+ titleLabel.showsDottedUnderline = true
526
+ titleLabel.dottedUnderlineColor = nativeListColor(
527
+ theme,
528
+ "secondaryText",
529
+ "#646464"
530
+ )
531
+ trailingStack.axis = .horizontal
532
+ trailingStack.alignment = .center
533
+ trailingStack.spacing = 12
534
+ topInset = 8
535
+ bottomInset = -8
536
+ accessoryButtons[0].titleLabel?.font = nativeListTabularFont(
537
+ ofSize: 16,
538
+ weight: .medium
539
+ )
540
+ setButtonLine(
541
+ accessoryButtons[0],
542
+ text: item.data.string("value"),
543
+ font: nativeListTabularFont(ofSize: 16, weight: .medium),
544
+ color: nativeListColor(theme, "primaryText", "#202020"),
545
+ lineHeight: 24
546
+ )
547
+ }
548
+ }
549
+ applyValueSegments(
550
+ item.data.dictionaries("valueSegments"), to: accessoryButtons[0], theme: theme)
551
+ }
552
+ private func setLineHeight(
553
+ _ label: UILabel,
554
+ text: String,
555
+ lineHeight: CGFloat,
556
+ letterSpacing: CGFloat = 0
557
+ ) {
558
+ let paragraphStyle = NSMutableParagraphStyle()
559
+ paragraphStyle.minimumLineHeight = lineHeight
560
+ paragraphStyle.maximumLineHeight = lineHeight
561
+ paragraphStyle.alignment = label.textAlignment
562
+ var attributes: [NSAttributedString.Key: Any] = [
563
+ .font: label.font as Any,
564
+ .foregroundColor: label.textColor as Any,
565
+ .paragraphStyle: paragraphStyle,
566
+ ]
567
+ if currentItem?.hasExplicitHeight == true
568
+ && currentItem?.data.string("presentation") == "networkSelector"
569
+ {
570
+ let baselineOffset = max(0, (lineHeight - label.font.lineHeight) / 2)
571
+ let scale = window?.screen.scale ?? traitCollection.displayScale
572
+ attributes[.baselineOffset] =
573
+ lineHeight == 20 && scale > 0 ? ceil(baselineOffset * scale) / scale : baselineOffset
574
+ }
575
+ if letterSpacing != 0 { attributes[.kern] = letterSpacing }
576
+ label.attributedText = NSAttributedString(string: text, attributes: attributes)
577
+ }
578
+ private func setButtonLine(
579
+ _ button: UIButton,
580
+ text: String,
581
+ font: UIFont,
582
+ color: UIColor,
583
+ lineHeight: CGFloat
584
+ ) {
585
+ guard !text.isEmpty else { return }
586
+ let paragraphStyle = NSMutableParagraphStyle()
587
+ paragraphStyle.minimumLineHeight = lineHeight
588
+ paragraphStyle.maximumLineHeight = lineHeight
589
+ let isSelectorValue =
590
+ currentItem?.data.string("presentation") == "networkSelector"
591
+ && currentItem?.hasExplicitHeight == true && currentItem?.data.string("variant") != "summary"
592
+ let isSelectorSummary =
593
+ currentItem?.data.string("presentation") == "networkSelector"
594
+ && currentItem?.hasExplicitHeight == true && currentItem?.data.string("variant") == "summary"
595
+ (button as? NativeListAccessoryButton)?.selectorSummaryLineHeight =
596
+ isSelectorSummary ? lineHeight : nil
597
+ // OneKey patch: summary text uses its source line box; currency retains trailing alignment.
598
+ paragraphStyle.alignment =
599
+ isSelectorValue ? .right : isSelectorSummary ? .natural : .center
600
+ if isSelectorSummary {
601
+ button.contentHorizontalAlignment = .leading
602
+ button.titleLabel?.textAlignment = .natural
603
+ }
604
+ if isSelectorValue {
605
+ button.contentHorizontalAlignment = .trailing
606
+ button.titleLabel?.textAlignment = .right
607
+ }
608
+ let baselineOffset: CGFloat =
609
+ isSelectorValue || isSelectorSummary
610
+ ? max(0, (lineHeight - font.lineHeight) / 2) : 0
611
+ let attributes: [NSAttributedString.Key: Any] = [
612
+ .font: font,
613
+ .foregroundColor: color,
614
+ .paragraphStyle: paragraphStyle,
615
+ .baselineOffset: baselineOffset,
616
+ ]
617
+ button.setAttributedTitle(
618
+ NSAttributedString(string: text, attributes: attributes),
619
+ for: .normal
620
+ )
621
+ }
622
+ private func applyValueSegments(
623
+ _ segments: [[String: Any]], to button: UIButton, theme: [String: Any]?
624
+ ) {
625
+ guard !segments.isEmpty else { return }
626
+ let value = NSMutableAttributedString(string: "")
627
+ let color = nativeListColor(theme, "primaryText", "#202020")
628
+ // OneKey patch: rich currency changes font runs without dropping the established line baseline.
629
+ let current = button.attributedTitle(for: .normal)
630
+ var attributes =
631
+ current.flatMap { $0.length > 0 ? $0.attributes(at: 0, effectiveRange: nil) : nil } ?? [:]
632
+ attributes[.foregroundColor] = color
633
+ if currentItem?.data.string("presentation") == "networkSelector"
634
+ && currentItem?.hasExplicitHeight == true
635
+ {
636
+ let paragraph =
637
+ (attributes[.paragraphStyle] as? NSParagraphStyle)?.mutableCopy()
638
+ as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
639
+ paragraph.alignment = .right
640
+ attributes[.paragraphStyle] = paragraph
641
+ }
642
+ for segment in segments {
643
+ attributes[.font] = nativeListTabularFont(
644
+ ofSize: segment.string("style") == "subscript" ? 10 : 16, weight: .medium)
645
+ value.append(NSAttributedString(string: segment.string("text"), attributes: attributes))
646
+ }
647
+ button.setAttributedTitle(value, for: .normal)
648
+ }
649
+ private func showAccessory(
650
+ _ index: Int,
651
+ _ value: String,
652
+ action: (String, NativeSelectionTarget?)? = nil,
653
+ color: UIColor? = nil
654
+ ) {
655
+ guard accessoryButtons.indices.contains(index), !value.isEmpty else { return }
656
+ let button = accessoryButtons[index]
657
+ button.isHidden = false
658
+ button.setTitle(value, for: .normal)
659
+ button.setContentHuggingPriority(.required, for: .horizontal)
660
+ button.setContentCompressionResistancePriority(.required, for: .horizontal)
661
+ if let color { button.setTitleColor(color, for: .normal) }
662
+ while accessoryActions.count <= index { accessoryActions.append(("", nil)) }
663
+ accessoryActions[index] = action ?? ("", nil)
664
+ }
665
+ private func updateSummaryText(_ item: NativeListItem) {
666
+ let title = item.data.string("title")
667
+ titleLabel.isHidden = title.isEmpty
668
+ setLineHeight(titleLabel, text: title, lineHeight: 24)
669
+
670
+ let value = item.data.string("value")
671
+ let isExplicitNetworkHeader =
672
+ item.data.string("presentation") == "networkSelector" && item.hasExplicitHeight
673
+ let valueButton = accessoryButtons[0]
674
+ valueButton.isHidden = value.isEmpty
675
+ if value.isEmpty {
676
+ valueButton.setTitle(nil, for: .normal)
677
+ valueButton.setAttributedTitle(nil, for: .normal)
678
+ } else {
679
+ setButtonLine(
680
+ valueButton,
681
+ text: value,
682
+ font: nativeListFont(ofSize: 16, weight: isExplicitNetworkHeader ? .medium : .regular),
683
+ color: nativeListColor(currentTheme, "secondaryText", "#646464"),
684
+ lineHeight: 24
685
+ )
686
+ }
687
+ }
688
+ private func selectorTabularFont(_ font: UIFont) -> UIFont {
689
+ var settings =
690
+ font.fontDescriptor.fontAttributes[.featureSettings] as? [[UIFontDescriptor.FeatureKey: Int]]
691
+ ?? []
692
+ settings.removeAll { $0[.type] == kNumberSpacingType }
693
+ settings.append([.type: kNumberSpacingType, .selector: kMonospacedNumbersSelector])
694
+ return UIFont(
695
+ descriptor: font.fontDescriptor.addingAttributes([.featureSettings: settings]),
696
+ size: font.pointSize)
697
+ }
698
+ private func selectorTabularText(_ original: NSAttributedString) -> NSAttributedString {
699
+ let result = NSMutableAttributedString(attributedString: original)
700
+ // OneKey patch: body typography explicitly supplies letterSpacing=0 in Tamagui.
701
+ result.addAttribute(.kern, value: 0, range: NSRange(location: 0, length: result.length))
702
+ original.enumerateAttribute(.font, in: NSRange(location: 0, length: original.length)) {
703
+ value, range, _ in
704
+ if let font = value as? UIFont {
705
+ result.addAttribute(.font, value: self.selectorTabularFont(font), range: range)
706
+ }
707
+ }
708
+ return result
709
+ }
710
+ private func applySelectorTypography(_ item: NativeListItem) {
711
+ guard
712
+ ["accountSelector", "networkSelector", "walletSidebar"].contains(
713
+ item.data.string("presentation"))
714
+ else { return }
715
+ func visit(_ view: UIView) {
716
+ if let button = view as? UIButton {
717
+ if let original = button.attributedTitle(for: .normal) {
718
+ selectorTypographyRestorers.append { button.setAttributedTitle(original, for: .normal) }
719
+ button.setAttributedTitle(selectorTabularText(original), for: .normal)
720
+ }
721
+ } else if let label = view as? UILabel, let font = label.font {
722
+ let original = label.attributedText
723
+ selectorTypographyRestorers.append {
724
+ label.font = font
725
+ label.attributedText = original
726
+ }
727
+ label.font = selectorTabularFont(font)
728
+ if let original { label.attributedText = selectorTabularText(original) }
729
+ }
730
+ for child in view.subviews { visit(child) }
731
+ }
732
+ visit(contentView)
733
+ }
734
+ }