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

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
@@ -4,10 +4,70 @@ import UIKit
4
4
  import UniformTypeIdentifiers
5
5
 
6
6
  final class NativeListView: UIView {
7
+ private var refreshEmittedForDrag = false
8
+ private var minimumDragOffset: CGFloat = 0
9
+ private var containerSlotHeights: [CGFloat] = [0, 0, 0]
10
+ // Fabric keeps assigning each slot root the frame React computed (inset, 0, width, height).
11
+ // Each root therefore lives in a list-owned host whose origin the list alone controls, so a
12
+ // React layout update can never move a slot out of its native position, even for a frame.
13
+ private var reactContainerSlots: [(content: UIView, host: UIView)] = []
14
+ private var lastLaidOutContentHeight: CGFloat?
15
+ private var needsContentShrinkCorrection = false
16
+ private var contentShrinkCorrectionScheduled = false
17
+
18
+ @objc func mountContainerSlot(_ view: UIView, atIndex index: Int) {
19
+ let host = UIView()
20
+ // Clipping to the reported height keeps new content from overlapping rows until the list
21
+ // has reserved space for it.
22
+ host.clipsToBounds = true
23
+ host.addSubview(view)
24
+ reactContainerSlots.insert((view, host), at: min(index, reactContainerSlots.count))
25
+ collectionView.addSubview(host)
26
+ layoutContainerSlots()
27
+ setNeedsLayout()
28
+ }
29
+
30
+ @objc func unmountContainerSlot(_ view: UIView) {
31
+ reactContainerSlots.removeAll { slot in
32
+ guard slot.content === view else { return false }
33
+ view.removeFromSuperview()
34
+ slot.host.removeFromSuperview()
35
+ return true
36
+ }
37
+ }
38
+
39
+ func setContainerSlotHeightsJson(_ json: String) {
40
+ guard let data = json.data(using: .utf8),
41
+ let heights = try? JSONSerialization.jsonObject(with: data) as? [Double],
42
+ heights.count == 3, heights.allSatisfy({ $0.isFinite && $0 >= 0 }) else { return }
43
+ containerSlotHeights = heights.map { CGFloat($0) }
44
+ if let config { configureLayout(config) }
45
+ layoutContainerSlots()
46
+ setNeedsLayout()
47
+ }
48
+
49
+ private func layoutContainerSlots() {
50
+ let empty = config?.items.isEmpty ?? true
51
+ let header = containerSlotHeights[0]
52
+ let emptyHeight = empty ? containerSlotHeights[1] : 0
53
+ let footer = containerSlotHeights[2]
54
+ let paddingTop = config?.contentPaddingTop ?? 0
55
+ let paddingBottom = config?.contentPaddingBottom ?? 0
56
+ let footerY = max(paddingTop + header + emptyHeight,
57
+ collectionView.contentSize.height - paddingBottom - footer)
58
+ let positions = [paddingTop, paddingTop + header, footerY]
59
+ for (index, slot) in reactContainerSlots.prefix(3).enumerated() {
60
+ slot.host.isHidden = index == 1 && !empty
61
+ // React places the root at the horizontal inset inside this full-width host.
62
+ slot.host.frame = CGRect(x: 0, y: positions[index],
63
+ width: collectionView.bounds.width, height: containerSlotHeights[index])
64
+ }
65
+ }
66
+
7
67
  private final class ActionAnchorRecord {
8
68
  let token: String
9
69
  weak var sourceView: UIView?
10
- weak var ownerCell: NativeListCell?
70
+ weak var ownerCell: NativeListRowHost?
11
71
  let bindingEpoch: Int
12
72
  var open = false
13
73
  var invalidatedReason: String?
@@ -47,6 +107,26 @@ final class NativeListView: UIView {
47
107
  case end(Bool)
48
108
  }
49
109
 
110
+ private var scrollPositionTracker = NativeListScrollPositionTracker()
111
+ var onScrollPositionThresholdChange: ((Bool) -> Void)? {
112
+ didSet {
113
+ scrollPositionTracker.resetDelivery()
114
+ emitScrollPositionThresholdIfNeeded()
115
+ }
116
+ }
117
+
118
+ func setScrollPositionThresholdsJson(_ json: String) {
119
+ scrollPositionTracker.configure(json: json)
120
+ emitScrollPositionThresholdIfNeeded()
121
+ }
122
+
123
+ private func emitScrollPositionThresholdIfNeeded() {
124
+ guard let callback = onScrollPositionThresholdChange,
125
+ let next = scrollPositionTracker.update(offset: Double(max(0,
126
+ collectionView.contentOffset.y + collectionView.contentInset.top))) else { return }
127
+ callback(next)
128
+ }
129
+
50
130
  var onRowAction: ((String) -> Void)?
51
131
  var onActionAnchorInvalidated: ((String) -> Void)?
52
132
  var onSelectionDelta: ((String) -> Void)?
@@ -60,9 +140,17 @@ final class NativeListView: UIView {
60
140
  }
61
141
 
62
142
  private let flowLayout = NativeListFlowLayout()
63
- private lazy var collectionView = NativeListCollectionView(frame: .zero, collectionViewLayout: flowLayout)
143
+ private lazy var collectionView: NativeListCollectionView = {
144
+ let view = NativeListCollectionView(frame: .zero, collectionViewLayout: flowLayout)
145
+ view.onContentLayout = { [weak self] in
146
+ self?.layoutContainerSlots()
147
+ self?.contentLayoutDidChange()
148
+ }
149
+ return view
150
+ }()
64
151
  private let footerContainer = UIView()
65
- private let footerCell = NativeListCell(frame: .zero)
152
+ private var footerCell: NativeListRowHost = NativeListRendererRegistry.create(.action)
153
+ private var footerRendererKey = NativeListRendererKey.action
66
154
  private let sectionIndexView = NativeListSectionIndexView()
67
155
  private let sectionIndexPreview = NativeListSectionIndexPreviewView()
68
156
  private var sectionIndexLayoutConstraints: [NSLayoutConstraint] = []
@@ -102,13 +190,13 @@ final class NativeListView: UIView {
102
190
  private var keyboardDismissMode: NativeListKeyboardDismissMode = .none
103
191
  private var keyboardShouldPersistTaps: NativeListKeyboardShouldPersistTaps = .never
104
192
  private var interactiveReorderSource: (key: String, index: Int)?
105
- private weak var interactiveReorderCell: NativeListCell?
193
+ private weak var interactiveReorderCell: NativeListRowHost?
106
194
  private var interactiveReorderCompactKey: String?
107
195
  private var interactiveReorderUsesAtomicTargeting = false
108
196
  private var interactiveReorderTargetIndex: Int?
109
197
  private var interactiveReorderTargetKey: String?
110
198
  private var interactiveReorderLockedCrossAxisPosition: CGFloat?
111
- private var interactiveReorderTransformedCells: [NativeListCell] = []
199
+ private var interactiveReorderTransformedCells: [NativeListRowHost] = []
112
200
  private var deferredReorderReconfigureKeys = Set<String>()
113
201
  private let interactiveReorderPlaceholder = UIView()
114
202
  private var interactiveReorderAnimator: UIViewPropertyAnimator?
@@ -129,7 +217,7 @@ final class NativeListView: UIView {
129
217
 
130
218
  override init(frame: CGRect) {
131
219
  super.init(frame: frame)
132
- collectionView.register(NativeListCell.self, forCellWithReuseIdentifier: NativeListCell.reuseIdentifier)
220
+ NativeListRendererRegistry.register(in: collectionView)
133
221
  collectionView.backgroundColor = .clear
134
222
  collectionView.delegate = self
135
223
  collectionView.dragDelegate = self
@@ -228,9 +316,9 @@ final class NativeListView: UIView {
228
316
  guard let self,
229
317
  let item = self.itemsByKey[key],
230
318
  let cell = collectionView.dequeueReusableCell(
231
- withReuseIdentifier: NativeListCell.reuseIdentifier,
319
+ withReuseIdentifier: NativeListRendererRegistry.reuseIdentifier(for: item.rendererKey),
232
320
  for: indexPath
233
- ) as? NativeListCell else { return nil }
321
+ ) as? NativeListRowHost else { return nil }
234
322
  cell.onAction = { [weak self] item, action, target, origin in
235
323
  self?.handleAction(item: item, actionKey: action, target: target, origin: origin)
236
324
  }
@@ -329,8 +417,37 @@ final class NativeListView: UIView {
329
417
  lastLayoutSize = bounds.size
330
418
  if lastLayoutDirection != direction, let config {
331
419
  configureLayout(config)
420
+ rebindRowsForLayoutDirection(config)
332
421
  }
333
422
  performPendingScrollIfNeeded()
423
+ layoutContainerSlots()
424
+ }
425
+
426
+ // A layout-direction change may arrive without a layout pass (semantic attribute or trait).
427
+ override var semanticContentAttribute: UISemanticContentAttribute {
428
+ didSet { if semanticContentAttribute != oldValue { setNeedsLayout() } }
429
+ }
430
+
431
+ override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
432
+ super.traitCollectionDidChange(previousTraitCollection)
433
+ if previousTraitCollection?.layoutDirection != traitCollection.layoutDirection {
434
+ setNeedsLayout()
435
+ }
436
+ }
437
+
438
+ /// Renderers resolve start/end alignment at bind time, and the layout direction is one of a
439
+ /// cell's bound inputs; rebinding visible rows and the footer re-resolves it. A cell whose
440
+ /// bound direction already matches only refreshes selection and appearance. Offscreen rows
441
+ /// rebind when they are next dequeued.
442
+ private func rebindRowsForLayoutDirection(_ config: NativeListConfig) {
443
+ for case let cell as NativeListRowHost in collectionView.visibleCells {
444
+ guard let indexPath = collectionView.indexPath(for: cell),
445
+ let item = item(at: indexPath) else { continue }
446
+ bind(cell: cell, item: item, itemIndex: indexPath.item)
447
+ }
448
+ if let footer = config.fixedFooter, !footerCell.isHidden {
449
+ bind(cell: footerCell, item: footer, itemIndex: nil)
450
+ }
334
451
  }
335
452
 
336
453
  func applySnapshotJson(_ json: String) {
@@ -352,7 +469,10 @@ final class NativeListView: UIView {
352
469
  cancelInteractiveReorderForStructuralUpdate()
353
470
  }
354
471
  let oldItems = itemsByKey
472
+ // Chrome lives outside the row payload, so a changed list style must rebind
473
+ // rows whose own content is unchanged.
355
474
  let themeChanged = !dictionariesEqual(config?.theme, next.theme)
475
+ || !dictionariesEqual(config?.listStyle, next.listStyle)
356
476
  if config?.generation != next.generation { endReachedGeneration = nil }
357
477
  config = next
358
478
  itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
@@ -371,7 +491,13 @@ final class NativeListView: UIView {
371
491
  })
372
492
  changedKeys.formUnion(deferredReorderReconfigureKeys)
373
493
  deferredReorderReconfigureKeys.removeAll()
374
- snapshot.reconfigureItems(changedKeys.filter { itemsByKey[$0] != nil })
494
+ let retainedKeys = Set(dataSource.snapshot().itemIdentifiers).intersection(keys)
495
+ let changedRetainedKeys = changedKeys.filter { retainedKeys.contains($0) }
496
+ // Reconfigure must keep its existing reuse identifier. A same-key renderer
497
+ // change needs reload so UIKit dequeues from the new structural pool.
498
+ let replacedKeys = changedRetainedKeys.filter { oldItems[$0]?.rendererKey != itemsByKey[$0]?.rendererKey }
499
+ snapshot.reloadItems(Array(replacedKeys))
500
+ snapshot.reconfigureItems(Array(changedRetainedKeys.subtracting(replacedKeys)))
375
501
  dataSource.apply(snapshot, animatingDifferences: false) { [weak self] in
376
502
  guard let self else { return }
377
503
  self.collectionView.layoutIfNeeded()
@@ -444,7 +570,7 @@ final class NativeListView: UIView {
444
570
  for indexPath in collectionView.indexPathsForVisibleItems {
445
571
  guard let item = item(at: indexPath),
446
572
  marketQuoteKeys.contains(item.key),
447
- let cell = collectionView.cellForItem(at: indexPath) as? NativeListCell else { continue }
573
+ let cell = collectionView.cellForItem(at: indexPath) as? NativeListRowHost else { continue }
448
574
  cell.updateMarketQuote(item, theme: current.theme)
449
575
  }
450
576
  if changedKeys.isEmpty {
@@ -635,6 +761,39 @@ final class NativeListView: UIView {
635
761
  collectionView.setContentOffset(point, animated: animated)
636
762
  }
637
763
 
764
+ private func contentLayoutDidChange() {
765
+ let height = collectionView.contentSize.height
766
+ if config?.orientation != "horizontal",
767
+ let previous = lastLaidOutContentHeight, height < previous {
768
+ needsContentShrinkCorrection = true
769
+ }
770
+ lastLaidOutContentHeight = height
771
+ scheduleContentShrinkCorrection()
772
+ }
773
+
774
+ private func scheduleContentShrinkCorrection() {
775
+ guard needsContentShrinkCorrection, !contentShrinkCorrectionScheduled, !disposed else { return }
776
+ contentShrinkCorrectionScheduled = true
777
+ // Wait for the collection layout and ancestor pager inset observers to settle.
778
+ DispatchQueue.main.async { [weak self] in
779
+ guard let self else { return }
780
+ self.contentShrinkCorrectionScheduled = false
781
+ guard !self.disposed, self.needsContentShrinkCorrection,
782
+ !self.collectionView.isTracking, !self.collectionView.isDragging,
783
+ !self.collectionView.isDecelerating,
784
+ self.collectionView.refreshControl?.isRefreshing != true,
785
+ self.config?.refreshing != true else { return }
786
+ self.needsContentShrinkCorrection = false
787
+ guard self.config?.orientation != "horizontal", self.collectionView.bounds.height > 0 else { return }
788
+ let insets = self.collectionView.adjustedContentInset
789
+ let maximum = max(-insets.top,
790
+ self.collectionView.contentSize.height - self.collectionView.bounds.height + insets.bottom)
791
+ if self.collectionView.contentOffset.y > maximum {
792
+ self.setScrollOffset(self.collectionView.contentOffset.y, animated: false)
793
+ }
794
+ }
795
+ }
796
+
638
797
  func setRefreshing(_ refreshing: Bool) {
639
798
  guard var current = config else { return }
640
799
  current.refreshing = refreshing
@@ -643,6 +802,7 @@ final class NativeListView: UIView {
643
802
  collectionView.refreshControl?.beginRefreshing()
644
803
  } else {
645
804
  collectionView.refreshControl?.endRefreshing()
805
+ scheduleContentShrinkCorrection()
646
806
  }
647
807
  }
648
808
 
@@ -655,11 +815,14 @@ final class NativeListView: UIView {
655
815
  flowLayout.minimumLineSpacing = config.itemSpacing
656
816
  flowLayout.minimumInteritemSpacing = config.itemSpacing
657
817
  flowLayout.sectionInset = UIEdgeInsets(
658
- top: config.contentPaddingTop,
818
+ top: config.contentPaddingTop + containerSlotHeights[0],
659
819
  left: config.contentPaddingHorizontal + (isRightToLeft ? indexGutter : 0),
660
- bottom: config.contentPaddingBottom,
820
+ bottom: config.contentPaddingBottom + containerSlotHeights[2],
661
821
  right: config.contentPaddingHorizontal + (isRightToLeft ? 0 : indexGutter)
662
822
  )
823
+ flowLayout.minimumContainerContentHeight = config.items.isEmpty
824
+ ? config.contentPaddingTop + config.contentPaddingBottom + containerSlotHeights.reduce(0, +)
825
+ : 0
663
826
  flowLayout.stickyItemIndexes = config.stickyHeaders
664
827
  ? Set(config.items.enumerated().compactMap {
665
828
  $0.element.type == "sectionHeader" && $0.element.data.bool("sticky", default: true) && $0.element.data.string("variant") != "summary"
@@ -685,7 +848,7 @@ final class NativeListView: UIView {
685
848
  let indexPath = collectionView.indexPathForItem(at: point),
686
849
  let item = item(at: indexPath),
687
850
  item.isReorderable,
688
- let cell = collectionView.cellForItem(at: indexPath) as? NativeListCell,
851
+ let cell = collectionView.cellForItem(at: indexPath) as? NativeListRowHost,
689
852
  cell.canStartWalletGroupReorder(at: gesture.location(in: cell)) else {
690
853
  interactiveReorderSource = nil
691
854
  interactiveReorderCell = nil
@@ -981,9 +1144,9 @@ final class NativeListView: UIView {
981
1144
  animator.startAnimation()
982
1145
  }
983
1146
 
984
- private func walletGroupCell(for key: String) -> NativeListCell? {
1147
+ private func walletGroupCell(for key: String) -> NativeListRowHost? {
985
1148
  guard let index = dataSource.snapshot().indexOfItem(key) else { return nil }
986
- return collectionView.cellForItem(at: IndexPath(item: index, section: 0)) as? NativeListCell
1149
+ return collectionView.cellForItem(at: IndexPath(item: index, section: 0)) as? NativeListRowHost
987
1150
  }
988
1151
 
989
1152
  // OneKey patch: flow layout sizes an interactive move in UIKit's in-flight order,
@@ -1017,7 +1180,7 @@ final class NativeListView: UIView {
1017
1180
  let distance = CGFloat(68) + flowLayout.minimumLineSpacing
1018
1181
  let updates = { [weak self] in
1019
1182
  guard let self else { return }
1020
- for case let cell as NativeListCell in self.collectionView.visibleCells {
1183
+ for case let cell as NativeListRowHost in self.collectionView.visibleCells {
1021
1184
  guard let indexPath = self.collectionView.indexPath(for: cell),
1022
1185
  indexPath.item != source.index else { continue }
1023
1186
  let offset: CGFloat
@@ -1286,8 +1449,14 @@ final class NativeListView: UIView {
1286
1449
 
1287
1450
  private func syncSectionIndexToVisibleRows() {
1288
1451
  guard !sectionIndexScrubbing, !sectionIndexEntries.isEmpty else { return }
1289
- let firstVisible = collectionView.indexPathsForVisibleItems.map(\.item).min() ?? 0
1290
- let index = sectionIndexEntries.lastIndex { $0.position <= firstVisible }
1452
+ let offset = collectionView.contentOffset.y + collectionView.adjustedContentInset.top
1453
+ // Legacy semantics: a header at the first position is active even while overscrolled;
1454
+ // no entry is active while rows above the first header are still visible.
1455
+ let index = sectionIndexEntries.lastIndex {
1456
+ if $0.position == 0 { return true }
1457
+ guard let attributes = flowLayout.layoutAttributesForItem(at: IndexPath(item: $0.position, section: 0)) else { return false }
1458
+ return attributes.frame.minY <= offset + 1
1459
+ }
1291
1460
  sectionIndexView.setActiveIndex(index)
1292
1461
  }
1293
1462
 
@@ -1303,6 +1472,7 @@ final class NativeListView: UIView {
1303
1472
  } else {
1304
1473
  collectionView.refreshControl = nil
1305
1474
  }
1475
+ if !config.refreshing { scheduleContentShrinkCorrection() }
1306
1476
  }
1307
1477
 
1308
1478
  private func configureFooter(_ config: NativeListConfig) {
@@ -1311,13 +1481,27 @@ final class NativeListView: UIView {
1311
1481
  footerCell.isHidden = true
1312
1482
  return
1313
1483
  }
1484
+ if footer.rendererKey != footerRendererKey {
1485
+ let previous = footerCell
1486
+ previous.prepareForReuse()
1487
+ footerCell = NativeListRendererRegistry.create(footer.rendererKey)
1488
+ footerCell.onAction = previous.onAction
1489
+ footerCell.onBindingInvalidated = previous.onBindingInvalidated
1490
+ for recognizer in previous.gestureRecognizers ?? [] { footerCell.addGestureRecognizer(recognizer) }
1491
+ previous.removeFromSuperview()
1492
+ footerContainer.addSubview(footerCell)
1493
+ footerCell.frame = footerContainer.bounds
1494
+ footerCell.autoresizingMask = [.flexibleWidth, .flexibleHeight]
1495
+ footerRendererKey = footer.rendererKey
1496
+ }
1314
1497
  footerCell.isHidden = false
1315
1498
  footerHeightConstraint.constant = rowHeight(footer)
1316
1499
  bind(cell: footerCell, item: footer, itemIndex: nil)
1317
1500
  }
1318
1501
 
1319
- private func bind(cell: NativeListCell, item: NativeListItem, itemIndex: Int? = nil) {
1502
+ private func bind(cell: NativeListRowHost, item: NativeListItem, itemIndex: Int? = nil) {
1320
1503
  guard let config else { return }
1504
+ cell.listStyle = config.listStyle
1321
1505
  cell.bind(
1322
1506
  item: item,
1323
1507
  theme: config.theme,
@@ -1360,7 +1544,7 @@ final class NativeListView: UIView {
1360
1544
  item.isRowPressEnabled else { return }
1361
1545
  let actionKey = item.data.string("longPressActionKey")
1362
1546
  guard !actionKey.isEmpty else { return }
1363
- let origin = (collectionView.cellForItem(at: indexPath) as? NativeListCell)?.rowActionOrigin()
1547
+ let origin = (collectionView.cellForItem(at: indexPath) as? NativeListRowHost)?.rowActionOrigin()
1364
1548
  origin?.windowPoint = gesture.location(in: window)
1365
1549
  handleAction(item: item, actionKey: actionKey, target: nil, origin: origin)
1366
1550
  }
@@ -1442,7 +1626,7 @@ final class NativeListView: UIView {
1442
1626
  }
1443
1627
  for indexPath in collectionView.indexPathsForVisibleItems {
1444
1628
  guard let item = item(at: indexPath),
1445
- let cell = collectionView.cellForItem(at: indexPath) as? NativeListCell else { continue }
1629
+ let cell = collectionView.cellForItem(at: indexPath) as? NativeListRowHost else { continue }
1446
1630
  if changedSummaryKeys.contains(item.key) {
1447
1631
  bind(cell: cell, item: item, itemIndex: indexPath.item)
1448
1632
  continue
@@ -1470,6 +1654,7 @@ final class NativeListView: UIView {
1470
1654
  current.layout == next.layout,
1471
1655
  current.orientation == next.orientation,
1472
1656
  current.gridColumns == next.gridColumns,
1657
+ dictionariesEqual(current.listStyle, next.listStyle),
1473
1658
  current.stickyHeaders == next.stickyHeaders,
1474
1659
  current.contentPadding == next.contentPadding,
1475
1660
  current.contentPaddingHorizontal == next.contentPaddingHorizontal,
@@ -1480,6 +1665,7 @@ final class NativeListView: UIView {
1480
1665
  current.rowPressToggles == next.rowPressToggles,
1481
1666
  current.reorderable == next.reorderable,
1482
1667
  current.pullToRefresh == next.pullToRefresh,
1668
+ current.refreshTriggerDistance == next.refreshTriggerDistance,
1483
1669
  current.refreshing == next.refreshing,
1484
1670
  current.loadMore == next.loadMore,
1485
1671
  current.endReachedThreshold == next.endReachedThreshold,
@@ -1517,6 +1703,7 @@ final class NativeListView: UIView {
1517
1703
  guard current.layout == next.layout,
1518
1704
  current.orientation == next.orientation,
1519
1705
  current.gridColumns == next.gridColumns,
1706
+ dictionariesEqual(current.listStyle, next.listStyle),
1520
1707
  current.stickyHeaders == next.stickyHeaders,
1521
1708
  current.contentPadding == next.contentPadding,
1522
1709
  current.contentPaddingHorizontal == next.contentPaddingHorizontal,
@@ -1670,149 +1857,29 @@ final class NativeListView: UIView {
1670
1857
 
1671
1858
  private func rowHeight(
1672
1859
  _ item: NativeListItem,
1673
- usingCompactReorderHeight: Bool = true
1860
+ usingCompactReorderHeight: Bool = true,
1861
+ allocatedWidth: CGFloat? = nil
1674
1862
  ) -> CGFloat {
1675
1863
  // OneKey patch: honor selector baseline geometry; keep compact drag sizing.
1676
- if item.type != "walletGroup", item.data["height"] != nil { return CGFloat(item.data.double("height")) }
1677
- if item.type == "system", item.data.string("variant") == "spacer" {
1678
- return CGFloat(item.data.int("height"))
1679
- }
1680
- // OneKey patch: warning height follows the current native font and available width.
1681
- if item.type == "system", item.data.string("variant") == "warning" {
1682
- let textWidth = max(1, collectionView.bounds.width - (config?.contentPaddingHorizontal ?? 0) * 2 - 24)
1683
- func textHeight(_ key: String, weight: NativeListFontWeight) -> CGFloat {
1684
- let paragraph = NSMutableParagraphStyle()
1685
- paragraph.minimumLineHeight = 20
1686
- paragraph.maximumLineHeight = 20
1687
- return ceil((item.data.string(key) as NSString).boundingRect(with: CGSize(width: textWidth, height: .greatestFiniteMagnitude), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font: nativeListFont(ofSize: 14, weight: weight), .paragraphStyle: paragraph], context: nil).height / 20) * 20
1688
- }
1689
- return 32 + textHeight("title", weight: .medium) + textHeight("message", weight: .regular)
1690
- }
1691
- if item.type == "walletGroup" {
1692
- if usingCompactReorderHeight, item.key == interactiveReorderCompactKey { return 68 }
1693
- let childCount = item.data.dictionaries("children").count
1694
- // OneKey patch: wallet badges contribute their own member heights.
1695
- // return CGFloat((childCount + 1) * 68 + childCount * 12)
1696
- let members = [item.data.dictionary("parent")].compactMap { $0 } + item.data.dictionaries("children")
1697
- return members.reduce(CGFloat(childCount * 12 + (members.first?["height"] != nil ? 2 : 0))) { total, data in
1698
- total + CGFloat(data.double("height", default: data.dictionaries("badges").isEmpty ? 68 : 92))
1699
- }
1864
+ if item.type == "walletGroup", usingCompactReorderHeight, item.key == interactiveReorderCompactKey { return 68 }
1865
+ if let height = item.styledHeight { return height }
1866
+ // Legacy WalletGroup ignored `row.height` (its height comes from its members);
1867
+ // `style.container.height` above still wins.
1868
+ if item.type != "walletGroup", item.data["height"] != nil {
1869
+ return CGFloat(item.data.double("height"))
1700
1870
  }
1701
- if item.type == "identity", item.data.string("presentation") == "walletSidebar" {
1702
- // OneKey patch: default sidebar badge geometry is 24 points taller.
1703
- // return 68
1704
- return item.data.dictionaries("badges").isEmpty ? 68 : 92
1705
- }
1706
- if item.type == "identity", item.data.string("presentation") == "networkSelector" {
1707
- return 47
1708
- }
1709
- let base: CGFloat
1710
- switch item.type {
1711
- case "rail": base = 40
1712
- case "activity": base = item.data.dictionaries("footerActions").isEmpty ? 60 : 100
1713
- case "message": base = messageHeight(item)
1714
- case "mediaTile": base = 244
1715
- case "metricCard":
1716
- base = item.data.string("variant") == "activity"
1717
- ? 160 + 1 / UIScreen.main.scale
1718
- : item.data.string("variant") == "performance" ? 178 : 132
1719
- case "sectionHeader":
1720
- let variant = item.data.string("variant")
1721
- let isNetworkSelector = item.data.string("presentation") == "networkSelector"
1722
- let isHistory = variant == "history" ||
1723
- item.key.hasPrefix("history-") ||
1724
- (item.sectionKey?.hasPrefix("history-") ?? false)
1725
- base = config?.layout == "table"
1726
- ? 28
1727
- : isNetworkSelector
1728
- ? 47
1729
- : isHistory
1730
- ? 16
1731
- : variant == "summary"
1732
- ? 68
1733
- : variant == "gallery"
1734
- ? 32
1735
- : item.data.dictionary("checkbox") != nil
1736
- ? 56
1737
- : config?.layout == "linear" ? 30 : 36
1738
- case "system":
1739
- if item.data.string("variant") == "loading" && item.data.string("loadingStyle") == "skeleton" {
1740
- base = 56
1741
- } else if item.data.string("variant") == "loading" && item.data.string("loadingStyle") == "spinner" {
1742
- base = 52
1743
- } else if item.data.string("presentation") == "market" {
1744
- base = item.data.string("variant") == "loading" ? 68 : 44
1745
- } else {
1746
- switch item.data.string("variant") {
1747
- case "noMatch", "end": base = 36
1748
- case "retry": base = 44
1749
- default: base = 56
1750
- }
1751
- }
1752
- case "action":
1753
- base = item.data.string("presentation") == "accountSelector"
1754
- ? 48
1755
- : item.data.dictionary("icon") == nil ? 44 : 60
1756
- case "dataRow":
1757
- base = item.data.dictionaries("columns").contains {
1758
- !$0.string("secondaryText").isEmpty
1759
- } ? 60 : 56
1760
- case "market":
1761
- let style = item.data.dictionary("style")
1762
- let imageHeight = CGFloat(style?.dictionary("image")?.double(
1763
- "height",
1764
- default: item.data.string("variant") == "stock" ? 40 : 32
1765
- ) ?? (item.data.string("variant") == "stock" ? 40 : 32))
1766
- let verticalPadding = CGFloat(style?.double("verticalPadding", default: 12) ?? 12)
1767
- base = max(item.data.string("variant") == "stock" ? 72 : 68, imageHeight + verticalPadding * 2)
1768
- default:
1769
- if item.type == "identity", !item.data.string("tertiary").isEmpty {
1770
- base = 72
1771
- } else if item.type == "identity", !item.data.string("subtitle").isEmpty {
1772
- base = 60
1773
- } else {
1774
- base = 56
1775
- }
1871
+ let availableWidth = max(0, collectionView.bounds.width - flowLayout.sectionInset.left - flowLayout.sectionInset.right)
1872
+ let columnWidth = config?.layout == "grid"
1873
+ ? floor((availableWidth - CGFloat((config?.gridColumns ?? 2) - 1) * (config?.itemSpacing ?? 0)) / CGFloat(config?.gridColumns ?? 2))
1874
+ : availableWidth
1875
+ let rowWidth = allocatedWidth ?? (config?.orientation == "horizontal" ? 280 : columnWidth)
1876
+ if let height = NativeListRendererRegistry.measure(item, width: rowWidth, theme: config?.theme, layout: config?.layout ?? "linear") {
1877
+ return max(0, height + (NativeListRendererRegistry.appliesSizePreset(item) ? (item.data.string("size") == "small" ? -8 : item.data.string("size") == "large" ? 12 : 0) : 0))
1776
1878
  }
1777
- let hasFixedHeaderHeight = item.type == "sectionHeader" &&
1778
- ["summary", "gallery"].contains(item.data.string("variant"))
1779
- let modifier: CGFloat = hasFixedHeaderHeight
1780
- ? 0
1781
- : item.data.string("size", default: "medium") == "small"
1782
- ? -8
1783
- : item.data.string("size") == "large" ? 12 : 0
1784
- let sectionSpacing: CGFloat = 0
1785
- let tableAdjustment: CGFloat = config?.layout == "table" &&
1786
- item.type == "dataRow" &&
1787
- !item.data.dictionaries("columns").contains(where: { !$0.string("secondaryText").isEmpty })
1788
- ? -8
1789
- : 0
1790
- return max(0, base + modifier + sectionSpacing + tableAdjustment)
1791
- }
1792
-
1793
- private func messageHeight(_ item: NativeListItem) -> CGFloat {
1794
- let maximumBodyLines = min(3, max(1, item.data.int("bodyLines", default: 3)))
1795
- let horizontalInsets = (config?.contentPaddingHorizontal ?? 0) * 2 + 40
1796
- let leadingWidth: CGFloat = item.data.dictionary("leading") == nil ? 0 : 40
1797
- let thumbnailWidth: CGFloat = item.data.dictionary("thumbnail") == nil ? 0 : 76
1798
- let textWidth = max(1, collectionView.bounds.width - horizontalInsets - leadingWidth - thumbnailWidth)
1799
- let bodyBounds = (item.data.string("body") as NSString).boundingRect(
1800
- with: CGSize(width: textWidth, height: .greatestFiniteMagnitude),
1801
- options: [.usesLineFragmentOrigin, .usesFontLeading],
1802
- attributes: [.font: nativeListFont(ofSize: 14)],
1803
- context: nil
1804
- )
1805
- let titleBounds = (item.data.string("title") as NSString).boundingRect(
1806
- with: CGSize(width: textWidth, height: .greatestFiniteMagnitude),
1807
- options: [.usesLineFragmentOrigin, .usesFontLeading],
1808
- attributes: [.font: nativeListFont(ofSize: 14, weight: .semibold)],
1809
- context: nil
1810
- )
1811
- let bodyLines = min(maximumBodyLines, max(1, Int(ceil(bodyBounds.height / 20))))
1812
- let titleLines = min(2, max(1, Int(ceil(titleBounds.height / 20))))
1813
- return 32 + CGFloat(titleLines * 20 + bodyLines * 20) + 22
1879
+ return 56
1814
1880
  }
1815
1881
 
1882
+
1816
1883
  private func emit(_ block: ((String) -> Void)?, _ value: [String: Any]) {
1817
1884
  guard JSONSerialization.isValidJSONObject(value),
1818
1885
  let data = try? JSONSerialization.data(withJSONObject: value),
@@ -1894,7 +1961,7 @@ final class NativeListView: UIView {
1894
1961
  reorderLongPress.delegate = nil
1895
1962
  marketLongPress.delegate = nil
1896
1963
 
1897
- for case let cell as NativeListCell in collectionView.visibleCells {
1964
+ for case let cell as NativeListRowHost in collectionView.visibleCells {
1898
1965
  cell.onAction = nil
1899
1966
  cell.onBindingInvalidated = nil
1900
1967
  cell.prepareForReuse()
@@ -1909,6 +1976,8 @@ final class NativeListView: UIView {
1909
1976
  itemsByKey.removeAll()
1910
1977
  sectionIndexEntries.removeAll()
1911
1978
  pendingScrollRequest = nil
1979
+ needsContentShrinkCorrection = false
1980
+ lastLaidOutContentHeight = nil
1912
1981
  lastVisibleRange = nil
1913
1982
  onRowAction = nil
1914
1983
  onActionAnchorInvalidated = nil
@@ -1916,6 +1985,7 @@ final class NativeListView: UIView {
1916
1985
  onReorder = nil
1917
1986
  onEndReached = nil
1918
1987
  onVisibleRangeChanged = nil
1988
+ onScrollPositionThresholdChange = nil
1919
1989
  }
1920
1990
 
1921
1991
  private func createActionAnchor(origin: NativeListActionOrigin) -> [String: Any]? {
@@ -1961,7 +2031,7 @@ final class NativeListView: UIView {
1961
2031
  && (sourceView === ownerCell.contentView || sourceView.isDescendant(of: ownerCell.contentView))
1962
2032
  }
1963
2033
 
1964
- private func handleBindingInvalidated(cell: NativeListCell, epoch: Int) {
2034
+ private func handleBindingInvalidated(cell: NativeListRowHost, epoch: Int) {
1965
2035
  guard let anchor = actionAnchor,
1966
2036
  anchor.ownerCell === cell,
1967
2037
  anchor.bindingEpoch == epoch else { return }
@@ -1981,6 +2051,9 @@ final class NativeListView: UIView {
1981
2051
  }
1982
2052
 
1983
2053
  @objc private func refreshTriggered() {
2054
+ guard !disposed, config?.pullToRefresh == true,
2055
+ config?.refreshing != true, !refreshEmittedForDrag else { return }
2056
+ refreshEmittedForDrag = true
1984
2057
  emit(onRowAction, ["actionKey": "nativeList.refresh"])
1985
2058
  }
1986
2059
 
@@ -2158,7 +2231,8 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
2158
2231
  if config.orientation == "horizontal" {
2159
2232
  let width: CGFloat = item.type == "rail" ? railWidth(item) : item.type == "mediaTile" ? 200 : 280
2160
2233
  let availableHeight = max(0, collectionView.bounds.height - insets.top - insets.bottom)
2161
- let height = item.type == "rail" ? min(rowHeight(item), availableHeight) : availableHeight
2234
+ let height = item.type == "walletGroup" && item.key == interactiveReorderCompactKey ? 68
2235
+ : item.styledHeight ?? (item.data["height"] != nil ? rowHeight(item) : item.type == "rail" ? min(rowHeight(item), availableHeight) : availableHeight)
2162
2236
  return CGSize(width: width, height: height)
2163
2237
  }
2164
2238
  let available = max(0, collectionView.bounds.width - insets.left - insets.right)
@@ -2166,34 +2240,20 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
2166
2240
  if config.layout == "grid", !structural {
2167
2241
  let spacing = CGFloat(config.gridColumns - 1) * config.itemSpacing
2168
2242
  let width = floor((available - spacing) / CGFloat(config.gridColumns))
2169
- let height = item.type == "mediaTile" ? width + 48 : rowHeight(item)
2243
+ let height = item.styledHeight ?? (item.type == "mediaTile" && item.data["height"] == nil ? width + 48 : rowHeight(item, allocatedWidth: width))
2170
2244
  return CGSize(width: width, height: height)
2171
2245
  }
2172
- return CGSize(width: available, height: rowHeight(item))
2246
+ return CGSize(width: available, height: rowHeight(item, allocatedWidth: available))
2173
2247
  }
2174
2248
 
2175
2249
  private func railWidth(_ item: NativeListItem) -> CGFloat {
2176
- let titleWidth = (item.data.string("title") as NSString).size(
2177
- withAttributes: [.font: nativeListFont(ofSize: 12, weight: .medium)]
2178
- ).width
2179
- let badge = item.data.dictionary("badge")?.string("text") ?? ""
2180
- let badgeWidth = (badge as NSString).size(
2181
- withAttributes: [.font: nativeListTabularFont(ofSize: 12, weight: .medium)]
2182
- ).width
2183
- let status = item.data.string("status")
2184
- let statusWidth = status.isEmpty || status == "none" ? 0 : (status as NSString).size(
2185
- withAttributes: [.font: nativeListTabularFont(ofSize: 12)]
2186
- ).width
2187
- let visibleTextCount = 1 + (badgeWidth > 0 ? 1 : 0) + (statusWidth > 0 ? 1 : 0)
2188
- let width = 4 + 20 + 6 + titleWidth + badgeWidth + statusWidth
2189
- + CGFloat(max(0, visibleTextCount - 1)) * 6 + 4
2190
- return min(288, max(72, ceil(width + 8)))
2250
+ NativeListRailRenderer.Resolved(item, theme: config?.theme).horizontalWidth
2191
2251
  }
2192
2252
 
2193
2253
  func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
2194
2254
  guard let item = config?.items[safe: indexPath.item] else { return }
2195
2255
  if item.type == "walletGroup" { return }
2196
- let origin = (collectionView.cellForItem(at: indexPath) as? NativeListCell)?.rowActionOrigin()
2256
+ let origin = (collectionView.cellForItem(at: indexPath) as? NativeListRowHost)?.rowActionOrigin()
2197
2257
  handleRowPress(item, origin: origin)
2198
2258
  }
2199
2259
 
@@ -2206,7 +2266,7 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
2206
2266
  guard let item = config?.items[safe: indexPath.item], item.type == "market" else { return }
2207
2267
  let actionKey = item.data.string("pressInActionKey")
2208
2268
  guard !actionKey.isEmpty else { return }
2209
- let origin = (collectionView.cellForItem(at: indexPath) as? NativeListCell)?.rowActionOrigin()
2269
+ let origin = (collectionView.cellForItem(at: indexPath) as? NativeListRowHost)?.rowActionOrigin()
2210
2270
  handleAction(item: item, actionKey: actionKey, target: nil, origin: origin)
2211
2271
  }
2212
2272
 
@@ -2215,7 +2275,31 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
2215
2275
  return item.isRowPressEnabled
2216
2276
  }
2217
2277
 
2278
+ func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
2279
+ minimumDragOffset = 0
2280
+ refreshEmittedForDrag = false
2281
+ }
2282
+
2283
+ func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
2284
+ defer { if !decelerate { scheduleContentShrinkCorrection() } }
2285
+ minimumDragOffset = min(minimumDragOffset, scrollView.contentOffset.y + scrollView.contentInset.top)
2286
+ guard let threshold = config?.refreshTriggerDistance,
2287
+ config?.pullToRefresh == true, config?.refreshing != true,
2288
+ minimumDragOffset <= -threshold, !refreshEmittedForDrag else { return }
2289
+ collectionView.refreshControl?.beginRefreshing()
2290
+ refreshTriggered()
2291
+ }
2292
+
2293
+ func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
2294
+ scheduleContentShrinkCorrection()
2295
+ }
2296
+
2218
2297
  func scrollViewDidScroll(_ scrollView: UIScrollView) {
2298
+ if scrollView.isDragging {
2299
+ minimumDragOffset = min(minimumDragOffset, scrollView.contentOffset.y + scrollView.contentInset.top)
2300
+ }
2301
+ layoutContainerSlots()
2302
+ emitScrollPositionThresholdIfNeeded()
2219
2303
  invalidateActionAnchor(reason: "scroll")
2220
2304
  syncSectionIndexToVisibleRows()
2221
2305
  emitVisibleRangeIfNeeded()
@@ -2278,6 +2362,13 @@ extension NativeListView: UICollectionViewDragDelegate, UICollectionViewDropDele
2278
2362
  // quick tap highlighted and unhighlighted a row within one frame and the pressed background never
2279
2363
  // rendered. Deliver touches immediately, as Android rows do.
2280
2364
  private final class NativeListCollectionView: UICollectionView {
2365
+ var onContentLayout: (() -> Void)?
2366
+
2367
+ override func layoutSubviews() {
2368
+ super.layoutSubviews()
2369
+ onContentLayout?()
2370
+ }
2371
+
2281
2372
  override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
2282
2373
  super.init(frame: frame, collectionViewLayout: layout)
2283
2374
  delaysContentTouches = false
@@ -2296,6 +2387,7 @@ private final class NativeListCollectionView: UICollectionView {
2296
2387
 
2297
2388
  final class NativeListFlowLayout: UICollectionViewFlowLayout {
2298
2389
  var stickyItemIndexes: Set<Int> = []
2390
+ var minimumContainerContentHeight: CGFloat = 0
2299
2391
  private var horizontalAttributes: [IndexPath: UICollectionViewLayoutAttributes] = [:]
2300
2392
  private var horizontalContentSize: CGSize = .zero
2301
2393
 
@@ -2324,7 +2416,9 @@ final class NativeListFlowLayout: UICollectionViewFlowLayout {
2324
2416
  }
2325
2417
 
2326
2418
  override var collectionViewContentSize: CGSize {
2327
- scrollDirection == .horizontal ? horizontalContentSize : super.collectionViewContentSize
2419
+ if scrollDirection == .horizontal { return horizontalContentSize }
2420
+ let size = super.collectionViewContentSize
2421
+ return CGSize(width: size.width, height: max(size.height, minimumContainerContentHeight))
2328
2422
  }
2329
2423
 
2330
2424
  override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
@@ -2365,11 +2459,15 @@ final class NativeListFlowLayout: UICollectionViewFlowLayout {
2365
2459
  !stickyItemIndexes.isEmpty,
2366
2460
  let collectionView else { return super.layoutAttributesForElements(in: rect) }
2367
2461
  let base = super.layoutAttributesForElements(in: rect)?.compactMap { $0.copy() as? UICollectionViewLayoutAttributes } ?? []
2368
- let firstVisible = collectionView.indexPathsForVisibleItems.map(\.item).min() ?? 0
2369
- guard let stickyIndex = stickyItemIndexes.filter({ $0 <= firstVisible }).max(),
2462
+ let pinY = collectionView.contentOffset.y + collectionView.adjustedContentInset.top
2463
+ // Visible cells can still describe the old viewport during an imperative
2464
+ // scroll. Resolve the pinned header from unmodified layout positions.
2465
+ guard let stickyIndex = stickyItemIndexes.filter({
2466
+ guard let attributes = super.layoutAttributesForItem(at: IndexPath(item: $0, section: 0)) else { return false }
2467
+ return attributes.frame.minY <= pinY
2468
+ }).max(),
2370
2469
  let original = super.layoutAttributesForItem(at: IndexPath(item: stickyIndex, section: 0)),
2371
2470
  let sticky = original.copy() as? UICollectionViewLayoutAttributes else { return base }
2372
- let pinY = collectionView.contentOffset.y + collectionView.adjustedContentInset.top
2373
2471
  let nextHeaderY = stickyItemIndexes
2374
2472
  .filter { $0 > stickyIndex }
2375
2473
  .min()