@onekeyfe/react-native-native-list 6.7.0-alpha.354 → 6.7.0-alpha.362

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 (112) hide show
  1. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +0 -7
  2. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +7 -240
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +4 -7
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +3 -6
  5. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +0 -12
  6. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +7 -87
  7. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +1 -135
  8. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +14 -43
  9. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +0 -25
  10. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +2 -17
  11. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +0 -22
  12. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +0 -2
  13. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +0 -2
  14. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +2 -3
  15. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +0 -69
  16. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +1 -55
  17. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +21 -585
  18. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +0 -1
  19. package/docs/ROW_TEMPLATES.md +9 -60
  20. package/docs/SPEC.md +5 -317
  21. package/docs/STYLE_SPEC.md +0 -6
  22. package/ios/HybridNativeList.swift +0 -10
  23. package/ios/NativeListAccessoryStack.swift +37 -220
  24. package/ios/NativeListActivityDetailsView.swift +8 -18
  25. package/ios/NativeListActivityRenderer.swift +2 -8
  26. package/ios/NativeListDataRowRenderer.swift +8 -105
  27. package/ios/NativeListDesignAssets.swift +0 -3
  28. package/ios/NativeListIdentityRenderer.swift +4 -119
  29. package/ios/NativeListLeadingVisual.swift +14 -49
  30. package/ios/NativeListMessageRenderer.swift +1 -34
  31. package/ios/NativeListModels.swift +2 -16
  32. package/ios/NativeListRendererRegistry.swift +0 -1
  33. package/ios/NativeListResolvedText.swift +1 -2
  34. package/ios/NativeListRowHost.swift +0 -14
  35. package/ios/NativeListSectionHeaderRenderer.swift +0 -88
  36. package/ios/RNCNativeListView.swift +29 -331
  37. package/ios/tests/NativeListActivityPresentationTests.swift +0 -56
  38. package/ios/tests/NativeListLifecycleTests.swift +3 -890
  39. package/lib/module/NativeList.js +21 -39
  40. package/lib/module/NativeList.web.js +4 -51
  41. package/lib/module/models.js +0 -1
  42. package/lib/module/selection.js +1 -1
  43. package/lib/module/validation.js +8 -320
  44. package/lib/module/web/NativeListWebEngine.js +18 -373
  45. package/lib/module/web/templates/ActivityRowRenderer.js +7 -8
  46. package/lib/module/web/templates/DataRowRenderer.js +5 -40
  47. package/lib/module/web/templates/IdentityRowRenderer.js +4 -90
  48. package/lib/module/web/templates/MessageRowRenderer.js +2 -18
  49. package/lib/module/web/templates/RowContainerStyle.js +0 -1
  50. package/lib/module/web/templates/RowRendererRegistry.js +0 -3
  51. package/lib/module/web/templates/SectionHeaderRowRenderer.js +2 -36
  52. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +0 -9
  53. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +0 -2
  54. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +0 -5
  55. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +0 -6
  56. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +0 -7
  57. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +0 -6
  58. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +0 -1
  59. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +0 -11
  60. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +0 -2
  61. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +0 -2
  62. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +0 -2
  63. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +0 -3
  64. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +0 -1
  65. package/lib/typescript/src/NativeList.nitro.d.ts +0 -1
  66. package/lib/typescript/src/NativeList.types.d.ts +0 -8
  67. package/lib/typescript/src/models.d.ts +9 -101
  68. package/lib/typescript/src/validation.d.ts +0 -10
  69. package/lib/typescript/src/web/NativeListWebEngine.d.ts +0 -26
  70. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  71. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +3 -9
  72. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +0 -9
  73. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +0 -2
  74. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +0 -5
  75. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +0 -6
  76. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +0 -7
  77. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +0 -6
  78. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +0 -1
  79. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +0 -11
  80. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +0 -2
  81. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +0 -2
  82. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +0 -2
  83. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +0 -3
  84. package/nitrogen/generated/shared/json/NativeListConfig.json +0 -1
  85. package/package.json +3 -3
  86. package/react-native-native-list.podspec +0 -1
  87. package/src/NativeList.nitro.ts +0 -1
  88. package/src/NativeList.tsx +24 -72
  89. package/src/NativeList.types.ts +0 -9
  90. package/src/NativeList.web.tsx +8 -72
  91. package/src/models.ts +3 -113
  92. package/src/selection.ts +0 -1
  93. package/src/validation.ts +6 -721
  94. package/src/web/NativeListWebEngine.ts +19 -568
  95. package/src/web/templates/ActivityRowRenderer.ts +6 -14
  96. package/src/web/templates/DataRowRenderer.ts +20 -93
  97. package/src/web/templates/IdentityRowRenderer.ts +5 -150
  98. package/src/web/templates/MessageRowRenderer.ts +7 -23
  99. package/src/web/templates/RowContainerStyle.ts +0 -2
  100. package/src/web/templates/RowRendererRegistry.ts +1 -11
  101. package/src/web/templates/SectionHeaderRowRenderer.ts +4 -47
  102. package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +0 -102
  103. package/ios/NativeListButtonGroupRenderer.swift +0 -89
  104. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +0 -15
  105. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +0 -4
  106. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +0 -15
  107. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +0 -3
  108. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +0 -15
  109. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +0 -3
  110. package/lib/module/web/templates/ButtonGroupRowRenderer.js +0 -47
  111. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +0 -14
  112. package/src/web/templates/ButtonGroupRowRenderer.ts +0 -58
@@ -30,13 +30,11 @@ final class NativeListView: UIView {
30
30
  }
31
31
  private var refreshEmittedForDrag = false
