@onekeyfe/react-native-native-list 6.7.0-4 → 6.7.0-40
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/README.md +4 -0
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +250 -9
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +35 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +25 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +102 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListGeneratedIcons.kt +47 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +225 -11
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +152 -33
- package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaPlaceholderView.kt +244 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +66 -31
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +32 -11
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +149 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +120 -287
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +7 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +3 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1953 -117
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +35 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
- package/docs/ROW_TEMPLATES.md +74 -13
- package/docs/SPEC.md +1206 -15
- package/docs/STYLE_SPEC.md +14 -0
- package/ios/HybridNativeList.swift +21 -2
- package/ios/NativeListAccessoryStack.swift +237 -51
- package/ios/NativeListActivityDetailsView.swift +30 -11
- package/ios/NativeListActivityRenderer.swift +8 -2
- package/ios/NativeListButtonGroupRenderer.swift +89 -0
- package/ios/NativeListDataRowRenderer.swift +167 -30
- package/ios/NativeListDesignAssets.swift +13 -75
- package/ios/NativeListGeneratedIcons.swift +55 -0
- package/ios/NativeListIconBinding.swift +171 -0
- package/ios/NativeListIdentityRenderer.swift +256 -39
- package/ios/NativeListLeadingVisual.swift +127 -28
- package/ios/NativeListMarketRenderer.swift +120 -31
- package/ios/NativeListMediaPlaceholderView.swift +189 -0
- package/ios/NativeListMediaPreviewSlot.swift +122 -61
- package/ios/NativeListMediaTileRenderer.swift +15 -11
- package/ios/NativeListMessageRenderer.swift +34 -1
- package/ios/NativeListMetricCardRenderer.swift +4 -2
- package/ios/NativeListModels.swift +42 -2
- package/ios/NativeListRendererRegistry.swift +1 -0
- package/ios/NativeListResolvedText.swift +2 -1
- package/ios/NativeListRowHost.swift +14 -0
- package/ios/NativeListSectionHeaderRenderer.swift +100 -4
- package/ios/RNCNativeListView.swift +1053 -58
- package/ios/tests/NativeListAccessoryStackTests.swift +101 -0
- package/ios/tests/NativeListAccountSelectorLayoutTests.swift +96 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +153 -0
- package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
- package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
- package/ios/tests/NativeListLifecycleTests.swift +2819 -3
- package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
- package/ios/tests/NativeListMediaVisibilityTests.swift +26 -1
- package/ios/tests/NativeListSharedIconTests.swift +236 -0
- package/lib/module/NativeList.js +221 -36
- package/lib/module/NativeList.web.js +167 -46
- package/lib/module/index.js +1 -1
- package/lib/module/models.js +3 -0
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +1246 -48
- package/lib/module/web/NativeListGeneratedIcons.js +31 -0
- package/lib/module/web/NativeListWebEngine.js +513 -275
- package/lib/module/web/templates/ActivityRowRenderer.js +120 -87
- package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
- package/lib/module/web/templates/DataRowRenderer.js +40 -5
- package/lib/module/web/templates/IdentityRowRenderer.js +158 -6
- package/lib/module/web/templates/MarketTableRowRenderer.js +36 -19
- package/lib/module/web/templates/MediaTileRowRenderer.js +84 -25
- package/lib/module/web/templates/MessageRowRenderer.js +18 -2
- package/lib/module/web/templates/RowContainerStyle.js +1 -0
- package/lib/module/web/templates/RowRendererRegistry.js +3 -0
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +36 -2
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
- package/lib/typescript/src/NativeList.d.ts +3 -3
- package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
- package/lib/typescript/src/NativeList.types.d.ts +20 -2
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/models.d.ts +126 -17
- package/lib/typescript/src/validation.d.ts +20 -0
- package/lib/typescript/src/web/NativeListGeneratedIcons.d.ts +2 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +32 -1
- package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
- package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +9 -3
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
- package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
- package/package.json +16 -10
- package/react-native-native-list.podspec +2 -6
- package/scripts/generate-icons.mjs +150 -0
- package/scripts/generate-icons.test.mjs +288 -0
- package/scripts/native-list-icons.json +260 -0
- package/src/NativeList.nitro.ts +2 -0
- package/src/NativeList.tsx +416 -89
- package/src/NativeList.types.ts +24 -2
- package/src/NativeList.web.tsx +295 -89
- package/src/index.ts +2 -0
- package/src/models.ts +263 -144
- package/src/selection.ts +1 -0
- package/src/validation.ts +3013 -152
- package/src/web/NativeListGeneratedIcons.ts +28 -0
- package/src/web/NativeListWebEngine.ts +818 -343
- package/src/web/templates/ActivityRowRenderer.ts +178 -141
- package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
- package/src/web/templates/DataRowRenderer.ts +93 -20
- package/src/web/templates/IdentityRowRenderer.ts +231 -6
- package/src/web/templates/MarketTableRowRenderer.ts +53 -33
- package/src/web/templates/MediaTileRowRenderer.ts +90 -28
- package/src/web/templates/MessageRowRenderer.ts +23 -7
- package/src/web/templates/RowContainerStyle.ts +2 -0
- package/src/web/templates/RowRendererRegistry.ts +11 -1
- package/src/web/templates/SectionHeaderRowRenderer.ts +47 -4
- package/ios/Resources/NativeListIcons.xcassets/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/icon.svg +0 -14
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/icon.svg +0 -12
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/icon.svg +0 -6
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/icon.svg +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/icon.svg +0 -3
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/icon.svg +0 -7
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/icon.svg +0 -18
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/icon.svg +0 -7
- package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/icon.svg +0 -1
|
@@ -30,11 +30,20 @@ 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, 0, 0, 0]
|
|
34
|
+
private var disclosureCVisibleHeight: CGFloat = 0
|
|
35
|
+
private var disclosureInset: CGFloat = 0
|
|
36
|
+
private var disclosureStartCHeight: CGFloat = 0
|
|
37
|
+
private var disclosureStartInset: CGFloat = 0
|
|
38
|
+
private var disclosureSegmentStartEased: CFTimeInterval = 0
|
|
39
|
+
private var deferredDisclosureGeometryInvalid = false
|
|
40
|
+
private var pendingDisclosureSettlement: (id: String, expanded: Bool)?
|
|
34
41
|
// Fabric keeps assigning each slot root the frame React computed (inset, 0, width, height).
|
|
35
42
|
// Each root therefore lives in a list-owned host whose origin the list alone controls, so a
|
|
36
43
|
// React layout update can never move a slot out of its native position, even for a frame.
|
|
37
44
|
private var reactContainerSlots: [(content: UIView, host: UIView)] = []
|
|
45
|
+
private var sidecarLayout: (width: CGFloat, gap: CGFloat, maxContentWidth: CGFloat)?
|
|
46
|
+
private let pagerStickyHeights = NSMapTable<AnyObject, NSNumber>(keyOptions: .weakMemory, valueOptions: .strongMemory)
|
|
38
47
|
private let topOverlayHost = UIView()
|
|
39
48
|
private weak var topOverlayContent: UIView?
|
|
40
49
|
private var topEdgeInteraction: UIInteraction?
|
|
@@ -47,16 +56,239 @@ final class NativeListView: UIView {
|
|
|
47
56
|
private var lastLaidOutContentHeight: CGFloat?
|
|
48
57
|
private var needsContentShrinkCorrection = false
|
|
49
58
|
private var contentShrinkCorrectionScheduled = false
|
|
59
|
+
private var consumedStructuralTransitionID: String?
|
|
60
|
+
private var structuralDisplayLink: CADisplayLink?
|
|
61
|
+
private var structuralScrollPhaseActive = false
|
|
62
|
+
private var structuralSpacerHeight: CGFloat = 0
|
|
63
|
+
private var structuralAnimationStart: CFTimeInterval = 0
|
|
64
|
+
private var structuralAnimationDuration: CFTimeInterval = 0
|
|
65
|
+
private var structuralStartSpacer: CGFloat = 0
|
|
66
|
+
private var structuralStartOffset: CGFloat = 0
|
|
67
|
+
private var structuralTargetOffset: CGFloat = 0
|
|
68
|
+
private var structuralScrollInterrupted = false
|
|
69
|
+
private var structuralFooterStartY: CGFloat?
|
|
70
|
+
private var structuralFooterProgress: CGFloat = 0
|
|
71
|
+
private var structuralRemovedItems: [String: NativeListItem] = [:]
|
|
72
|
+
private var structuralRemovedHeights: [String: CGFloat] = [:]
|
|
73
|
+
private var structuralRemovalProgress: CGFloat = 0
|
|
74
|
+
private final class StructuralTail {
|
|
75
|
+
var items: [NativeListItem]
|
|
76
|
+
let starts: [CGFloat]
|
|
77
|
+
let heights: [CGFloat]
|
|
78
|
+
let indexByKey: [String: Int]
|
|
79
|
+
let extent: CGFloat
|
|
80
|
+
let prefixCount: Int
|
|
81
|
+
let finalExtent: CGFloat
|
|
82
|
+
let retiringKeys: Set<String>
|
|
83
|
+
init(items: [NativeListItem], heights: [CGFloat], spacing: CGFloat,
|
|
84
|
+
prefixCount: Int, finalExtent: CGFloat) {
|
|
85
|
+
self.items = items
|
|
86
|
+
self.heights = heights
|
|
87
|
+
self.indexByKey = Dictionary(uniqueKeysWithValues: items.enumerated().map { ($1.key, $0) })
|
|
88
|
+
self.prefixCount = prefixCount
|
|
89
|
+
self.finalExtent = finalExtent
|
|
90
|
+
self.retiringKeys = finalExtent == 0 ? Set(items.map(\.key)) : []
|
|
91
|
+
var edge: CGFloat = prefixCount == 0 ? 0 : spacing
|
|
92
|
+
var starts: [CGFloat] = []
|
|
93
|
+
for (index, height) in heights.enumerated() {
|
|
94
|
+
starts.append(edge)
|
|
95
|
+
edge += height + (index + 1 < heights.count ? spacing : 0)
|
|
96
|
+
}
|
|
97
|
+
self.starts = starts
|
|
98
|
+
self.extent = edge
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
private var structuralTail: StructuralTail?
|
|
102
|
+
private var structuralTailStartExtent: CGFloat = 0
|
|
103
|
+
private var structuralTailSegmentStartEased: CFTimeInterval = 0
|
|
104
|
+
private var structuralTailStartY: CGFloat = 0
|
|
105
|
+
private func prefixTailCount(from old: NativeListConfig, to next: NativeListConfig) -> Int? {
|
|
106
|
+
guard old.orientation == "vertical", next.orientation == "vertical",
|
|
107
|
+
old.layout == next.layout, next.layout == "linear" || next.layout == "table",
|
|
108
|
+
old.itemSpacing == next.itemSpacing,
|
|
109
|
+
old.contentPaddingTop == next.contentPaddingTop,
|
|
110
|
+
old.contentPaddingBottom == next.contentPaddingBottom,
|
|
111
|
+
old.contentPaddingHorizontal == next.contentPaddingHorizontal,
|
|
112
|
+
dictionariesEqual(old.theme, next.theme),
|
|
113
|
+
dictionariesEqual(old.listStyle, next.listStyle),
|
|
114
|
+
old.items.count != next.items.count,
|
|
115
|
+
structuralDisplayLink == nil || structuralTail != nil,
|
|
116
|
+
!old.items.contains(where: { $0.type == "sectionHeader" }),
|
|
117
|
+
!next.items.contains(where: { $0.type == "sectionHeader" }) else { return nil }
|
|
118
|
+
let prefix = min(old.items.count, next.items.count)
|
|
119
|
+
guard prefix > 0 else { return nil }
|
|
120
|
+
for index in 0..<prefix {
|
|
121
|
+
let before = old.items[index], after = next.items[index]
|
|
122
|
+
guard before.key == after.key, before.type == after.type,
|
|
123
|
+
rowHeight(before) == rowHeight(after) else { return nil }
|
|
124
|
+
}
|
|
125
|
+
return prefix
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private func tailExceedsHostLimit(_ tail: StructuralTail) -> Bool {
|
|
129
|
+
let window = max(0, collectionView.bounds.height) * 3
|
|
130
|
+
var end = 0
|
|
131
|
+
for first in tail.items.indices {
|
|
132
|
+
end = max(end, first)
|
|
133
|
+
while end < tail.items.count && tail.starts[end] <= tail.starts[first] + window {
|
|
134
|
+
end += 1
|
|
135
|
+
}
|
|
136
|
+
if end - first > 128 { return true }
|
|
137
|
+
}
|
|
138
|
+
return false
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private func clearStructuralTail() {
|
|
142
|
+
structuralTail = nil
|
|
143
|
+
flowLayout.animatedBodyContentHeight = nil
|
|
144
|
+
flowLayout.tailClip = nil
|
|
145
|
+
for case let cell as NativeListRowHost in collectionView.visibleCells {
|
|
146
|
+
let indexPath = collectionView.indexPath(for: cell)
|
|
147
|
+
let key = indexPath.flatMap { dataSource?.itemIdentifier(for: $0) }
|
|
148
|
+
let accepted = indexPath.flatMap { config?.items[safe: $0.item]?.key } == key && key != nil
|
|
149
|
+
cell.layer.mask = nil
|
|
150
|
+
cell.isHidden = !accepted
|
|
151
|
+
cell.accessibilityElementsHidden = !accepted
|
|
152
|
+
cell.isUserInteractionEnabled = accepted && !(key.flatMap { itemsByKey[$0] }?.data.bool("disabled") ?? false)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private func updateStructuralTailWindow() {
|
|
157
|
+
guard let tail = structuralTail else { return }
|
|
158
|
+
let clipEnd = structuralTailStartY + structuralSpacerHeight
|
|
159
|
+
flowLayout.animatedBodyContentHeight = clipEnd
|
|
160
|
+
+ (config?.contentPaddingBottom ?? 0) + containerSlotHeights[2]
|
|
161
|
+
+ (config?.disclosure == nil ? 0 : disclosureCVisibleHeight
|
|
162
|
+
+ containerSlotHeights[5] + disclosureInset)
|
|
163
|
+
flowLayout.tailClip = (tail.prefixCount, clipEnd)
|
|
164
|
+
for case let cell as NativeListRowHost in collectionView.visibleCells {
|
|
165
|
+
guard let indexPath = collectionView.indexPath(for: cell),
|
|
166
|
+
let key = dataSource.itemIdentifier(for: indexPath) else { continue }
|
|
167
|
+
presentTailCell(cell, key: key, index: indexPath.item, tail: tail)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private func presentTailCell(_ cell: NativeListRowHost, key: String, index: Int,
|
|
172
|
+
tail: StructuralTail) {
|
|
173
|
+
let clipEnd = structuralTailStartY + structuralSpacerHeight
|
|
174
|
+
let visibleHeight = index >= tail.prefixCount
|
|
175
|
+
? max(0, min(cell.bounds.height, clipEnd - cell.frame.minY)) : cell.bounds.height
|
|
176
|
+
let clipped = visibleHeight < cell.bounds.height
|
|
177
|
+
CATransaction.begin()
|
|
178
|
+
CATransaction.setDisableActions(true)
|
|
179
|
+
cell.isHidden = visibleHeight <= 0
|
|
180
|
+
if clipped && visibleHeight > 0 {
|
|
181
|
+
let mask = cell.layer.mask ?? CALayer()
|
|
182
|
+
mask.backgroundColor = UIColor.black.cgColor
|
|
183
|
+
mask.frame = CGRect(x: 0, y: 0, width: cell.bounds.width, height: visibleHeight)
|
|
184
|
+
cell.layer.mask = mask
|
|
185
|
+
} else {
|
|
186
|
+
cell.layer.mask = nil
|
|
187
|
+
}
|
|
188
|
+
CATransaction.commit()
|
|
189
|
+
let inert = index >= tail.prefixCount || clipped
|
|
190
|
+
cell.isUserInteractionEnabled = !inert && !(itemsByKey[key]?.data.bool("disabled") ?? false)
|
|
191
|
+
cell.accessibilityElementsHidden = inert
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private func finishStructuralTail(interrupted: Bool) {
|
|
195
|
+
guard let tail = structuralTail, let config else { return }
|
|
196
|
+
stopStructuralAnimation()
|
|
197
|
+
if !tail.retiringKeys.isEmpty {
|
|
198
|
+
var snapshot = dataSource.snapshot()
|
|
199
|
+
snapshot.deleteItems(Array(tail.retiringKeys))
|
|
200
|
+
dataSource.apply(snapshot, animatingDifferences: false)
|
|
201
|
+
itemsByKey = Dictionary(uniqueKeysWithValues: config.items.map { ($0.key, $0) })
|
|
202
|
+
}
|
|
203
|
+
clearStructuralTail()
|
|
204
|
+
structuralSpacerHeight = 0
|
|
205
|
+
disclosureCVisibleHeight = config.disclosure?.expanded == true ? containerSlotHeights[4] : 0
|
|
206
|
+
disclosureInset = config.disclosure?.expanded == true
|
|
207
|
+
? config.disclosure?.expandedTrailingInset ?? 0 : 0
|
|
208
|
+
structuralFooterStartY = nil
|
|
209
|
+
structuralFooterProgress = 0
|
|
210
|
+
configureLayout(config)
|
|
211
|
+
collectionView.layoutIfNeeded()
|
|
212
|
+
if interrupted {
|
|
213
|
+
// A diffable deletion can leave UIKit's content-shrink scroll animation active.
|
|
214
|
+
// Cancel it without choosing a new offset for the user's gesture.
|
|
215
|
+
collectionView.setContentOffset(collectionView.contentOffset, animated: false)
|
|
216
|
+
} else if !collectionView.isTracking && !collectionView.isDragging
|
|
217
|
+
&& !collectionView.isDecelerating {
|
|
218
|
+
let inset = collectionView.adjustedContentInset
|
|
219
|
+
let maximum = max(-inset.top,
|
|
220
|
+
collectionView.contentSize.height - collectionView.bounds.height + inset.bottom)
|
|
221
|
+
let target = min(max(-inset.top, structuralTargetOffset), maximum)
|
|
222
|
+
collectionView.setContentOffset(CGPoint(x: collectionView.contentOffset.x, y: target), animated: false)
|
|
223
|
+
}
|
|
224
|
+
layoutContainerSlots()
|
|
225
|
+
emitVisibleRangeIfNeeded()
|
|
226
|
+
checkEndReached()
|
|
227
|
+
settleDisclosure(interrupted ? "interrupted" : "completed")
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private func updateStructuralTailTarget() {
|
|
231
|
+
guard let tail = structuralTail, let config else { return }
|
|
232
|
+
let inset = collectionView.adjustedContentInset
|
|
233
|
+
let leftHeight = structuralTailStartY + tail.finalExtent
|
|
234
|
+
+ config.contentPaddingBottom + containerSlotHeights[2]
|
|
235
|
+
+ (config.disclosure == nil ? 0 :
|
|
236
|
+
(config.disclosure?.expanded == true ? containerSlotHeights[4] : 0)
|
|
237
|
+
+ containerSlotHeights[5]
|
|
238
|
+
+ (config.disclosure?.expanded == true
|
|
239
|
+
? config.disclosure?.expandedTrailingInset ?? 0 : 0))
|
|
240
|
+
let sidecarHeight = sidecarLayout == nil ? 0 :
|
|
241
|
+
config.contentPaddingTop + containerSlotHeights[3] + config.contentPaddingBottom
|
|
242
|
+
let finalHeight = max(leftHeight, sidecarHeight)
|
|
243
|
+
let maximum = max(-inset.top,
|
|
244
|
+
finalHeight - collectionView.bounds.height + inset.bottom)
|
|
245
|
+
var target = min(max(-inset.top, structuralStartOffset), maximum)
|
|
246
|
+
if tail.finalExtent == 0, config.disclosure != nil, containerSlotHeights[5] > 0 {
|
|
247
|
+
let toggleTop = structuralTailStartY
|
|
248
|
+
let toggleBottom = toggleTop + containerSlotHeights[5]
|
|
249
|
+
var sticky: CGFloat = 0
|
|
250
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
251
|
+
sticky += CGFloat(value.doubleValue)
|
|
252
|
+
}
|
|
253
|
+
let lower = toggleBottom - collectionView.bounds.height + inset.bottom
|
|
254
|
+
let upper = toggleTop - inset.top - sticky
|
|
255
|
+
target = lower <= upper ? min(max(target, lower), upper) : upper
|
|
256
|
+
} else if tail.finalExtent == 0, containerSlotHeights[2] > 0 {
|
|
257
|
+
let footerTop = structuralTailStartY
|
|
258
|
+
let footerBottom = footerTop + containerSlotHeights[2]
|
|
259
|
+
var sticky: CGFloat = 0
|
|
260
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
261
|
+
sticky += CGFloat(value.doubleValue)
|
|
262
|
+
}
|
|
263
|
+
let lower = footerBottom - collectionView.bounds.height + inset.bottom
|
|
264
|
+
let upper = footerTop - inset.top - sticky
|
|
265
|
+
target = lower <= upper ? min(max(target, lower), upper) : upper
|
|
266
|
+
}
|
|
267
|
+
structuralTargetOffset = min(max(-inset.top, target), maximum)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private func structuralTailSegmentProgress(_ eased: CFTimeInterval) -> CFTimeInterval {
|
|
271
|
+
if eased >= 1 { return 1 }
|
|
272
|
+
let remaining = max(0.001, 1 - structuralTailSegmentStartEased)
|
|
273
|
+
return min(1, max(0, (eased - structuralTailSegmentStartEased) / remaining))
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private func disclosureSegmentProgress(_ eased: CFTimeInterval) -> CFTimeInterval {
|
|
277
|
+
if eased >= 1 { return 1 }
|
|
278
|
+
let remaining = max(0.001, 1 - disclosureSegmentStartEased)
|
|
279
|
+
return min(1, max(0, (eased - disclosureSegmentStartEased) / remaining))
|
|
280
|
+
}
|
|
50
281
|
|
|
51
282
|
@objc func mountContainerSlot(_ view: UIView, atIndex index: Int) {
|
|
52
|
-
if index ==
|
|
283
|
+
if index == 6 {
|
|
53
284
|
topOverlayContent?.removeFromSuperview()
|
|
54
285
|
topOverlayContent = view
|
|
55
286
|
topOverlayHost.addSubview(view)
|
|
56
287
|
updateTopScrollEdge()
|
|
57
288
|
return
|
|
58
289
|
}
|
|
59
|
-
let host =
|
|
290
|
+
let host: UIView = index == 2 || index == 4 || index == 5
|
|
291
|
+
? NativeListClippedSlotHost() : UIView()
|
|
60
292
|
// Clipping to the reported height keeps new content from overlapping rows until the list
|
|
61
293
|
// has reserved space for it.
|
|
62
294
|
host.clipsToBounds = true
|
|
@@ -142,16 +374,113 @@ final class NativeListView: UIView {
|
|
|
142
374
|
}
|
|
143
375
|
}
|
|
144
376
|
|
|
145
|
-
func setContainerSlotHeightsJson(_ json: String) {
|
|
377
|
+
func setContainerSlotHeightsJson(_ json: String, followedBySnapshot: Bool = false) {
|
|
146
378
|
guard let data = json.data(using: .utf8),
|
|
147
379
|
let heights = try? JSONSerialization.jsonObject(with: data) as? [Double],
|
|
148
|
-
heights.count ==
|
|
149
|
-
|
|
380
|
+
(heights.count == 4 || heights.count == 6),
|
|
381
|
+
heights.allSatisfy({ $0.isFinite && $0 >= 0 }) else { return }
|
|
382
|
+
let previousHeights = containerSlotHeights
|
|
383
|
+
let footerDelta = containerSlotHeights[2] - CGFloat(heights[2])
|
|
384
|
+
containerSlotHeights = heights.map { CGFloat($0) } + (heights.count == 4 ? [0, 0] : [])
|
|
385
|
+
let contentHeightChanged = previousHeights[4] != containerSlotHeights[4]
|
|
386
|
+
let toggleHeightChanged = previousHeights[5] != containerSlotHeights[5]
|
|
387
|
+
let disclosureGeometryInvalid = structuralTail != nil && config?.disclosure != nil
|
|
388
|
+
&& (toggleHeightChanged || footerDelta != 0
|
|
389
|
+
|| containerSlotHeights[4] < disclosureCVisibleHeight - 0.5)
|
|
390
|
+
let surroundingSlotGeometryInvalid = structuralTail != nil
|
|
391
|
+
&& (previousHeights[0] != containerSlotHeights[0]
|
|
392
|
+
|| previousHeights[1] != containerSlotHeights[1]
|
|
393
|
+
|| previousHeights[3] != containerSlotHeights[3])
|
|
394
|
+
if surroundingSlotGeometryInvalid || disclosureGeometryInvalid {
|
|
395
|
+
if followedBySnapshot, config?.disclosure != nil {
|
|
396
|
+
deferredDisclosureGeometryInvalid = true
|
|
397
|
+
}
|
|
398
|
+
else { finishStructuralTail(interrupted: true) }
|
|
399
|
+
}
|
|
400
|
+
if structuralTail != nil, contentHeightChanged, !disclosureGeometryInvalid,
|
|
401
|
+
!surroundingSlotGeometryInvalid,
|
|
402
|
+
config?.disclosure != nil, structuralDisplayLink != nil {
|
|
403
|
+
let progress = min(1, max(0,
|
|
404
|
+
(CACurrentMediaTime() - structuralAnimationStart) / max(0.001, structuralAnimationDuration)))
|
|
405
|
+
let eased = progress * progress * (3 - 2 * progress)
|
|
406
|
+
disclosureStartCHeight = disclosureCVisibleHeight
|
|
407
|
+
disclosureSegmentStartEased = eased
|
|
408
|
+
}
|
|
409
|
+
if structuralTail != nil, structuralDisplayLink != nil, footerDelta != 0,
|
|
410
|
+
config?.disclosure == nil {
|
|
411
|
+
let progress = min(1, max(0,
|
|
412
|
+
(CACurrentMediaTime() - structuralAnimationStart) / max(0.001, structuralAnimationDuration)))
|
|
413
|
+
let eased = progress * progress * (3 - 2 * progress)
|
|
414
|
+
// Rebase from the last extent actually presented, not elapsed wall time.
|
|
415
|
+
structuralTailStartExtent = structuralSpacerHeight + footerDelta
|
|
416
|
+
structuralSpacerHeight = structuralTailStartExtent
|
|
417
|
+
structuralTailSegmentStartEased = eased
|
|
418
|
+
disclosureStartCHeight = disclosureCVisibleHeight
|
|
419
|
+
disclosureSegmentStartEased = eased
|
|
420
|
+
disclosureStartInset = disclosureInset
|
|
421
|
+
structuralStartOffset = collectionView.contentOffset.y
|
|
422
|
+
} else if structuralTail == nil, structuralDisplayLink != nil,
|
|
423
|
+
footerDelta != 0, config?.disclosure == nil {
|
|
424
|
+
let progress = min(1, max(0,
|
|
425
|
+
(CACurrentMediaTime() - structuralAnimationStart) / max(0.001, structuralAnimationDuration)))
|
|
426
|
+
let eased = progress * progress * (3 - 2 * progress)
|
|
427
|
+
structuralStartSpacer = max(0, structuralStartSpacer + footerDelta)
|
|
428
|
+
structuralSpacerHeight = structuralStartSpacer * (1 - eased)
|
|
429
|
+
if let startY = structuralFooterStartY { structuralFooterStartY = startY + footerDelta }
|
|
430
|
+
}
|
|
431
|
+
if structuralTail == nil, let disclosure = config?.disclosure {
|
|
432
|
+
disclosureCVisibleHeight = disclosure.expanded ? containerSlotHeights[4] : 0
|
|
433
|
+
disclosureInset = disclosure.expanded ? disclosure.expandedTrailingInset : 0
|
|
434
|
+
}
|
|
150
435
|
if let config { configureLayout(config) }
|
|
436
|
+
if structuralTail != nil {
|
|
437
|
+
updateStructuralTailTarget()
|
|
438
|
+
updateStructuralTailWindow()
|
|
439
|
+
flowLayout.invalidateLayout()
|
|
440
|
+
collectionView.layoutIfNeeded()
|
|
441
|
+
updateStructuralTailWindow()
|
|
442
|
+
} else if structuralDisplayLink != nil {
|
|
443
|
+
collectionView.layoutIfNeeded()
|
|
444
|
+
let inset = collectionView.adjustedContentInset
|
|
445
|
+
let finalMaximum = max(-inset.top,
|
|
446
|
+
collectionView.contentSize.height - structuralSpacerHeight
|
|
447
|
+
- collectionView.bounds.height + inset.bottom)
|
|
448
|
+
structuralTargetOffset = min(structuralTargetOffset, finalMaximum)
|
|
449
|
+
}
|
|
151
450
|
layoutContainerSlots()
|
|
152
451
|
setNeedsLayout()
|
|
153
452
|
}
|
|
154
453
|
|
|
454
|
+
func setSidecarLayoutJson(_ json: String) {
|
|
455
|
+
if json.isEmpty {
|
|
456
|
+
sidecarLayout = nil
|
|
457
|
+
} else if let data = json.data(using: .utf8),
|
|
458
|
+
let value = try? JSONSerialization.jsonObject(with: data) as? [String: Double],
|
|
459
|
+
let width = value["width"], let gap = value["gap"],
|
|
460
|
+
let maxWidth = value["maxContentWidth"],
|
|
461
|
+
width.isFinite, width > 0, gap.isFinite, gap >= 0,
|
|
462
|
+
maxWidth.isFinite, maxWidth > width + gap {
|
|
463
|
+
sidecarLayout = (CGFloat(width), CGFloat(gap), CGFloat(maxWidth))
|
|
464
|
+
} else { return }
|
|
465
|
+
if structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
466
|
+
if let config { configureLayout(config) }
|
|
467
|
+
layoutContainerSlots()
|
|
468
|
+
setNeedsLayout()
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
private func sidecarBaseInset(_ width: CGFloat) -> CGFloat {
|
|
472
|
+
guard let sidecarLayout else { return 0 }
|
|
473
|
+
return max(0, (width - min(width, sidecarLayout.maxContentWidth)) / 2)
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
@objc(setPagerStickyHeight:forOwner:)
|
|
477
|
+
func setPagerStickyHeight(_ height: CGFloat, forOwner owner: AnyObject) {
|
|
478
|
+
let next = height.isFinite ? max(0, height) : 0
|
|
479
|
+
if next == 0 { pagerStickyHeights.removeObject(forKey: owner) }
|
|
480
|
+
else { pagerStickyHeights.setObject(NSNumber(value: Double(next)), forKey: owner) }
|
|
481
|
+
layoutContainerSlots()
|
|
482
|
+
}
|
|
483
|
+
|
|
155
484
|
private func layoutContainerSlots() {
|
|
156
485
|
let empty = config?.items.isEmpty ?? true
|
|
157
486
|
let header = containerSlotHeights[0]
|
|
@@ -159,15 +488,76 @@ final class NativeListView: UIView {
|
|
|
159
488
|
let footer = containerSlotHeights[2]
|
|
160
489
|
let paddingTop = config?.contentPaddingTop ?? 0
|
|
161
490
|
let paddingBottom = config?.contentPaddingBottom ?? 0
|
|
162
|
-
let
|
|
163
|
-
|
|
164
|
-
|
|
491
|
+
let naturalFooterY = flowLayout.bodyContentHeight - paddingBottom - footer
|
|
492
|
+
let footerY = structuralTail == nil
|
|
493
|
+
? max(paddingTop + header + emptyHeight, naturalFooterY) : naturalFooterY
|
|
494
|
+
let footerPosition = structuralTail == nil && structuralRemovedItems.isEmpty ? structuralFooterStartY.map {
|
|
495
|
+
$0 + (footerY - $0) * structuralFooterProgress
|
|
496
|
+
} ?? footerY : footerY
|
|
497
|
+
let positions = [paddingTop, paddingTop + header, footerPosition]
|
|
165
498
|
for (index, slot) in reactContainerSlots.prefix(3).enumerated() {
|
|
166
499
|
slot.host.isHidden = index == 1 && !empty
|
|
167
500
|
// React places the root at the horizontal inset inside this full-width host.
|
|
168
501
|
slot.host.frame = CGRect(x: 0, y: positions[index],
|
|
169
502
|
width: collectionView.bounds.width, height: containerSlotHeights[index])
|
|
170
503
|
}
|
|
504
|
+
if reactContainerSlots.count > 3 {
|
|
505
|
+
let slot = reactContainerSlots[3]
|
|
506
|
+
let width = sidecarLayout?.width ?? 0
|
|
507
|
+
let base = sidecarBaseInset(collectionView.bounds.width)
|
|
508
|
+
slot.host.isHidden = sidecarLayout == nil || containerSlotHeights[3] <= 0
|
|
509
|
+
let x = effectiveUserInterfaceLayoutDirection == .rightToLeft
|
|
510
|
+
? base : collectionView.bounds.width - base - width
|
|
511
|
+
slot.host.frame = CGRect(x: x,
|
|
512
|
+
y: paddingTop, width: width, height: containerSlotHeights[3])
|
|
513
|
+
}
|
|
514
|
+
if reactContainerSlots.count > 5 {
|
|
515
|
+
let disclosureEnabled = config?.disclosure != nil
|
|
516
|
+
let content = reactContainerSlots[4].host
|
|
517
|
+
let toggle = reactContainerSlots[5].host
|
|
518
|
+
let toggleHeight = disclosureEnabled ? containerSlotHeights[5] : 0
|
|
519
|
+
let contentY = footerPosition - disclosureInset - toggleHeight
|
|
520
|
+
- disclosureCVisibleHeight
|
|
521
|
+
content.frame = CGRect(x: 0, y: contentY, width: collectionView.bounds.width,
|
|
522
|
+
height: containerSlotHeights[4])
|
|
523
|
+
toggle.frame = CGRect(x: 0, y: contentY + disclosureCVisibleHeight,
|
|
524
|
+
width: collectionView.bounds.width, height: containerSlotHeights[5])
|
|
525
|
+
content.isHidden = !disclosureEnabled || disclosureCVisibleHeight <= 0
|
|
526
|
+
toggle.isHidden = !disclosureEnabled || toggleHeight <= 0
|
|
527
|
+
let contentSettled = structuralDisplayLink == nil && structuralTail == nil
|
|
528
|
+
&& config?.disclosure?.expanded == true
|
|
529
|
+
&& disclosureCVisibleHeight >= containerSlotHeights[4] - 0.5
|
|
530
|
+
content.isUserInteractionEnabled = contentSettled
|
|
531
|
+
content.accessibilityElementsHidden = !contentSettled
|
|
532
|
+
toggle.isUserInteractionEnabled = disclosureEnabled && toggleHeight > 0
|
|
533
|
+
toggle.accessibilityElementsHidden = !disclosureEnabled || toggleHeight <= 0
|
|
534
|
+
}
|
|
535
|
+
var stickyHeight: CGFloat = 0
|
|
536
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
537
|
+
stickyHeight += CGFloat(value.doubleValue)
|
|
538
|
+
}
|
|
539
|
+
CATransaction.begin()
|
|
540
|
+
CATransaction.setDisableActions(true)
|
|
541
|
+
for (index, slot) in reactContainerSlots.enumerated() {
|
|
542
|
+
let stickyTop = max(0, collectionView.contentOffset.y + stickyHeight - slot.host.frame.minY)
|
|
543
|
+
let tailTop = index == 2 && structuralTail != nil ? max(0, -structuralSpacerHeight) : 0
|
|
544
|
+
let top = max(stickyHeight > 0 ? stickyTop : 0, tailTop)
|
|
545
|
+
let bottom = index == 4 && config?.disclosure != nil
|
|
546
|
+
? min(slot.host.bounds.height, max(0, disclosureCVisibleHeight))
|
|
547
|
+
: slot.host.bounds.height
|
|
548
|
+
(slot.host as? NativeListClippedSlotHost)?.visibleTop = top
|
|
549
|
+
(slot.host as? NativeListClippedSlotHost)?.visibleBottom = index == 4 ? bottom : nil
|
|
550
|
+
guard top > 0 || bottom < slot.host.bounds.height else {
|
|
551
|
+
slot.host.layer.mask = nil
|
|
552
|
+
continue
|
|
553
|
+
}
|
|
554
|
+
let mask = slot.host.layer.mask ?? CALayer()
|
|
555
|
+
mask.backgroundColor = UIColor.black.cgColor
|
|
556
|
+
mask.frame = CGRect(x: 0, y: top, width: slot.host.bounds.width,
|
|
557
|
+
height: max(0, bottom - top))
|
|
558
|
+
slot.host.layer.mask = mask
|
|
559
|
+
}
|
|
560
|
+
CATransaction.commit()
|
|
171
561
|
}
|
|
172
562
|
|
|
173
563
|
private final class ActionAnchorRecord {
|
|
@@ -238,6 +628,7 @@ final class NativeListView: UIView {
|
|
|
238
628
|
var onSelectionDelta: ((String) -> Void)?
|
|
239
629
|
var onReorder: ((String) -> Void)?
|
|
240
630
|
var onEndReached: ((String) -> Void)?
|
|
631
|
+
var onStructuralTransitionSettled: ((String) -> Void)?
|
|
241
632
|
var onVisibleRangeChanged: ((String) -> Void)? {
|
|
242
633
|
didSet {
|
|
243
634
|
lastVisibleRange = nil
|
|
@@ -263,7 +654,16 @@ final class NativeListView: UIView {
|
|
|
263
654
|
private var sectionIndexHostHeightConstraint: NSLayoutConstraint?
|
|
264
655
|
private var footerHeightConstraint: NSLayoutConstraint!
|
|
265
656
|
private var dataSource: UICollectionViewDiffableDataSource<Int, String>!
|
|
657
|
+
private final class AcceptedRowIndex {
|
|
658
|
+
let byKey: [String: Int]
|
|
659
|
+
|
|
660
|
+
init(items: [NativeListItem]) {
|
|
661
|
+
byKey = Dictionary(uniqueKeysWithValues: items.enumerated().map { ($1.key, $0) })
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
266
665
|
private var config: NativeListConfig?
|
|
666
|
+
private var acceptedRowIndex: AcceptedRowIndex?
|
|
267
667
|
private var itemsByKey: [String: NativeListItem] = [:]
|
|
268
668
|
private var endReachedGeneration: Int?
|
|
269
669
|
private var lastVisibleRange: (first: Int, last: Int, firstKey: String?, lastKey: String?)?
|
|
@@ -273,9 +673,11 @@ final class NativeListView: UIView {
|
|
|
273
673
|
private var sectionIndexHapticsEnabled = true
|
|
274
674
|
private var lastLayoutDirection: UIUserInterfaceLayoutDirection?
|
|
275
675
|
private var lastLayoutSize: CGSize?
|
|
676
|
+
private var lastConfiguredCollectionWidth: CGFloat?
|
|
276
677
|
private var commandAcceptedForPendingScroll = false
|
|
277
678
|
private var performingExplicitScrollCommand = false
|
|
278
679
|
private var animatedExplicitScrollCommand = false
|
|
680
|
+
private var explicitScrollRevision = 0
|
|
279
681
|
private var pagerCommandCancelObserver: NSObjectProtocol?
|
|
280
682
|
private var pendingScrollRequest: ScrollRequest?
|
|
281
683
|
private let sectionIndexFeedback = UISelectionFeedbackGenerator()
|
|
@@ -452,7 +854,8 @@ final class NativeListView: UIView {
|
|
|
452
854
|
}
|
|
453
855
|
dataSource.reorderingHandlers.canReorderItem = { [weak self] key in
|
|
454
856
|
guard let self else { return false }
|
|
455
|
-
return self.config?.reorderable == true && self.
|
|
857
|
+
return self.config?.reorderable == true && !self.isInertPresentationKey(key)
|
|
858
|
+
&& self.itemsByKey[key]?.isReorderable == true
|
|
456
859
|
}
|
|
457
860
|
dataSource.reorderingHandlers.didReorder = { [weak self] transaction in
|
|
458
861
|
guard self?.interactiveReorderUsesAtomicTargeting != true else { return }
|
|
@@ -510,7 +913,7 @@ final class NativeListView: UIView {
|
|
|
510
913
|
let point = touch.location(in: collectionView)
|
|
511
914
|
guard collectionView.bounds.contains(point),
|
|
512
915
|
let indexPath = collectionView.indexPathForItem(at: point),
|
|
513
|
-
let item = item(at: indexPath) else { return false }
|
|
916
|
+
let item = item(at: indexPath), !isInertPresentationKey(item.key) else { return false }
|
|
514
917
|
return item.isRowPressEnabled
|
|
515
918
|
}
|
|
516
919
|
|
|
@@ -523,33 +926,56 @@ final class NativeListView: UIView {
|
|
|
523
926
|
}
|
|
524
927
|
|
|
525
928
|
override func willMove(toWindow newWindow: UIWindow?) {
|
|
526
|
-
if newWindow == nil {
|
|
929
|
+
if newWindow == nil {
|
|
930
|
+
attachSectionIndexToList()
|
|
931
|
+
if structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
932
|
+
}
|
|
527
933
|
super.willMove(toWindow: newWindow)
|
|
528
934
|
}
|
|
529
935
|
|
|
936
|
+
private func notifyPagerScrollViewReadyIfNeeded() {
|
|
937
|
+
guard !disposed,
|
|
938
|
+
window != nil,
|
|
939
|
+
collectionView.delegate === self,
|
|
940
|
+
collectionView.bounds.width > 0,
|
|
941
|
+
collectionView.bounds.height > 0 else { return }
|
|
942
|
+
NotificationCenter.default.post(
|
|
943
|
+
name: Notification.Name("OneKeyNativeScrollViewDidBecomeReady"),
|
|
944
|
+
object: collectionView
|
|
945
|
+
)
|
|
946
|
+
}
|
|
947
|
+
|
|
530
948
|
override func didMoveToWindow() {
|
|
531
949
|
super.didMoveToWindow()
|
|
532
950
|
updateTopScrollEdge()
|
|
533
951
|
updateSectionIndexAttachment()
|
|
952
|
+
notifyPagerScrollViewReadyIfNeeded()
|
|
534
953
|
}
|
|
535
954
|
|
|
536
955
|
override func layoutSubviews() {
|
|
956
|
+
let hadUsableBounds = (lastLayoutSize?.width ?? 0) > 0 && (lastLayoutSize?.height ?? 0) > 0
|
|
537
957
|
super.layoutSubviews()
|
|
538
958
|
topOverlayHost.frame = CGRect(x: 0, y: 0, width: collectionView.bounds.width,
|
|
539
959
|
height: requestedTopOverlayHeight)
|
|
540
960
|
updateSectionIndexAttachment()
|
|
541
961
|
let direction = effectiveUserInterfaceLayoutDirection
|
|
542
|
-
|
|
543
|
-
|
|
962
|
+
let sizeChanged = lastLayoutSize != nil && lastLayoutSize != bounds.size
|
|
963
|
+
if sizeChanged && structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
964
|
+
if sizeChanged || lastLayoutDirection != nil && lastLayoutDirection != direction {
|
|
544
965
|
invalidateActionAnchor(reason: "layout")
|
|
545
966
|
}
|
|
546
967
|
lastLayoutSize = bounds.size
|
|
547
|
-
|
|
968
|
+
let collectionWidthChanged = collectionView.bounds.width > 0
|
|
969
|
+
&& lastConfiguredCollectionWidth != collectionView.bounds.width
|
|
970
|
+
if (lastLayoutDirection != direction || collectionWidthChanged), let config {
|
|
548
971
|
configureLayout(config)
|
|
549
|
-
rebindRowsForLayoutDirection(config)
|
|
972
|
+
if lastLayoutDirection != direction { rebindRowsForLayoutDirection(config) }
|
|
550
973
|
}
|
|
551
974
|
performPendingScrollIfNeeded()
|
|
552
975
|
layoutContainerSlots()
|
|
976
|
+
if !hadUsableBounds && collectionView.bounds.width > 0 && collectionView.bounds.height > 0 {
|
|
977
|
+
notifyPagerScrollViewReadyIfNeeded()
|
|
978
|
+
}
|
|
553
979
|
}
|
|
554
980
|
|
|
555
981
|
// A layout-direction change may arrive without a layout pass (semantic attribute or trait).
|
|
@@ -579,10 +1005,163 @@ final class NativeListView: UIView {
|
|
|
579
1005
|
}
|
|
580
1006
|
}
|
|
581
1007
|
|
|
1008
|
+
private func acceptRowIndex(for next: NativeListConfig, replacing previous: NativeListConfig?) {
|
|
1009
|
+
if let previous, acceptedRowIndex != nil,
|
|
1010
|
+
previous.generation == next.generation,
|
|
1011
|
+
previous.items.count == next.items.count,
|
|
1012
|
+
zip(previous.items, next.items).allSatisfy({ old, new in
|
|
1013
|
+
old.key == new.key && old.type == new.type
|
|
1014
|
+
}) {
|
|
1015
|
+
return
|
|
1016
|
+
}
|
|
1017
|
+
acceptedRowIndex = AcceptedRowIndex(items: next.items)
|
|
1018
|
+
}
|
|
1019
|
+
|
|
582
1020
|
func applySnapshotJson(_ json: String) {
|
|
583
1021
|
guard let next = try? NativeListConfig.parse(json: json) else { return }
|
|
1022
|
+
let transition = next.structuralTransition
|
|
1023
|
+
let isNewTransition = transition != nil && transition?.id != consumedStructuralTransitionID
|
|
1024
|
+
let disclosureGeometryInvalid = deferredDisclosureGeometryInvalid
|
|
1025
|
+
deferredDisclosureGeometryInvalid = false
|
|
1026
|
+
let disclosureTargetChanged = config?.disclosure?.expanded != next.disclosure?.expanded
|
|
1027
|
+
let disclosureInsetChanged = config?.disclosure?.expandedTrailingInset
|
|
1028
|
+
!= next.disclosure?.expandedTrailingInset
|
|
1029
|
+
let disclosureStateChanged = disclosureTargetChanged || disclosureInsetChanged
|
|
1030
|
+
let activePendingID = structuralTail == nil ? nil : pendingDisclosureSettlement?.id
|
|
1031
|
+
let oldKeys = dataSource.snapshot().itemIdentifiers
|
|
1032
|
+
let logicalOldKeys = config?.items.map(\.key) ?? []
|
|
1033
|
+
let presentationItems = itemsByKey
|
|
1034
|
+
let newKeys = next.items.map(\.key)
|
|
1035
|
+
let newDisclosureCommand = config != nil && next.disclosure != nil && isNewTransition
|
|
1036
|
+
if let transition { consumedStructuralTransitionID = transition.id }
|
|
1037
|
+
if newDisclosureCommand, let transition, let disclosure = next.disclosure {
|
|
1038
|
+
pendingDisclosureSettlement = (transition.id, disclosure.expanded)
|
|
1039
|
+
} else if next.disclosure == nil || disclosureTargetChanged {
|
|
1040
|
+
// A target change without a new command cannot settle the previous target.
|
|
1041
|
+
pendingDisclosureSettlement = nil
|
|
1042
|
+
}
|
|
1043
|
+
let wantsStructure = config?.orientation == "vertical"
|
|
1044
|
+
&& (config?.layout == "linear" || config?.layout == "table")
|
|
1045
|
+
&& isNewTransition && logicalOldKeys != newKeys
|
|
1046
|
+
&& next.orientation == "vertical" && (next.layout == "linear" || next.layout == "table")
|
|
1047
|
+
&& !UIAccessibility.isReduceMotionEnabled
|
|
1048
|
+
&& (transition?.duration ?? 0) > 0
|
|
1049
|
+
let tailPrefix = wantsStructure ? config.flatMap { prefixTailCount(from: $0, to: next) } : nil
|
|
1050
|
+
// A carried tail extent belongs to its original prefix boundary.
|
|
1051
|
+
// Commit a new boundary atomically instead of starting a legacy row animation.
|
|
1052
|
+
let prefixChangedDuringTail = structuralTail != nil && tailPrefix != nil
|
|
1053
|
+
&& structuralTail?.prefixCount != tailPrefix
|
|
1054
|
+
let rawTailCandidate: StructuralTail? = tailPrefix.flatMap { prefix in
|
|
1055
|
+
guard let previous = config else { return nil }
|
|
1056
|
+
let items = previous.items.count > next.items.count
|
|
1057
|
+
? Array(previous.items.dropFirst(prefix)) : Array(next.items.dropFirst(prefix))
|
|
1058
|
+
let heights = items.map { rowHeight($0) }
|
|
1059
|
+
let tail = StructuralTail(items: items, heights: heights,
|
|
1060
|
+
spacing: next.itemSpacing, prefixCount: prefix,
|
|
1061
|
+
finalExtent: previous.items.count > next.items.count ? 0 :
|
|
1062
|
+
heights.reduce(0, +) + CGFloat(max(0, items.count - 1)) * next.itemSpacing
|
|
1063
|
+
+ (prefix == 0 ? 0 : next.itemSpacing))
|
|
1064
|
+
return tail
|
|
1065
|
+
}
|
|
1066
|
+
let tailOverCap = rawTailCandidate.map(tailExceedsHostLimit) ?? false
|
|
1067
|
+
let animateStructure = wantsStructure && !tailOverCap && !prefixChangedDuringTail
|
|
1068
|
+
&& !disclosureGeometryInvalid
|
|
1069
|
+
&& (next.disclosure == nil ||
|
|
1070
|
+
(rawTailCandidate != nil && reactContainerSlots.count > 5))
|
|
1071
|
+
let directDisclosureStatus: String? = newDisclosureCommand && !animateStructure
|
|
1072
|
+
? (disclosureGeometryInvalid || logicalOldKeys != newKeys && (transition?.duration ?? 0) > 0
|
|
1073
|
+
&& !UIAccessibility.isReduceMotionEnabled ? "interrupted" : "completed")
|
|
1074
|
+
: nil
|
|
1075
|
+
var interruptedPendingID: String?
|
|
1076
|
+
let tailCandidate = animateStructure ? rawTailCandidate : nil
|
|
1077
|
+
let presentationHeights: [String: CGFloat] = animateStructure ? Dictionary(uniqueKeysWithValues: oldKeys.compactMap { key -> (String, CGFloat)? in
|
|
1078
|
+
guard let item = presentationItems[key] else { return nil }
|
|
1079
|
+
let height = structuralRemovedHeights[key].map { $0 * (1 - structuralRemovalProgress) }
|
|
1080
|
+
?? rowHeight(item)
|
|
1081
|
+
return (key, height)
|
|
1082
|
+
}) : [:]
|
|
1083
|
+
let previousOffset = collectionView.contentOffset.y
|
|
1084
|
+
let oldLeftContentHeight = animateStructure ? flowLayout.bodyContentHeight : 0
|
|
1085
|
+
let oldSpacerHeight = structuralSpacerHeight
|
|
1086
|
+
let oldRowsHeight = animateStructure
|
|
1087
|
+
? presentationHeights.values.reduce(CGFloat(0), +)
|
|
1088
|
+
+ CGFloat(max(0, oldKeys.count - 1)) * (config?.itemSpacing ?? 0)
|
|
1089
|
+
: 0
|
|
1090
|
+
let newRowsHeight = animateStructure
|
|
1091
|
+
? next.items.reduce(CGFloat(0)) { $0 + rowHeight($1) }
|
|
1092
|
+
+ CGFloat(max(0, newKeys.count - 1)) * next.itemSpacing
|
|
1093
|
+
: 0
|
|
1094
|
+
let survivingKeys = animateStructure ? Set(newKeys) : Set<String>()
|
|
1095
|
+
let visibleAnchor = animateStructure
|
|
1096
|
+
? collectionView.indexPathsForVisibleItems.sorted().first {
|
|
1097
|
+
oldKeys.indices.contains($0.item) && survivingKeys.contains(oldKeys[$0.item])
|
|
1098
|
+
}
|
|
1099
|
+
: nil
|
|
1100
|
+
let anchorKey = visibleAnchor.map { oldKeys[$0.item] }
|
|
1101
|
+
let oldPrefix = (animateStructure ? anchorKey : nil).flatMap { key -> CGFloat? in
|
|
1102
|
+
guard let index = oldKeys.firstIndex(of: key) else { return nil }
|
|
1103
|
+
return oldKeys.prefix(index).reduce(CGFloat(0)) { $0 + (presentationHeights[$1] ?? 0) }
|
|
1104
|
+
+ CGFloat(index) * (config?.itemSpacing ?? 0)
|
|
1105
|
+
} ?? 0
|
|
1106
|
+
let newPrefix = (animateStructure ? anchorKey : nil).flatMap { key -> CGFloat? in
|
|
1107
|
+
guard let index = newKeys.firstIndex(of: key) else { return nil }
|
|
1108
|
+
return next.items.prefix(index).reduce(CGFloat(0)) { $0 + rowHeight($1) }
|
|
1109
|
+
+ CGFloat(index) * next.itemSpacing
|
|
1110
|
+
} ?? 0
|
|
1111
|
+
if animateStructure {
|
|
1112
|
+
let carriedExtent = structuralTail == nil ? nil : structuralSpacerHeight
|
|
1113
|
+
stopStructuralAnimation()
|
|
1114
|
+
clearStructuralTail()
|
|
1115
|
+
structuralScrollInterrupted = false
|
|
1116
|
+
structuralFooterStartY = reactContainerSlots.count > 2
|
|
1117
|
+
? reactContainerSlots[2].host.frame.minY : nil
|
|
1118
|
+
structuralFooterProgress = 0
|
|
1119
|
+
let removedKeys = Set(oldKeys).subtracting(newKeys)
|
|
1120
|
+
let retainsOrder = oldKeys.filter { survivingKeys.contains($0) } == newKeys
|
|
1121
|
+
structuralRemovedItems = tailCandidate == nil && retainsOrder
|
|
1122
|
+
? presentationItems.filter { removedKeys.contains($0.key) } : [:]
|
|
1123
|
+
structuralRemovedHeights = tailCandidate == nil && retainsOrder
|
|
1124
|
+
? presentationHeights.filter { removedKeys.contains($0.key) } : [:]
|
|
1125
|
+
structuralRemovalProgress = 0
|
|
1126
|
+
if let tail = tailCandidate {
|
|
1127
|
+
structuralTail = tail
|
|
1128
|
+
structuralTailStartExtent = carriedExtent ?? (tail.finalExtent == 0 ? tail.extent : 0)
|
|
1129
|
+
structuralTailSegmentStartEased = 0
|
|
1130
|
+
structuralSpacerHeight = structuralTailStartExtent
|
|
1131
|
+
let prefixHeights = next.items.prefix(tail.prefixCount).reduce(CGFloat(0)) {
|
|
1132
|
+
$0 + rowHeight($1)
|
|
1133
|
+
}
|
|
1134
|
+
structuralTailStartY = next.contentPaddingTop + containerSlotHeights[0]
|
|
1135
|
+
+ prefixHeights + CGFloat(max(0, tail.prefixCount - 1)) * next.itemSpacing
|
|
1136
|
+
disclosureStartCHeight = disclosureCVisibleHeight
|
|
1137
|
+
disclosureStartInset = disclosureInset
|
|
1138
|
+
disclosureSegmentStartEased = 0
|
|
1139
|
+
} else {
|
|
1140
|
+
structuralSpacerHeight = structuralRemovedItems.isEmpty
|
|
1141
|
+
? max(0, structuralSpacerHeight + oldRowsHeight - newRowsHeight) : 0
|
|
1142
|
+
}
|
|
1143
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1144
|
+
object: collectionView, userInfo: ["phase": 0])
|
|
1145
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1146
|
+
object: collectionView, userInfo: ["phase": 1])
|
|
1147
|
+
structuralScrollPhaseActive = true
|
|
1148
|
+
needsContentShrinkCorrection = false
|
|
1149
|
+
} else if logicalOldKeys != newKeys
|
|
1150
|
+
|| (newDisclosureCommand || disclosureGeometryInvalid || disclosureStateChanged)
|
|
1151
|
+
&& structuralTail != nil {
|
|
1152
|
+
if !newDisclosureCommand && !disclosureTargetChanged { interruptedPendingID = activePendingID }
|
|
1153
|
+
stopStructuralAnimation()
|
|
1154
|
+
clearStructuralTail()
|
|
1155
|
+
structuralSpacerHeight = 0
|
|
1156
|
+
structuralFooterStartY = nil
|
|
1157
|
+
structuralRemovedItems.removeAll()
|
|
1158
|
+
structuralRemovedHeights.removeAll()
|
|
1159
|
+
}
|
|
584
1160
|
invalidateActionAnchor(reason: "snapshot")
|
|
585
|
-
if let current = config,
|
|
1161
|
+
if let current = config, !newDisclosureCommand,
|
|
1162
|
+
structuralRemovedItems.isEmpty, structuralTail == nil,
|
|
1163
|
+
isControlledSelectionSnapshotUpdate(from: current, to: next) {
|
|
1164
|
+
acceptRowIndex(for: next, replacing: current)
|
|
586
1165
|
config = next
|
|
587
1166
|
itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
|
|
588
1167
|
// OneKey patch: A controlled selection echo is fully handled by the
|
|
@@ -591,7 +1170,7 @@ final class NativeListView: UIView {
|
|
|
591
1170
|
return
|
|
592
1171
|
}
|
|
593
1172
|
if let current = config, interactiveReorderSource != nil {
|
|
594
|
-
if canDeferSnapshotDuringInteractiveReorder(from: current, to: next) {
|
|
1173
|
+
if !newDisclosureCommand && canDeferSnapshotDuringInteractiveReorder(from: current, to: next) {
|
|
595
1174
|
deferSnapshotDuringInteractiveReorder(from: current, to: next)
|
|
596
1175
|
return
|
|
597
1176
|
}
|
|
@@ -602,17 +1181,111 @@ final class NativeListView: UIView {
|
|
|
602
1181
|
// rows whose own content is unchanged.
|
|
603
1182
|
let themeChanged = !dictionariesEqual(config?.theme, next.theme)
|
|
604
1183
|
|| !dictionariesEqual(config?.listStyle, next.listStyle)
|
|
1184
|
+
|| config?.layout != next.layout
|
|
1185
|
+
let tailGeometryChanged = config.map { current in
|
|
1186
|
+
current.disclosure?.expanded != next.disclosure?.expanded
|
|
1187
|
+
|| current.disclosure?.expandedTrailingInset != next.disclosure?.expandedTrailingInset
|
|
1188
|
+
|| current.orientation != next.orientation
|
|
1189
|
+
|| current.stickyHeaders != next.stickyHeaders
|
|
1190
|
+
|| current.sectionIndexEnabled != next.sectionIndexEnabled
|
|
1191
|
+
|| current.contentPadding != next.contentPadding
|
|
1192
|
+
|| current.itemSpacing != next.itemSpacing
|
|
1193
|
+
|| current.contentPaddingTop != next.contentPaddingTop
|
|
1194
|
+
|| current.contentPaddingBottom != next.contentPaddingBottom
|
|
1195
|
+
|| current.contentPaddingHorizontal != next.contentPaddingHorizontal
|
|
1196
|
+
|| current.items.count != next.items.count
|
|
1197
|
+
|| zip(current.items, next.items).contains { old, new in
|
|
1198
|
+
old.key != new.key || old.rendererKey != new.rendererKey
|
|
1199
|
+
|| rowHeight(old) != rowHeight(new)
|
|
1200
|
+
}
|
|
1201
|
+
} ?? false
|
|
605
1202
|
if config?.generation != next.generation { endReachedGeneration = nil }
|
|
1203
|
+
acceptRowIndex(for: next, replacing: config)
|
|
606
1204
|
config = next
|
|
1205
|
+
if structuralTail == nil {
|
|
1206
|
+
disclosureCVisibleHeight = next.disclosure?.expanded == true ? containerSlotHeights[4] : 0
|
|
1207
|
+
disclosureInset = next.disclosure?.expanded == true
|
|
1208
|
+
? next.disclosure?.expandedTrailingInset ?? 0 : 0
|
|
1209
|
+
}
|
|
607
1210
|
itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
|
|
1211
|
+
itemsByKey.merge(structuralRemovedItems) { current, _ in current }
|
|
1212
|
+
if let tail = structuralTail, !tail.retiringKeys.isEmpty {
|
|
1213
|
+
itemsByKey.merge(presentationItems.filter { tail.retiringKeys.contains($0.key) }) {
|
|
1214
|
+
current, _ in current
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
if !animateStructure, let tail = structuralTail {
|
|
1218
|
+
if themeChanged || tailGeometryChanged {
|
|
1219
|
+
if !newDisclosureCommand { interruptedPendingID = activePendingID }
|
|
1220
|
+
stopStructuralAnimation()
|
|
1221
|
+
clearStructuralTail()
|
|
1222
|
+
structuralSpacerHeight = 0
|
|
1223
|
+
structuralFooterStartY = nil
|
|
1224
|
+
disclosureCVisibleHeight = next.disclosure?.expanded == true ? containerSlotHeights[4] : 0
|
|
1225
|
+
disclosureInset = next.disclosure?.expanded == true
|
|
1226
|
+
? next.disclosure?.expandedTrailingInset ?? 0 : 0
|
|
1227
|
+
} else {
|
|
1228
|
+
for (index, previous) in tail.items.enumerated() {
|
|
1229
|
+
guard let item = itemsByKey[previous.key], item.content != previous.content else { continue }
|
|
1230
|
+
tail.items[index] = item
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
608
1234
|
configureSectionIndex(next)
|
|
609
1235
|
configureLayout(next)
|
|
610
1236
|
configureRefresh(next)
|
|
611
1237
|
configureFooter(next)
|
|
1238
|
+
if structuralTail != nil { updateStructuralTailWindow() }
|
|
1239
|
+
|
|
1240
|
+
if animateStructure, let transition {
|
|
1241
|
+
let inset = collectionView.adjustedContentInset
|
|
1242
|
+
let finalLeftHeight = structuralTail.map { tail in
|
|
1243
|
+
structuralTailStartY + tail.finalExtent + next.contentPaddingBottom + containerSlotHeights[2]
|
|
1244
|
+
+ (next.disclosure == nil ? 0 :
|
|
1245
|
+
(next.disclosure?.expanded == true ? containerSlotHeights[4] : 0)
|
|
1246
|
+
+ containerSlotHeights[5]
|
|
1247
|
+
+ (next.disclosure?.expanded == true
|
|
1248
|
+
? next.disclosure?.expandedTrailingInset ?? 0 : 0))
|
|
1249
|
+
} ?? max(0, oldLeftContentHeight + newRowsHeight - oldRowsHeight - oldSpacerHeight)
|
|
1250
|
+
let sidecarHeight = sidecarLayout == nil ? 0 :
|
|
1251
|
+
next.contentPaddingTop + containerSlotHeights[3] + next.contentPaddingBottom
|
|
1252
|
+
let finalHeight = max(finalLeftHeight, sidecarHeight)
|
|
1253
|
+
let finalMaximum = max(-inset.top, finalHeight - collectionView.bounds.height + inset.bottom)
|
|
1254
|
+
structuralStartSpacer = structuralSpacerHeight
|
|
1255
|
+
structuralStartOffset = previousOffset
|
|
1256
|
+
var targetOffset = structuralTail == nil
|
|
1257
|
+
? min(max(-inset.top, previousOffset + newPrefix - oldPrefix), finalMaximum)
|
|
1258
|
+
: min(max(-inset.top, previousOffset), finalMaximum)
|
|
1259
|
+
if let tail = structuralTail, tail.finalExtent == 0,
|
|
1260
|
+
(next.disclosure != nil ? containerSlotHeights[5] : containerSlotHeights[2]) > 0 {
|
|
1261
|
+
let targetTop = structuralTailStartY
|
|
1262
|
+
let targetBottom = targetTop + (next.disclosure != nil
|
|
1263
|
+
? containerSlotHeights[5] : containerSlotHeights[2])
|
|
1264
|
+
var sticky: CGFloat = 0
|
|
1265
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
1266
|
+
sticky += CGFloat(value.doubleValue)
|
|
1267
|
+
}
|
|
1268
|
+
let lower = targetBottom - collectionView.bounds.height + inset.bottom
|
|
1269
|
+
let upper = targetTop - inset.top - sticky
|
|
1270
|
+
targetOffset = lower <= upper
|
|
1271
|
+
? min(max(targetOffset, lower), upper) : upper
|
|
1272
|
+
targetOffset = min(max(-inset.top, targetOffset), finalMaximum)
|
|
1273
|
+
} else if structuralTail == nil, visibleAnchor == nil, let fallbackKey = transition.anchorKey,
|
|
1274
|
+
let fallbackIndex = newKeys.firstIndex(of: fallbackKey) {
|
|
1275
|
+
let fallbackY = next.contentPaddingTop + containerSlotHeights[0]
|
|
1276
|
+
+ next.items.prefix(fallbackIndex).reduce(CGFloat(0)) { $0 + rowHeight($1) }
|
|
1277
|
+
+ CGFloat(fallbackIndex) * next.itemSpacing
|
|
1278
|
+
targetOffset = min(targetOffset, max(-inset.top, fallbackY - inset.top))
|
|
1279
|
+
}
|
|
1280
|
+
structuralTargetOffset = targetOffset
|
|
1281
|
+
if structuralTail != nil { updateStructuralTailTarget() }
|
|
1282
|
+
structuralAnimationDuration = transition.duration
|
|
1283
|
+
}
|
|
612
1284
|
|
|
613
1285
|
var snapshot = NSDiffableDataSourceSnapshot<Int, String>()
|
|
614
1286
|
snapshot.appendSections([0])
|
|
615
|
-
let keys =
|
|
1287
|
+
let keys = structuralTail.map { $0.retiringKeys.isEmpty ? newKeys : oldKeys }
|
|
1288
|
+
?? (structuralRemovedItems.isEmpty ? newKeys : oldKeys)
|
|
616
1289
|
snapshot.appendItems(keys, toSection: 0)
|
|
617
1290
|
var changedKeys = Set(keys.filter { key in
|
|
618
1291
|
guard let old = oldItems[key], let new = itemsByKey[key] else { return false }
|
|
@@ -627,26 +1300,219 @@ final class NativeListView: UIView {
|
|
|
627
1300
|
let replacedKeys = changedRetainedKeys.filter { oldItems[$0]?.rendererKey != itemsByKey[$0]?.rendererKey }
|
|
628
1301
|
snapshot.reloadItems(Array(replacedKeys))
|
|
629
1302
|
snapshot.reconfigureItems(Array(changedRetainedKeys.subtracting(replacedKeys)))
|
|
630
|
-
|
|
1303
|
+
let scrollRevisionAtApply = explicitScrollRevision
|
|
1304
|
+
let explicitScrollPendingAtApply = pendingScrollRequest != nil
|
|
1305
|
+
dataSource.apply(snapshot, animatingDifferences: animateStructure && structuralRemovedItems.isEmpty
|
|
1306
|
+
&& structuralTail == nil) { [weak self] in
|
|
631
1307
|
guard let self else { return }
|
|
632
1308
|
self.collectionView.layoutIfNeeded()
|
|
1309
|
+
self.updateStructuralTailWindow()
|
|
1310
|
+
self.layoutContainerSlots()
|
|
1311
|
+
self.notifyPagerScrollViewReadyIfNeeded()
|
|
633
1312
|
self.performPendingScrollIfNeeded()
|
|
1313
|
+
if directDisclosureStatus == "completed", let transition {
|
|
1314
|
+
self.revealDirectCollapsedToggle(expectedID: transition.id,
|
|
1315
|
+
scrollRevision: scrollRevisionAtApply,
|
|
1316
|
+
explicitScrollPendingAtApply: explicitScrollPendingAtApply)
|
|
1317
|
+
}
|
|
634
1318
|
self.emitVisibleRangeIfNeeded()
|
|
635
1319
|
self.checkEndReached()
|
|
636
1320
|
self.syncSectionIndexToVisibleRows()
|
|
1321
|
+
if let directDisclosureStatus, let transition {
|
|
1322
|
+
self.settleDisclosure(directDisclosureStatus, expectedID: transition.id)
|
|
1323
|
+
} else if let interruptedPendingID {
|
|
1324
|
+
self.settleDisclosure("interrupted", expectedID: interruptedPendingID)
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
if animateStructure && (structuralTail != nil || tailCandidate == nil) {
|
|
1328
|
+
updateStructuralTailWindow()
|
|
1329
|
+
if tailCandidate != nil && structuralTail == nil { return }
|
|
1330
|
+
structuralAnimationStart = CACurrentMediaTime()
|
|
1331
|
+
let displayLink = CADisplayLink(target: self, selector: #selector(advanceStructuralAnimation(_:)))
|
|
1332
|
+
structuralDisplayLink = displayLink
|
|
1333
|
+
displayLink.add(to: .main, forMode: .common)
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
private func stopStructuralAnimation() {
|
|
1338
|
+
if structuralScrollPhaseActive {
|
|
1339
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1340
|
+
object: collectionView, userInfo: ["phase": 2])
|
|
1341
|
+
structuralScrollPhaseActive = false
|
|
1342
|
+
}
|
|
1343
|
+
structuralDisplayLink?.invalidate()
|
|
1344
|
+
structuralDisplayLink = nil
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
private func revealDirectCollapsedToggle(expectedID: String, scrollRevision: Int,
|
|
1348
|
+
explicitScrollPendingAtApply: Bool) {
|
|
1349
|
+
guard !disposed, let pending = pendingDisclosureSettlement,
|
|
1350
|
+
pending.id == expectedID, !pending.expanded,
|
|
1351
|
+
consumedStructuralTransitionID == expectedID,
|
|
1352
|
+
config?.disclosure?.expanded == false,
|
|
1353
|
+
structuralTail == nil, structuralDisplayLink == nil,
|
|
1354
|
+
!structuralScrollPhaseActive, scrollRevision == explicitScrollRevision,
|
|
1355
|
+
!explicitScrollPendingAtApply,
|
|
1356
|
+
pendingScrollRequest == nil, !animatedExplicitScrollCommand,
|
|
1357
|
+
!collectionView.isTracking, !collectionView.isDragging,
|
|
1358
|
+
!collectionView.isDecelerating,
|
|
1359
|
+
collectionView.bounds.height > 0, reactContainerSlots.count > 5 else { return }
|
|
1360
|
+
let toggle = reactContainerSlots[5].host
|
|
1361
|
+
guard !toggle.isHidden, toggle.bounds.height > 0 else { return }
|
|
1362
|
+
let inset = collectionView.adjustedContentInset
|
|
1363
|
+
let maximum = max(-inset.top,
|
|
1364
|
+
collectionView.contentSize.height - collectionView.bounds.height + inset.bottom)
|
|
1365
|
+
var sticky: CGFloat = 0
|
|
1366
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
1367
|
+
sticky += CGFloat(value.doubleValue)
|
|
1368
|
+
}
|
|
1369
|
+
let lower = toggle.frame.maxY - collectionView.bounds.height + inset.bottom
|
|
1370
|
+
let upper = toggle.frame.minY - inset.top - sticky
|
|
1371
|
+
let current = collectionView.contentOffset.y
|
|
1372
|
+
let visibleTarget = lower <= upper ? min(max(current, lower), upper) : upper
|
|
1373
|
+
let target = min(max(-inset.top, visibleTarget), maximum)
|
|
1374
|
+
guard abs(target - current) > 0.5 else { return }
|
|
1375
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1376
|
+
object: collectionView, userInfo: ["phase": 0])
|
|
1377
|
+
defer {
|
|
1378
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1379
|
+
object: collectionView, userInfo: ["phase": 2])
|
|
1380
|
+
}
|
|
1381
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1382
|
+
object: collectionView, userInfo: ["phase": 1])
|
|
1383
|
+
collectionView.setContentOffset(CGPoint(x: collectionView.contentOffset.x, y: target), animated: false)
|
|
1384
|
+
layoutContainerSlots()
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
private func settleDisclosure(_ status: String, expectedID: String? = nil) {
|
|
1388
|
+
guard let pending = pendingDisclosureSettlement,
|
|
1389
|
+
expectedID == nil || pending.id == expectedID,
|
|
1390
|
+
consumedStructuralTransitionID == pending.id,
|
|
1391
|
+
config?.disclosure?.expanded == pending.expanded else { return }
|
|
1392
|
+
pendingDisclosureSettlement = nil
|
|
1393
|
+
guard let callback = onStructuralTransitionSettled else { return }
|
|
1394
|
+
emit(callback, [
|
|
1395
|
+
"transitionId": pending.id,
|
|
1396
|
+
"status": status,
|
|
1397
|
+
"settledExpanded": pending.expanded,
|
|
1398
|
+
])
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
@objc private func advanceStructuralAnimation(_ link: CADisplayLink) {
|
|
1402
|
+
guard let config else { stopStructuralAnimation(); return }
|
|
1403
|
+
if structuralTail != nil && UIAccessibility.isReduceMotionEnabled {
|
|
1404
|
+
finishStructuralTail(interrupted: false)
|
|
1405
|
+
return
|
|
1406
|
+
}
|
|
1407
|
+
let elapsed = CACurrentMediaTime() - structuralAnimationStart
|
|
1408
|
+
let progress = min(1, max(0, elapsed / max(0.001, structuralAnimationDuration)))
|
|
1409
|
+
let eased = progress * progress * (3 - 2 * progress)
|
|
1410
|
+
if let tail = structuralTail {
|
|
1411
|
+
// Commit cell clipping, viewport movement, and slots together for this tick.
|
|
1412
|
+
CATransaction.begin()
|
|
1413
|
+
CATransaction.setDisableActions(true)
|
|
1414
|
+
defer { CATransaction.commit() }
|
|
1415
|
+
let segment = structuralTailSegmentProgress(eased)
|
|
1416
|
+
structuralSpacerHeight = structuralTailStartExtent
|
|
1417
|
+
+ (tail.finalExtent - structuralTailStartExtent) * segment
|
|
1418
|
+
if let disclosure = config.disclosure {
|
|
1419
|
+
let targetC = disclosure.expanded ? containerSlotHeights[4] : 0
|
|
1420
|
+
let targetInset = disclosure.expanded ? disclosure.expandedTrailingInset : 0
|
|
1421
|
+
let contentSegment = disclosureSegmentProgress(eased)
|
|
1422
|
+
disclosureCVisibleHeight = disclosureStartCHeight
|
|
1423
|
+
+ (targetC - disclosureStartCHeight) * contentSegment
|
|
1424
|
+
disclosureInset = disclosureStartInset
|
|
1425
|
+
+ (targetInset - disclosureStartInset) * segment
|
|
1426
|
+
}
|
|
1427
|
+
structuralFooterProgress = CGFloat(eased)
|
|
1428
|
+
updateStructuralTailWindow()
|
|
1429
|
+
flowLayout.invalidateLayout()
|
|
1430
|
+
collectionView.layoutIfNeeded()
|
|
1431
|
+
if !structuralScrollInterrupted && !collectionView.isTracking
|
|
1432
|
+
&& !collectionView.isDragging && !collectionView.isDecelerating {
|
|
1433
|
+
collectionView.contentOffset.y = structuralStartOffset
|
|
1434
|
+
+ (structuralTargetOffset - structuralStartOffset) * segment
|
|
1435
|
+
collectionView.layoutIfNeeded()
|
|
1436
|
+
}
|
|
1437
|
+
updateStructuralTailWindow()
|
|
1438
|
+
layoutContainerSlots()
|
|
1439
|
+
if progress >= 1 { finishStructuralTail(interrupted: structuralScrollInterrupted) }
|
|
1440
|
+
return
|
|
1441
|
+
}
|
|
1442
|
+
structuralSpacerHeight = structuralStartSpacer * (1 - eased)
|
|
1443
|
+
structuralFooterProgress = CGFloat(eased)
|
|
1444
|
+
structuralRemovalProgress = CGFloat(eased)
|
|
1445
|
+
for case let cell as NativeListRowHost in collectionView.visibleCells {
|
|
1446
|
+
guard let indexPath = collectionView.indexPath(for: cell),
|
|
1447
|
+
let key = dataSource.itemIdentifier(for: indexPath) else { continue }
|
|
1448
|
+
cell.structuralContentHeight = structuralRemovedItems[key].map {
|
|
1449
|
+
rowHeight($0, allocatedWidth: cell.bounds.width)
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
var inset = flowLayout.sectionInset
|
|
1453
|
+
inset.bottom = config.contentPaddingBottom + containerSlotHeights[2] + structuralSpacerHeight
|
|
1454
|
+
flowLayout.sectionInset = inset
|
|
1455
|
+
flowLayout.invalidateLayout()
|
|
1456
|
+
collectionView.layoutIfNeeded()
|
|
1457
|
+
if !structuralScrollInterrupted && !collectionView.isTracking
|
|
1458
|
+
&& !collectionView.isDragging && !collectionView.isDecelerating {
|
|
1459
|
+
collectionView.contentOffset.y = structuralStartOffset
|
|
1460
|
+
+ (structuralTargetOffset - structuralStartOffset) * eased
|
|
1461
|
+
// Materialize the new viewport before updating presentation cells.
|
|
1462
|
+
collectionView.layoutIfNeeded()
|
|
1463
|
+
}
|
|
1464
|
+
for cell in collectionView.visibleCells {
|
|
1465
|
+
guard let indexPath = collectionView.indexPath(for: cell),
|
|
1466
|
+
let key = dataSource.itemIdentifier(for: indexPath) else { continue }
|
|
1467
|
+
let retiring = structuralRemovedItems[key] != nil
|
|
1468
|
+
if retiring { cell.clipsToBounds = true }
|
|
1469
|
+
cell.alpha = retiring ? 1 - structuralRemovalProgress : 1
|
|
1470
|
+
cell.isUserInteractionEnabled = !retiring && !(itemsByKey[key]?.data.bool("disabled") ?? false)
|
|
1471
|
+
}
|
|
1472
|
+
layoutContainerSlots()
|
|
1473
|
+
if progress >= 1 {
|
|
1474
|
+
if !structuralRemovedItems.isEmpty {
|
|
1475
|
+
var snapshot = dataSource.snapshot()
|
|
1476
|
+
snapshot.deleteItems(Array(structuralRemovedItems.keys))
|
|
1477
|
+
structuralRemovedItems.removeAll()
|
|
1478
|
+
structuralRemovedHeights.removeAll()
|
|
1479
|
+
dataSource.apply(snapshot, animatingDifferences: false)
|
|
1480
|
+
itemsByKey = Dictionary(uniqueKeysWithValues: config.items.map { ($0.key, $0) })
|
|
1481
|
+
collectionView.layoutIfNeeded()
|
|
1482
|
+
if !structuralScrollInterrupted && !collectionView.isTracking
|
|
1483
|
+
&& !collectionView.isDragging && !collectionView.isDecelerating {
|
|
1484
|
+
let inset = collectionView.adjustedContentInset
|
|
1485
|
+
let maximum = max(-inset.top,
|
|
1486
|
+
collectionView.contentSize.height - collectionView.bounds.height + inset.bottom)
|
|
1487
|
+
let target = min(max(-inset.top, structuralTargetOffset), maximum)
|
|
1488
|
+
// Cancel UIKit's residual content-shrink scroll animation after deleting retired rows.
|
|
1489
|
+
collectionView.setContentOffset(
|
|
1490
|
+
CGPoint(x: collectionView.contentOffset.x, y: target), animated: false)
|
|
1491
|
+
collectionView.layoutIfNeeded()
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
stopStructuralAnimation()
|
|
1495
|
+
structuralSpacerHeight = 0
|
|
1496
|
+
structuralFooterStartY = nil
|
|
1497
|
+
layoutContainerSlots()
|
|
1498
|
+
emitVisibleRangeIfNeeded()
|
|
1499
|
+
checkEndReached()
|
|
1500
|
+
scheduleContentShrinkCorrection()
|
|
637
1501
|
}
|
|
638
1502
|
}
|
|
639
1503
|
|
|
640
1504
|
func applyPatchesJson(_ json: String) {
|
|
641
1505
|
guard var current = config,
|
|
1506
|
+
let indexByKey = acceptedRowIndex?.byKey,
|
|
642
1507
|
let bytes = json.data(using: .utf8),
|
|
643
1508
|
let patches = try? JSONSerialization.jsonObject(with: bytes) as? [[String: Any]] else { return }
|
|
644
|
-
let indexByKey = Dictionary(uniqueKeysWithValues: current.items.enumerated().map { ($1.key, $0) })
|
|
645
1509
|
var seen = Set<String>()
|
|
646
1510
|
var pending: [(Int, [String: Any])] = []
|
|
647
1511
|
for patch in patches {
|
|
648
1512
|
let key = patch.string("key")
|
|
649
1513
|
guard let index = indexByKey[key],
|
|
1514
|
+
current.items.indices.contains(index),
|
|
1515
|
+
current.items[index].key == key,
|
|
650
1516
|
seen.insert(key).inserted,
|
|
651
1517
|
patch.string("type") == current.items[index].type,
|
|
652
1518
|
let changes = patch.dictionary("changes") else { return }
|
|
@@ -658,13 +1524,16 @@ final class NativeListView: UIView {
|
|
|
658
1524
|
var sizeChanged = false
|
|
659
1525
|
var reorderStructureChanged = false
|
|
660
1526
|
let marketQuoteFields: Set<String> = [
|
|
661
|
-
"revision", "price", "priceSegments", "change", "accessibilityLabel",
|
|
1527
|
+
"revision", "price", "priceSegments", "change", "accessibilityLabel", "metrics",
|
|
662
1528
|
]
|
|
663
1529
|
for (index, changes) in pending {
|
|
664
1530
|
let previous = current.items[index]
|
|
665
1531
|
var merged = current.items[index].data
|
|
666
1532
|
changes.forEach { key, value in
|
|
667
|
-
if key != "key" && key != "type" {
|
|
1533
|
+
if key != "key" && key != "type" {
|
|
1534
|
+
if value is NSNull { merged.removeValue(forKey: key) }
|
|
1535
|
+
else { merged[key] = value }
|
|
1536
|
+
}
|
|
668
1537
|
}
|
|
669
1538
|
guard let item = try? NativeListItem(data: merged) else { return }
|
|
670
1539
|
if rowHeight(previous, usingCompactReorderHeight: false) != rowHeight(item, usingCompactReorderHeight: false) ||
|
|
@@ -681,13 +1550,28 @@ final class NativeListView: UIView {
|
|
|
681
1550
|
reorderStructureChanged = true
|
|
682
1551
|
}
|
|
683
1552
|
current.items[index] = item
|
|
684
|
-
|
|
1553
|
+
let previousMetrics = previous.data.dictionaries("metrics")
|
|
1554
|
+
let nextMetrics = item.data.dictionaries("metrics")
|
|
1555
|
+
let sameMetricStructure = previousMetrics.count == nextMetrics.count &&
|
|
1556
|
+
previousMetrics.indices.allSatisfy { metricIndex in
|
|
1557
|
+
let before = previousMetrics[metricIndex]
|
|
1558
|
+
let after = nextMetrics[metricIndex]
|
|
1559
|
+
return before.string("key") == after.string("key") &&
|
|
1560
|
+
before.int("weight", default: 1) == after.int("weight", default: 1) &&
|
|
1561
|
+
before.string("alignment", default: "end") ==
|
|
1562
|
+
after.string("alignment", default: "end")
|
|
1563
|
+
}
|
|
1564
|
+
if previous.type == "market", Set(changes.keys).isSubset(of: marketQuoteFields),
|
|
1565
|
+
sameMetricStructure
|
|
1566
|
+
{
|
|
685
1567
|
marketQuoteKeys.insert(item.key)
|
|
686
1568
|
} else {
|
|
687
1569
|
changedKeys.insert(item.key)
|
|
688
1570
|
}
|
|
689
1571
|
if let selected = changes["selected"] as? Bool {
|
|
690
1572
|
if selected { current.selectedKeys.insert(item.key) } else { current.selectedKeys.remove(item.key) }
|
|
1573
|
+
} else if changes["selected"] is NSNull {
|
|
1574
|
+
current.selectedKeys.remove(item.key)
|
|
691
1575
|
}
|
|
692
1576
|
}
|
|
693
1577
|
if !changedKeys.isEmpty { invalidateActionAnchor(reason: "snapshot") }
|
|
@@ -695,7 +1579,17 @@ final class NativeListView: UIView {
|
|
|
695
1579
|
cancelInteractiveReorderForStructuralUpdate()
|
|
696
1580
|
}
|
|
697
1581
|
config = current
|
|
698
|
-
|
|
1582
|
+
for (index, _) in pending {
|
|
1583
|
+
let item = current.items[index]
|
|
1584
|
+
itemsByKey[item.key] = item
|
|
1585
|
+
}
|
|
1586
|
+
if let tail = structuralTail {
|
|
1587
|
+
for key in changedKeys.union(marketQuoteKeys) {
|
|
1588
|
+
guard let index = tail.indexByKey[key], let item = itemsByKey[key] else { continue }
|
|
1589
|
+
tail.items[index] = item
|
|
1590
|
+
}
|
|
1591
|
+
if sizeChanged { finishStructuralTail(interrupted: true) }
|
|
1592
|
+
}
|
|
699
1593
|
for indexPath in collectionView.indexPathsForVisibleItems {
|
|
700
1594
|
guard let item = item(at: indexPath),
|
|
701
1595
|
marketQuoteKeys.contains(item.key),
|
|
@@ -759,6 +1653,7 @@ final class NativeListView: UIView {
|
|
|
759
1653
|
requestScroll(.index(index, animated, alignment, viewPosition, viewOffset))
|
|
760
1654
|
}
|
|
761
1655
|
|
|
1656
|
+
@objc(onekeyScrollToOffset:animated:)
|
|
762
1657
|
func scrollToOffset(_ offset: Double, animated: Bool) {
|
|
763
1658
|
requestScroll(.offset(offset, animated))
|
|
764
1659
|
}
|
|
@@ -796,6 +1691,8 @@ final class NativeListView: UIView {
|
|
|
796
1691
|
|
|
797
1692
|
private func requestScroll(_ request: ScrollRequest) {
|
|
798
1693
|
if config != nil && explicitTopForScrollCommand(request) == nil { return }
|
|
1694
|
+
explicitScrollRevision &+= 1
|
|
1695
|
+
if structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
799
1696
|
animatedExplicitScrollCommand = false
|
|
800
1697
|
commandAcceptedForPendingScroll = false
|
|
801
1698
|
acceptScrollCommand(request)
|
|
@@ -959,6 +1856,7 @@ final class NativeListView: UIView {
|
|
|
959
1856
|
guard let self else { return }
|
|
960
1857
|
self.contentShrinkCorrectionScheduled = false
|
|
961
1858
|
guard !self.disposed, self.needsContentShrinkCorrection,
|
|
1859
|
+
self.structuralDisplayLink == nil,
|
|
962
1860
|
!self.collectionView.isTracking, !self.collectionView.isDragging,
|
|
963
1861
|
!self.collectionView.isDecelerating,
|
|
964
1862
|
self.collectionView.refreshControl?.isRefreshing != true,
|
|
@@ -994,15 +1892,25 @@ final class NativeListView: UIView {
|
|
|
994
1892
|
flowLayout.scrollDirection = isHorizontal ? .horizontal : .vertical
|
|
995
1893
|
flowLayout.minimumLineSpacing = config.itemSpacing
|
|
996
1894
|
flowLayout.minimumInteritemSpacing = config.itemSpacing
|
|
1895
|
+
let sidecarInset = sidecarBaseInset(collectionView.bounds.width)
|
|
1896
|
+
let sidecarSpace = sidecarLayout.map { $0.width + $0.gap } ?? 0
|
|
1897
|
+
let horizontalInset = config.contentPaddingHorizontal + sidecarInset
|
|
1898
|
+
let disclosureHeight = config.disclosure == nil ? 0 :
|
|
1899
|
+
disclosureCVisibleHeight + containerSlotHeights[5] + disclosureInset
|
|
997
1900
|
flowLayout.sectionInset = UIEdgeInsets(
|
|
998
1901
|
top: config.contentPaddingTop + containerSlotHeights[0],
|
|
999
|
-
left:
|
|
1000
|
-
bottom: config.contentPaddingBottom + containerSlotHeights[2]
|
|
1001
|
-
|
|
1902
|
+
left: horizontalInset + (isRightToLeft ? sidecarSpace + indexGutter : 0),
|
|
1903
|
+
bottom: config.contentPaddingBottom + containerSlotHeights[2] + disclosureHeight
|
|
1904
|
+
+ (structuralTail == nil ? structuralSpacerHeight : 0),
|
|
1905
|
+
right: horizontalInset + (isRightToLeft ? 0 : sidecarSpace + indexGutter)
|
|
1002
1906
|
)
|
|
1003
|
-
|
|
1004
|
-
? config.contentPaddingTop + config.contentPaddingBottom
|
|
1907
|
+
let emptyMinimum = config.items.isEmpty
|
|
1908
|
+
? config.contentPaddingTop + config.contentPaddingBottom
|
|
1909
|
+
+ containerSlotHeights.prefix(3).reduce(0, +) + disclosureHeight
|
|
1005
1910
|
: 0
|
|
1911
|
+
let sidecarMinimum = sidecarLayout == nil ? 0 :
|
|
1912
|
+
config.contentPaddingTop + containerSlotHeights[3] + config.contentPaddingBottom
|
|
1913
|
+
flowLayout.minimumContainerContentHeight = max(emptyMinimum, sidecarMinimum)
|
|
1006
1914
|
flowLayout.stickyItemIndexes = config.stickyHeaders
|
|
1007
1915
|
? Set(config.items.enumerated().compactMap {
|
|
1008
1916
|
$0.element.type == "sectionHeader" && $0.element.data.bool("sticky", default: true) && $0.element.data.string("variant") != "summary"
|
|
@@ -1016,6 +1924,7 @@ final class NativeListView: UIView {
|
|
|
1016
1924
|
listBodyGestureGuard.isEnabled = !isHorizontal
|
|
1017
1925
|
collectionView.showsVerticalScrollIndicator = sectionIndexEntries.isEmpty
|
|
1018
1926
|
collectionView.dragInteractionEnabled = false
|
|
1927
|
+
lastConfiguredCollectionWidth = collectionView.bounds.width
|
|
1019
1928
|
lastLayoutDirection = effectiveUserInterfaceLayoutDirection
|
|
1020
1929
|
}
|
|
1021
1930
|
|
|
@@ -1283,6 +2192,7 @@ final class NativeListView: UIView {
|
|
|
1283
2192
|
let toIndex = keys.firstIndex(of: source.key),
|
|
1284
2193
|
items.count == keys.count else { return }
|
|
1285
2194
|
current.items = items
|
|
2195
|
+
acceptedRowIndex = AcceptedRowIndex(items: items)
|
|
1286
2196
|
config = current
|
|
1287
2197
|
guard source.index != toIndex else { return }
|
|
1288
2198
|
var payload: [String: Any] = [
|
|
@@ -1353,6 +2263,10 @@ final class NativeListView: UIView {
|
|
|
1353
2263
|
return config?.items[safe: indexPath.item]
|
|
1354
2264
|
}
|
|
1355
2265
|
|
|
2266
|
+
private func isInertPresentationKey(_ key: String) -> Bool {
|
|
2267
|
+
structuralTail?.indexByKey[key] != nil || structuralRemovedItems[key] != nil
|
|
2268
|
+
}
|
|
2269
|
+
|
|
1356
2270
|
private func updateAtomicReorderTarget(to targetIndex: Int, key targetKey: String, animated: Bool) {
|
|
1357
2271
|
guard let source = interactiveReorderSource else { return }
|
|
1358
2272
|
interactiveReorderTargetIndex = targetIndex
|
|
@@ -1696,11 +2610,23 @@ final class NativeListView: UIView {
|
|
|
1696
2610
|
if item.key == interactiveReorderCompactKey {
|
|
1697
2611
|
cell.setWalletGroupReorderCompact(true)
|
|
1698
2612
|
}
|
|
2613
|
+
let retiring = structuralRemovedItems[item.key] != nil
|
|
2614
|
+
cell.structuralContentHeight = retiring
|
|
2615
|
+
? rowHeight(item, allocatedWidth: cell.bounds.width) : nil
|
|
2616
|
+
if retiring { cell.clipsToBounds = true }
|
|
2617
|
+
cell.alpha = retiring ? 1 - structuralRemovalProgress : 1
|
|
2618
|
+
cell.isUserInteractionEnabled = !retiring && !item.data.bool("disabled")
|
|
2619
|
+
cell.layer.mask = nil
|
|
2620
|
+
cell.isHidden = false
|
|
2621
|
+
cell.accessibilityElementsHidden = false
|
|
2622
|
+
if let structuralTail, let itemIndex {
|
|
2623
|
+
presentTailCell(cell, key: item.key, index: itemIndex, tail: structuralTail)
|
|
2624
|
+
}
|
|
1699
2625
|
}
|
|
1700
2626
|
|
|
1701
2627
|
private func handleRowPress(_ item: NativeListItem, origin: NativeListActionOrigin?) {
|
|
1702
2628
|
// OneKey patch: missing-address rows keep accessory actions available.
|
|
1703
|
-
guard let config, item.isRowPressEnabled else { return }
|
|
2629
|
+
guard let config, item.isRowPressEnabled, !isInertPresentationKey(item.key) else { return }
|
|
1704
2630
|
if config.rowPressToggles && item.isSelectable && config.selectionMode != "none" {
|
|
1705
2631
|
updateSelection(target: NativeSelectionTarget(scope: "row", key: item.key), sourceKey: item.key)
|
|
1706
2632
|
return
|
|
@@ -1720,8 +2646,8 @@ final class NativeListView: UIView {
|
|
|
1720
2646
|
guard gesture.state == .began else { return }
|
|
1721
2647
|
let point = gesture.location(in: collectionView)
|
|
1722
2648
|
guard let indexPath = collectionView.indexPathForItem(at: point),
|
|
1723
|
-
let item =
|
|
1724
|
-
item.type == "market",
|
|
2649
|
+
let item = item(at: indexPath), !isInertPresentationKey(item.key),
|
|
2650
|
+
(item.type == "market" || item.type == "identity"),
|
|
1725
2651
|
item.isRowPressEnabled else { return }
|
|
1726
2652
|
let actionKey = item.data.string("longPressActionKey")
|
|
1727
2653
|
guard !actionKey.isEmpty else { return }
|
|
@@ -1736,7 +2662,7 @@ final class NativeListView: UIView {
|
|
|
1736
2662
|
target: NativeSelectionTarget?,
|
|
1737
2663
|
origin: NativeListActionOrigin?
|
|
1738
2664
|
) {
|
|
1739
|
-
guard !item.data.bool("disabled") else { return }
|
|
2665
|
+
guard !item.data.bool("disabled"), !isInertPresentationKey(item.key) else { return }
|
|
1740
2666
|
if let target, config?.selectionMode != "none" {
|
|
1741
2667
|
updateSelection(target: target, sourceKey: item.key)
|
|
1742
2668
|
return
|
|
@@ -1745,7 +2671,8 @@ final class NativeListView: UIView {
|
|
|
1745
2671
|
}
|
|
1746
2672
|
|
|
1747
2673
|
private func updateSelection(target: NativeSelectionTarget, sourceKey: String) {
|
|
1748
|
-
guard var current = config, current.selectionMode != "none"
|
|
2674
|
+
guard var current = config, current.selectionMode != "none",
|
|
2675
|
+
!isInertPresentationKey(sourceKey) else { return }
|
|
1749
2676
|
let keys = selectionKeys(target: target, items: current.items)
|
|
1750
2677
|
guard !keys.isEmpty else { return }
|
|
1751
2678
|
let before = current.selectedKeys
|
|
@@ -1806,7 +2733,7 @@ final class NativeListView: UIView {
|
|
|
1806
2733
|
self?.resolveCheckboxState(item: item, target: target, fallback: fallback) ?? fallback
|
|
1807
2734
|
}
|
|
1808
2735
|
for indexPath in collectionView.indexPathsForVisibleItems {
|
|
1809
|
-
guard let item = item(at: indexPath),
|
|
2736
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key),
|
|
1810
2737
|
let cell = collectionView.cellForItem(at: indexPath) as? NativeListRowHost else { continue }
|
|
1811
2738
|
if changedSummaryKeys.contains(item.key) {
|
|
1812
2739
|
bind(cell: cell, item: item, itemIndex: indexPath.item)
|
|
@@ -1957,6 +2884,7 @@ final class NativeListView: UIView {
|
|
|
1957
2884
|
let selectionChanged = current.selectionMode != next.selectionMode ||
|
|
1958
2885
|
current.selectedKeys != next.selectedKeys
|
|
1959
2886
|
if current.generation != next.generation { endReachedGeneration = nil }
|
|
2887
|
+
acceptRowIndex(for: next, replacing: current)
|
|
1960
2888
|
config = next
|
|
1961
2889
|
itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
|
|
1962
2890
|
let changedKeys = next.items.compactMap { item -> String? in
|
|
@@ -2157,6 +3085,13 @@ final class NativeListView: UIView {
|
|
|
2157
3085
|
dataSource = nil
|
|
2158
3086
|
|
|
2159
3087
|
config = nil
|
|
3088
|
+
acceptedRowIndex = nil
|
|
3089
|
+
pagerStickyHeights.removeAllObjects()
|
|
3090
|
+
for slot in reactContainerSlots { slot.host.layer.mask = nil }
|
|
3091
|
+
stopStructuralAnimation()
|
|
3092
|
+
clearStructuralTail()
|
|
3093
|
+
structuralSpacerHeight = 0
|
|
3094
|
+
structuralFooterStartY = nil
|
|
2160
3095
|
itemsByKey.removeAll()
|
|
2161
3096
|
sectionIndexEntries.removeAll()
|
|
2162
3097
|
if let pagerCommandCancelObserver {
|
|
@@ -2175,8 +3110,10 @@ final class NativeListView: UIView {
|
|
|
2175
3110
|
onSelectionDelta = nil
|
|
2176
3111
|
onReorder = nil
|
|
2177
3112
|
onEndReached = nil
|
|
3113
|
+
onStructuralTransitionSettled = nil
|
|
2178
3114
|
onVisibleRangeChanged = nil
|
|
2179
3115
|
onScrollPositionThresholdChange = nil
|
|
3116
|
+
pendingDisclosureSettlement = nil
|
|
2180
3117
|
}
|
|
2181
3118
|
|
|
2182
3119
|
private func createActionAnchor(origin: NativeListActionOrigin) -> [String: Any]? {
|
|
@@ -2272,8 +3209,9 @@ final class NativeListView: UIView {
|
|
|
2272
3209
|
DispatchQueue.main.async { [weak self] in
|
|
2273
3210
|
guard let self else { return }
|
|
2274
3211
|
self.visibleEventScheduled = false
|
|
2275
|
-
guard
|
|
2276
|
-
|
|
3212
|
+
guard self.structuralRemovedItems.isEmpty,
|
|
3213
|
+
let onVisibleRangeChanged = self.onVisibleRangeChanged else { return }
|
|
3214
|
+
let indexes = self.acceptedVisibleIndexes()
|
|
2277
3215
|
let first = indexes.first ?? -1
|
|
2278
3216
|
let last = indexes.last ?? -1
|
|
2279
3217
|
let firstKey = self.config?.items[safe: first]?.key
|
|
@@ -2291,11 +3229,11 @@ final class NativeListView: UIView {
|
|
|
2291
3229
|
}
|
|
2292
3230
|
|
|
2293
3231
|
private func checkEndReached() {
|
|
2294
|
-
guard let config,
|
|
3232
|
+
guard let config, structuralRemovedItems.isEmpty,
|
|
2295
3233
|
config.loadMore,
|
|
2296
3234
|
endReachedGeneration != config.generation,
|
|
2297
3235
|
!config.items.isEmpty else { return }
|
|
2298
|
-
let lastVisible =
|
|
3236
|
+
let lastVisible = acceptedVisibleIndexes().last ?? -1
|
|
2299
3237
|
let threshold = max(1, Int(ceil(Double(config.items.count) * config.endReachedThreshold)))
|
|
2300
3238
|
guard lastVisible >= config.items.count - threshold else { return }
|
|
2301
3239
|
endReachedGeneration = config.generation
|
|
@@ -2304,6 +3242,18 @@ final class NativeListView: UIView {
|
|
|
2304
3242
|
emit(onEndReached, payload)
|
|
2305
3243
|
}
|
|
2306
3244
|
|
|
3245
|
+
private func acceptedVisibleIndexes() -> [Int] {
|
|
3246
|
+
guard let config else { return [] }
|
|
3247
|
+
let presentedPrefix = structuralTail?.prefixCount
|
|
3248
|
+
return collectionView.indexPathsForVisibleItems.compactMap { indexPath in
|
|
3249
|
+
guard presentedPrefix.map({ indexPath.item < $0 }) ?? true,
|
|
3250
|
+
let item = config.items[safe: indexPath.item],
|
|
3251
|
+
dataSource.itemIdentifier(for: indexPath) == item.key,
|
|
3252
|
+
let cell = collectionView.cellForItem(at: indexPath), !cell.isHidden else { return nil }
|
|
3253
|
+
return indexPath.item
|
|
3254
|
+
}.sorted()
|
|
3255
|
+
}
|
|
3256
|
+
|
|
2307
3257
|
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
|
|
2308
3258
|
if gestureRecognizer === keyboardDragRecognizer {
|
|
2309
3259
|
return keyboardDismissMode == .onDrag && focusedTextInput(in: window) != nil
|
|
@@ -2311,12 +3261,13 @@ final class NativeListView: UIView {
|
|
|
2311
3261
|
if gestureRecognizer === reorderLongPress || gestureRecognizer === marketLongPress {
|
|
2312
3262
|
let point = gestureRecognizer.location(in: collectionView)
|
|
2313
3263
|
guard let indexPath = collectionView.indexPathForItem(at: point),
|
|
2314
|
-
let item = item(at: indexPath),
|
|
3264
|
+
let item = item(at: indexPath), !isInertPresentationKey(item.key),
|
|
2315
3265
|
!item.data.bool("disabled") else { return false }
|
|
2316
3266
|
if gestureRecognizer === reorderLongPress {
|
|
2317
3267
|
return config?.reorderable == true && item.isReorderable
|
|
2318
3268
|
}
|
|
2319
|
-
return item.type == "market"
|
|
3269
|
+
return (item.type == "market" || item.type == "identity")
|
|
3270
|
+
&& item.isRowPressEnabled && !item.data.string("longPressActionKey").isEmpty
|
|
2320
3271
|
}
|
|
2321
3272
|
guard gestureRecognizer === listBodyGestureGuard,
|
|
2322
3273
|
let pan = gestureRecognizer as? UIPanGestureRecognizer else { return true }
|
|
@@ -2427,14 +3378,16 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2427
3378
|
return CGSize(width: width, height: height)
|
|
2428
3379
|
}
|
|
2429
3380
|
let available = max(0, collectionView.bounds.width - insets.left - insets.right)
|
|
2430
|
-
let structural = item.type == "sectionHeader" || item.type == "system" || item.type == "action"
|
|
3381
|
+
let structural = item.type == "sectionHeader" || item.type == "system" || item.type == "action" || item.type == "buttonGroup"
|
|
2431
3382
|
if config.layout == "grid", !structural {
|
|
2432
3383
|
let spacing = CGFloat(config.gridColumns - 1) * config.itemSpacing
|
|
2433
3384
|
let width = floor((available - spacing) / CGFloat(config.gridColumns))
|
|
2434
3385
|
let height = item.styledHeight ?? (item.type == "mediaTile" && item.data["height"] == nil ? width + 48 : rowHeight(item, allocatedWidth: width))
|
|
2435
3386
|
return CGSize(width: width, height: height)
|
|
2436
3387
|
}
|
|
2437
|
-
|
|
3388
|
+
let height = structuralRemovedHeights[item.key].map { $0 * (1 - structuralRemovalProgress) }
|
|
3389
|
+
?? rowHeight(item, allocatedWidth: available)
|
|
3390
|
+
return CGSize(width: available, height: max(0.01, height))
|
|
2438
3391
|
}
|
|
2439
3392
|
|
|
2440
3393
|
private func railWidth(_ item: NativeListItem) -> CGFloat {
|
|
@@ -2442,19 +3395,20 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2442
3395
|
}
|
|
2443
3396
|
|
|
2444
3397
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
2445
|
-
guard let item =
|
|
3398
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key) else { return }
|
|
2446
3399
|
if item.type == "walletGroup" { return }
|
|
2447
3400
|
let origin = (collectionView.cellForItem(at: indexPath) as? NativeListRowHost)?.rowActionOrigin()
|
|
2448
3401
|
handleRowPress(item, origin: origin)
|
|
2449
3402
|
}
|
|
2450
3403
|
|
|
2451
3404
|
func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool {
|
|
2452
|
-
guard let item =
|
|
3405
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key) else { return false }
|
|
2453
3406
|
return item.isRowPressEnabled
|
|
2454
3407
|
}
|
|
2455
3408
|
|
|
2456
3409
|
func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
|
|
2457
|
-
guard let item =
|
|
3410
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key),
|
|
3411
|
+
item.type == "market" else { return }
|
|
2458
3412
|
let actionKey = item.data.string("pressInActionKey")
|
|
2459
3413
|
guard !actionKey.isEmpty else { return }
|
|
2460
3414
|
let origin = (collectionView.cellForItem(at: indexPath) as? NativeListRowHost)?.rowActionOrigin()
|
|
@@ -2462,7 +3416,7 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2462
3416
|
}
|
|
2463
3417
|
|
|
2464
3418
|
func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
|
2465
|
-
guard let item =
|
|
3419
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key) else { return false }
|
|
2466
3420
|
return item.isRowPressEnabled
|
|
2467
3421
|
}
|
|
2468
3422
|
|
|
@@ -2474,6 +3428,15 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2474
3428
|
}
|
|
2475
3429
|
|
|
2476
3430
|
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
|
|
3431
|
+
if structuralDisplayLink != nil {
|
|
3432
|
+
structuralScrollInterrupted = true
|
|
3433
|
+
if structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
3434
|
+
else {
|
|
3435
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
3436
|
+
object: collectionView, userInfo: ["phase": 2])
|
|
3437
|
+
structuralScrollPhaseActive = false
|
|
3438
|
+
}
|
|
3439
|
+
}
|
|
2477
3440
|
scrollViewDidEndScrollingAnimation(scrollView)
|
|
2478
3441
|
minimumDragOffset = 0
|
|
2479
3442
|
refreshEmittedForDrag = false
|
|
@@ -2512,7 +3475,7 @@ extension NativeListView: UICollectionViewDragDelegate, UICollectionViewDropDele
|
|
|
2512
3475
|
itemsForBeginning session: UIDragSession,
|
|
2513
3476
|
at indexPath: IndexPath
|
|
2514
3477
|
) -> [UIDragItem] {
|
|
2515
|
-
guard config?.reorderable == true,
|
|
3478
|
+
guard config?.reorderable == true, structuralDisplayLink == nil,
|
|
2516
3479
|
let item = config?.items[safe: indexPath.item],
|
|
2517
3480
|
item.isReorderable else { return [] }
|
|
2518
3481
|
let dragItem = UIDragItem(itemProvider: NSItemProvider(object: item.key as NSString))
|
|
@@ -2539,6 +3502,7 @@ extension NativeListView: UICollectionViewDragDelegate, UICollectionViewDropDele
|
|
|
2539
3502
|
guard sourceItem.isReorderable, targetItem.isReorderable, sourceItem.sectionKey == targetItem.sectionKey else { return }
|
|
2540
3503
|
current.items.remove(at: source.item)
|
|
2541
3504
|
current.items.insert(sourceItem, at: destination.item)
|
|
3505
|
+
acceptedRowIndex = AcceptedRowIndex(items: current.items)
|
|
2542
3506
|
config = current
|
|
2543
3507
|
itemsByKey = Dictionary(uniqueKeysWithValues: current.items.map { ($0.key, $0) })
|
|
2544
3508
|
var snapshot = NSDiffableDataSourceSnapshot<Int, String>()
|
|
@@ -2584,12 +3548,26 @@ private final class NativeListCollectionView: UICollectionView {
|
|
|
2584
3548
|
}
|
|
2585
3549
|
}
|
|
2586
3550
|
|
|
3551
|
+
private final class NativeListClippedSlotHost: UIView {
|
|
3552
|
+
var visibleTop: CGFloat = 0
|
|
3553
|
+
var visibleBottom: CGFloat?
|
|
3554
|
+
|
|
3555
|
+
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
|
3556
|
+
super.point(inside: point, with: event) && point.y >= visibleTop
|
|
3557
|
+
&& point.y < (visibleBottom ?? bounds.height)
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
|
|
2587
3561
|
final class NativeListFlowLayout: UICollectionViewFlowLayout {
|
|
2588
3562
|
var stickyItemIndexes: Set<Int> = []
|
|
2589
3563
|
var minimumContainerContentHeight: CGFloat = 0
|
|
3564
|
+
var animatedBodyContentHeight: CGFloat?
|
|
3565
|
+
var tailClip: (firstIndex: Int, endY: CGFloat)?
|
|
3566
|
+
var bodyContentHeight: CGFloat {
|
|
3567
|
+
animatedBodyContentHeight ?? super.collectionViewContentSize.height
|
|
3568
|
+
}
|
|
2590
3569
|
private var horizontalAttributes: [IndexPath: UICollectionViewLayoutAttributes] = [:]
|
|
2591
3570
|
private var horizontalContentSize: CGSize = .zero
|
|
2592
|
-
|
|
2593
3571
|
override func prepare() {
|
|
2594
3572
|
super.prepare()
|
|
2595
3573
|
horizontalAttributes.removeAll(keepingCapacity: true)
|
|
@@ -2617,7 +3595,7 @@ final class NativeListFlowLayout: UICollectionViewFlowLayout {
|
|
|
2617
3595
|
override var collectionViewContentSize: CGSize {
|
|
2618
3596
|
if scrollDirection == .horizontal { return horizontalContentSize }
|
|
2619
3597
|
let size = super.collectionViewContentSize
|
|
2620
|
-
return CGSize(width: size.width, height: max(
|
|
3598
|
+
return CGSize(width: size.width, height: max(bodyContentHeight, minimumContainerContentHeight))
|
|
2621
3599
|
}
|
|
2622
3600
|
|
|
2623
3601
|
override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
|
|
@@ -2654,10 +3632,17 @@ final class NativeListFlowLayout: UICollectionViewFlowLayout {
|
|
|
2654
3632
|
.filter { $0.frame.intersects(rect) }
|
|
2655
3633
|
.sorted { $0.indexPath.item < $1.indexPath.item }
|
|
2656
3634
|
}
|
|
2657
|
-
guard scrollDirection == .vertical,
|
|
2658
|
-
!stickyItemIndexes.isEmpty,
|
|
2659
|
-
let collectionView else { return super.layoutAttributesForElements(in: rect) }
|
|
2660
3635
|
let base = super.layoutAttributesForElements(in: rect)?.compactMap { $0.copy() as? UICollectionViewLayoutAttributes } ?? []
|
|
3636
|
+
guard scrollDirection == .vertical else { return base }
|
|
3637
|
+
let clipped = base.filter { attributes in
|
|
3638
|
+
guard let tailClip, attributes.representedElementCategory == .cell,
|
|
3639
|
+
attributes.indexPath.item >= tailClip.firstIndex else { return true }
|
|
3640
|
+
return attributes.frame.minY < tailClip.endY
|
|
3641
|
+
}
|
|
3642
|
+
guard !stickyItemIndexes.isEmpty,
|
|
3643
|
+
let collectionView else {
|
|
3644
|
+
return clipped
|
|
3645
|
+
}
|
|
2661
3646
|
let pinY = collectionView.contentOffset.y + collectionView.adjustedContentInset.top
|
|
2662
3647
|
// Visible cells can still describe the old viewport during an imperative
|
|
2663
3648
|
// scroll. Resolve the pinned header from unmodified layout positions.
|
|
@@ -2666,20 +3651,30 @@ final class NativeListFlowLayout: UICollectionViewFlowLayout {
|
|
|
2666
3651
|
return attributes.frame.minY <= pinY
|
|
2667
3652
|
}).max(),
|
|
2668
3653
|
let original = super.layoutAttributesForItem(at: IndexPath(item: stickyIndex, section: 0)),
|
|
2669
|
-
let sticky = original.copy() as? UICollectionViewLayoutAttributes else {
|
|
3654
|
+
let sticky = original.copy() as? UICollectionViewLayoutAttributes else {
|
|
3655
|
+
return clipped
|
|
3656
|
+
}
|
|
2670
3657
|
let nextHeaderY = stickyItemIndexes
|
|
2671
3658
|
.filter { $0 > stickyIndex }
|
|
2672
3659
|
.min()
|
|
2673
3660
|
.flatMap { super.layoutAttributesForItem(at: IndexPath(item: $0, section: 0))?.frame.minY }
|
|
2674
3661
|
sticky.frame.origin.y = min(max(pinY, original.frame.minY), (nextHeaderY ?? .greatestFiniteMagnitude) - sticky.frame.height)
|
|
2675
3662
|
sticky.zIndex = 10_000
|
|
2676
|
-
let filtered =
|
|
2677
|
-
|
|
3663
|
+
let filtered = clipped.filter { $0.indexPath != sticky.indexPath }
|
|
3664
|
+
let returned = filtered + [sticky]
|
|
3665
|
+
return returned
|
|
2678
3666
|
}
|
|
2679
3667
|
|
|
2680
3668
|
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
|
|
2681
3669
|
if scrollDirection == .horizontal { return horizontalAttributes[indexPath] }
|
|
2682
|
-
|
|
3670
|
+
guard let attributes = super.layoutAttributesForItem(at: indexPath) else {
|
|
3671
|
+
return nil
|
|
3672
|
+
}
|
|
3673
|
+
if let tailClip, indexPath.item >= tailClip.firstIndex,
|
|
3674
|
+
attributes.frame.minY >= tailClip.endY {
|
|
3675
|
+
return nil
|
|
3676
|
+
}
|
|
3677
|
+
return attributes
|
|
2683
3678
|
}
|
|
2684
3679
|
|
|
2685
3680
|
}
|