@onekeyfe/react-native-native-list 6.7.0-alpha.359 → 6.7.0-alpha.363
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.
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +0 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +7 -240
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +4 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +3 -6
- package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +0 -12
- package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +7 -87
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +1 -135
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +14 -43
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +0 -25
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +2 -17
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +0 -22
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +0 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +0 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +2 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +0 -69
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +1 -55
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +29 -587
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +0 -1
- package/docs/ROW_TEMPLATES.md +9 -60
- package/docs/SPEC.md +15 -317
- package/docs/STYLE_SPEC.md +0 -6
- package/ios/HybridNativeList.swift +0 -10
- package/ios/NativeListAccessoryStack.swift +37 -220
- package/ios/NativeListActivityDetailsView.swift +8 -18
- package/ios/NativeListActivityRenderer.swift +2 -8
- package/ios/NativeListDataRowRenderer.swift +16 -128
- package/ios/NativeListDesignAssets.swift +0 -3
- package/ios/NativeListIdentityRenderer.swift +5 -123
- package/ios/NativeListLeadingVisual.swift +14 -49
- package/ios/NativeListMessageRenderer.swift +1 -34
- package/ios/NativeListModels.swift +2 -16
- package/ios/NativeListRendererRegistry.swift +0 -1
- package/ios/NativeListResolvedText.swift +1 -2
- package/ios/NativeListRowHost.swift +0 -14
- package/ios/NativeListSectionHeaderRenderer.swift +0 -88
- package/ios/RNCNativeListView.swift +29 -335
- package/ios/tests/NativeListActivityPresentationTests.swift +0 -56
- package/ios/tests/NativeListLifecycleTests.swift +3 -1283
- package/lib/module/NativeList.js +21 -39
- package/lib/module/NativeList.web.js +4 -51
- package/lib/module/models.js +0 -1
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +8 -320
- package/lib/module/web/NativeListWebEngine.js +18 -373
- package/lib/module/web/templates/ActivityRowRenderer.js +7 -8
- package/lib/module/web/templates/DataRowRenderer.js +5 -40
- package/lib/module/web/templates/IdentityRowRenderer.js +4 -90
- package/lib/module/web/templates/MessageRowRenderer.js +2 -18
- package/lib/module/web/templates/RowContainerStyle.js +0 -1
- package/lib/module/web/templates/RowRendererRegistry.js +0 -3
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +2 -36
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +0 -9
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +0 -2
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +0 -5
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +0 -6
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +0 -7
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +0 -6
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +0 -1
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +0 -11
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +0 -2
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +0 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +0 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +0 -3
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +0 -1
- package/lib/typescript/src/NativeList.nitro.d.ts +0 -1
- package/lib/typescript/src/NativeList.types.d.ts +0 -8
- package/lib/typescript/src/models.d.ts +9 -101
- package/lib/typescript/src/validation.d.ts +0 -10
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +0 -26
- package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +3 -9
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +0 -9
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +0 -2
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +0 -5
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +0 -6
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +0 -7
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +0 -6
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +0 -11
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +0 -2
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +0 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +0 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +0 -3
- package/nitrogen/generated/shared/json/NativeListConfig.json +0 -1
- package/package.json +3 -3
- package/react-native-native-list.podspec +0 -1
- package/src/NativeList.nitro.ts +0 -1
- package/src/NativeList.tsx +24 -72
- package/src/NativeList.types.ts +0 -9
- package/src/NativeList.web.tsx +8 -72
- package/src/models.ts +3 -113
- package/src/selection.ts +0 -1
- package/src/validation.ts +6 -721
- package/src/web/NativeListWebEngine.ts +19 -568
- package/src/web/templates/ActivityRowRenderer.ts +6 -14
- package/src/web/templates/DataRowRenderer.ts +20 -93
- package/src/web/templates/IdentityRowRenderer.ts +5 -150
- package/src/web/templates/MessageRowRenderer.ts +7 -23
- package/src/web/templates/RowContainerStyle.ts +0 -2
- package/src/web/templates/RowRendererRegistry.ts +1 -11
- package/src/web/templates/SectionHeaderRowRenderer.ts +4 -47
- package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +0 -102
- package/ios/NativeListButtonGroupRenderer.swift +0 -89
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +0 -4
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +0 -3
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +0 -3
- package/lib/module/web/templates/ButtonGroupRowRenderer.js +0 -47
- package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +0 -14
- 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
|
|
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 ==
|
|
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 ==
|
|
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
|
-
|
|
226
|
-
let
|
|
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 {
|
|
@@ -364,7 +273,6 @@ final class NativeListView: UIView {
|
|
|
364
273
|
private var sectionIndexHapticsEnabled = true
|
|
365
274
|
private var lastLayoutDirection: UIUserInterfaceLayoutDirection?
|
|
366
275
|
private var lastLayoutSize: CGSize?
|
|
367
|
-
private var lastConfiguredCollectionWidth: CGFloat?
|
|
368
276
|
private var commandAcceptedForPendingScroll = false
|
|
369
277
|
private var performingExplicitScrollCommand = false
|
|
370
278
|
private var animatedExplicitScrollCommand = false
|
|
@@ -631,16 +539,14 @@ final class NativeListView: UIView {
|
|
|
631
539
|
height: requestedTopOverlayHeight)
|
|
632
540
|
updateSectionIndexAttachment()
|
|
633
541
|
let direction = effectiveUserInterfaceLayoutDirection
|
|
634
|
-
let
|
|
635
|
-
|
|
542
|
+
if let lastLayoutSize,
|
|
543
|
+
lastLayoutSize != bounds.size || lastLayoutDirection != nil && lastLayoutDirection != direction {
|
|
636
544
|
invalidateActionAnchor(reason: "layout")
|
|
637
545
|
}
|
|
638
546
|
lastLayoutSize = bounds.size
|
|
639
|
-
|
|
640
|
-
&& lastConfiguredCollectionWidth != collectionView.bounds.width
|
|
641
|
-
if (lastLayoutDirection != direction || collectionWidthChanged), let config {
|
|
547
|
+
if lastLayoutDirection != direction, let config {
|
|
642
548
|
configureLayout(config)
|
|
643
|
-
|
|
549
|
+
rebindRowsForLayoutDirection(config)
|
|
644
550
|
}
|
|
645
551
|
performPendingScrollIfNeeded()
|
|
646
552
|
layoutContainerSlots()
|
|
@@ -675,83 +581,8 @@ final class NativeListView: UIView {
|
|
|
675
581
|
|
|
676
582
|
func applySnapshotJson(_ json: String) {
|
|
677
583
|
guard let next = try? NativeListConfig.parse(json: json) else { return }
|
|
678
|
-
let oldKeys = dataSource.snapshot().itemIdentifiers
|
|
679
|
-
let logicalOldKeys = config?.items.map(\.key) ?? []
|
|
680
|
-
let presentationItems = itemsByKey
|
|
681
|
-
let newKeys = next.items.map(\.key)
|
|
682
|
-
let transition = next.structuralTransition
|
|
683
|
-
let isNewTransition = transition != nil && transition?.id != consumedStructuralTransitionID
|
|
684
|
-
if let transition { consumedStructuralTransitionID = transition.id }
|
|
685
|
-
let animateStructure = config != nil && isNewTransition && logicalOldKeys != newKeys
|
|
686
|
-
&& next.orientation == "vertical" && (next.layout == "linear" || next.layout == "table")
|
|
687
|
-
&& !UIAccessibility.isReduceMotionEnabled
|
|
688
|
-
&& (transition?.duration ?? 0) > 0
|
|
689
|
-
let presentationHeights: [String: CGFloat] = animateStructure ? Dictionary(uniqueKeysWithValues: oldKeys.compactMap { key -> (String, CGFloat)? in
|
|
690
|
-
guard let item = presentationItems[key] else { return nil }
|
|
691
|
-
let height = structuralRemovedHeights[key].map { $0 * (1 - structuralRemovalProgress) }
|
|
692
|
-
?? rowHeight(item)
|
|
693
|
-
return (key, height)
|
|
694
|
-
}) : [:]
|
|
695
|
-
let previousOffset = collectionView.contentOffset.y
|
|
696
|
-
let oldLeftContentHeight = animateStructure ? flowLayout.bodyContentHeight : 0
|
|
697
|
-
let oldSpacerHeight = structuralSpacerHeight
|
|
698
|
-
let oldRowsHeight = animateStructure
|
|
699
|
-
? presentationHeights.values.reduce(CGFloat(0), +)
|
|
700
|
-
+ CGFloat(max(0, oldKeys.count - 1)) * (config?.itemSpacing ?? 0)
|
|
701
|
-
: 0
|
|
702
|
-
let newRowsHeight = animateStructure
|
|
703
|
-
? next.items.reduce(CGFloat(0)) { $0 + rowHeight($1) }
|
|
704
|
-
+ CGFloat(max(0, newKeys.count - 1)) * next.itemSpacing
|
|
705
|
-
: 0
|
|
706
|
-
let survivingKeys = animateStructure ? Set(newKeys) : Set<String>()
|
|
707
|
-
let visibleAnchor = animateStructure
|
|
708
|
-
? collectionView.indexPathsForVisibleItems.sorted().first {
|
|
709
|
-
oldKeys.indices.contains($0.item) && survivingKeys.contains(oldKeys[$0.item])
|
|
710
|
-
}
|
|
711
|
-
: nil
|
|
712
|
-
let anchorKey = visibleAnchor.map { oldKeys[$0.item] }
|
|
713
|
-
let oldPrefix = (animateStructure ? anchorKey : nil).flatMap { key -> CGFloat? in
|
|
714
|
-
guard let index = oldKeys.firstIndex(of: key) else { return nil }
|
|
715
|
-
return oldKeys.prefix(index).reduce(CGFloat(0)) { $0 + (presentationHeights[$1] ?? 0) }
|
|
716
|
-
+ CGFloat(index) * (config?.itemSpacing ?? 0)
|
|
717
|
-
} ?? 0
|
|
718
|
-
let newPrefix = (animateStructure ? anchorKey : nil).flatMap { key -> CGFloat? in
|
|
719
|
-
guard let index = newKeys.firstIndex(of: key) else { return nil }
|
|
720
|
-
return next.items.prefix(index).reduce(CGFloat(0)) { $0 + rowHeight($1) }
|
|
721
|
-
+ CGFloat(index) * next.itemSpacing
|
|
722
|
-
} ?? 0
|
|
723
|
-
if animateStructure {
|
|
724
|
-
stopStructuralAnimation()
|
|
725
|
-
structuralScrollInterrupted = false
|
|
726
|
-
structuralFooterStartY = reactContainerSlots.count > 2
|
|
727
|
-
? reactContainerSlots[2].host.frame.minY : nil
|
|
728
|
-
structuralFooterProgress = 0
|
|
729
|
-
// Keep deletion-only snapshots in their presentation order until their heights
|
|
730
|
-
// reach zero. Replacing these rows with a spacer produces a blank viewport.
|
|
731
|
-
let removedKeys = Set(oldKeys).subtracting(newKeys)
|
|
732
|
-
let retainsOrder = oldKeys.filter { survivingKeys.contains($0) } == newKeys
|
|
733
|
-
structuralRemovedItems = retainsOrder
|
|
734
|
-
? presentationItems.filter { removedKeys.contains($0.key) } : [:]
|
|
735
|
-
structuralRemovedHeights = retainsOrder
|
|
736
|
-
? presentationHeights.filter { removedKeys.contains($0.key) } : [:]
|
|
737
|
-
structuralRemovalProgress = 0
|
|
738
|
-
structuralSpacerHeight = structuralRemovedItems.isEmpty
|
|
739
|
-
? max(0, structuralSpacerHeight + oldRowsHeight - newRowsHeight) : 0
|
|
740
|
-
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
741
|
-
object: collectionView, userInfo: ["phase": 0])
|
|
742
|
-
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
743
|
-
object: collectionView, userInfo: ["phase": 1])
|
|
744
|
-
needsContentShrinkCorrection = false
|
|
745
|
-
} else if logicalOldKeys != newKeys {
|
|
746
|
-
stopStructuralAnimation()
|
|
747
|
-
structuralSpacerHeight = 0
|
|
748
|
-
structuralFooterStartY = nil
|
|
749
|
-
structuralRemovedItems.removeAll()
|
|
750
|
-
structuralRemovedHeights.removeAll()
|
|
751
|
-
}
|
|
752
584
|
invalidateActionAnchor(reason: "snapshot")
|
|
753
|
-
if let current = config,
|
|
754
|
-
isControlledSelectionSnapshotUpdate(from: current, to: next) {
|
|
585
|
+
if let current = config, isControlledSelectionSnapshotUpdate(from: current, to: next) {
|
|
755
586
|
config = next
|
|
756
587
|
itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
|
|
757
588
|
// OneKey patch: A controlled selection echo is fully handled by the
|
|
@@ -771,41 +602,17 @@ final class NativeListView: UIView {
|
|
|
771
602
|
// rows whose own content is unchanged.
|
|
772
603
|
let themeChanged = !dictionariesEqual(config?.theme, next.theme)
|
|
773
604
|
|| !dictionariesEqual(config?.listStyle, next.listStyle)
|
|
774
|
-
|| config?.layout != next.layout
|
|
775
605
|
if config?.generation != next.generation { endReachedGeneration = nil }
|
|
776
606
|
config = next
|
|
777
607
|
itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
|
|
778
|
-
itemsByKey.merge(structuralRemovedItems) { current, _ in current }
|
|
779
608
|
configureSectionIndex(next)
|
|
780
609
|
configureLayout(next)
|
|
781
610
|
configureRefresh(next)
|
|
782
611
|
configureFooter(next)
|
|
783
612
|
|
|
784
|
-
if animateStructure, let transition {
|
|
785
|
-
let inset = collectionView.adjustedContentInset
|
|
786
|
-
let finalLeftHeight = max(0,
|
|
787
|
-
oldLeftContentHeight + newRowsHeight - oldRowsHeight - oldSpacerHeight)
|
|
788
|
-
let sidecarHeight = sidecarLayout == nil ? 0 :
|
|
789
|
-
next.contentPaddingTop + containerSlotHeights[3] + next.contentPaddingBottom
|
|
790
|
-
let finalHeight = max(finalLeftHeight, sidecarHeight)
|
|
791
|
-
let finalMaximum = max(-inset.top, finalHeight - collectionView.bounds.height + inset.bottom)
|
|
792
|
-
structuralStartSpacer = structuralSpacerHeight
|
|
793
|
-
structuralStartOffset = previousOffset
|
|
794
|
-
var targetOffset = min(max(-inset.top, previousOffset + newPrefix - oldPrefix), finalMaximum)
|
|
795
|
-
if visibleAnchor == nil, let fallbackKey = transition.anchorKey,
|
|
796
|
-
let fallbackIndex = newKeys.firstIndex(of: fallbackKey) {
|
|
797
|
-
let fallbackY = next.contentPaddingTop + containerSlotHeights[0]
|
|
798
|
-
+ next.items.prefix(fallbackIndex).reduce(CGFloat(0)) { $0 + rowHeight($1) }
|
|
799
|
-
+ CGFloat(fallbackIndex) * next.itemSpacing
|
|
800
|
-
targetOffset = min(targetOffset, max(-inset.top, fallbackY - inset.top))
|
|
801
|
-
}
|
|
802
|
-
structuralTargetOffset = targetOffset
|
|
803
|
-
structuralAnimationDuration = transition.duration
|
|
804
|
-
}
|
|
805
|
-
|
|
806
613
|
var snapshot = NSDiffableDataSourceSnapshot<Int, String>()
|
|
807
614
|
snapshot.appendSections([0])
|
|
808
|
-
let keys =
|
|
615
|
+
let keys = next.items.map(\.key)
|
|
809
616
|
snapshot.appendItems(keys, toSection: 0)
|
|
810
617
|
var changedKeys = Set(keys.filter { key in
|
|
811
618
|
guard let old = oldItems[key], let new = itemsByKey[key] else { return false }
|
|
@@ -820,7 +627,7 @@ final class NativeListView: UIView {
|
|
|
820
627
|
let replacedKeys = changedRetainedKeys.filter { oldItems[$0]?.rendererKey != itemsByKey[$0]?.rendererKey }
|
|
821
628
|
snapshot.reloadItems(Array(replacedKeys))
|
|
822
629
|
snapshot.reconfigureItems(Array(changedRetainedKeys.subtracting(replacedKeys)))
|
|
823
|
-
dataSource.apply(snapshot, animatingDifferences:
|
|
630
|
+
dataSource.apply(snapshot, animatingDifferences: false) { [weak self] in
|
|
824
631
|
guard let self else { return }
|
|
825
632
|
self.collectionView.layoutIfNeeded()
|
|
826
633
|
self.performPendingScrollIfNeeded()
|
|
@@ -828,88 +635,6 @@ final class NativeListView: UIView {
|
|
|
828
635
|
self.checkEndReached()
|
|
829
636
|
self.syncSectionIndexToVisibleRows()
|
|
830
637
|
}
|
|
831
|
-
if animateStructure {
|
|
832
|
-
structuralAnimationStart = CACurrentMediaTime()
|
|
833
|
-
let displayLink = CADisplayLink(target: self, selector: #selector(advanceStructuralAnimation))
|
|
834
|
-
structuralDisplayLink = displayLink
|
|
835
|
-
displayLink.add(to: .main, forMode: .common)
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
private func stopStructuralAnimation() {
|
|
840
|
-
if structuralDisplayLink != nil {
|
|
841
|
-
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
842
|
-
object: collectionView, userInfo: ["phase": 2])
|
|
843
|
-
}
|
|
844
|
-
structuralDisplayLink?.invalidate()
|
|
845
|
-
structuralDisplayLink = nil
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
@objc private func advanceStructuralAnimation() {
|
|
849
|
-
guard let config else { stopStructuralAnimation(); return }
|
|
850
|
-
let elapsed = CACurrentMediaTime() - structuralAnimationStart
|
|
851
|
-
let progress = min(1, max(0, elapsed / max(0.001, structuralAnimationDuration)))
|
|
852
|
-
let eased = progress * progress * (3 - 2 * progress)
|
|
853
|
-
structuralSpacerHeight = structuralStartSpacer * (1 - eased)
|
|
854
|
-
structuralFooterProgress = CGFloat(eased)
|
|
855
|
-
structuralRemovalProgress = CGFloat(eased)
|
|
856
|
-
for case let cell as NativeListRowHost in collectionView.visibleCells {
|
|
857
|
-
guard let indexPath = collectionView.indexPath(for: cell),
|
|
858
|
-
let key = dataSource.itemIdentifier(for: indexPath) else { continue }
|
|
859
|
-
cell.structuralContentHeight = structuralRemovedItems[key].map {
|
|
860
|
-
rowHeight($0, allocatedWidth: cell.bounds.width)
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
var inset = flowLayout.sectionInset
|
|
864
|
-
inset.bottom = config.contentPaddingBottom + containerSlotHeights[2] + structuralSpacerHeight
|
|
865
|
-
flowLayout.sectionInset = inset
|
|
866
|
-
flowLayout.invalidateLayout()
|
|
867
|
-
collectionView.layoutIfNeeded()
|
|
868
|
-
if !structuralScrollInterrupted && !collectionView.isTracking
|
|
869
|
-
&& !collectionView.isDragging && !collectionView.isDecelerating {
|
|
870
|
-
collectionView.contentOffset.y = structuralStartOffset
|
|
871
|
-
+ (structuralTargetOffset - structuralStartOffset) * eased
|
|
872
|
-
// Materialize the new viewport before updating presentation cells.
|
|
873
|
-
collectionView.layoutIfNeeded()
|
|
874
|
-
}
|
|
875
|
-
for cell in collectionView.visibleCells {
|
|
876
|
-
guard let indexPath = collectionView.indexPath(for: cell),
|
|
877
|
-
let key = dataSource.itemIdentifier(for: indexPath) else { continue }
|
|
878
|
-
let retiring = structuralRemovedItems[key] != nil
|
|
879
|
-
if retiring { cell.clipsToBounds = true }
|
|
880
|
-
cell.alpha = retiring ? 1 - structuralRemovalProgress : 1
|
|
881
|
-
cell.isUserInteractionEnabled = !retiring && !(itemsByKey[key]?.data.bool("disabled") ?? false)
|
|
882
|
-
}
|
|
883
|
-
layoutContainerSlots()
|
|
884
|
-
if progress >= 1 {
|
|
885
|
-
if !structuralRemovedItems.isEmpty {
|
|
886
|
-
var snapshot = dataSource.snapshot()
|
|
887
|
-
snapshot.deleteItems(Array(structuralRemovedItems.keys))
|
|
888
|
-
structuralRemovedItems.removeAll()
|
|
889
|
-
structuralRemovedHeights.removeAll()
|
|
890
|
-
dataSource.apply(snapshot, animatingDifferences: false)
|
|
891
|
-
itemsByKey = Dictionary(uniqueKeysWithValues: config.items.map { ($0.key, $0) })
|
|
892
|
-
collectionView.layoutIfNeeded()
|
|
893
|
-
if !structuralScrollInterrupted && !collectionView.isTracking
|
|
894
|
-
&& !collectionView.isDragging && !collectionView.isDecelerating {
|
|
895
|
-
let inset = collectionView.adjustedContentInset
|
|
896
|
-
let maximum = max(-inset.top,
|
|
897
|
-
collectionView.contentSize.height - collectionView.bounds.height + inset.bottom)
|
|
898
|
-
let target = min(max(-inset.top, structuralTargetOffset), maximum)
|
|
899
|
-
// Cancel UIKit's residual content-shrink scroll animation after deleting retired rows.
|
|
900
|
-
collectionView.setContentOffset(
|
|
901
|
-
CGPoint(x: collectionView.contentOffset.x, y: target), animated: false)
|
|
902
|
-
collectionView.layoutIfNeeded()
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
stopStructuralAnimation()
|
|
906
|
-
structuralSpacerHeight = 0
|
|
907
|
-
structuralFooterStartY = nil
|
|
908
|
-
layoutContainerSlots()
|
|
909
|
-
emitVisibleRangeIfNeeded()
|
|
910
|
-
checkEndReached()
|
|
911
|
-
scheduleContentShrinkCorrection()
|
|
912
|
-
}
|
|
913
638
|
}
|
|
914
639
|
|
|
915
640
|
func applyPatchesJson(_ json: String) {
|
|
@@ -971,7 +696,6 @@ final class NativeListView: UIView {
|
|
|
971
696
|
}
|
|
972
697
|
config = current
|
|
973
698
|
itemsByKey = Dictionary(uniqueKeysWithValues: current.items.map { ($0.key, $0) })
|
|
974
|
-
itemsByKey.merge(structuralRemovedItems) { current, _ in current }
|
|
975
699
|
for indexPath in collectionView.indexPathsForVisibleItems {
|
|
976
700
|
guard let item = item(at: indexPath),
|
|
977
701
|
marketQuoteKeys.contains(item.key),
|
|
@@ -1235,7 +959,6 @@ final class NativeListView: UIView {
|
|
|
1235
959
|
guard let self else { return }
|
|
1236
960
|
self.contentShrinkCorrectionScheduled = false
|
|
1237
961
|
guard !self.disposed, self.needsContentShrinkCorrection,
|
|
1238
|
-
self.structuralDisplayLink == nil,
|
|
1239
962
|
!self.collectionView.isTracking, !self.collectionView.isDragging,
|
|
1240
963
|
!self.collectionView.isDecelerating,
|
|
1241
964
|
self.collectionView.refreshControl?.isRefreshing != true,
|
|
@@ -1271,21 +994,15 @@ final class NativeListView: UIView {
|
|
|
1271
994
|
flowLayout.scrollDirection = isHorizontal ? .horizontal : .vertical
|
|
1272
995
|
flowLayout.minimumLineSpacing = config.itemSpacing
|
|
1273
996
|
flowLayout.minimumInteritemSpacing = config.itemSpacing
|
|
1274
|
-
let sidecarInset = sidecarBaseInset(collectionView.bounds.width)
|
|
1275
|
-
let sidecarSpace = sidecarLayout.map { $0.width + $0.gap } ?? 0
|
|
1276
|
-
let horizontalInset = config.contentPaddingHorizontal + sidecarInset
|
|
1277
997
|
flowLayout.sectionInset = UIEdgeInsets(
|
|
1278
998
|
top: config.contentPaddingTop + containerSlotHeights[0],
|
|
1279
|
-
left:
|
|
1280
|
-
bottom: config.contentPaddingBottom + containerSlotHeights[2]
|
|
1281
|
-
right:
|
|
999
|
+
left: config.contentPaddingHorizontal + (isRightToLeft ? indexGutter : 0),
|
|
1000
|
+
bottom: config.contentPaddingBottom + containerSlotHeights[2],
|
|
1001
|
+
right: config.contentPaddingHorizontal + (isRightToLeft ? 0 : indexGutter)
|
|
1282
1002
|
)
|
|
1283
|
-
|
|
1284
|
-
? config.contentPaddingTop + config.contentPaddingBottom + containerSlotHeights.
|
|
1003
|
+
flowLayout.minimumContainerContentHeight = config.items.isEmpty
|
|
1004
|
+
? config.contentPaddingTop + config.contentPaddingBottom + containerSlotHeights.reduce(0, +)
|
|
1285
1005
|
: 0
|
|
1286
|
-
let sidecarMinimum = sidecarLayout == nil ? 0 :
|
|
1287
|
-
config.contentPaddingTop + containerSlotHeights[3] + config.contentPaddingBottom
|
|
1288
|
-
flowLayout.minimumContainerContentHeight = max(emptyMinimum, sidecarMinimum)
|
|
1289
1006
|
flowLayout.stickyItemIndexes = config.stickyHeaders
|
|
1290
1007
|
? Set(config.items.enumerated().compactMap {
|
|
1291
1008
|
$0.element.type == "sectionHeader" && $0.element.data.bool("sticky", default: true) && $0.element.data.string("variant") != "summary"
|
|
@@ -1299,7 +1016,6 @@ final class NativeListView: UIView {
|
|
|
1299
1016
|
listBodyGestureGuard.isEnabled = !isHorizontal
|
|
1300
1017
|
collectionView.showsVerticalScrollIndicator = sectionIndexEntries.isEmpty
|
|
1301
1018
|
collectionView.dragInteractionEnabled = false
|
|
1302
|
-
lastConfiguredCollectionWidth = collectionView.bounds.width
|
|
1303
1019
|
lastLayoutDirection = effectiveUserInterfaceLayoutDirection
|
|
1304
1020
|
}
|
|
1305
1021
|
|
|
@@ -1980,12 +1696,6 @@ final class NativeListView: UIView {
|
|
|
1980
1696
|
if item.key == interactiveReorderCompactKey {
|
|
1981
1697
|
cell.setWalletGroupReorderCompact(true)
|
|
1982
1698
|
}
|
|
1983
|
-
let retiring = structuralRemovedItems[item.key] != nil
|
|
1984
|
-
cell.structuralContentHeight = retiring
|
|
1985
|
-
? rowHeight(item, allocatedWidth: cell.bounds.width) : nil
|
|
1986
|
-
if retiring { cell.clipsToBounds = true }
|
|
1987
|
-
cell.alpha = retiring ? 1 - structuralRemovalProgress : 1
|
|
1988
|
-
cell.isUserInteractionEnabled = !retiring && !item.data.bool("disabled")
|
|
1989
1699
|
}
|
|
1990
1700
|
|
|
1991
1701
|
private func handleRowPress(_ item: NativeListItem, origin: NativeListActionOrigin?) {
|
|
@@ -2010,8 +1720,8 @@ final class NativeListView: UIView {
|
|
|
2010
1720
|
guard gesture.state == .began else { return }
|
|
2011
1721
|
let point = gesture.location(in: collectionView)
|
|
2012
1722
|
guard let indexPath = collectionView.indexPathForItem(at: point),
|
|
2013
|
-
let item =
|
|
2014
|
-
|
|
1723
|
+
let item = config?.items[safe: indexPath.item],
|
|
1724
|
+
item.type == "market",
|
|
2015
1725
|
item.isRowPressEnabled else { return }
|
|
2016
1726
|
let actionKey = item.data.string("longPressActionKey")
|
|
2017
1727
|
guard !actionKey.isEmpty else { return }
|
|
@@ -2447,11 +2157,6 @@ final class NativeListView: UIView {
|
|
|
2447
2157
|
dataSource = nil
|
|
2448
2158
|
|
|
2449
2159
|
config = nil
|
|
2450
|
-
pagerStickyHeights.removeAllObjects()
|
|
2451
|
-
for slot in reactContainerSlots { slot.host.layer.mask = nil }
|
|
2452
|
-
stopStructuralAnimation()
|
|
2453
|
-
structuralSpacerHeight = 0
|
|
2454
|
-
structuralFooterStartY = nil
|
|
2455
2160
|
itemsByKey.removeAll()
|
|
2456
2161
|
sectionIndexEntries.removeAll()
|
|
2457
2162
|
if let pagerCommandCancelObserver {
|
|
@@ -2567,8 +2272,7 @@ final class NativeListView: UIView {
|
|
|
2567
2272
|
DispatchQueue.main.async { [weak self] in
|
|
2568
2273
|
guard let self else { return }
|
|
2569
2274
|
self.visibleEventScheduled = false
|
|
2570
|
-
guard self.
|
|
2571
|
-
let onVisibleRangeChanged = self.onVisibleRangeChanged else { return }
|
|
2275
|
+
guard let onVisibleRangeChanged = self.onVisibleRangeChanged else { return }
|
|
2572
2276
|
let indexes = self.collectionView.indexPathsForVisibleItems.map(\.item).sorted()
|
|
2573
2277
|
let first = indexes.first ?? -1
|
|
2574
2278
|
let last = indexes.last ?? -1
|
|
@@ -2587,7 +2291,7 @@ final class NativeListView: UIView {
|
|
|
2587
2291
|
}
|
|
2588
2292
|
|
|
2589
2293
|
private func checkEndReached() {
|
|
2590
|
-
guard let config,
|
|
2294
|
+
guard let config,
|
|
2591
2295
|
config.loadMore,
|
|
2592
2296
|
endReachedGeneration != config.generation,
|
|
2593
2297
|
!config.items.isEmpty else { return }
|
|
@@ -2612,8 +2316,7 @@ final class NativeListView: UIView {
|
|
|
2612
2316
|
if gestureRecognizer === reorderLongPress {
|
|
2613
2317
|
return config?.reorderable == true && item.isReorderable
|
|
2614
2318
|
}
|
|
2615
|
-
return
|
|
2616
|
-
&& item.isRowPressEnabled && !item.data.string("longPressActionKey").isEmpty
|
|
2319
|
+
return item.type == "market" && item.isRowPressEnabled && !item.data.string("longPressActionKey").isEmpty
|
|
2617
2320
|
}
|
|
2618
2321
|
guard gestureRecognizer === listBodyGestureGuard,
|
|
2619
2322
|
let pan = gestureRecognizer as? UIPanGestureRecognizer else { return true }
|
|
@@ -2724,16 +2427,14 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2724
2427
|
return CGSize(width: width, height: height)
|
|
2725
2428
|
}
|
|
2726
2429
|
let available = max(0, collectionView.bounds.width - insets.left - insets.right)
|
|
2727
|
-
let structural = item.type == "sectionHeader" || item.type == "system" || item.type == "action"
|
|
2430
|
+
let structural = item.type == "sectionHeader" || item.type == "system" || item.type == "action"
|
|
2728
2431
|
if config.layout == "grid", !structural {
|
|
2729
2432
|
let spacing = CGFloat(config.gridColumns - 1) * config.itemSpacing
|
|
2730
2433
|
let width = floor((available - spacing) / CGFloat(config.gridColumns))
|
|
2731
2434
|
let height = item.styledHeight ?? (item.type == "mediaTile" && item.data["height"] == nil ? width + 48 : rowHeight(item, allocatedWidth: width))
|
|
2732
2435
|
return CGSize(width: width, height: height)
|
|
2733
2436
|
}
|
|
2734
|
-
|
|
2735
|
-
?? rowHeight(item, allocatedWidth: available)
|
|
2736
|
-
return CGSize(width: available, height: max(0.01, height))
|
|
2437
|
+
return CGSize(width: available, height: rowHeight(item, allocatedWidth: available))
|
|
2737
2438
|
}
|
|
2738
2439
|
|
|
2739
2440
|
private func railWidth(_ item: NativeListItem) -> CGFloat {
|
|
@@ -2741,20 +2442,19 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2741
2442
|
}
|
|
2742
2443
|
|
|
2743
2444
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
2744
|
-
guard let item =
|
|
2445
|
+
guard let item = config?.items[safe: indexPath.item] else { return }
|
|
2745
2446
|
if item.type == "walletGroup" { return }
|
|
2746
2447
|
let origin = (collectionView.cellForItem(at: indexPath) as? NativeListRowHost)?.rowActionOrigin()
|
|
2747
2448
|
handleRowPress(item, origin: origin)
|
|
2748
2449
|
}
|
|
2749
2450
|
|
|
2750
2451
|
func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool {
|
|
2751
|
-
guard let item =
|
|
2452
|
+
guard let item = config?.items[safe: indexPath.item] else { return false }
|
|
2752
2453
|
return item.isRowPressEnabled
|
|
2753
2454
|
}
|
|
2754
2455
|
|
|
2755
2456
|
func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
|
|
2756
|
-
guard let item =
|
|
2757
|
-
item.type == "market" else { return }
|
|
2457
|
+
guard let item = config?.items[safe: indexPath.item], item.type == "market" else { return }
|
|
2758
2458
|
let actionKey = item.data.string("pressInActionKey")
|
|
2759
2459
|
guard !actionKey.isEmpty else { return }
|
|
2760
2460
|
let origin = (collectionView.cellForItem(at: indexPath) as? NativeListRowHost)?.rowActionOrigin()
|
|
@@ -2762,7 +2462,7 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2762
2462
|
}
|
|
2763
2463
|
|
|
2764
2464
|
func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
|
2765
|
-
guard let item =
|
|
2465
|
+
guard let item = config?.items[safe: indexPath.item] else { return false }
|
|
2766
2466
|
return item.isRowPressEnabled
|
|
2767
2467
|
}
|
|
2768
2468
|
|
|
@@ -2774,11 +2474,6 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2774
2474
|
}
|
|
2775
2475
|
|
|
2776
2476
|
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
|
|
2777
|
-
if structuralDisplayLink != nil {
|
|
2778
|
-
structuralScrollInterrupted = true
|
|
2779
|
-
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
2780
|
-
object: collectionView, userInfo: ["phase": 2])
|
|
2781
|
-
}
|
|
2782
2477
|
scrollViewDidEndScrollingAnimation(scrollView)
|
|
2783
2478
|
minimumDragOffset = 0
|
|
2784
2479
|
refreshEmittedForDrag = false
|
|
@@ -2817,7 +2512,7 @@ extension NativeListView: UICollectionViewDragDelegate, UICollectionViewDropDele
|
|
|
2817
2512
|
itemsForBeginning session: UIDragSession,
|
|
2818
2513
|
at indexPath: IndexPath
|
|
2819
2514
|
) -> [UIDragItem] {
|
|
2820
|
-
guard config?.reorderable == true,
|
|
2515
|
+
guard config?.reorderable == true,
|
|
2821
2516
|
let item = config?.items[safe: indexPath.item],
|
|
2822
2517
|
item.isReorderable else { return [] }
|
|
2823
2518
|
let dragItem = UIDragItem(itemProvider: NSItemProvider(object: item.key as NSString))
|
|
@@ -2892,7 +2587,6 @@ private final class NativeListCollectionView: UICollectionView {
|
|
|
2892
2587
|
final class NativeListFlowLayout: UICollectionViewFlowLayout {
|
|
2893
2588
|
var stickyItemIndexes: Set<Int> = []
|
|
2894
2589
|
var minimumContainerContentHeight: CGFloat = 0
|
|
2895
|
-
var bodyContentHeight: CGFloat { super.collectionViewContentSize.height }
|
|
2896
2590
|
private var horizontalAttributes: [IndexPath: UICollectionViewLayoutAttributes] = [:]
|
|
2897
2591
|
private var horizontalContentSize: CGSize = .zero
|
|
2898
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]]
|