32
32
  private var minimumDragOffset: CGFloat = 0
33
- private var containerSlotHeights: [CGFloat] = [0, 0, 0, 0]
33
+ private var containerSlotHeights: [CGFloat] = [0, 0, 0]
34
34
  // Fabric keeps assigning each slot root the frame React computed (inset, 0, width, height).
35
35
  // Each root therefore lives in a list-owned host whose origin the list alone controls, so a
36
36
  // React layout update can never move a slot out of its native position, even for a frame.
37
37
  private var reactContainerSlots: [(content: UIView, host: UIView)] = []
38
- private var sidecarLayout: (width: CGFloat, gap: CGFloat, maxContentWidth: CGFloat)?
39
- private let pagerStickyHeights = NSMapTable<AnyObject, NSNumber>(keyOptions: .weakMemory, valueOptions: .strongMemory)
40
38
  private let topOverlayHost = UIView()
41
39
  private weak var topOverlayContent: UIView?
42
40
  private var topEdgeInteraction: UIInteraction?
@@ -49,23 +47,9 @@ final class NativeListView: UIView {
49
47
  private var lastLaidOutContentHeight: CGFloat?
50
48
  private var needsContentShrinkCorrection = false
51
49
  private var contentShrinkCorrectionScheduled = false
52
- private var consumedStructuralTransitionID: String?
53
- private var structuralDisplayLink: CADisplayLink?
54
- private var structuralSpacerHeight: CGFloat = 0
55
- private var structuralAnimationStart: CFTimeInterval = 0
56
- private var structuralAnimationDuration: CFTimeInterval = 0
57
- private var structuralStartSpacer: CGFloat = 0
58
- private var structuralStartOffset: CGFloat = 0
59
- private var structuralTargetOffset: CGFloat = 0
60
- private var structuralScrollInterrupted = false
61
- private var structuralFooterStartY: CGFloat?
62
- private var structuralFooterProgress: CGFloat = 0
63
- private var structuralRemovedItems: [String: NativeListItem] = [:]
64
- private var structuralRemovedHeights: [String: CGFloat] = [:]
65
- private var structuralRemovalProgress: CGFloat = 0
66
50
 
67
51
  @objc func mountContainerSlot(_ view: UIView, atIndex index: Int) {
68
- if index == 4 {
52
+ if index == 3 {
69
53
  topOverlayContent?.removeFromSuperview()
70
54
  topOverlayContent = view
71
55
  topOverlayHost.addSubview(view)
@@ -161,59 +145,13 @@ final class NativeListView: UIView {
161
145
  func setContainerSlotHeightsJson(_ json: String) {
162
146
  guard let data = json.data(using: .utf8),
163
147
  let heights = try? JSONSerialization.jsonObject(with: data) as? [Double],
164
- heights.count == 4, heights.allSatisfy({ $0.isFinite && $0 >= 0 }) else { return }
165
- let footerDelta = containerSlotHeights[2] - CGFloat(heights[2])
148
+ heights.count == 3, heights.allSatisfy({ $0.isFinite && $0 >= 0 }) else { return }
166
149
  containerSlotHeights = heights.map { CGFloat($0) }
167
- if structuralDisplayLink != nil, footerDelta != 0 {
168
- let progress = min(1, max(0,
169
- (CACurrentMediaTime() - structuralAnimationStart) / max(0.001, structuralAnimationDuration)))
170
- let eased = progress * progress * (3 - 2 * progress)
171
- structuralStartSpacer = max(0, structuralStartSpacer + footerDelta)
172
- structuralSpacerHeight = structuralStartSpacer * (1 - eased)
173
- if let startY = structuralFooterStartY { structuralFooterStartY = startY + footerDelta }
174
- }
175
- if let config { configureLayout(config) }
176
- if structuralDisplayLink != nil {
177
- collectionView.layoutIfNeeded()
178
- let inset = collectionView.adjustedContentInset
179
- let finalMaximum = max(-inset.top,
180
- collectionView.contentSize.height - structuralSpacerHeight
181
- - collectionView.bounds.height + inset.bottom)
182
- structuralTargetOffset = min(structuralTargetOffset, finalMaximum)
183
- }
184
- layoutContainerSlots()
185
- setNeedsLayout()
186
- }
187
-
188
- func setSidecarLayoutJson(_ json: String) {
189
- if json.isEmpty {
190
- sidecarLayout = nil
191
- } else if let data = json.data(using: .utf8),
192
- let value = try? JSONSerialization.jsonObject(with: data) as? [String: Double],
193
- let width = value["width"], let gap = value["gap"],
194
- let maxWidth = value["maxContentWidth"],
195
- width.isFinite, width > 0, gap.isFinite, gap >= 0,
196
- maxWidth.isFinite, maxWidth > width + gap {
197
- sidecarLayout = (CGFloat(width), CGFloat(gap), CGFloat(maxWidth))
198
- } else { return }
199
150
  if let config { configureLayout(config) }
200
151
  layoutContainerSlots()
201
152
  setNeedsLayout()
202
153
  }
203
154
 
204
- private func sidecarBaseInset(_ width: CGFloat) -> CGFloat {
205
- guard let sidecarLayout else { return 0 }
206
- return max(0, (width - min(width, sidecarLayout.maxContentWidth)) / 2)
207
- }
208
-
209
- @objc(setPagerStickyHeight:forOwner:)
210
- func setPagerStickyHeight(_ height: CGFloat, forOwner owner: AnyObject) {
211
- let next = height.isFinite ? max(0, height) : 0
212
- if next == 0 { pagerStickyHeights.removeObject(forKey: owner) }
213
- else { pagerStickyHeights.setObject(NSNumber(value: Double(next)), forKey: owner) }
214
- layoutContainerSlots()
215
- }
216
-
217
155
  private func layoutContainerSlots() {
218
156
  let empty = config?.items.isEmpty ?? true
219
157
  let header = containerSlotHeights[0]
@@ -222,43 +160,14 @@ final class NativeListView: UIView {
222
160
  let paddingTop = config?.contentPaddingTop ?? 0
223
161
  let paddingBottom = config?.contentPaddingBottom ?? 0
224
162
  let footerY = max(paddingTop + header + emptyHeight,
225
- flowLayout.bodyContentHeight - paddingBottom - footer)
226
- let footerPosition = structuralRemovedItems.isEmpty ? structuralFooterStartY.map {
227
- $0 + (footerY - $0) * structuralFooterProgress
228
- } ?? footerY : footerY
229
- let positions = [paddingTop, paddingTop + header, footerPosition]
163
+ collectionView.contentSize.height - paddingBottom - footer)
164
+ let positions = [paddingTop, paddingTop + header, footerY]
230
165
  for (index, slot) in reactContainerSlots.prefix(3).enumerated() {
231
166
  slot.host.isHidden = index == 1 && !empty
232
167
  // React places the root at the horizontal inset inside this full-width host.
233
168
  slot.host.frame = CGRect(x: 0, y: positions[index],
234
169
  width: collectionView.bounds.width, height: containerSlotHeights[index])
235
170
  }
236
- if reactContainerSlots.count > 3 {
237
- let slot = reactContainerSlots[3]
238
- let width = sidecarLayout?.width ?? 0
239
- let base = sidecarBaseInset(collectionView.bounds.width)
240
- slot.host.isHidden = sidecarLayout == nil || containerSlotHeights[3] <= 0
241
- let x = effectiveUserInterfaceLayoutDirection == .rightToLeft
242
- ? base : collectionView.bounds.width - base - width
243
- slot.host.frame = CGRect(x: x,
244
- y: paddingTop, width: width, height: containerSlotHeights[3])
245
- }
246
- var stickyHeight: CGFloat = 0
247
- for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
248
- stickyHeight += CGFloat(value.doubleValue)
249
- }
250
- CATransaction.begin()
251
- CATransaction.setDisableActions(true)
252
- for slot in reactContainerSlots {
253
- guard stickyHeight > 0 else { slot.host.layer.mask = nil; continue }
254
- let mask = slot.host.layer.mask ?? CALayer()
255
- mask.backgroundColor = UIColor.black.cgColor
256
- let top = max(0, collectionView.contentOffset.y + stickyHeight - slot.host.frame.minY)
257
- mask.frame = CGRect(x: 0, y: top, width: slot.host.bounds.width,
258
- height: max(0, slot.host.bounds.height - top))
259
- slot.host.layer.mask = mask
260
- }
261
- CATransaction.commit()
262
171
  }
263
172
 
264
173
  private final class ActionAnchorRecord {
@@ -630,14 +539,14 @@ final class NativeListView: UIView {
630
539
  height: requestedTopOverlayHeight)
631
540
  updateSectionIndexAttachment()
632
541
  let direction = effectiveUserInterfaceLayoutDirection
633
- let sizeChanged = lastLayoutSize != nil && lastLayoutSize != bounds.size
634
- if sizeChanged || lastLayoutDirection != nil && lastLayoutDirection != direction {
542
+ if let lastLayoutSize,
543
+ lastLayoutSize != bounds.size || lastLayoutDirection != nil && lastLayoutDirection != direction {
635
544
  invalidateActionAnchor(reason: "layout")
636
545
  }
637
546
  lastLayoutSize = bounds.size
638
- if (lastLayoutDirection != direction || sizeChanged && sidecarLayout != nil), let config {
547
+ if lastLayoutDirection != direction, let config {
639
548
  configureLayout(config)
640
- if lastLayoutDirection != direction { rebindRowsForLayoutDirection(config) }
549
+ rebindRowsForLayoutDirection(config)
641
550
  }
642
551
  performPendingScrollIfNeeded()
643
552
  layoutContainerSlots()
@@ -672,83 +581,8 @@ final class NativeListView: UIView {
672
581
 
673
582
  func applySnapshotJson(_ json: String) {
674
583
  guard let next = try? NativeListConfig.parse(json: json) else { return }
675
- let oldKeys = dataSource.snapshot().itemIdentifiers
676
- let logicalOldKeys = config?.items.map(\.key) ?? []
677
- let presentationItems = itemsByKey
678
- let newKeys = next.items.map(\.key)
679
- let transition = next.structuralTransition
680
- let isNewTransition = transition != nil && transition?.id != consumedStructuralTransitionID
681
- if let transition { consumedStructuralTransitionID = transition.id }
682
- let animateStructure = config != nil && isNewTransition && logicalOldKeys != newKeys
683
- && next.orientation == "vertical" && (next.layout == "linear" || next.layout == "table")
684
- && !UIAccessibility.isReduceMotionEnabled
685
- && (transition?.duration ?? 0) > 0
686
- let presentationHeights: [String: CGFloat] = animateStructure ? Dictionary(uniqueKeysWithValues: oldKeys.compactMap { key -> (String, CGFloat)? in
687
- guard let item = presentationItems[key] else { return nil }
688
- let height = structuralRemovedHeights[key].map { $0 * (1 - structuralRemovalProgress) }
689
- ?? rowHeight(item)
690
- return (key, height)
691
- }) : [:]
692
- let previousOffset = collectionView.contentOffset.y
693
- let oldLeftContentHeight = animateStructure ? flowLayout.bodyContentHeight : 0
694
- let oldSpacerHeight = structuralSpacerHeight
695
- let oldRowsHeight = animateStructure
696
- ? presentationHeights.values.reduce(CGFloat(0), +)
697
- + CGFloat(max(0, oldKeys.count - 1)) * (config?.itemSpacing ?? 0)
698
- : 0
699
- let newRowsHeight = animateStructure
700
- ? next.items.reduce(CGFloat(0)) { $0 + rowHeight($1) }
701
- + CGFloat(max(0, newKeys.count - 1)) * next.itemSpacing
702
- : 0
703
- let survivingKeys = animateStructure ? Set(newKeys) : Set<String>()
704
- let visibleAnchor = animateStructure
705
- ? collectionView.indexPathsForVisibleItems.sorted().first {
706
- oldKeys.indices.contains($0.item) && survivingKeys.contains(oldKeys[$0.item])
707
- }
708
- : nil
709
- let anchorKey = visibleAnchor.map { oldKeys[$0.item] }
710
- let oldPrefix = (animateStructure ? anchorKey : nil).flatMap { key -> CGFloat? in
711
- guard let index = oldKeys.firstIndex(of: key) else { return nil }
712
- return oldKeys.prefix(index).reduce(CGFloat(0)) { $0 + (presentationHeights[$1] ?? 0) }
713
- + CGFloat(index) * (config?.itemSpacing ?? 0)
714
- } ?? 0
715
- let newPrefix = (animateStructure ? anchorKey : nil).flatMap { key -> CGFloat? in
716
- guard let index = newKeys.firstIndex(of: key) else { return nil }
717
- return next.items.prefix(index).reduce(CGFloat(0)) { $0 + rowHeight($1) }
718
- + CGFloat(index) * next.itemSpacing
719
- } ?? 0
720
- if animateStructure {
721
- stopStructuralAnimation()
722
- structuralScrollInterrupted = false
723
- structuralFooterStartY = reactContainerSlots.count > 2
724
- ? reactContainerSlots[2].host.frame.minY : nil
725
- structuralFooterProgress = 0
726
- // Keep deletion-only snapshots in their presentation order until their heights
727
- // reach zero. Replacing these rows with a spacer produces a blank viewport.
728
- let removedKeys = Set(oldKeys).subtracting(newKeys)
729
- let retainsOrder = oldKeys.filter { survivingKeys.contains($0) } == newKeys
730
- structuralRemovedItems = retainsOrder
731
- ? presentationItems.filter { removedKeys.contains($0.key) } : [:]
732
- structuralRemovedHeights = retainsOrder
733
- ? presentationHeights.filter { removedKeys.contains($0.key) } : [:]
734
- structuralRemovalProgress = 0
735
- structuralSpacerHeight = structuralRemovedItems.isEmpty
736
- ? max(0, structuralSpacerHeight + oldRowsHeight - newRowsHeight) : 0
737
- NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
738
- object: collectionView, userInfo: ["phase": 0])
739
- NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
740
- object: collectionView, userInfo: ["phase": 1])
741
- needsContentShrinkCorrection = false
742
- } else if logicalOldKeys != newKeys {
743
- stopStructuralAnimation()
744
- structuralSpacerHeight = 0
745
- structuralFooterStartY = nil
746
- structuralRemovedItems.removeAll()
747
- structuralRemovedHeights.removeAll()
748
- }
749
584
  invalidateActionAnchor(reason: "snapshot")
750
- if let current = config, structuralRemovedItems.isEmpty,
751
- isControlledSelectionSnapshotUpdate(from: current, to: next) {
585
+ if let current = config, isControlledSelectionSnapshotUpdate(from: current, to: next) {
752
586
  config = next
753
587
  itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
754
588
  // OneKey patch: A controlled selection echo is fully handled by the
@@ -768,41 +602,17 @@ final class NativeListView: UIView {
768
602
  // rows whose own content is unchanged.
769
603
  let themeChanged = !dictionariesEqual(config?.theme, next.theme)
770
604
  || !dictionariesEqual(config?.listStyle, next.listStyle)
771
- || config?.layout != next.layout
772
605
  if config?.generation != next.generation { endReachedGeneration = nil }
773
606
  config = next
774
607
  itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
775
- itemsByKey.merge(structuralRemovedItems) { current, _ in current }
776
608
  configureSectionIndex(next)
777
609
  configureLayout(next)
778
610
  configureRefresh(next)
779
611
  configureFooter(next)
780
612
 
781
- if animateStructure, let transition {
782
- let inset = collectionView.adjustedContentInset
783
- let finalLeftHeight = max(0,
784
- oldLeftContentHeight + newRowsHeight - oldRowsHeight - oldSpacerHeight)
785
- let sidecarHeight = sidecarLayout == nil ? 0 :
786
- next.contentPaddingTop + containerSlotHeights[3] + next.contentPaddingBottom
787
- let finalHeight = max(finalLeftHeight, sidecarHeight)
788
- let finalMaximum = max(-inset.top, finalHeight - collectionView.bounds.height + inset.bottom)
789
- structuralStartSpacer = structuralSpacerHeight
790
- structuralStartOffset = previousOffset
791
- var targetOffset = min(max(-inset.top, previousOffset + newPrefix - oldPrefix), finalMaximum)
792
- if visibleAnchor == nil, let fallbackKey = transition.anchorKey,
793
- let fallbackIndex = newKeys.firstIndex(of: fallbackKey) {
794
- let fallbackY = next.contentPaddingTop + containerSlotHeights[0]
795
- + next.items.prefix(fallbackIndex).reduce(CGFloat(0)) { $0 + rowHeight($1) }
796
- + CGFloat(fallbackIndex) * next.itemSpacing
797
- targetOffset = min(targetOffset, max(-inset.top, fallbackY - inset.top))
798
- }
799
- structuralTargetOffset = targetOffset
800
- structuralAnimationDuration = transition.duration
801
- }
802
-
803
613
  var snapshot = NSDiffableDataSourceSnapshot<Int, String>()
804
614
  snapshot.appendSections([0])
805
- let keys = structuralRemovedItems.isEmpty ? newKeys : oldKeys
615
+ let keys = next.items.map(\.key)
806
616
  snapshot.appendItems(keys, toSection: 0)
807
617
  var changedKeys = Set(keys.filter { key in
808
618
  guard let old = oldItems[key], let new = itemsByKey[key] else { return false }
@@ -817,7 +627,7 @@ final class NativeListView: UIView {
817
627
  let replacedKeys = changedRetainedKeys.filter { oldItems[$0]?.rendererKey != itemsByKey[$0]?.rendererKey }
818
628
  snapshot.reloadItems(Array(replacedKeys))
819
629
  snapshot.reconfigureItems(Array(changedRetainedKeys.subtracting(replacedKeys)))
820
- dataSource.apply(snapshot, animatingDifferences: animateStructure && structuralRemovedItems.isEmpty) { [weak self] in
630
+ dataSource.apply(snapshot, animatingDifferences: false) { [weak self] in
821
631
  guard let self else { return }
822
632
  self.collectionView.layoutIfNeeded()
823
633
  self.performPendingScrollIfNeeded()
@@ -825,88 +635,6 @@ final class NativeListView: UIView {
825
635
  self.checkEndReached()
826
636
  self.syncSectionIndexToVisibleRows()
827
637
  }
828
- if animateStructure {
829
- structuralAnimationStart = CACurrentMediaTime()
830
- let displayLink = CADisplayLink(target: self, selector: #selector(advanceStructuralAnimation))
831
- structuralDisplayLink = displayLink
832
- displayLink.add(to: .main, forMode: .common)
833
- }
834
- }
835
-
836
- private func stopStructuralAnimation() {
837
- if structuralDisplayLink != nil {
838
- NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
839
- object: collectionView, userInfo: ["phase": 2])
840
- }
841
- structuralDisplayLink?.invalidate()
842
- structuralDisplayLink = nil
843
- }
844
-
845
- @objc private func advanceStructuralAnimation() {
846
- guard let config else { stopStructuralAnimation(); return }
847
- let elapsed = CACurrentMediaTime() - structuralAnimationStart
848
- let progress = min(1, max(0, elapsed / max(0.001, structuralAnimationDuration)))
849
- let eased = progress * progress * (3 - 2 * progress)
850
- structuralSpacerHeight = structuralStartSpacer * (1 - eased)
851
- structuralFooterProgress = CGFloat(eased)
852
- structuralRemovalProgress = CGFloat(eased)
853
- for case let cell as NativeListRowHost in collectionView.visibleCells {
854
- guard let indexPath = collectionView.indexPath(for: cell),
855
- let key = dataSource.itemIdentifier(for: indexPath) else { continue }
856
- cell.structuralContentHeight = structuralRemovedItems[key].map {
857
- rowHeight($0, allocatedWidth: cell.bounds.width)
858
- }
859
- }
860
- var inset = flowLayout.sectionInset
861
- inset.bottom = config.contentPaddingBottom + containerSlotHeights[2] + structuralSpacerHeight
862
- flowLayout.sectionInset = inset
863
- flowLayout.invalidateLayout()
864
- collectionView.layoutIfNeeded()
865
- if !structuralScrollInterrupted && !collectionView.isTracking
866
- && !collectionView.isDragging && !collectionView.isDecelerating {
867
- collectionView.contentOffset.y = structuralStartOffset
868
- + (structuralTargetOffset - structuralStartOffset) * eased
869
- // Materialize the new viewport before updating presentation cells.
870
- collectionView.layoutIfNeeded()
871
- }
872
- for cell in collectionView.visibleCells {
873
- guard let indexPath = collectionView.indexPath(for: cell),
874
- let key = dataSource.itemIdentifier(for: indexPath) else { continue }
875
- let retiring = structuralRemovedItems[key] != nil
876
- if retiring { cell.clipsToBounds = true }
877
- cell.alpha = retiring ? 1 - structuralRemovalProgress : 1
878
- cell.isUserInteractionEnabled = !retiring && !(itemsByKey[key]?.data.bool("disabled") ?? false)
879
- }
880
- layoutContainerSlots()
881
- if progress >= 1 {
882
- if !structuralRemovedItems.isEmpty {
883
- var snapshot = dataSource.snapshot()
884
- snapshot.deleteItems(Array(structuralRemovedItems.keys))
885
- structuralRemovedItems.removeAll()
886
- structuralRemovedHeights.removeAll()
887
- dataSource.apply(snapshot, animatingDifferences: false)
888
- itemsByKey = Dictionary(uniqueKeysWithValues: config.items.map { ($0.key, $0) })
889
- collectionView.layoutIfNeeded()
890
- if !structuralScrollInterrupted && !collectionView.isTracking
891
- && !collectionView.isDragging && !collectionView.isDecelerating {
892
- let inset = collectionView.adjustedContentInset
893
- let maximum = max(-inset.top,
894
- collectionView.contentSize.height - collectionView.bounds.height + inset.bottom)
895
- let target = min(max(-inset.top, structuralTargetOffset), maximum)
896
- // Cancel UIKit's residual content-shrink scroll animation after deleting retired rows.
897
- collectionView.setContentOffset(
898
- CGPoint(x: collectionView.contentOffset.x, y: target), animated: false)
899
- collectionView.layoutIfNeeded()
900
- }
901
- }
902
- stopStructuralAnimation()
903
- structuralSpacerHeight = 0
904
- structuralFooterStartY = nil
905
- layoutContainerSlots()
906
- emitVisibleRangeIfNeeded()
907
- checkEndReached()
908
- scheduleContentShrinkCorrection()
909
- }
910
638
  }
911
639
 
912
640
  func applyPatchesJson(_ json: String) {
@@ -968,7 +696,6 @@ final class NativeListView: UIView {
968
696
  }
969
697
  config = current
970
698
  itemsByKey = Dictionary(uniqueKeysWithValues: current.items.map { ($0.key, $0) })
971
- itemsByKey.merge(structuralRemovedItems) { current, _ in current }
972
699
  for indexPath in collectionView.indexPathsForVisibleItems {
973
700
  guard let item = item(at: indexPath),
974
701
  marketQuoteKeys.contains(item.key),
@@ -1232,7 +959,6 @@ final class NativeListView: UIView {
1232
959
  guard let self else { return }
1233
960
  self.contentShrinkCorrectionScheduled = false
1234
961
  guard !self.disposed, self.needsContentShrinkCorrection,
1235
- self.structuralDisplayLink == nil,
1236
962
  !self.collectionView.isTracking, !self.collectionView.isDragging,
1237
963
  !self.collectionView.isDecelerating,
1238
964
  self.collectionView.refreshControl?.isRefreshing != true,
@@ -1268,21 +994,15 @@ final class NativeListView: UIView {
1268
994
  flowLayout.scrollDirection = isHorizontal ? .horizontal : .vertical
1269
995
  flowLayout.minimumLineSpacing = config.itemSpacing
1270
996
  flowLayout.minimumInteritemSpacing = config.itemSpacing
1271
- let sidecarInset = sidecarBaseInset(collectionView.bounds.width)
1272
- let sidecarSpace = sidecarLayout.map { $0.width + $0.gap } ?? 0
1273
- let horizontalInset = config.contentPaddingHorizontal + sidecarInset
1274
997
  flowLayout.sectionInset = UIEdgeInsets(
1275
998
  top: config.contentPaddingTop + containerSlotHeights[0],
1276
- left: horizontalInset + (isRightToLeft ? sidecarSpace + indexGutter : 0),
1277
- bottom: config.contentPaddingBottom + containerSlotHeights[2] + structuralSpacerHeight,
1278
- right: horizontalInset + (isRightToLeft ? 0 : sidecarSpace + indexGutter)
999
+ left: config.contentPaddingHorizontal + (isRightToLeft ? indexGutter : 0),
1000
+ bottom: config.contentPaddingBottom + containerSlotHeights[2],
1001
+ right: config.contentPaddingHorizontal + (isRightToLeft ? 0 : indexGutter)
1279
1002
  )
1280
- let emptyMinimum = config.items.isEmpty
1281
- ? config.contentPaddingTop + config.contentPaddingBottom + containerSlotHeights.prefix(3).reduce(0, +)
1003
+ flowLayout.minimumContainerContentHeight = config.items.isEmpty
1004
+ ? config.contentPaddingTop + config.contentPaddingBottom + containerSlotHeights.reduce(0, +)
1282
1005
  : 0
1283
- let sidecarMinimum = sidecarLayout == nil ? 0 :
1284
- config.contentPaddingTop + containerSlotHeights[3] + config.contentPaddingBottom
1285
- flowLayout.minimumContainerContentHeight = max(emptyMinimum, sidecarMinimum)
1286
1006
  flowLayout.stickyItemIndexes = config.stickyHeaders
1287
1007
  ? Set(config.items.enumerated().compactMap {
1288
1008
  $0.element.type == "sectionHeader" && $0.element.data.bool("sticky", default: true) && $0.element.data.string("variant") != "summary"
@@ -1976,12 +1696,6 @@ final class NativeListView: UIView {
1976
1696
  if item.key == interactiveReorderCompactKey {
1977
1697
  cell.setWalletGroupReorderCompact(true)
1978
1698
  }
1979
- let retiring = structuralRemovedItems[item.key] != nil
1980
- cell.structuralContentHeight = retiring
1981
- ? rowHeight(item, allocatedWidth: cell.bounds.width) : nil
1982
- if retiring { cell.clipsToBounds = true }
1983
- cell.alpha = retiring ? 1 - structuralRemovalProgress : 1
1984
- cell.isUserInteractionEnabled = !retiring && !item.data.bool("disabled")
1985
1699
  }
1986
1700
 
1987
1701
  private func handleRowPress(_ item: NativeListItem, origin: NativeListActionOrigin?) {
@@ -2006,8 +1720,8 @@ final class NativeListView: UIView {
2006
1720
  guard gesture.state == .began else { return }
2007
1721
  let point = gesture.location(in: collectionView)
2008
1722
  guard let indexPath = collectionView.indexPathForItem(at: point),
2009
- let item = item(at: indexPath), structuralRemovedItems[item.key] == nil,
2010
- (item.type == "market" || item.type == "identity"),
1723
+ let item = config?.items[safe: indexPath.item],
1724
+ item.type == "market",
2011
1725
  item.isRowPressEnabled else { return }
2012
1726
  let actionKey = item.data.string("longPressActionKey")
2013
1727
  guard !actionKey.isEmpty else { return }
@@ -2443,11 +2157,6 @@ final class NativeListView: UIView {
2443
2157
  dataSource = nil
2444
2158
 
2445
2159
  config = nil
2446
- pagerStickyHeights.removeAllObjects()
2447
- for slot in reactContainerSlots { slot.host.layer.mask = nil }
2448
- stopStructuralAnimation()
2449
- structuralSpacerHeight = 0
2450
- structuralFooterStartY = nil
2451
2160
  itemsByKey.removeAll()
2452
2161
  sectionIndexEntries.removeAll()
2453
2162
  if let pagerCommandCancelObserver {
@@ -2563,8 +2272,7 @@ final class NativeListView: UIView {
2563
2272
  DispatchQueue.main.async { [weak self] in
2564
2273
  guard let self else { return }
2565
2274
  self.visibleEventScheduled = false
2566
- guard self.structuralRemovedItems.isEmpty,
2567
- let onVisibleRangeChanged = self.onVisibleRangeChanged else { return }
2275
+ guard let onVisibleRangeChanged = self.onVisibleRangeChanged else { return }
2568
2276
  let indexes = self.collectionView.indexPathsForVisibleItems.map(\.item).sorted()
2569
2277
  let first = indexes.first ?? -1
2570
2278
  let last = indexes.last ?? -1
@@ -2583,7 +2291,7 @@ final class NativeListView: UIView {
2583
2291
  }
2584
2292
 
2585
2293
  private func checkEndReached() {
2586
- guard let config, structuralRemovedItems.isEmpty,
2294
+ guard let config,
2587
2295
  config.loadMore,
2588
2296
  endReachedGeneration != config.generation,
2589
2297
  !config.items.isEmpty else { return }
@@ -2608,8 +2316,7 @@ final class NativeListView: UIView {
2608
2316
  if gestureRecognizer === reorderLongPress {
2609
2317
  return config?.reorderable == true && item.isReorderable
2610
2318
  }
2611
- return (item.type == "market" || item.type == "identity")
2612
- && item.isRowPressEnabled && !item.data.string("longPressActionKey").isEmpty
2319
+ return item.type == "market" && item.isRowPressEnabled && !item.data.string("longPressActionKey").isEmpty
2613
2320
  }
2614
2321
  guard gestureRecognizer === listBodyGestureGuard,
2615
2322
  let pan = gestureRecognizer as? UIPanGestureRecognizer else { return true }
@@ -2720,16 +2427,14 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
2720
2427
  return CGSize(width: width, height: height)
2721
2428
  }
2722
2429
  let available = max(0, collectionView.bounds.width - insets.left - insets.right)
2723
- let structural = item.type == "sectionHeader" || item.type == "system" || item.type == "action" || item.type == "buttonGroup"
2430
+ let structural = item.type == "sectionHeader" || item.type == "system" || item.type == "action"
2724
2431
  if config.layout == "grid", !structural {
2725
2432
  let spacing = CGFloat(config.gridColumns - 1) * config.itemSpacing
2726
2433
  let width = floor((available - spacing) / CGFloat(config.gridColumns))
2727
2434
  let height = item.styledHeight ?? (item.type == "mediaTile" && item.data["height"] == nil ? width + 48 : rowHeight(item, allocatedWidth: width))
2728
2435
  return CGSize(width: width, height: height)
2729
2436
  }
2730
- let height = structuralRemovedHeights[item.key].map { $0 * (1 - structuralRemovalProgress) }
2731
- ?? rowHeight(item, allocatedWidth: available)
2732
- return CGSize(width: available, height: max(0.01, height))
2437
+ return CGSize(width: available, height: rowHeight(item, allocatedWidth: available))
2733
2438
  }
2734
2439
 
2735
2440
  private func railWidth(_ item: NativeListItem) -> CGFloat {
@@ -2737,20 +2442,19 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
2737
2442
  }
2738
2443
 
2739
2444
  func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
2740
- guard let item = item(at: indexPath), structuralRemovedItems[item.key] == nil else { return }
2445
+ guard let item = config?.items[safe: indexPath.item] else { return }
2741
2446
  if item.type == "walletGroup" { return }
2742
2447
  let origin = (collectionView.cellForItem(at: indexPath) as? NativeListRowHost)?.rowActionOrigin()
2743
2448
  handleRowPress(item, origin: origin)
2744
2449
  }
2745
2450
 
2746
2451
  func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool {
2747
- guard let item = item(at: indexPath), structuralRemovedItems[item.key] == nil else { return false }
2452
+ guard let item = config?.items[safe: indexPath.item] else { return false }
2748
2453
  return item.isRowPressEnabled
2749
2454
  }
2750
2455
 
2751
2456
  func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
2752
- guard let item = item(at: indexPath), structuralRemovedItems[item.key] == nil,
2753
- item.type == "market" else { return }
2457
+ guard let item = config?.items[safe: indexPath.item], item.type == "market" else { return }
2754
2458
  let actionKey = item.data.string("pressInActionKey")
2755
2459
  guard !actionKey.isEmpty else { return }
2756
2460
  let origin = (collectionView.cellForItem(at: indexPath) as? NativeListRowHost)?.rowActionOrigin()
@@ -2758,7 +2462,7 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
2758
2462
  }
2759
2463
 
2760
2464
  func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
2761
- guard let item = item(at: indexPath), structuralRemovedItems[item.key] == nil else { return false }
2465
+ guard let item = config?.items[safe: indexPath.item] else { return false }
2762
2466
  return item.isRowPressEnabled
2763
2467
  }
2764
2468
 
@@ -2770,11 +2474,6 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
2770
2474
  }
2771
2475
 
2772
2476
  func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
2773
- if structuralDisplayLink != nil {
2774
- structuralScrollInterrupted = true
2775
- NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
2776
- object: collectionView, userInfo: ["phase": 2])
2777
- }
2778
2477
  scrollViewDidEndScrollingAnimation(scrollView)
2779
2478
  minimumDragOffset = 0
2780
2479
  refreshEmittedForDrag = false
@@ -2813,7 +2512,7 @@ extension NativeListView: UICollectionViewDragDelegate, UICollectionViewDropDele
2813
2512
  itemsForBeginning session: UIDragSession,
2814
2513
  at indexPath: IndexPath
2815
2514
  ) -> [UIDragItem] {
2816
- guard config?.reorderable == true, structuralDisplayLink == nil,
2515
+ guard config?.reorderable == true,
2817
2516
  let item = config?.items[safe: indexPath.item],
2818
2517
  item.isReorderable else { return [] }
2819
2518
  let dragItem = UIDragItem(itemProvider: NSItemProvider(object: item.key as NSString))
@@ -2888,7 +2587,6 @@ private final class NativeListCollectionView: UICollectionView {
2888
2587
  final class NativeListFlowLayout: UICollectionViewFlowLayout {
2889
2588
  var stickyItemIndexes: Set<Int> = []
2890
2589
  var minimumContainerContentHeight: CGFloat = 0
2891
- var bodyContentHeight: CGFloat { super.collectionViewContentSize.height }
2892
2590
  private var horizontalAttributes: [IndexPath: UICollectionViewLayoutAttributes] = [:]
2893
2591
  private var horizontalContentSize: CGSize = .zero
2894
2592
 
@@ -4,62 +4,6 @@ import XCTest
4
4
 
5
5
  @MainActor
6
6
  final class NativeListActivityPresentationTests: XCTestCase {
7
- func testActivityLeadingVisibilityAndFooterAlignmentRestoreOnRebind() throws {
8
- func item(rich: Bool, hidden: Bool) throws -> NativeListItem {
9
- var data: [String: Any] = [
10
- "type": "activity", "key": "tx", "title": "Send", "description": "To Alice",
11
- "leading": ["kind": "icon", "name": "ArrowTopOutline"],
12
- "hideLeading": hidden,
13
- "footerActions": [["key": "speed-up", "label": "Speed up"]],
14
- ]
15
- if rich { data["amounts"] = [["key": "send", "text": "••••"]] }
16
- else { data["primaryAmount"] = "••••" }
17
- return try NativeListItem(data: data)
18
- }
19
- let details = NativeListActivityDetailsView()
20
- let main = try XCTUnwrap(details.arrangedSubviews.first as? UIStackView)
21
- let richVisual = try XCTUnwrap(main.arrangedSubviews.first)
22
- let richActions = try XCTUnwrap(details.arrangedSubviews.last as? UIStackView)
23
- let container = UIView(frame: CGRect(x: 0, y: 0, width: 366, height: 300))
24
- details.translatesAutoresizingMaskIntoConstraints = false
25
- container.addSubview(details)
26
- NSLayoutConstraint.activate([
27
- details.leadingAnchor.constraint(equalTo: container.leadingAnchor),
28
- details.trailingAnchor.constraint(equalTo: container.trailingAnchor),
29
- details.topAnchor.constraint(equalTo: container.topAnchor),
30
- ])
31
- for hidden in [false, true, false] {
32
- let current = try item(rich: true, hidden: hidden)
33
- details.bind(current, theme: nil, fonts: NativeListFontFamilies())
34
- container.layoutIfNeeded()
35
- XCTAssertEqual(richVisual.isHidden, hidden)
36
- XCTAssertEqual(richActions.directionalLayoutMargins.leading, hidden ? 0 : 52)
37
- XCTAssertEqual(
38
- NativeListActivityDetailsView.measure(
39
- current.data, width: 390,
40
- fonts: NativeListFontFamilies()),
41
- ceil(details.frame.height) + 16, accuracy: 1)
42
- func hasAmount(_ view: UIView) -> Bool {
43
- if (view as? UILabel)?.text == "••••" { return true }
44
- return view.subviews.contains(where: hasAmount)
45
- }
46
- XCTAssertTrue(hasAmount(details))
47
- }
48
-
49
- let cell = NativeListActivityCell(frame: CGRect(x: 0, y: 0, width: 390, height: 100))
50
- let legacyVisual = try XCTUnwrap(cell.root.arrangedSubviews.first)
51
- let column = try XCTUnwrap(cell.root.arrangedSubviews[1] as? UIStackView)
52
- let legacyActions = try XCTUnwrap(column.arrangedSubviews.last as? UIStackView)
53
- for hidden in [false, true, false] {
54
- cell.bind(item: try item(rich: false, hidden: hidden), theme: nil,
55
- layout: "linear", selected: false, checkboxState: { _, _, fallback in fallback },
56
- fonts: NativeListFontFamilies())
57
- XCTAssertEqual(legacyVisual.isHidden, hidden)
58
- XCTAssertFalse(legacyActions.isHidden)
59
- XCTAssertEqual((legacyActions.arrangedSubviews.first as? UIButton)?.currentTitle, "Speed up")
60
- }
61
- }
62
-
63
7
  func testSmallNumberRunsPreserveBaselineAcrossAmountsFiatAndFee() throws {
64
8
  func segments(_ prefix: String, _ suffix: String) -> [[String: Any]] {
65
9
  [["text": prefix], ["text": "5", "style": "subscript"], ["text": suffix]]