@onekeyfe/react-native-native-list 6.7.0-5 → 6.7.0-50
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 +312 -375
- 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 +1978 -136
- 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 +1232 -16
- 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 +1093 -59
- 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 +2915 -4
- 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 +236 -38
- 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 +12 -31
- 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 +439 -91
- 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 +29 -59
- 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,22 @@ 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 containerHeaderHeightIsAuthoritative = false
|
|
35
|
+
private weak var currentHeaderRoot: UIView?
|
|
36
|
+
private var disclosureCVisibleHeight: CGFloat = 0
|
|
37
|
+
private var disclosureInset: CGFloat = 0
|
|
38
|
+
private var disclosureStartCHeight: CGFloat = 0
|
|
39
|
+
private var disclosureStartInset: CGFloat = 0
|
|
40
|
+
private var disclosureSegmentStartEased: CFTimeInterval = 0
|
|
41
|
+
private var deferredDisclosureGeometryInvalid = false
|
|
42
|
+
private var pendingDisclosureSettlement: (id: String, expanded: Bool)?
|
|
34
43
|
// Fabric keeps assigning each slot root the frame React computed (inset, 0, width, height).
|
|
35
44
|
// Each root therefore lives in a list-owned host whose origin the list alone controls, so a
|
|
36
45
|
// React layout update can never move a slot out of its native position, even for a frame.
|
|
37
46
|
private var reactContainerSlots: [(content: UIView, host: UIView)] = []
|
|
47
|
+
private var sidecarLayout: (width: CGFloat, gap: CGFloat, maxContentWidth: CGFloat)?
|
|
48
|
+
private let pagerStickyHeights = NSMapTable<AnyObject, NSNumber>(keyOptions: .weakMemory, valueOptions: .strongMemory)
|
|
38
49
|
private let topOverlayHost = UIView()
|
|
39
50
|
private weak var topOverlayContent: UIView?
|
|
40
51
|
private var topEdgeInteraction: UIInteraction?
|
|
@@ -47,22 +58,249 @@ final class NativeListView: UIView {
|
|
|
47
58
|
private var lastLaidOutContentHeight: CGFloat?
|
|
48
59
|
private var needsContentShrinkCorrection = false
|
|
49
60
|
private var contentShrinkCorrectionScheduled = false
|
|
61
|
+
private var consumedStructuralTransitionID: String?
|
|
62
|
+
private var structuralDisplayLink: CADisplayLink?
|
|
63
|
+
private var structuralScrollPhaseActive = false
|
|
64
|
+
private var structuralSpacerHeight: CGFloat = 0
|
|
65
|
+
private var structuralAnimationStart: CFTimeInterval = 0
|
|
66
|
+
private var structuralAnimationDuration: CFTimeInterval = 0
|
|
67
|
+
private var structuralStartSpacer: CGFloat = 0
|
|
68
|
+
private var structuralStartOffset: CGFloat = 0
|
|
69
|
+
private var structuralTargetOffset: CGFloat = 0
|
|
70
|
+
private var structuralScrollInterrupted = false
|
|
71
|
+
private var structuralFooterStartY: CGFloat?
|
|
72
|
+
private var structuralFooterProgress: CGFloat = 0
|
|
73
|
+
private var structuralRemovedItems: [String: NativeListItem] = [:]
|
|
74
|
+
private var structuralRemovedHeights: [String: CGFloat] = [:]
|
|
75
|
+
private var structuralRemovalProgress: CGFloat = 0
|
|
76
|
+
private final class StructuralTail {
|
|
77
|
+
var items: [NativeListItem]
|
|
78
|
+
let starts: [CGFloat]
|
|
79
|
+
let heights: [CGFloat]
|
|
80
|
+
let indexByKey: [String: Int]
|
|
81
|
+
let extent: CGFloat
|
|
82
|
+
let prefixCount: Int
|
|
83
|
+
let finalExtent: CGFloat
|
|
84
|
+
let retiringKeys: Set<String>
|
|
85
|
+
init(items: [NativeListItem], heights: [CGFloat], spacing: CGFloat,
|
|
86
|
+
prefixCount: Int, finalExtent: CGFloat) {
|
|
87
|
+
self.items = items
|
|
88
|
+
self.heights = heights
|
|
89
|
+
self.indexByKey = Dictionary(uniqueKeysWithValues: items.enumerated().map { ($1.key, $0) })
|
|
90
|
+
self.prefixCount = prefixCount
|
|
91
|
+
self.finalExtent = finalExtent
|
|
92
|
+
self.retiringKeys = finalExtent == 0 ? Set(items.map(\.key)) : []
|
|
93
|
+
var edge: CGFloat = prefixCount == 0 ? 0 : spacing
|
|
94
|
+
var starts: [CGFloat] = []
|
|
95
|
+
for (index, height) in heights.enumerated() {
|
|
96
|
+
starts.append(edge)
|
|
97
|
+
edge += height + (index + 1 < heights.count ? spacing : 0)
|
|
98
|
+
}
|
|
99
|
+
self.starts = starts
|
|
100
|
+
self.extent = edge
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
private var structuralTail: StructuralTail?
|
|
104
|
+
private var structuralTailStartExtent: CGFloat = 0
|
|
105
|
+
private var structuralTailSegmentStartEased: CFTimeInterval = 0
|
|
106
|
+
private var structuralTailStartY: CGFloat = 0
|
|
107
|
+
private func prefixTailCount(from old: NativeListConfig, to next: NativeListConfig) -> Int? {
|
|
108
|
+
guard old.orientation == "vertical", next.orientation == "vertical",
|
|
109
|
+
old.layout == next.layout, next.layout == "linear" || next.layout == "table",
|
|
110
|
+
old.itemSpacing == next.itemSpacing,
|
|
111
|
+
old.contentPaddingTop == next.contentPaddingTop,
|
|
112
|
+
old.contentPaddingBottom == next.contentPaddingBottom,
|
|
113
|
+
old.contentPaddingHorizontal == next.contentPaddingHorizontal,
|
|
114
|
+
dictionariesEqual(old.theme, next.theme),
|
|
115
|
+
dictionariesEqual(old.listStyle, next.listStyle),
|
|
116
|
+
old.items.count != next.items.count,
|
|
117
|
+
structuralDisplayLink == nil || structuralTail != nil,
|
|
118
|
+
!old.items.contains(where: { $0.type == "sectionHeader" }),
|
|
119
|
+
!next.items.contains(where: { $0.type == "sectionHeader" }) else { return nil }
|
|
120
|
+
let prefix = min(old.items.count, next.items.count)
|
|
121
|
+
guard prefix > 0 else { return nil }
|
|
122
|
+
for index in 0..<prefix {
|
|
123
|
+
let before = old.items[index], after = next.items[index]
|
|
124
|
+
guard before.key == after.key, before.type == after.type,
|
|
125
|
+
rowHeight(before) == rowHeight(after) else { return nil }
|
|
126
|
+
}
|
|
127
|
+
return prefix
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private func tailExceedsHostLimit(_ tail: StructuralTail) -> Bool {
|
|
131
|
+
let window = max(0, collectionView.bounds.height) * 3
|
|
132
|
+
var end = 0
|
|
133
|
+
for first in tail.items.indices {
|
|
134
|
+
end = max(end, first)
|
|
135
|
+
while end < tail.items.count && tail.starts[end] <= tail.starts[first] + window {
|
|
136
|
+
end += 1
|
|
137
|
+
}
|
|
138
|
+
if end - first > 128 { return true }
|
|
139
|
+
}
|
|
140
|
+
return false
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private func clearStructuralTail() {
|
|
144
|
+
structuralTail = nil
|
|
145
|
+
flowLayout.animatedBodyContentHeight = nil
|
|
146
|
+
flowLayout.tailClip = nil
|
|
147
|
+
for case let cell as NativeListRowHost in collectionView.visibleCells {
|
|
148
|
+
let indexPath = collectionView.indexPath(for: cell)
|
|
149
|
+
let key = indexPath.flatMap { dataSource?.itemIdentifier(for: $0) }
|
|
150
|
+
let accepted = indexPath.flatMap { config?.items[safe: $0.item]?.key } == key && key != nil
|
|
151
|
+
cell.layer.mask = nil
|
|
152
|
+
cell.isHidden = !accepted
|
|
153
|
+
cell.accessibilityElementsHidden = !accepted
|
|
154
|
+
cell.isUserInteractionEnabled = accepted && !(key.flatMap { itemsByKey[$0] }?.data.bool("disabled") ?? false)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private func updateStructuralTailWindow() {
|
|
159
|
+
guard let tail = structuralTail else { return }
|
|
160
|
+
let clipEnd = structuralTailStartY + structuralSpacerHeight
|
|
161
|
+
flowLayout.animatedBodyContentHeight = clipEnd
|
|
162
|
+
+ (config?.contentPaddingBottom ?? 0) + containerSlotHeights[2]
|
|
163
|
+
+ (config?.disclosure == nil ? 0 : disclosureCVisibleHeight
|
|
164
|
+
+ containerSlotHeights[5] + disclosureInset)
|
|
165
|
+
flowLayout.tailClip = (tail.prefixCount, clipEnd)
|
|
166
|
+
for case let cell as NativeListRowHost in collectionView.visibleCells {
|
|
167
|
+
guard let indexPath = collectionView.indexPath(for: cell),
|
|
168
|
+
let key = dataSource.itemIdentifier(for: indexPath) else { continue }
|
|
169
|
+
presentTailCell(cell, key: key, index: indexPath.item, tail: tail)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private func presentTailCell(_ cell: NativeListRowHost, key: String, index: Int,
|
|
174
|
+
tail: StructuralTail) {
|
|
175
|
+
let clipEnd = structuralTailStartY + structuralSpacerHeight
|
|
176
|
+
let visibleHeight = index >= tail.prefixCount
|
|
177
|
+
? max(0, min(cell.bounds.height, clipEnd - cell.frame.minY)) : cell.bounds.height
|
|
178
|
+
let clipped = visibleHeight < cell.bounds.height
|
|
179
|
+
CATransaction.begin()
|
|
180
|
+
CATransaction.setDisableActions(true)
|
|
181
|
+
cell.isHidden = visibleHeight <= 0
|
|
182
|
+
if clipped && visibleHeight > 0 {
|
|
183
|
+
let mask = cell.layer.mask ?? CALayer()
|
|
184
|
+
mask.backgroundColor = UIColor.black.cgColor
|
|
185
|
+
mask.frame = CGRect(x: 0, y: 0, width: cell.bounds.width, height: visibleHeight)
|
|
186
|
+
cell.layer.mask = mask
|
|
187
|
+
} else {
|
|
188
|
+
cell.layer.mask = nil
|
|
189
|
+
}
|
|
190
|
+
CATransaction.commit()
|
|
191
|
+
let inert = index >= tail.prefixCount || clipped
|
|
192
|
+
cell.isUserInteractionEnabled = !inert && !(itemsByKey[key]?.data.bool("disabled") ?? false)
|
|
193
|
+
cell.accessibilityElementsHidden = inert
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private func finishStructuralTail(interrupted: Bool) {
|
|
197
|
+
guard let tail = structuralTail, let config else { return }
|
|
198
|
+
stopStructuralAnimation()
|
|
199
|
+
if !tail.retiringKeys.isEmpty {
|
|
200
|
+
var snapshot = dataSource.snapshot()
|
|
201
|
+
snapshot.deleteItems(Array(tail.retiringKeys))
|
|
202
|
+
dataSource.apply(snapshot, animatingDifferences: false)
|
|
203
|
+
itemsByKey = Dictionary(uniqueKeysWithValues: config.items.map { ($0.key, $0) })
|
|
204
|
+
}
|
|
205
|
+
clearStructuralTail()
|
|
206
|
+
structuralSpacerHeight = 0
|
|
207
|
+
disclosureCVisibleHeight = config.disclosure?.expanded == true ? containerSlotHeights[4] : 0
|
|
208
|
+
disclosureInset = config.disclosure?.expanded == true
|
|
209
|
+
? config.disclosure?.expandedTrailingInset ?? 0 : 0
|
|
210
|
+
structuralFooterStartY = nil
|
|
211
|
+
structuralFooterProgress = 0
|
|
212
|
+
configureLayout(config)
|
|
213
|
+
collectionView.layoutIfNeeded()
|
|
214
|
+
if interrupted {
|
|
215
|
+
// A diffable deletion can leave UIKit's content-shrink scroll animation active.
|
|
216
|
+
// Cancel it without choosing a new offset for the user's gesture.
|
|
217
|
+
collectionView.setContentOffset(collectionView.contentOffset, animated: false)
|
|
218
|
+
} else if !collectionView.isTracking && !collectionView.isDragging
|
|
219
|
+
&& !collectionView.isDecelerating {
|
|
220
|
+
let inset = collectionView.adjustedContentInset
|
|
221
|
+
let maximum = max(-inset.top,
|
|
222
|
+
collectionView.contentSize.height - collectionView.bounds.height + inset.bottom)
|
|
223
|
+
let target = min(max(-inset.top, structuralTargetOffset), maximum)
|
|
224
|
+
collectionView.setContentOffset(CGPoint(x: collectionView.contentOffset.x, y: target), animated: false)
|
|
225
|
+
}
|
|
226
|
+
layoutContainerSlots()
|
|
227
|
+
emitVisibleRangeIfNeeded()
|
|
228
|
+
checkEndReached()
|
|
229
|
+
settleDisclosure(interrupted ? "interrupted" : "completed")
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private func updateStructuralTailTarget() {
|
|
233
|
+
guard let tail = structuralTail, let config else { return }
|
|
234
|
+
let inset = collectionView.adjustedContentInset
|
|
235
|
+
let leftHeight = structuralTailStartY + tail.finalExtent
|
|
236
|
+
+ config.contentPaddingBottom + containerSlotHeights[2]
|
|
237
|
+
+ (config.disclosure == nil ? 0 :
|
|
238
|
+
(config.disclosure?.expanded == true ? containerSlotHeights[4] : 0)
|
|
239
|
+
+ containerSlotHeights[5]
|
|
240
|
+
+ (config.disclosure?.expanded == true
|
|
241
|
+
? config.disclosure?.expandedTrailingInset ?? 0 : 0))
|
|
242
|
+
let sidecarHeight = sidecarLayout == nil ? 0 :
|
|
243
|
+
config.contentPaddingTop + containerSlotHeights[3] + config.contentPaddingBottom
|
|
244
|
+
let finalHeight = max(leftHeight, sidecarHeight)
|
|
245
|
+
let maximum = max(-inset.top,
|
|
246
|
+
finalHeight - collectionView.bounds.height + inset.bottom)
|
|
247
|
+
var target = min(max(-inset.top, structuralStartOffset), maximum)
|
|
248
|
+
if tail.finalExtent == 0, config.disclosure != nil, containerSlotHeights[5] > 0 {
|
|
249
|
+
let toggleTop = structuralTailStartY
|
|
250
|
+
let toggleBottom = toggleTop + containerSlotHeights[5]
|
|
251
|
+
var sticky: CGFloat = 0
|
|
252
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
253
|
+
sticky += CGFloat(value.doubleValue)
|
|
254
|
+
}
|
|
255
|
+
let lower = toggleBottom - collectionView.bounds.height + inset.bottom
|
|
256
|
+
let upper = toggleTop - inset.top - sticky
|
|
257
|
+
target = lower <= upper ? min(max(target, lower), upper) : upper
|
|
258
|
+
} else if tail.finalExtent == 0, containerSlotHeights[2] > 0 {
|
|
259
|
+
let footerTop = structuralTailStartY
|
|
260
|
+
let footerBottom = footerTop + containerSlotHeights[2]
|
|
261
|
+
var sticky: CGFloat = 0
|
|
262
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
263
|
+
sticky += CGFloat(value.doubleValue)
|
|
264
|
+
}
|
|
265
|
+
let lower = footerBottom - collectionView.bounds.height + inset.bottom
|
|
266
|
+
let upper = footerTop - inset.top - sticky
|
|
267
|
+
target = lower <= upper ? min(max(target, lower), upper) : upper
|
|
268
|
+
}
|
|
269
|
+
structuralTargetOffset = min(max(-inset.top, target), maximum)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private func structuralTailSegmentProgress(_ eased: CFTimeInterval) -> CFTimeInterval {
|
|
273
|
+
if eased >= 1 { return 1 }
|
|
274
|
+
let remaining = max(0.001, 1 - structuralTailSegmentStartEased)
|
|
275
|
+
return min(1, max(0, (eased - structuralTailSegmentStartEased) / remaining))
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
private func disclosureSegmentProgress(_ eased: CFTimeInterval) -> CFTimeInterval {
|
|
279
|
+
if eased >= 1 { return 1 }
|
|
280
|
+
let remaining = max(0.001, 1 - disclosureSegmentStartEased)
|
|
281
|
+
return min(1, max(0, (eased - disclosureSegmentStartEased) / remaining))
|
|
282
|
+
}
|
|
50
283
|
|
|
51
284
|
@objc func mountContainerSlot(_ view: UIView, atIndex index: Int) {
|
|
52
|
-
if index ==
|
|
285
|
+
if index == 6 {
|
|
53
286
|
topOverlayContent?.removeFromSuperview()
|
|
54
287
|
topOverlayContent = view
|
|
55
288
|
topOverlayHost.addSubview(view)
|
|
56
289
|
updateTopScrollEdge()
|
|
57
290
|
return
|
|
58
291
|
}
|
|
59
|
-
let host =
|
|
292
|
+
let host: UIView = index == 2 || index == 4 || index == 5
|
|
293
|
+
? NativeListClippedSlotHost() : UIView()
|
|
60
294
|
// Clipping to the reported height keeps new content from overlapping rows until the list
|
|
61
295
|
// has reserved space for it.
|
|
62
296
|
host.clipsToBounds = true
|
|
63
297
|
host.addSubview(view)
|
|
64
298
|
reactContainerSlots.insert((view, host), at: min(index, reactContainerSlots.count))
|
|
65
299
|
collectionView.addSubview(host)
|
|
300
|
+
if index == 0 {
|
|
301
|
+
currentHeaderRoot = view
|
|
302
|
+
if !containerHeaderHeightIsAuthoritative { updatePendingHeaderHeight() }
|
|
303
|
+
}
|
|
66
304
|
layoutContainerSlots()
|
|
67
305
|
setNeedsLayout()
|
|
68
306
|
}
|
|
@@ -74,12 +312,17 @@ final class NativeListView: UIView {
|
|
|
74
312
|
updateTopScrollEdge()
|
|
75
313
|
return
|
|
76
314
|
}
|
|
315
|
+
let removedCurrentHeader = currentHeaderRoot === view
|
|
316
|
+
if removedCurrentHeader { currentHeaderRoot = nil }
|
|
77
317
|
reactContainerSlots.removeAll { slot in
|
|
78
318
|
guard slot.content === view else { return false }
|
|
79
319
|
view.removeFromSuperview()
|
|
80
320
|
slot.host.removeFromSuperview()
|
|
81
321
|
return true
|
|
82
322
|
}
|
|
323
|
+
if removedCurrentHeader && !containerHeaderHeightIsAuthoritative {
|
|
324
|
+
updatePendingHeaderHeight()
|
|
325
|
+
}
|
|
83
326
|
}
|
|
84
327
|
|
|
85
328
|
func setTopScrollEdge(effect: NativeListTopScrollEdgeEffect, overlayHeight: CGFloat) {
|
|
@@ -142,16 +385,138 @@ final class NativeListView: UIView {
|
|
|
142
385
|
}
|
|
143
386
|
}
|
|
144
387
|
|
|
145
|
-
func setContainerSlotHeightsJson(_ json: String) {
|
|
388
|
+
func setContainerSlotHeightsJson(_ json: String, followedBySnapshot: Bool = false) {
|
|
146
389
|
guard let data = json.data(using: .utf8),
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
390
|
+
var values = try? JSONSerialization.jsonObject(with: data) as? [Any],
|
|
391
|
+
(values.count == 4 || values.count == 6) else { return }
|
|
392
|
+
let headerPending = values[0] is NSNull
|
|
393
|
+
if headerPending { values[0] = 0.0 }
|
|
394
|
+
guard let heights = values as? [Double],
|
|
395
|
+
heights.allSatisfy({ $0.isFinite && $0 >= 0 }) else { return }
|
|
396
|
+
containerHeaderHeightIsAuthoritative = !headerPending
|
|
397
|
+
var next = heights.map { CGFloat($0) } + (heights.count == 4 ? [0, 0] : [])
|
|
398
|
+
if headerPending { next[0] = pendingHeaderHeight() }
|
|
399
|
+
applyContainerSlotHeights(next, followedBySnapshot: followedBySnapshot)
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
private func pendingHeaderHeight() -> CGFloat {
|
|
403
|
+
guard let bounds = currentHeaderRoot?.bounds,
|
|
404
|
+
bounds.width.isFinite, bounds.width > 0,
|
|
405
|
+
bounds.height.isFinite, bounds.height >= 0 else { return 0 }
|
|
406
|
+
return ceil(bounds.height)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
private func updatePendingHeaderHeight() {
|
|
410
|
+
let height = pendingHeaderHeight()
|
|
411
|
+
guard height != containerSlotHeights[0] else { return }
|
|
412
|
+
var next = containerSlotHeights
|
|
413
|
+
next[0] = height
|
|
414
|
+
applyContainerSlotHeights(next)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
private func applyContainerSlotHeights(_ heights: [CGFloat], followedBySnapshot: Bool = false) {
|
|
418
|
+
let previousHeights = containerSlotHeights
|
|
419
|
+
let footerDelta = containerSlotHeights[2] - heights[2]
|
|
420
|
+
containerSlotHeights = heights
|
|
421
|
+
let contentHeightChanged = previousHeights[4] != containerSlotHeights[4]
|
|
422
|
+
let toggleHeightChanged = previousHeights[5] != containerSlotHeights[5]
|
|
423
|
+
let disclosureGeometryInvalid = structuralTail != nil && config?.disclosure != nil
|
|
424
|
+
&& (toggleHeightChanged || footerDelta != 0
|
|
425
|
+
|| containerSlotHeights[4] < disclosureCVisibleHeight - 0.5)
|
|
426
|
+
let surroundingSlotGeometryInvalid = structuralTail != nil
|
|
427
|
+
&& (previousHeights[0] != containerSlotHeights[0]
|
|
428
|
+
|| previousHeights[1] != containerSlotHeights[1]
|
|
429
|
+
|| previousHeights[3] != containerSlotHeights[3])
|
|
430
|
+
if surroundingSlotGeometryInvalid || disclosureGeometryInvalid {
|
|
431
|
+
if followedBySnapshot, config?.disclosure != nil {
|
|
432
|
+
deferredDisclosureGeometryInvalid = true
|
|
433
|
+
}
|
|
434
|
+
else { finishStructuralTail(interrupted: true) }
|
|
435
|
+
}
|
|
436
|
+
if structuralTail != nil, contentHeightChanged, !disclosureGeometryInvalid,
|
|
437
|
+
!surroundingSlotGeometryInvalid,
|
|
438
|
+
config?.disclosure != nil, structuralDisplayLink != nil {
|
|
439
|
+
let progress = min(1, max(0,
|
|
440
|
+
(CACurrentMediaTime() - structuralAnimationStart) / max(0.001, structuralAnimationDuration)))
|
|
441
|
+
let eased = progress * progress * (3 - 2 * progress)
|
|
442
|
+
disclosureStartCHeight = disclosureCVisibleHeight
|
|
443
|
+
disclosureSegmentStartEased = eased
|
|
444
|
+
}
|
|
445
|
+
if structuralTail != nil, structuralDisplayLink != nil, footerDelta != 0,
|
|
446
|
+
config?.disclosure == nil {
|
|
447
|
+
let progress = min(1, max(0,
|
|
448
|
+
(CACurrentMediaTime() - structuralAnimationStart) / max(0.001, structuralAnimationDuration)))
|
|
449
|
+
let eased = progress * progress * (3 - 2 * progress)
|
|
450
|
+
// Rebase from the last extent actually presented, not elapsed wall time.
|
|
451
|
+
structuralTailStartExtent = structuralSpacerHeight + footerDelta
|
|
452
|
+
structuralSpacerHeight = structuralTailStartExtent
|
|
453
|
+
structuralTailSegmentStartEased = eased
|
|
454
|
+
disclosureStartCHeight = disclosureCVisibleHeight
|
|
455
|
+
disclosureSegmentStartEased = eased
|
|
456
|
+
disclosureStartInset = disclosureInset
|
|
457
|
+
structuralStartOffset = collectionView.contentOffset.y
|
|
458
|
+
} else if structuralTail == nil, structuralDisplayLink != nil,
|
|
459
|
+
footerDelta != 0, config?.disclosure == nil {
|
|
460
|
+
let progress = min(1, max(0,
|
|
461
|
+
(CACurrentMediaTime() - structuralAnimationStart) / max(0.001, structuralAnimationDuration)))
|
|
462
|
+
let eased = progress * progress * (3 - 2 * progress)
|
|
463
|
+
structuralStartSpacer = max(0, structuralStartSpacer + footerDelta)
|
|
464
|
+
structuralSpacerHeight = structuralStartSpacer * (1 - eased)
|
|
465
|
+
if let startY = structuralFooterStartY { structuralFooterStartY = startY + footerDelta }
|
|
466
|
+
}
|
|
467
|
+
if structuralTail == nil, let disclosure = config?.disclosure {
|
|
468
|
+
disclosureCVisibleHeight = disclosure.expanded ? containerSlotHeights[4] : 0
|
|
469
|
+
disclosureInset = disclosure.expanded ? disclosure.expandedTrailingInset : 0
|
|
470
|
+
}
|
|
471
|
+
if let config { configureLayout(config) }
|
|
472
|
+
if structuralTail != nil {
|
|
473
|
+
updateStructuralTailTarget()
|
|
474
|
+
updateStructuralTailWindow()
|
|
475
|
+
flowLayout.invalidateLayout()
|
|
476
|
+
collectionView.layoutIfNeeded()
|
|
477
|
+
updateStructuralTailWindow()
|
|
478
|
+
} else if structuralDisplayLink != nil {
|
|
479
|
+
collectionView.layoutIfNeeded()
|
|
480
|
+
let inset = collectionView.adjustedContentInset
|
|
481
|
+
let finalMaximum = max(-inset.top,
|
|
482
|
+
collectionView.contentSize.height - structuralSpacerHeight
|
|
483
|
+
- collectionView.bounds.height + inset.bottom)
|
|
484
|
+
structuralTargetOffset = min(structuralTargetOffset, finalMaximum)
|
|
485
|
+
}
|
|
486
|
+
layoutContainerSlots()
|
|
487
|
+
setNeedsLayout()
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
func setSidecarLayoutJson(_ json: String) {
|
|
491
|
+
if json.isEmpty {
|
|
492
|
+
sidecarLayout = nil
|
|
493
|
+
} else if let data = json.data(using: .utf8),
|
|
494
|
+
let value = try? JSONSerialization.jsonObject(with: data) as? [String: Double],
|
|
495
|
+
let width = value["width"], let gap = value["gap"],
|
|
496
|
+
let maxWidth = value["maxContentWidth"],
|
|
497
|
+
width.isFinite, width > 0, gap.isFinite, gap >= 0,
|
|
498
|
+
maxWidth.isFinite, maxWidth > width + gap {
|
|
499
|
+
sidecarLayout = (CGFloat(width), CGFloat(gap), CGFloat(maxWidth))
|
|
500
|
+
} else { return }
|
|
501
|
+
if structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
150
502
|
if let config { configureLayout(config) }
|
|
151
503
|
layoutContainerSlots()
|
|
152
504
|
setNeedsLayout()
|
|
153
505
|
}
|
|
154
506
|
|
|
507
|
+
private func sidecarBaseInset(_ width: CGFloat) -> CGFloat {
|
|
508
|
+
guard let sidecarLayout else { return 0 }
|
|
509
|
+
return max(0, (width - min(width, sidecarLayout.maxContentWidth)) / 2)
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
@objc(setPagerStickyHeight:forOwner:)
|
|
513
|
+
func setPagerStickyHeight(_ height: CGFloat, forOwner owner: AnyObject) {
|
|
514
|
+
let next = height.isFinite ? max(0, height) : 0
|
|
515
|
+
if next == 0 { pagerStickyHeights.removeObject(forKey: owner) }
|
|
516
|
+
else { pagerStickyHeights.setObject(NSNumber(value: Double(next)), forKey: owner) }
|
|
517
|
+
layoutContainerSlots()
|
|
518
|
+
}
|
|
519
|
+
|
|
155
520
|
private func layoutContainerSlots() {
|
|
156
521
|
let empty = config?.items.isEmpty ?? true
|
|
157
522
|
let header = containerSlotHeights[0]
|
|
@@ -159,15 +524,76 @@ final class NativeListView: UIView {
|
|
|
159
524
|
let footer = containerSlotHeights[2]
|
|
160
525
|
let paddingTop = config?.contentPaddingTop ?? 0
|
|
161
526
|
let paddingBottom = config?.contentPaddingBottom ?? 0
|
|
162
|
-
let
|
|
163
|
-
|
|
164
|
-
|
|
527
|
+
let naturalFooterY = flowLayout.bodyContentHeight - paddingBottom - footer
|
|
528
|
+
let footerY = structuralTail == nil
|
|
529
|
+
? max(paddingTop + header + emptyHeight, naturalFooterY) : naturalFooterY
|
|
530
|
+
let footerPosition = structuralTail == nil && structuralRemovedItems.isEmpty ? structuralFooterStartY.map {
|
|
531
|
+
$0 + (footerY - $0) * structuralFooterProgress
|
|
532
|
+
} ?? footerY : footerY
|
|
533
|
+
let positions = [paddingTop, paddingTop + header, footerPosition]
|
|
165
534
|
for (index, slot) in reactContainerSlots.prefix(3).enumerated() {
|
|
166
535
|
slot.host.isHidden = index == 1 && !empty
|
|
167
536
|
// React places the root at the horizontal inset inside this full-width host.
|
|
168
537
|
slot.host.frame = CGRect(x: 0, y: positions[index],
|
|
169
538
|
width: collectionView.bounds.width, height: containerSlotHeights[index])
|
|
170
539
|
}
|
|
540
|
+
if reactContainerSlots.count > 3 {
|
|
541
|
+
let slot = reactContainerSlots[3]
|
|
542
|
+
let width = sidecarLayout?.width ?? 0
|
|
543
|
+
let base = sidecarBaseInset(collectionView.bounds.width)
|
|
544
|
+
slot.host.isHidden = sidecarLayout == nil || containerSlotHeights[3] <= 0
|
|
545
|
+
let x = effectiveUserInterfaceLayoutDirection == .rightToLeft
|
|
546
|
+
? base : collectionView.bounds.width - base - width
|
|
547
|
+
slot.host.frame = CGRect(x: x,
|
|
548
|
+
y: paddingTop, width: width, height: containerSlotHeights[3])
|
|
549
|
+
}
|
|
550
|
+
if reactContainerSlots.count > 5 {
|
|
551
|
+
let disclosureEnabled = config?.disclosure != nil
|
|
552
|
+
let content = reactContainerSlots[4].host
|
|
553
|
+
let toggle = reactContainerSlots[5].host
|
|
554
|
+
let toggleHeight = disclosureEnabled ? containerSlotHeights[5] : 0
|
|
555
|
+
let contentY = footerPosition - disclosureInset - toggleHeight
|
|
556
|
+
- disclosureCVisibleHeight
|
|
557
|
+
content.frame = CGRect(x: 0, y: contentY, width: collectionView.bounds.width,
|
|
558
|
+
height: containerSlotHeights[4])
|
|
559
|
+
toggle.frame = CGRect(x: 0, y: contentY + disclosureCVisibleHeight,
|
|
560
|
+
width: collectionView.bounds.width, height: containerSlotHeights[5])
|
|
561
|
+
content.isHidden = !disclosureEnabled || disclosureCVisibleHeight <= 0
|
|
562
|
+
toggle.isHidden = !disclosureEnabled || toggleHeight <= 0
|
|
563
|
+
let contentSettled = structuralDisplayLink == nil && structuralTail == nil
|
|
564
|
+
&& config?.disclosure?.expanded == true
|
|
565
|
+
&& disclosureCVisibleHeight >= containerSlotHeights[4] - 0.5
|
|
566
|
+
content.isUserInteractionEnabled = contentSettled
|
|
567
|
+
content.accessibilityElementsHidden = !contentSettled
|
|
568
|
+
toggle.isUserInteractionEnabled = disclosureEnabled && toggleHeight > 0
|
|
569
|
+
toggle.accessibilityElementsHidden = !disclosureEnabled || toggleHeight <= 0
|
|
570
|
+
}
|
|
571
|
+
var stickyHeight: CGFloat = 0
|
|
572
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
573
|
+
stickyHeight += CGFloat(value.doubleValue)
|
|
574
|
+
}
|
|
575
|
+
CATransaction.begin()
|
|
576
|
+
CATransaction.setDisableActions(true)
|
|
577
|
+
for (index, slot) in reactContainerSlots.enumerated() {
|
|
578
|
+
let stickyTop = max(0, collectionView.contentOffset.y + stickyHeight - slot.host.frame.minY)
|
|
579
|
+
let tailTop = index == 2 && structuralTail != nil ? max(0, -structuralSpacerHeight) : 0
|
|
580
|
+
let top = max(stickyHeight > 0 ? stickyTop : 0, tailTop)
|
|
581
|
+
let bottom = index == 4 && config?.disclosure != nil
|
|
582
|
+
? min(slot.host.bounds.height, max(0, disclosureCVisibleHeight))
|
|
583
|
+
: slot.host.bounds.height
|
|
584
|
+
(slot.host as? NativeListClippedSlotHost)?.visibleTop = top
|
|
585
|
+
(slot.host as? NativeListClippedSlotHost)?.visibleBottom = index == 4 ? bottom : nil
|
|
586
|
+
guard top > 0 || bottom < slot.host.bounds.height else {
|
|
587
|
+
slot.host.layer.mask = nil
|
|
588
|
+
continue
|
|
589
|
+
}
|
|
590
|
+
let mask = slot.host.layer.mask ?? CALayer()
|
|
591
|
+
mask.backgroundColor = UIColor.black.cgColor
|
|
592
|
+
mask.frame = CGRect(x: 0, y: top, width: slot.host.bounds.width,
|
|
593
|
+
height: max(0, bottom - top))
|
|
594
|
+
slot.host.layer.mask = mask
|
|
595
|
+
}
|
|
596
|
+
CATransaction.commit()
|
|
171
597
|
}
|
|
172
598
|
|
|
173
599
|
private final class ActionAnchorRecord {
|
|
@@ -238,6 +664,7 @@ final class NativeListView: UIView {
|
|
|
238
664
|
var onSelectionDelta: ((String) -> Void)?
|
|
239
665
|
var onReorder: ((String) -> Void)?
|
|
240
666
|
var onEndReached: ((String) -> Void)?
|
|
667
|
+
var onStructuralTransitionSettled: ((String) -> Void)?
|
|
241
668
|
var onVisibleRangeChanged: ((String) -> Void)? {
|
|
242
669
|
didSet {
|
|
243
670
|
lastVisibleRange = nil
|
|
@@ -263,7 +690,16 @@ final class NativeListView: UIView {
|
|
|
263
690
|
private var sectionIndexHostHeightConstraint: NSLayoutConstraint?
|
|
264
691
|
private var footerHeightConstraint: NSLayoutConstraint!
|
|
265
692
|
private var dataSource: UICollectionViewDiffableDataSource<Int, String>!
|
|
693
|
+
private final class AcceptedRowIndex {
|
|
694
|
+
let byKey: [String: Int]
|
|
695
|
+
|
|
696
|
+
init(items: [NativeListItem]) {
|
|
697
|
+
byKey = Dictionary(uniqueKeysWithValues: items.enumerated().map { ($1.key, $0) })
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
266
701
|
private var config: NativeListConfig?
|
|
702
|
+
private var acceptedRowIndex: AcceptedRowIndex?
|
|
267
703
|
private var itemsByKey: [String: NativeListItem] = [:]
|
|
268
704
|
private var endReachedGeneration: Int?
|
|
269
705
|
private var lastVisibleRange: (first: Int, last: Int, firstKey: String?, lastKey: String?)?
|
|
@@ -273,9 +709,11 @@ final class NativeListView: UIView {
|
|
|
273
709
|
private var sectionIndexHapticsEnabled = true
|
|
274
710
|
private var lastLayoutDirection: UIUserInterfaceLayoutDirection?
|
|
275
711
|
private var lastLayoutSize: CGSize?
|
|
712
|
+
private var lastConfiguredCollectionWidth: CGFloat?
|
|
276
713
|
private var commandAcceptedForPendingScroll = false
|
|
277
714
|
private var performingExplicitScrollCommand = false
|
|
278
715
|
private var animatedExplicitScrollCommand = false
|
|
716
|
+
private var explicitScrollRevision = 0
|
|
279
717
|
private var pagerCommandCancelObserver: NSObjectProtocol?
|
|
280
718
|
private var pendingScrollRequest: ScrollRequest?
|
|
281
719
|
private let sectionIndexFeedback = UISelectionFeedbackGenerator()
|
|
@@ -452,7 +890,8 @@ final class NativeListView: UIView {
|
|
|
452
890
|
}
|
|
453
891
|
dataSource.reorderingHandlers.canReorderItem = { [weak self] key in
|
|
454
892
|
guard let self else { return false }
|
|
455
|
-
return self.config?.reorderable == true && self.
|
|
893
|
+
return self.config?.reorderable == true && !self.isInertPresentationKey(key)
|
|
894
|
+
&& self.itemsByKey[key]?.isReorderable == true
|
|
456
895
|
}
|
|
457
896
|
dataSource.reorderingHandlers.didReorder = { [weak self] transaction in
|
|
458
897
|
guard self?.interactiveReorderUsesAtomicTargeting != true else { return }
|
|
@@ -510,7 +949,7 @@ final class NativeListView: UIView {
|
|
|
510
949
|
let point = touch.location(in: collectionView)
|
|
511
950
|
guard collectionView.bounds.contains(point),
|
|
512
951
|
let indexPath = collectionView.indexPathForItem(at: point),
|
|
513
|
-
let item = item(at: indexPath) else { return false }
|
|
952
|
+
let item = item(at: indexPath), !isInertPresentationKey(item.key) else { return false }
|
|
514
953
|
return item.isRowPressEnabled
|
|
515
954
|
}
|
|
516
955
|
|
|
@@ -523,33 +962,56 @@ final class NativeListView: UIView {
|
|
|
523
962
|
}
|
|
524
963
|
|
|
525
964
|
override func willMove(toWindow newWindow: UIWindow?) {
|
|
526
|
-
if newWindow == nil {
|
|
965
|
+
if newWindow == nil {
|
|
966
|
+
attachSectionIndexToList()
|
|
967
|
+
if structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
968
|
+
}
|
|
527
969
|
super.willMove(toWindow: newWindow)
|
|
528
970
|
}
|
|
529
971
|
|
|
972
|
+
private func notifyPagerScrollViewReadyIfNeeded() {
|
|
973
|
+
guard !disposed,
|
|
974
|
+
window != nil,
|
|
975
|
+
collectionView.delegate === self,
|
|
976
|
+
collectionView.bounds.width > 0,
|
|
977
|
+
collectionView.bounds.height > 0 else { return }
|
|
978
|
+
NotificationCenter.default.post(
|
|
979
|
+
name: Notification.Name("OneKeyNativeScrollViewDidBecomeReady"),
|
|
980
|
+
object: collectionView
|
|
981
|
+
)
|
|
982
|
+
}
|
|
983
|
+
|
|
530
984
|
override func didMoveToWindow() {
|
|
531
985
|
super.didMoveToWindow()
|
|
532
986
|
updateTopScrollEdge()
|
|
533
987
|
updateSectionIndexAttachment()
|
|
988
|
+
notifyPagerScrollViewReadyIfNeeded()
|
|
534
989
|
}
|
|
535
990
|
|
|
536
991
|
override func layoutSubviews() {
|
|
992
|
+
let hadUsableBounds = (lastLayoutSize?.width ?? 0) > 0 && (lastLayoutSize?.height ?? 0) > 0
|
|
537
993
|
super.layoutSubviews()
|
|
538
994
|
topOverlayHost.frame = CGRect(x: 0, y: 0, width: collectionView.bounds.width,
|
|
539
995
|
height: requestedTopOverlayHeight)
|
|
540
996
|
updateSectionIndexAttachment()
|
|
541
997
|
let direction = effectiveUserInterfaceLayoutDirection
|
|
542
|
-
|
|
543
|
-
|
|
998
|
+
let sizeChanged = lastLayoutSize != nil && lastLayoutSize != bounds.size
|
|
999
|
+
if sizeChanged && structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
1000
|
+
if sizeChanged || lastLayoutDirection != nil && lastLayoutDirection != direction {
|
|
544
1001
|
invalidateActionAnchor(reason: "layout")
|
|
545
1002
|
}
|
|
546
1003
|
lastLayoutSize = bounds.size
|
|
547
|
-
|
|
1004
|
+
let collectionWidthChanged = collectionView.bounds.width > 0
|
|
1005
|
+
&& lastConfiguredCollectionWidth != collectionView.bounds.width
|
|
1006
|
+
if (lastLayoutDirection != direction || collectionWidthChanged), let config {
|
|
548
1007
|
configureLayout(config)
|
|
549
|
-
rebindRowsForLayoutDirection(config)
|
|
1008
|
+
if lastLayoutDirection != direction { rebindRowsForLayoutDirection(config) }
|
|
550
1009
|
}
|
|
551
1010
|
performPendingScrollIfNeeded()
|
|
552
1011
|
layoutContainerSlots()
|
|
1012
|
+
if !hadUsableBounds && collectionView.bounds.width > 0 && collectionView.bounds.height > 0 {
|
|
1013
|
+
notifyPagerScrollViewReadyIfNeeded()
|
|
1014
|
+
}
|
|
553
1015
|
}
|
|
554
1016
|
|
|
555
1017
|
// A layout-direction change may arrive without a layout pass (semantic attribute or trait).
|
|
@@ -579,10 +1041,163 @@ final class NativeListView: UIView {
|
|
|
579
1041
|
}
|
|
580
1042
|
}
|
|
581
1043
|
|
|
1044
|
+
private func acceptRowIndex(for next: NativeListConfig, replacing previous: NativeListConfig?) {
|
|
1045
|
+
if let previous, acceptedRowIndex != nil,
|
|
1046
|
+
previous.generation == next.generation,
|
|
1047
|
+
previous.items.count == next.items.count,
|
|
1048
|
+
zip(previous.items, next.items).allSatisfy({ old, new in
|
|
1049
|
+
old.key == new.key && old.type == new.type
|
|
1050
|
+
}) {
|
|
1051
|
+
return
|
|
1052
|
+
}
|
|
1053
|
+
acceptedRowIndex = AcceptedRowIndex(items: next.items)
|
|
1054
|
+
}
|
|
1055
|
+
|
|
582
1056
|
func applySnapshotJson(_ json: String) {
|
|
583
1057
|
guard let next = try? NativeListConfig.parse(json: json) else { return }
|
|
1058
|
+
let transition = next.structuralTransition
|
|
1059
|
+
let isNewTransition = transition != nil && transition?.id != consumedStructuralTransitionID
|
|
1060
|
+
let disclosureGeometryInvalid = deferredDisclosureGeometryInvalid
|
|
1061
|
+
deferredDisclosureGeometryInvalid = false
|
|
1062
|
+
let disclosureTargetChanged = config?.disclosure?.expanded != next.disclosure?.expanded
|
|
1063
|
+
let disclosureInsetChanged = config?.disclosure?.expandedTrailingInset
|
|
1064
|
+
!= next.disclosure?.expandedTrailingInset
|
|
1065
|
+
let disclosureStateChanged = disclosureTargetChanged || disclosureInsetChanged
|
|
1066
|
+
let activePendingID = structuralTail == nil ? nil : pendingDisclosureSettlement?.id
|
|
1067
|
+
let oldKeys = dataSource.snapshot().itemIdentifiers
|
|
1068
|
+
let logicalOldKeys = config?.items.map(\.key) ?? []
|
|
1069
|
+
let presentationItems = itemsByKey
|
|
1070
|
+
let newKeys = next.items.map(\.key)
|
|
1071
|
+
let newDisclosureCommand = config != nil && next.disclosure != nil && isNewTransition
|
|
1072
|
+
if let transition { consumedStructuralTransitionID = transition.id }
|
|
1073
|
+
if newDisclosureCommand, let transition, let disclosure = next.disclosure {
|
|
1074
|
+
pendingDisclosureSettlement = (transition.id, disclosure.expanded)
|
|
1075
|
+
} else if next.disclosure == nil || disclosureTargetChanged {
|
|
1076
|
+
// A target change without a new command cannot settle the previous target.
|
|
1077
|
+
pendingDisclosureSettlement = nil
|
|
1078
|
+
}
|
|
1079
|
+
let wantsStructure = config?.orientation == "vertical"
|
|
1080
|
+
&& (config?.layout == "linear" || config?.layout == "table")
|
|
1081
|
+
&& isNewTransition && logicalOldKeys != newKeys
|
|
1082
|
+
&& next.orientation == "vertical" && (next.layout == "linear" || next.layout == "table")
|
|
1083
|
+
&& !UIAccessibility.isReduceMotionEnabled
|
|
1084
|
+
&& (transition?.duration ?? 0) > 0
|
|
1085
|
+
let tailPrefix = wantsStructure ? config.flatMap { prefixTailCount(from: $0, to: next) } : nil
|
|
1086
|
+
// A carried tail extent belongs to its original prefix boundary.
|
|
1087
|
+
// Commit a new boundary atomically instead of starting a legacy row animation.
|
|
1088
|
+
let prefixChangedDuringTail = structuralTail != nil && tailPrefix != nil
|
|
1089
|
+
&& structuralTail?.prefixCount != tailPrefix
|
|
1090
|
+
let rawTailCandidate: StructuralTail? = tailPrefix.flatMap { prefix in
|
|
1091
|
+
guard let previous = config else { return nil }
|
|
1092
|
+
let items = previous.items.count > next.items.count
|
|
1093
|
+
? Array(previous.items.dropFirst(prefix)) : Array(next.items.dropFirst(prefix))
|
|
1094
|
+
let heights = items.map { rowHeight($0) }
|
|
1095
|
+
let tail = StructuralTail(items: items, heights: heights,
|
|
1096
|
+
spacing: next.itemSpacing, prefixCount: prefix,
|
|
1097
|
+
finalExtent: previous.items.count > next.items.count ? 0 :
|
|
1098
|
+
heights.reduce(0, +) + CGFloat(max(0, items.count - 1)) * next.itemSpacing
|
|
1099
|
+
+ (prefix == 0 ? 0 : next.itemSpacing))
|
|
1100
|
+
return tail
|
|
1101
|
+
}
|
|
1102
|
+
let tailOverCap = rawTailCandidate.map(tailExceedsHostLimit) ?? false
|
|
1103
|
+
let animateStructure = wantsStructure && !tailOverCap && !prefixChangedDuringTail
|
|
1104
|
+
&& !disclosureGeometryInvalid
|
|
1105
|
+
&& (next.disclosure == nil ||
|
|
1106
|
+
(rawTailCandidate != nil && reactContainerSlots.count > 5))
|
|
1107
|
+
let directDisclosureStatus: String? = newDisclosureCommand && !animateStructure
|
|
1108
|
+
? (disclosureGeometryInvalid || logicalOldKeys != newKeys && (transition?.duration ?? 0) > 0
|
|
1109
|
+
&& !UIAccessibility.isReduceMotionEnabled ? "interrupted" : "completed")
|
|
1110
|
+
: nil
|
|
1111
|
+
var interruptedPendingID: String?
|
|
1112
|
+
let tailCandidate = animateStructure ? rawTailCandidate : nil
|
|
1113
|
+
let presentationHeights: [String: CGFloat] = animateStructure ? Dictionary(uniqueKeysWithValues: oldKeys.compactMap { key -> (String, CGFloat)? in
|
|
1114
|
+
guard let item = presentationItems[key] else { return nil }
|
|
1115
|
+
let height = structuralRemovedHeights[key].map { $0 * (1 - structuralRemovalProgress) }
|
|
1116
|
+
?? rowHeight(item)
|
|
1117
|
+
return (key, height)
|
|
1118
|
+
}) : [:]
|
|
1119
|
+
let previousOffset = collectionView.contentOffset.y
|
|
1120
|
+
let oldLeftContentHeight = animateStructure ? flowLayout.bodyContentHeight : 0
|
|
1121
|
+
let oldSpacerHeight = structuralSpacerHeight
|
|
1122
|
+
let oldRowsHeight = animateStructure
|
|
1123
|
+
? presentationHeights.values.reduce(CGFloat(0), +)
|
|
1124
|
+
+ CGFloat(max(0, oldKeys.count - 1)) * (config?.itemSpacing ?? 0)
|
|
1125
|
+
: 0
|
|
1126
|
+
let newRowsHeight = animateStructure
|
|
1127
|
+
? next.items.reduce(CGFloat(0)) { $0 + rowHeight($1) }
|
|
1128
|
+
+ CGFloat(max(0, newKeys.count - 1)) * next.itemSpacing
|
|
1129
|
+
: 0
|
|
1130
|
+
let survivingKeys = animateStructure ? Set(newKeys) : Set<String>()
|
|
1131
|
+
let visibleAnchor = animateStructure
|
|
1132
|
+
? collectionView.indexPathsForVisibleItems.sorted().first {
|
|
1133
|
+
oldKeys.indices.contains($0.item) && survivingKeys.contains(oldKeys[$0.item])
|
|
1134
|
+
}
|
|
1135
|
+
: nil
|
|
1136
|
+
let anchorKey = visibleAnchor.map { oldKeys[$0.item] }
|
|
1137
|
+
let oldPrefix = (animateStructure ? anchorKey : nil).flatMap { key -> CGFloat? in
|
|
1138
|
+
guard let index = oldKeys.firstIndex(of: key) else { return nil }
|
|
1139
|
+
return oldKeys.prefix(index).reduce(CGFloat(0)) { $0 + (presentationHeights[$1] ?? 0) }
|
|
1140
|
+
+ CGFloat(index) * (config?.itemSpacing ?? 0)
|
|
1141
|
+
} ?? 0
|
|
1142
|
+
let newPrefix = (animateStructure ? anchorKey : nil).flatMap { key -> CGFloat? in
|
|
1143
|
+
guard let index = newKeys.firstIndex(of: key) else { return nil }
|
|
1144
|
+
return next.items.prefix(index).reduce(CGFloat(0)) { $0 + rowHeight($1) }
|
|
1145
|
+
+ CGFloat(index) * next.itemSpacing
|
|
1146
|
+
} ?? 0
|
|
1147
|
+
if animateStructure {
|
|
1148
|
+
let carriedExtent = structuralTail == nil ? nil : structuralSpacerHeight
|
|
1149
|
+
stopStructuralAnimation()
|
|
1150
|
+
clearStructuralTail()
|
|
1151
|
+
structuralScrollInterrupted = false
|
|
1152
|
+
structuralFooterStartY = reactContainerSlots.count > 2
|
|
1153
|
+
? reactContainerSlots[2].host.frame.minY : nil
|
|
1154
|
+
structuralFooterProgress = 0
|
|
1155
|
+
let removedKeys = Set(oldKeys).subtracting(newKeys)
|
|
1156
|
+
let retainsOrder = oldKeys.filter { survivingKeys.contains($0) } == newKeys
|
|
1157
|
+
structuralRemovedItems = tailCandidate == nil && retainsOrder
|
|
1158
|
+
? presentationItems.filter { removedKeys.contains($0.key) } : [:]
|
|
1159
|
+
structuralRemovedHeights = tailCandidate == nil && retainsOrder
|
|
1160
|
+
? presentationHeights.filter { removedKeys.contains($0.key) } : [:]
|
|
1161
|
+
structuralRemovalProgress = 0
|
|
1162
|
+
if let tail = tailCandidate {
|
|
1163
|
+
structuralTail = tail
|
|
1164
|
+
structuralTailStartExtent = carriedExtent ?? (tail.finalExtent == 0 ? tail.extent : 0)
|
|
1165
|
+
structuralTailSegmentStartEased = 0
|
|
1166
|
+
structuralSpacerHeight = structuralTailStartExtent
|
|
1167
|
+
let prefixHeights = next.items.prefix(tail.prefixCount).reduce(CGFloat(0)) {
|
|
1168
|
+
$0 + rowHeight($1)
|
|
1169
|
+
}
|
|
1170
|
+
structuralTailStartY = next.contentPaddingTop + containerSlotHeights[0]
|
|
1171
|
+
+ prefixHeights + CGFloat(max(0, tail.prefixCount - 1)) * next.itemSpacing
|
|
1172
|
+
disclosureStartCHeight = disclosureCVisibleHeight
|
|
1173
|
+
disclosureStartInset = disclosureInset
|
|
1174
|
+
disclosureSegmentStartEased = 0
|
|
1175
|
+
} else {
|
|
1176
|
+
structuralSpacerHeight = structuralRemovedItems.isEmpty
|
|
1177
|
+
? max(0, structuralSpacerHeight + oldRowsHeight - newRowsHeight) : 0
|
|
1178
|
+
}
|
|
1179
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1180
|
+
object: collectionView, userInfo: ["phase": 0])
|
|
1181
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1182
|
+
object: collectionView, userInfo: ["phase": 1])
|
|
1183
|
+
structuralScrollPhaseActive = true
|
|
1184
|
+
needsContentShrinkCorrection = false
|
|
1185
|
+
} else if logicalOldKeys != newKeys
|
|
1186
|
+
|| (newDisclosureCommand || disclosureGeometryInvalid || disclosureStateChanged)
|
|
1187
|
+
&& structuralTail != nil {
|
|
1188
|
+
if !newDisclosureCommand && !disclosureTargetChanged { interruptedPendingID = activePendingID }
|
|
1189
|
+
stopStructuralAnimation()
|
|
1190
|
+
clearStructuralTail()
|
|
1191
|
+
structuralSpacerHeight = 0
|
|
1192
|
+
structuralFooterStartY = nil
|
|
1193
|
+
structuralRemovedItems.removeAll()
|
|
1194
|
+
structuralRemovedHeights.removeAll()
|
|
1195
|
+
}
|
|
584
1196
|
invalidateActionAnchor(reason: "snapshot")
|
|
585
|
-
if let current = config,
|
|
1197
|
+
if let current = config, !newDisclosureCommand,
|
|
1198
|
+
structuralRemovedItems.isEmpty, structuralTail == nil,
|
|
1199
|
+
isControlledSelectionSnapshotUpdate(from: current, to: next) {
|
|
1200
|
+
acceptRowIndex(for: next, replacing: current)
|
|
586
1201
|
config = next
|
|
587
1202
|
itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
|
|
588
1203
|
// OneKey patch: A controlled selection echo is fully handled by the
|
|
@@ -591,7 +1206,7 @@ final class NativeListView: UIView {
|
|
|
591
1206
|
return
|
|
592
1207
|
}
|
|
593
1208
|
if let current = config, interactiveReorderSource != nil {
|
|
594
|
-
if canDeferSnapshotDuringInteractiveReorder(from: current, to: next) {
|
|
1209
|
+
if !newDisclosureCommand && canDeferSnapshotDuringInteractiveReorder(from: current, to: next) {
|
|
595
1210
|
deferSnapshotDuringInteractiveReorder(from: current, to: next)
|
|
596
1211
|
return
|
|
597
1212
|
}
|
|
@@ -602,17 +1217,111 @@ final class NativeListView: UIView {
|
|
|
602
1217
|
// rows whose own content is unchanged.
|
|
603
1218
|
let themeChanged = !dictionariesEqual(config?.theme, next.theme)
|
|
604
1219
|
|| !dictionariesEqual(config?.listStyle, next.listStyle)
|
|
1220
|
+
|| config?.layout != next.layout
|
|
1221
|
+
let tailGeometryChanged = config.map { current in
|
|
1222
|
+
current.disclosure?.expanded != next.disclosure?.expanded
|
|
1223
|
+
|| current.disclosure?.expandedTrailingInset != next.disclosure?.expandedTrailingInset
|
|
1224
|
+
|| current.orientation != next.orientation
|
|
1225
|
+
|| current.stickyHeaders != next.stickyHeaders
|
|
1226
|
+
|| current.sectionIndexEnabled != next.sectionIndexEnabled
|
|
1227
|
+
|| current.contentPadding != next.contentPadding
|
|
1228
|
+
|| current.itemSpacing != next.itemSpacing
|
|
1229
|
+
|| current.contentPaddingTop != next.contentPaddingTop
|
|
1230
|
+
|| current.contentPaddingBottom != next.contentPaddingBottom
|
|
1231
|
+
|| current.contentPaddingHorizontal != next.contentPaddingHorizontal
|
|
1232
|
+
|| current.items.count != next.items.count
|
|
1233
|
+
|| zip(current.items, next.items).contains { old, new in
|
|
1234
|
+
old.key != new.key || old.rendererKey != new.rendererKey
|
|
1235
|
+
|| rowHeight(old) != rowHeight(new)
|
|
1236
|
+
}
|
|
1237
|
+
} ?? false
|
|
605
1238
|
if config?.generation != next.generation { endReachedGeneration = nil }
|
|
1239
|
+
acceptRowIndex(for: next, replacing: config)
|
|
606
1240
|
config = next
|
|
1241
|
+
if structuralTail == nil {
|
|
1242
|
+
disclosureCVisibleHeight = next.disclosure?.expanded == true ? containerSlotHeights[4] : 0
|
|
1243
|
+
disclosureInset = next.disclosure?.expanded == true
|
|
1244
|
+
? next.disclosure?.expandedTrailingInset ?? 0 : 0
|
|
1245
|
+
}
|
|
607
1246
|
itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
|
|
1247
|
+
itemsByKey.merge(structuralRemovedItems) { current, _ in current }
|
|
1248
|
+
if let tail = structuralTail, !tail.retiringKeys.isEmpty {
|
|
1249
|
+
itemsByKey.merge(presentationItems.filter { tail.retiringKeys.contains($0.key) }) {
|
|
1250
|
+
current, _ in current
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
if !animateStructure, let tail = structuralTail {
|
|
1254
|
+
if themeChanged || tailGeometryChanged {
|
|
1255
|
+
if !newDisclosureCommand { interruptedPendingID = activePendingID }
|
|
1256
|
+
stopStructuralAnimation()
|
|
1257
|
+
clearStructuralTail()
|
|
1258
|
+
structuralSpacerHeight = 0
|
|
1259
|
+
structuralFooterStartY = nil
|
|
1260
|
+
disclosureCVisibleHeight = next.disclosure?.expanded == true ? containerSlotHeights[4] : 0
|
|
1261
|
+
disclosureInset = next.disclosure?.expanded == true
|
|
1262
|
+
? next.disclosure?.expandedTrailingInset ?? 0 : 0
|
|
1263
|
+
} else {
|
|
1264
|
+
for (index, previous) in tail.items.enumerated() {
|
|
1265
|
+
guard let item = itemsByKey[previous.key], item.content != previous.content else { continue }
|
|
1266
|
+
tail.items[index] = item
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
608
1270
|
configureSectionIndex(next)
|
|
609
1271
|
configureLayout(next)
|
|
610
1272
|
configureRefresh(next)
|
|
611
1273
|
configureFooter(next)
|
|
1274
|
+
if structuralTail != nil { updateStructuralTailWindow() }
|
|
1275
|
+
|
|
1276
|
+
if animateStructure, let transition {
|
|
1277
|
+
let inset = collectionView.adjustedContentInset
|
|
1278
|
+
let finalLeftHeight = structuralTail.map { tail in
|
|
1279
|
+
structuralTailStartY + tail.finalExtent + next.contentPaddingBottom + containerSlotHeights[2]
|
|
1280
|
+
+ (next.disclosure == nil ? 0 :
|
|
1281
|
+
(next.disclosure?.expanded == true ? containerSlotHeights[4] : 0)
|
|
1282
|
+
+ containerSlotHeights[5]
|
|
1283
|
+
+ (next.disclosure?.expanded == true
|
|
1284
|
+
? next.disclosure?.expandedTrailingInset ?? 0 : 0))
|
|
1285
|
+
} ?? max(0, oldLeftContentHeight + newRowsHeight - oldRowsHeight - oldSpacerHeight)
|
|
1286
|
+
let sidecarHeight = sidecarLayout == nil ? 0 :
|
|
1287
|
+
next.contentPaddingTop + containerSlotHeights[3] + next.contentPaddingBottom
|
|
1288
|
+
let finalHeight = max(finalLeftHeight, sidecarHeight)
|
|
1289
|
+
let finalMaximum = max(-inset.top, finalHeight - collectionView.bounds.height + inset.bottom)
|
|
1290
|
+
structuralStartSpacer = structuralSpacerHeight
|
|
1291
|
+
structuralStartOffset = previousOffset
|
|
1292
|
+
var targetOffset = structuralTail == nil
|
|
1293
|
+
? min(max(-inset.top, previousOffset + newPrefix - oldPrefix), finalMaximum)
|
|
1294
|
+
: min(max(-inset.top, previousOffset), finalMaximum)
|
|
1295
|
+
if let tail = structuralTail, tail.finalExtent == 0,
|
|
1296
|
+
(next.disclosure != nil ? containerSlotHeights[5] : containerSlotHeights[2]) > 0 {
|
|
1297
|
+
let targetTop = structuralTailStartY
|
|
1298
|
+
let targetBottom = targetTop + (next.disclosure != nil
|
|
1299
|
+
? containerSlotHeights[5] : containerSlotHeights[2])
|
|
1300
|
+
var sticky: CGFloat = 0
|
|
1301
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
1302
|
+
sticky += CGFloat(value.doubleValue)
|
|
1303
|
+
}
|
|
1304
|
+
let lower = targetBottom - collectionView.bounds.height + inset.bottom
|
|
1305
|
+
let upper = targetTop - inset.top - sticky
|
|
1306
|
+
targetOffset = lower <= upper
|
|
1307
|
+
? min(max(targetOffset, lower), upper) : upper
|
|
1308
|
+
targetOffset = min(max(-inset.top, targetOffset), finalMaximum)
|
|
1309
|
+
} else if structuralTail == nil, visibleAnchor == nil, let fallbackKey = transition.anchorKey,
|
|
1310
|
+
let fallbackIndex = newKeys.firstIndex(of: fallbackKey) {
|
|
1311
|
+
let fallbackY = next.contentPaddingTop + containerSlotHeights[0]
|
|
1312
|
+
+ next.items.prefix(fallbackIndex).reduce(CGFloat(0)) { $0 + rowHeight($1) }
|
|
1313
|
+
+ CGFloat(fallbackIndex) * next.itemSpacing
|
|
1314
|
+
targetOffset = min(targetOffset, max(-inset.top, fallbackY - inset.top))
|
|
1315
|
+
}
|
|
1316
|
+
structuralTargetOffset = targetOffset
|
|
1317
|
+
if structuralTail != nil { updateStructuralTailTarget() }
|
|
1318
|
+
structuralAnimationDuration = transition.duration
|
|
1319
|
+
}
|
|
612
1320
|
|
|
613
1321
|
var snapshot = NSDiffableDataSourceSnapshot<Int, String>()
|
|
614
1322
|
snapshot.appendSections([0])
|
|
615
|
-
let keys =
|
|
1323
|
+
let keys = structuralTail.map { $0.retiringKeys.isEmpty ? newKeys : oldKeys }
|
|
1324
|
+
?? (structuralRemovedItems.isEmpty ? newKeys : oldKeys)
|
|
616
1325
|
snapshot.appendItems(keys, toSection: 0)
|
|
617
1326
|
var changedKeys = Set(keys.filter { key in
|
|
618
1327
|
guard let old = oldItems[key], let new = itemsByKey[key] else { return false }
|
|
@@ -627,26 +1336,219 @@ final class NativeListView: UIView {
|
|
|
627
1336
|
let replacedKeys = changedRetainedKeys.filter { oldItems[$0]?.rendererKey != itemsByKey[$0]?.rendererKey }
|
|
628
1337
|
snapshot.reloadItems(Array(replacedKeys))
|
|
629
1338
|
snapshot.reconfigureItems(Array(changedRetainedKeys.subtracting(replacedKeys)))
|
|
630
|
-
|
|
1339
|
+
let scrollRevisionAtApply = explicitScrollRevision
|
|
1340
|
+
let explicitScrollPendingAtApply = pendingScrollRequest != nil
|
|
1341
|
+
dataSource.apply(snapshot, animatingDifferences: animateStructure && structuralRemovedItems.isEmpty
|
|
1342
|
+
&& structuralTail == nil) { [weak self] in
|
|
631
1343
|
guard let self else { return }
|
|
632
1344
|
self.collectionView.layoutIfNeeded()
|
|
1345
|
+
self.updateStructuralTailWindow()
|
|
1346
|
+
self.layoutContainerSlots()
|
|
1347
|
+
self.notifyPagerScrollViewReadyIfNeeded()
|
|
633
1348
|
self.performPendingScrollIfNeeded()
|
|
1349
|
+
if directDisclosureStatus == "completed", let transition {
|
|
1350
|
+
self.revealDirectCollapsedToggle(expectedID: transition.id,
|
|
1351
|
+
scrollRevision: scrollRevisionAtApply,
|
|
1352
|
+
explicitScrollPendingAtApply: explicitScrollPendingAtApply)
|
|
1353
|
+
}
|
|
634
1354
|
self.emitVisibleRangeIfNeeded()
|
|
635
1355
|
self.checkEndReached()
|
|
636
1356
|
self.syncSectionIndexToVisibleRows()
|
|
1357
|
+
if let directDisclosureStatus, let transition {
|
|
1358
|
+
self.settleDisclosure(directDisclosureStatus, expectedID: transition.id)
|
|
1359
|
+
} else if let interruptedPendingID {
|
|
1360
|
+
self.settleDisclosure("interrupted", expectedID: interruptedPendingID)
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
if animateStructure && (structuralTail != nil || tailCandidate == nil) {
|
|
1364
|
+
updateStructuralTailWindow()
|
|
1365
|
+
if tailCandidate != nil && structuralTail == nil { return }
|
|
1366
|
+
structuralAnimationStart = CACurrentMediaTime()
|
|
1367
|
+
let displayLink = CADisplayLink(target: self, selector: #selector(advanceStructuralAnimation(_:)))
|
|
1368
|
+
structuralDisplayLink = displayLink
|
|
1369
|
+
displayLink.add(to: .main, forMode: .common)
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
private func stopStructuralAnimation() {
|
|
1374
|
+
if structuralScrollPhaseActive {
|
|
1375
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1376
|
+
object: collectionView, userInfo: ["phase": 2])
|
|
1377
|
+
structuralScrollPhaseActive = false
|
|
1378
|
+
}
|
|
1379
|
+
structuralDisplayLink?.invalidate()
|
|
1380
|
+
structuralDisplayLink = nil
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
private func revealDirectCollapsedToggle(expectedID: String, scrollRevision: Int,
|
|
1384
|
+
explicitScrollPendingAtApply: Bool) {
|
|
1385
|
+
guard !disposed, let pending = pendingDisclosureSettlement,
|
|
1386
|
+
pending.id == expectedID, !pending.expanded,
|
|
1387
|
+
consumedStructuralTransitionID == expectedID,
|
|
1388
|
+
config?.disclosure?.expanded == false,
|
|
1389
|
+
structuralTail == nil, structuralDisplayLink == nil,
|
|
1390
|
+
!structuralScrollPhaseActive, scrollRevision == explicitScrollRevision,
|
|
1391
|
+
!explicitScrollPendingAtApply,
|
|
1392
|
+
pendingScrollRequest == nil, !animatedExplicitScrollCommand,
|
|
1393
|
+
!collectionView.isTracking, !collectionView.isDragging,
|
|
1394
|
+
!collectionView.isDecelerating,
|
|
1395
|
+
collectionView.bounds.height > 0, reactContainerSlots.count > 5 else { return }
|
|
1396
|
+
let toggle = reactContainerSlots[5].host
|
|
1397
|
+
guard !toggle.isHidden, toggle.bounds.height > 0 else { return }
|
|
1398
|
+
let inset = collectionView.adjustedContentInset
|
|
1399
|
+
let maximum = max(-inset.top,
|
|
1400
|
+
collectionView.contentSize.height - collectionView.bounds.height + inset.bottom)
|
|
1401
|
+
var sticky: CGFloat = 0
|
|
1402
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
1403
|
+
sticky += CGFloat(value.doubleValue)
|
|
1404
|
+
}
|
|
1405
|
+
let lower = toggle.frame.maxY - collectionView.bounds.height + inset.bottom
|
|
1406
|
+
let upper = toggle.frame.minY - inset.top - sticky
|
|
1407
|
+
let current = collectionView.contentOffset.y
|
|
1408
|
+
let visibleTarget = lower <= upper ? min(max(current, lower), upper) : upper
|
|
1409
|
+
let target = min(max(-inset.top, visibleTarget), maximum)
|
|
1410
|
+
guard abs(target - current) > 0.5 else { return }
|
|
1411
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1412
|
+
object: collectionView, userInfo: ["phase": 0])
|
|
1413
|
+
defer {
|
|
1414
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1415
|
+
object: collectionView, userInfo: ["phase": 2])
|
|
1416
|
+
}
|
|
1417
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1418
|
+
object: collectionView, userInfo: ["phase": 1])
|
|
1419
|
+
collectionView.setContentOffset(CGPoint(x: collectionView.contentOffset.x, y: target), animated: false)
|
|
1420
|
+
layoutContainerSlots()
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
private func settleDisclosure(_ status: String, expectedID: String? = nil) {
|
|
1424
|
+
guard let pending = pendingDisclosureSettlement,
|
|
1425
|
+
expectedID == nil || pending.id == expectedID,
|
|
1426
|
+
consumedStructuralTransitionID == pending.id,
|
|
1427
|
+
config?.disclosure?.expanded == pending.expanded else { return }
|
|
1428
|
+
pendingDisclosureSettlement = nil
|
|
1429
|
+
guard let callback = onStructuralTransitionSettled else { return }
|
|
1430
|
+
emit(callback, [
|
|
1431
|
+
"transitionId": pending.id,
|
|
1432
|
+
"status": status,
|
|
1433
|
+
"settledExpanded": pending.expanded,
|
|
1434
|
+
])
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
@objc private func advanceStructuralAnimation(_ link: CADisplayLink) {
|
|
1438
|
+
guard let config else { stopStructuralAnimation(); return }
|
|
1439
|
+
if structuralTail != nil && UIAccessibility.isReduceMotionEnabled {
|
|
1440
|
+
finishStructuralTail(interrupted: false)
|
|
1441
|
+
return
|
|
1442
|
+
}
|
|
1443
|
+
let elapsed = CACurrentMediaTime() - structuralAnimationStart
|
|
1444
|
+
let progress = min(1, max(0, elapsed / max(0.001, structuralAnimationDuration)))
|
|
1445
|
+
let eased = progress * progress * (3 - 2 * progress)
|
|
1446
|
+
if let tail = structuralTail {
|
|
1447
|
+
// Commit cell clipping, viewport movement, and slots together for this tick.
|
|
1448
|
+
CATransaction.begin()
|
|
1449
|
+
CATransaction.setDisableActions(true)
|
|
1450
|
+
defer { CATransaction.commit() }
|
|
1451
|
+
let segment = structuralTailSegmentProgress(eased)
|
|
1452
|
+
structuralSpacerHeight = structuralTailStartExtent
|
|
1453
|
+
+ (tail.finalExtent - structuralTailStartExtent) * segment
|
|
1454
|
+
if let disclosure = config.disclosure {
|
|
1455
|
+
let targetC = disclosure.expanded ? containerSlotHeights[4] : 0
|
|
1456
|
+
let targetInset = disclosure.expanded ? disclosure.expandedTrailingInset : 0
|
|
1457
|
+
let contentSegment = disclosureSegmentProgress(eased)
|
|
1458
|
+
disclosureCVisibleHeight = disclosureStartCHeight
|
|
1459
|
+
+ (targetC - disclosureStartCHeight) * contentSegment
|
|
1460
|
+
disclosureInset = disclosureStartInset
|
|
1461
|
+
+ (targetInset - disclosureStartInset) * segment
|
|
1462
|
+
}
|
|
1463
|
+
structuralFooterProgress = CGFloat(eased)
|
|
1464
|
+
updateStructuralTailWindow()
|
|
1465
|
+
flowLayout.invalidateLayout()
|
|
1466
|
+
collectionView.layoutIfNeeded()
|
|
1467
|
+
if !structuralScrollInterrupted && !collectionView.isTracking
|
|
1468
|
+
&& !collectionView.isDragging && !collectionView.isDecelerating {
|
|
1469
|
+
collectionView.contentOffset.y = structuralStartOffset
|
|
1470
|
+
+ (structuralTargetOffset - structuralStartOffset) * segment
|
|
1471
|
+
collectionView.layoutIfNeeded()
|
|
1472
|
+
}
|
|
1473
|
+
updateStructuralTailWindow()
|
|
1474
|
+
layoutContainerSlots()
|
|
1475
|
+
if progress >= 1 { finishStructuralTail(interrupted: structuralScrollInterrupted) }
|
|
1476
|
+
return
|
|
1477
|
+
}
|
|
1478
|
+
structuralSpacerHeight = structuralStartSpacer * (1 - eased)
|
|
1479
|
+
structuralFooterProgress = CGFloat(eased)
|
|
1480
|
+
structuralRemovalProgress = CGFloat(eased)
|
|
1481
|
+
for case let cell as NativeListRowHost in collectionView.visibleCells {
|
|
1482
|
+
guard let indexPath = collectionView.indexPath(for: cell),
|
|
1483
|
+
let key = dataSource.itemIdentifier(for: indexPath) else { continue }
|
|
1484
|
+
cell.structuralContentHeight = structuralRemovedItems[key].map {
|
|
1485
|
+
rowHeight($0, allocatedWidth: cell.bounds.width)
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
var inset = flowLayout.sectionInset
|
|
1489
|
+
inset.bottom = config.contentPaddingBottom + containerSlotHeights[2] + structuralSpacerHeight
|
|
1490
|
+
flowLayout.sectionInset = inset
|
|
1491
|
+
flowLayout.invalidateLayout()
|
|
1492
|
+
collectionView.layoutIfNeeded()
|
|
1493
|
+
if !structuralScrollInterrupted && !collectionView.isTracking
|
|
1494
|
+
&& !collectionView.isDragging && !collectionView.isDecelerating {
|
|
1495
|
+
collectionView.contentOffset.y = structuralStartOffset
|
|
1496
|
+
+ (structuralTargetOffset - structuralStartOffset) * eased
|
|
1497
|
+
// Materialize the new viewport before updating presentation cells.
|
|
1498
|
+
collectionView.layoutIfNeeded()
|
|
1499
|
+
}
|
|
1500
|
+
for cell in collectionView.visibleCells {
|
|
1501
|
+
guard let indexPath = collectionView.indexPath(for: cell),
|
|
1502
|
+
let key = dataSource.itemIdentifier(for: indexPath) else { continue }
|
|
1503
|
+
let retiring = structuralRemovedItems[key] != nil
|
|
1504
|
+
if retiring { cell.clipsToBounds = true }
|
|
1505
|
+
cell.alpha = retiring ? 1 - structuralRemovalProgress : 1
|
|
1506
|
+
cell.isUserInteractionEnabled = !retiring && !(itemsByKey[key]?.data.bool("disabled") ?? false)
|
|
1507
|
+
}
|
|
1508
|
+
layoutContainerSlots()
|
|
1509
|
+
if progress >= 1 {
|
|
1510
|
+
if !structuralRemovedItems.isEmpty {
|
|
1511
|
+
var snapshot = dataSource.snapshot()
|
|
1512
|
+
snapshot.deleteItems(Array(structuralRemovedItems.keys))
|
|
1513
|
+
structuralRemovedItems.removeAll()
|
|
1514
|
+
structuralRemovedHeights.removeAll()
|
|
1515
|
+
dataSource.apply(snapshot, animatingDifferences: false)
|
|
1516
|
+
itemsByKey = Dictionary(uniqueKeysWithValues: config.items.map { ($0.key, $0) })
|
|
1517
|
+
collectionView.layoutIfNeeded()
|
|
1518
|
+
if !structuralScrollInterrupted && !collectionView.isTracking
|
|
1519
|
+
&& !collectionView.isDragging && !collectionView.isDecelerating {
|
|
1520
|
+
let inset = collectionView.adjustedContentInset
|
|
1521
|
+
let maximum = max(-inset.top,
|
|
1522
|
+
collectionView.contentSize.height - collectionView.bounds.height + inset.bottom)
|
|
1523
|
+
let target = min(max(-inset.top, structuralTargetOffset), maximum)
|
|
1524
|
+
// Cancel UIKit's residual content-shrink scroll animation after deleting retired rows.
|
|
1525
|
+
collectionView.setContentOffset(
|
|
1526
|
+
CGPoint(x: collectionView.contentOffset.x, y: target), animated: false)
|
|
1527
|
+
collectionView.layoutIfNeeded()
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
stopStructuralAnimation()
|
|
1531
|
+
structuralSpacerHeight = 0
|
|
1532
|
+
structuralFooterStartY = nil
|
|
1533
|
+
layoutContainerSlots()
|
|
1534
|
+
emitVisibleRangeIfNeeded()
|
|
1535
|
+
checkEndReached()
|
|
1536
|
+
scheduleContentShrinkCorrection()
|
|
637
1537
|
}
|
|
638
1538
|
}
|
|
639
1539
|
|
|
640
1540
|
func applyPatchesJson(_ json: String) {
|
|
641
1541
|
guard var current = config,
|
|
1542
|
+
let indexByKey = acceptedRowIndex?.byKey,
|
|
642
1543
|
let bytes = json.data(using: .utf8),
|
|
643
1544
|
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
1545
|
var seen = Set<String>()
|
|
646
1546
|
var pending: [(Int, [String: Any])] = []
|
|
647
1547
|
for patch in patches {
|
|
648
1548
|
let key = patch.string("key")
|
|
649
1549
|
guard let index = indexByKey[key],
|
|
1550
|
+
current.items.indices.contains(index),
|
|
1551
|
+
current.items[index].key == key,
|
|
650
1552
|
seen.insert(key).inserted,
|
|
651
1553
|
patch.string("type") == current.items[index].type,
|
|
652
1554
|
let changes = patch.dictionary("changes") else { return }
|
|
@@ -658,13 +1560,16 @@ final class NativeListView: UIView {
|
|
|
658
1560
|
var sizeChanged = false
|
|
659
1561
|
var reorderStructureChanged = false
|
|
660
1562
|
let marketQuoteFields: Set<String> = [
|
|
661
|
-
"revision", "price", "priceSegments", "change", "accessibilityLabel",
|
|
1563
|
+
"revision", "price", "priceSegments", "change", "accessibilityLabel", "metrics",
|
|
662
1564
|
]
|
|
663
1565
|
for (index, changes) in pending {
|
|
664
1566
|
let previous = current.items[index]
|
|
665
1567
|
var merged = current.items[index].data
|
|
666
1568
|
changes.forEach { key, value in
|
|
667
|
-
if key != "key" && key != "type" {
|
|
1569
|
+
if key != "key" && key != "type" {
|
|
1570
|
+
if value is NSNull { merged.removeValue(forKey: key) }
|
|
1571
|
+
else { merged[key] = value }
|
|
1572
|
+
}
|
|
668
1573
|
}
|
|
669
1574
|
guard let item = try? NativeListItem(data: merged) else { return }
|
|
670
1575
|
if rowHeight(previous, usingCompactReorderHeight: false) != rowHeight(item, usingCompactReorderHeight: false) ||
|
|
@@ -681,13 +1586,28 @@ final class NativeListView: UIView {
|
|
|
681
1586
|
reorderStructureChanged = true
|
|
682
1587
|
}
|
|
683
1588
|
current.items[index] = item
|
|
684
|
-
|
|
1589
|
+
let previousMetrics = previous.data.dictionaries("metrics")
|
|
1590
|
+
let nextMetrics = item.data.dictionaries("metrics")
|
|
1591
|
+
let sameMetricStructure = previousMetrics.count == nextMetrics.count &&
|
|
1592
|
+
previousMetrics.indices.allSatisfy { metricIndex in
|
|
1593
|
+
let before = previousMetrics[metricIndex]
|
|
1594
|
+
let after = nextMetrics[metricIndex]
|
|
1595
|
+
return before.string("key") == after.string("key") &&
|
|
1596
|
+
before.int("weight", default: 1) == after.int("weight", default: 1) &&
|
|
1597
|
+
before.string("alignment", default: "end") ==
|
|
1598
|
+
after.string("alignment", default: "end")
|
|
1599
|
+
}
|
|
1600
|
+
if previous.type == "market", Set(changes.keys).isSubset(of: marketQuoteFields),
|
|
1601
|
+
sameMetricStructure
|
|
1602
|
+
{
|
|
685
1603
|
marketQuoteKeys.insert(item.key)
|
|
686
1604
|
} else {
|
|
687
1605
|
changedKeys.insert(item.key)
|
|
688
1606
|
}
|
|
689
1607
|
if let selected = changes["selected"] as? Bool {
|
|
690
1608
|
if selected { current.selectedKeys.insert(item.key) } else { current.selectedKeys.remove(item.key) }
|
|
1609
|
+
} else if changes["selected"] is NSNull {
|
|
1610
|
+
current.selectedKeys.remove(item.key)
|
|
691
1611
|
}
|
|
692
1612
|
}
|
|
693
1613
|
if !changedKeys.isEmpty { invalidateActionAnchor(reason: "snapshot") }
|
|
@@ -695,7 +1615,17 @@ final class NativeListView: UIView {
|
|
|
695
1615
|
cancelInteractiveReorderForStructuralUpdate()
|
|
696
1616
|
}
|
|
697
1617
|
config = current
|
|
698
|
-
|
|
1618
|
+
for (index, _) in pending {
|
|
1619
|
+
let item = current.items[index]
|
|
1620
|
+
itemsByKey[item.key] = item
|
|
1621
|
+
}
|
|
1622
|
+
if let tail = structuralTail {
|
|
1623
|
+
for key in changedKeys.union(marketQuoteKeys) {
|
|
1624
|
+
guard let index = tail.indexByKey[key], let item = itemsByKey[key] else { continue }
|
|
1625
|
+
tail.items[index] = item
|
|
1626
|
+
}
|
|
1627
|
+
if sizeChanged { finishStructuralTail(interrupted: true) }
|
|
1628
|
+
}
|
|
699
1629
|
for indexPath in collectionView.indexPathsForVisibleItems {
|
|
700
1630
|
guard let item = item(at: indexPath),
|
|
701
1631
|
marketQuoteKeys.contains(item.key),
|
|
@@ -759,6 +1689,7 @@ final class NativeListView: UIView {
|
|
|
759
1689
|
requestScroll(.index(index, animated, alignment, viewPosition, viewOffset))
|
|
760
1690
|
}
|
|
761
1691
|
|
|
1692
|
+
@objc(onekeyScrollToOffset:animated:)
|
|
762
1693
|
func scrollToOffset(_ offset: Double, animated: Bool) {
|
|
763
1694
|
requestScroll(.offset(offset, animated))
|
|
764
1695
|
}
|
|
@@ -796,6 +1727,8 @@ final class NativeListView: UIView {
|
|
|
796
1727
|
|
|
797
1728
|
private func requestScroll(_ request: ScrollRequest) {
|
|
798
1729
|
if config != nil && explicitTopForScrollCommand(request) == nil { return }
|
|
1730
|
+
explicitScrollRevision &+= 1
|
|
1731
|
+
if structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
799
1732
|
animatedExplicitScrollCommand = false
|
|
800
1733
|
commandAcceptedForPendingScroll = false
|
|
801
1734
|
acceptScrollCommand(request)
|
|
@@ -959,6 +1892,7 @@ final class NativeListView: UIView {
|
|
|
959
1892
|
guard let self else { return }
|
|
960
1893
|
self.contentShrinkCorrectionScheduled = false
|
|
961
1894
|
guard !self.disposed, self.needsContentShrinkCorrection,
|
|
1895
|
+
self.structuralDisplayLink == nil,
|
|
962
1896
|
!self.collectionView.isTracking, !self.collectionView.isDragging,
|
|
963
1897
|
!self.collectionView.isDecelerating,
|
|
964
1898
|
self.collectionView.refreshControl?.isRefreshing != true,
|
|
@@ -994,15 +1928,25 @@ final class NativeListView: UIView {
|
|
|
994
1928
|
flowLayout.scrollDirection = isHorizontal ? .horizontal : .vertical
|
|
995
1929
|
flowLayout.minimumLineSpacing = config.itemSpacing
|
|
996
1930
|
flowLayout.minimumInteritemSpacing = config.itemSpacing
|
|
1931
|
+
let sidecarInset = sidecarBaseInset(collectionView.bounds.width)
|
|
1932
|
+
let sidecarSpace = sidecarLayout.map { $0.width + $0.gap } ?? 0
|
|
1933
|
+
let horizontalInset = config.contentPaddingHorizontal + sidecarInset
|
|
1934
|
+
let disclosureHeight = config.disclosure == nil ? 0 :
|
|
1935
|
+
disclosureCVisibleHeight + containerSlotHeights[5] + disclosureInset
|
|
997
1936
|
flowLayout.sectionInset = UIEdgeInsets(
|
|
998
1937
|
top: config.contentPaddingTop + containerSlotHeights[0],
|
|
999
|
-
left:
|
|
1000
|
-
bottom: config.contentPaddingBottom + containerSlotHeights[2]
|
|
1001
|
-
|
|
1938
|
+
left: horizontalInset + (isRightToLeft ? sidecarSpace + indexGutter : 0),
|
|
1939
|
+
bottom: config.contentPaddingBottom + containerSlotHeights[2] + disclosureHeight
|
|
1940
|
+
+ (structuralTail == nil ? structuralSpacerHeight : 0),
|
|
1941
|
+
right: horizontalInset + (isRightToLeft ? 0 : sidecarSpace + indexGutter)
|
|
1002
1942
|
)
|
|
1003
|
-
|
|
1004
|
-
? config.contentPaddingTop + config.contentPaddingBottom
|
|
1943
|
+
let emptyMinimum = config.items.isEmpty
|
|
1944
|
+
? config.contentPaddingTop + config.contentPaddingBottom
|
|
1945
|
+
+ containerSlotHeights.prefix(3).reduce(0, +) + disclosureHeight
|
|
1005
1946
|
: 0
|
|
1947
|
+
let sidecarMinimum = sidecarLayout == nil ? 0 :
|
|
1948
|
+
config.contentPaddingTop + containerSlotHeights[3] + config.contentPaddingBottom
|
|
1949
|
+
flowLayout.minimumContainerContentHeight = max(emptyMinimum, sidecarMinimum)
|
|
1006
1950
|
flowLayout.stickyItemIndexes = config.stickyHeaders
|
|
1007
1951
|
? Set(config.items.enumerated().compactMap {
|
|
1008
1952
|
$0.element.type == "sectionHeader" && $0.element.data.bool("sticky", default: true) && $0.element.data.string("variant") != "summary"
|
|
@@ -1016,6 +1960,7 @@ final class NativeListView: UIView {
|
|
|
1016
1960
|
listBodyGestureGuard.isEnabled = !isHorizontal
|
|
1017
1961
|
collectionView.showsVerticalScrollIndicator = sectionIndexEntries.isEmpty
|
|
1018
1962
|
collectionView.dragInteractionEnabled = false
|
|
1963
|
+
lastConfiguredCollectionWidth = collectionView.bounds.width
|
|
1019
1964
|
lastLayoutDirection = effectiveUserInterfaceLayoutDirection
|
|
1020
1965
|
}
|
|
1021
1966
|
|
|
@@ -1283,6 +2228,7 @@ final class NativeListView: UIView {
|
|
|
1283
2228
|
let toIndex = keys.firstIndex(of: source.key),
|
|
1284
2229
|
items.count == keys.count else { return }
|
|
1285
2230
|
current.items = items
|
|
2231
|
+
acceptedRowIndex = AcceptedRowIndex(items: items)
|
|
1286
2232
|
config = current
|
|
1287
2233
|
guard source.index != toIndex else { return }
|
|
1288
2234
|
var payload: [String: Any] = [
|
|
@@ -1353,6 +2299,10 @@ final class NativeListView: UIView {
|
|
|
1353
2299
|
return config?.items[safe: indexPath.item]
|
|
1354
2300
|
}
|
|
1355
2301
|
|
|
2302
|
+
private func isInertPresentationKey(_ key: String) -> Bool {
|
|
2303
|
+
structuralTail?.indexByKey[key] != nil || structuralRemovedItems[key] != nil
|
|
2304
|
+
}
|
|
2305
|
+
|
|
1356
2306
|
private func updateAtomicReorderTarget(to targetIndex: Int, key targetKey: String, animated: Bool) {
|
|
1357
2307
|
guard let source = interactiveReorderSource else { return }
|
|
1358
2308
|
interactiveReorderTargetIndex = targetIndex
|
|
@@ -1696,11 +2646,23 @@ final class NativeListView: UIView {
|
|
|
1696
2646
|
if item.key == interactiveReorderCompactKey {
|
|
1697
2647
|
cell.setWalletGroupReorderCompact(true)
|
|
1698
2648
|
}
|
|
2649
|
+
let retiring = structuralRemovedItems[item.key] != nil
|
|
2650
|
+
cell.structuralContentHeight = retiring
|
|
2651
|
+
? rowHeight(item, allocatedWidth: cell.bounds.width) : nil
|
|
2652
|
+
if retiring { cell.clipsToBounds = true }
|
|
2653
|
+
cell.alpha = retiring ? 1 - structuralRemovalProgress : 1
|
|
2654
|
+
cell.isUserInteractionEnabled = !retiring && !item.data.bool("disabled")
|
|
2655
|
+
cell.layer.mask = nil
|
|
2656
|
+
cell.isHidden = false
|
|
2657
|
+
cell.accessibilityElementsHidden = false
|
|
2658
|
+
if let structuralTail, let itemIndex {
|
|
2659
|
+
presentTailCell(cell, key: item.key, index: itemIndex, tail: structuralTail)
|
|
2660
|
+
}
|
|
1699
2661
|
}
|
|
1700
2662
|
|
|
1701
2663
|
private func handleRowPress(_ item: NativeListItem, origin: NativeListActionOrigin?) {
|
|
1702
2664
|
// OneKey patch: missing-address rows keep accessory actions available.
|
|
1703
|
-
guard let config, item.isRowPressEnabled else { return }
|
|
2665
|
+
guard let config, item.isRowPressEnabled, !isInertPresentationKey(item.key) else { return }
|
|
1704
2666
|
if config.rowPressToggles && item.isSelectable && config.selectionMode != "none" {
|
|
1705
2667
|
updateSelection(target: NativeSelectionTarget(scope: "row", key: item.key), sourceKey: item.key)
|
|
1706
2668
|
return
|
|
@@ -1720,8 +2682,8 @@ final class NativeListView: UIView {
|
|
|
1720
2682
|
guard gesture.state == .began else { return }
|
|
1721
2683
|
let point = gesture.location(in: collectionView)
|
|
1722
2684
|
guard let indexPath = collectionView.indexPathForItem(at: point),
|
|
1723
|
-
let item =
|
|
1724
|
-
item.type == "market",
|
|
2685
|
+
let item = item(at: indexPath), !isInertPresentationKey(item.key),
|
|
2686
|
+
(item.type == "market" || item.type == "identity"),
|
|
1725
2687
|
item.isRowPressEnabled else { return }
|
|
1726
2688
|
let actionKey = item.data.string("longPressActionKey")
|
|
1727
2689
|
guard !actionKey.isEmpty else { return }
|
|
@@ -1736,7 +2698,7 @@ final class NativeListView: UIView {
|
|
|
1736
2698
|
target: NativeSelectionTarget?,
|
|
1737
2699
|
origin: NativeListActionOrigin?
|
|
1738
2700
|
) {
|
|
1739
|
-
guard !item.data.bool("disabled") else { return }
|
|
2701
|
+
guard !item.data.bool("disabled"), !isInertPresentationKey(item.key) else { return }
|
|
1740
2702
|
if let target, config?.selectionMode != "none" {
|
|
1741
2703
|
updateSelection(target: target, sourceKey: item.key)
|
|
1742
2704
|
return
|
|
@@ -1745,7 +2707,8 @@ final class NativeListView: UIView {
|
|
|
1745
2707
|
}
|
|
1746
2708
|
|
|
1747
2709
|
private func updateSelection(target: NativeSelectionTarget, sourceKey: String) {
|
|
1748
|
-
guard var current = config, current.selectionMode != "none"
|
|
2710
|
+
guard var current = config, current.selectionMode != "none",
|
|
2711
|
+
!isInertPresentationKey(sourceKey) else { return }
|
|
1749
2712
|
let keys = selectionKeys(target: target, items: current.items)
|
|
1750
2713
|
guard !keys.isEmpty else { return }
|
|
1751
2714
|
let before = current.selectedKeys
|
|
@@ -1806,7 +2769,7 @@ final class NativeListView: UIView {
|
|
|
1806
2769
|
self?.resolveCheckboxState(item: item, target: target, fallback: fallback) ?? fallback
|
|
1807
2770
|
}
|
|
1808
2771
|
for indexPath in collectionView.indexPathsForVisibleItems {
|
|
1809
|
-
guard let item = item(at: indexPath),
|
|
2772
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key),
|
|
1810
2773
|
let cell = collectionView.cellForItem(at: indexPath) as? NativeListRowHost else { continue }
|
|
1811
2774
|
if changedSummaryKeys.contains(item.key) {
|
|
1812
2775
|
bind(cell: cell, item: item, itemIndex: indexPath.item)
|
|
@@ -1957,6 +2920,7 @@ final class NativeListView: UIView {
|
|
|
1957
2920
|
let selectionChanged = current.selectionMode != next.selectionMode ||
|
|
1958
2921
|
current.selectedKeys != next.selectedKeys
|
|
1959
2922
|
if current.generation != next.generation { endReachedGeneration = nil }
|
|
2923
|
+
acceptRowIndex(for: next, replacing: current)
|
|
1960
2924
|
config = next
|
|
1961
2925
|
itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
|
|
1962
2926
|
let changedKeys = next.items.compactMap { item -> String? in
|
|
@@ -2157,6 +3121,16 @@ final class NativeListView: UIView {
|
|
|
2157
3121
|
dataSource = nil
|
|
2158
3122
|
|
|
2159
3123
|
config = nil
|
|
3124
|
+
currentHeaderRoot = nil
|
|
3125
|
+
containerHeaderHeightIsAuthoritative = false
|
|
3126
|
+
containerSlotHeights[0] = 0
|
|
3127
|
+
acceptedRowIndex = nil
|
|
3128
|
+
pagerStickyHeights.removeAllObjects()
|
|
3129
|
+
for slot in reactContainerSlots { slot.host.layer.mask = nil }
|
|
3130
|
+
stopStructuralAnimation()
|
|
3131
|
+
clearStructuralTail()
|
|
3132
|
+
structuralSpacerHeight = 0
|
|
3133
|
+
structuralFooterStartY = nil
|
|
2160
3134
|
itemsByKey.removeAll()
|
|
2161
3135
|
sectionIndexEntries.removeAll()
|
|
2162
3136
|
if let pagerCommandCancelObserver {
|
|
@@ -2175,8 +3149,10 @@ final class NativeListView: UIView {
|
|
|
2175
3149
|
onSelectionDelta = nil
|
|
2176
3150
|
onReorder = nil
|
|
2177
3151
|
onEndReached = nil
|
|
3152
|
+
onStructuralTransitionSettled = nil
|
|
2178
3153
|
onVisibleRangeChanged = nil
|
|
2179
3154
|
onScrollPositionThresholdChange = nil
|
|
3155
|
+
pendingDisclosureSettlement = nil
|
|
2180
3156
|
}
|
|
2181
3157
|
|
|
2182
3158
|
private func createActionAnchor(origin: NativeListActionOrigin) -> [String: Any]? {
|
|
@@ -2272,8 +3248,9 @@ final class NativeListView: UIView {
|
|
|
2272
3248
|
DispatchQueue.main.async { [weak self] in
|
|
2273
3249
|
guard let self else { return }
|
|
2274
3250
|
self.visibleEventScheduled = false
|
|
2275
|
-
guard
|
|
2276
|
-
|
|
3251
|
+
guard self.structuralRemovedItems.isEmpty,
|
|
3252
|
+
let onVisibleRangeChanged = self.onVisibleRangeChanged else { return }
|
|
3253
|
+
let indexes = self.acceptedVisibleIndexes()
|
|
2277
3254
|
let first = indexes.first ?? -1
|
|
2278
3255
|
let last = indexes.last ?? -1
|
|
2279
3256
|
let firstKey = self.config?.items[safe: first]?.key
|
|
@@ -2291,11 +3268,11 @@ final class NativeListView: UIView {
|
|
|
2291
3268
|
}
|
|
2292
3269
|
|
|
2293
3270
|
private func checkEndReached() {
|
|
2294
|
-
guard let config,
|
|
3271
|
+
guard let config, structuralRemovedItems.isEmpty,
|
|
2295
3272
|
config.loadMore,
|
|
2296
3273
|
endReachedGeneration != config.generation,
|
|
2297
3274
|
!config.items.isEmpty else { return }
|
|
2298
|
-
let lastVisible =
|
|
3275
|
+
let lastVisible = acceptedVisibleIndexes().last ?? -1
|
|
2299
3276
|
let threshold = max(1, Int(ceil(Double(config.items.count) * config.endReachedThreshold)))
|
|
2300
3277
|
guard lastVisible >= config.items.count - threshold else { return }
|
|
2301
3278
|
endReachedGeneration = config.generation
|
|
@@ -2304,6 +3281,18 @@ final class NativeListView: UIView {
|
|
|
2304
3281
|
emit(onEndReached, payload)
|
|
2305
3282
|
}
|
|
2306
3283
|
|
|
3284
|
+
private func acceptedVisibleIndexes() -> [Int] {
|
|
3285
|
+
guard let config else { return [] }
|
|
3286
|
+
let presentedPrefix = structuralTail?.prefixCount
|
|
3287
|
+
return collectionView.indexPathsForVisibleItems.compactMap { indexPath in
|
|
3288
|
+
guard presentedPrefix.map({ indexPath.item < $0 }) ?? true,
|
|
3289
|
+
let item = config.items[safe: indexPath.item],
|
|
3290
|
+
dataSource.itemIdentifier(for: indexPath) == item.key,
|
|
3291
|
+
let cell = collectionView.cellForItem(at: indexPath), !cell.isHidden else { return nil }
|
|
3292
|
+
return indexPath.item
|
|
3293
|
+
}.sorted()
|
|
3294
|
+
}
|
|
3295
|
+
|
|
2307
3296
|
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
|
|
2308
3297
|
if gestureRecognizer === keyboardDragRecognizer {
|
|
2309
3298
|
return keyboardDismissMode == .onDrag && focusedTextInput(in: window) != nil
|
|
@@ -2311,12 +3300,13 @@ final class NativeListView: UIView {
|
|
|
2311
3300
|
if gestureRecognizer === reorderLongPress || gestureRecognizer === marketLongPress {
|
|
2312
3301
|
let point = gestureRecognizer.location(in: collectionView)
|
|
2313
3302
|
guard let indexPath = collectionView.indexPathForItem(at: point),
|
|
2314
|
-
let item = item(at: indexPath),
|
|
3303
|
+
let item = item(at: indexPath), !isInertPresentationKey(item.key),
|
|
2315
3304
|
!item.data.bool("disabled") else { return false }
|
|
2316
3305
|
if gestureRecognizer === reorderLongPress {
|
|
2317
3306
|
return config?.reorderable == true && item.isReorderable
|
|
2318
3307
|
}
|
|
2319
|
-
return item.type == "market"
|
|
3308
|
+
return (item.type == "market" || item.type == "identity")
|
|
3309
|
+
&& item.isRowPressEnabled && !item.data.string("longPressActionKey").isEmpty
|
|
2320
3310
|
}
|
|
2321
3311
|
guard gestureRecognizer === listBodyGestureGuard,
|
|
2322
3312
|
let pan = gestureRecognizer as? UIPanGestureRecognizer else { return true }
|
|
@@ -2427,14 +3417,16 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2427
3417
|
return CGSize(width: width, height: height)
|
|
2428
3418
|
}
|
|
2429
3419
|
let available = max(0, collectionView.bounds.width - insets.left - insets.right)
|
|
2430
|
-
let structural = item.type == "sectionHeader" || item.type == "system" || item.type == "action"
|
|
3420
|
+
let structural = item.type == "sectionHeader" || item.type == "system" || item.type == "action" || item.type == "buttonGroup"
|
|
2431
3421
|
if config.layout == "grid", !structural {
|
|
2432
3422
|
let spacing = CGFloat(config.gridColumns - 1) * config.itemSpacing
|
|
2433
3423
|
let width = floor((available - spacing) / CGFloat(config.gridColumns))
|
|
2434
3424
|
let height = item.styledHeight ?? (item.type == "mediaTile" && item.data["height"] == nil ? width + 48 : rowHeight(item, allocatedWidth: width))
|
|
2435
3425
|
return CGSize(width: width, height: height)
|
|
2436
3426
|
}
|
|
2437
|
-
|
|
3427
|
+
let height = structuralRemovedHeights[item.key].map { $0 * (1 - structuralRemovalProgress) }
|
|
3428
|
+
?? rowHeight(item, allocatedWidth: available)
|
|
3429
|
+
return CGSize(width: available, height: max(0.01, height))
|
|
2438
3430
|
}
|
|
2439
3431
|
|
|
2440
3432
|
private func railWidth(_ item: NativeListItem) -> CGFloat {
|
|
@@ -2442,19 +3434,20 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2442
3434
|
}
|
|
2443
3435
|
|
|
2444
3436
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
2445
|
-
guard let item =
|
|
3437
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key) else { return }
|
|
2446
3438
|
if item.type == "walletGroup" { return }
|
|
2447
3439
|
let origin = (collectionView.cellForItem(at: indexPath) as? NativeListRowHost)?.rowActionOrigin()
|
|
2448
3440
|
handleRowPress(item, origin: origin)
|
|
2449
3441
|
}
|
|
2450
3442
|
|
|
2451
3443
|
func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool {
|
|
2452
|
-
guard let item =
|
|
3444
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key) else { return false }
|
|
2453
3445
|
return item.isRowPressEnabled
|
|
2454
3446
|
}
|
|
2455
3447
|
|
|
2456
3448
|
func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
|
|
2457
|
-
guard let item =
|
|
3449
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key),
|
|
3450
|
+
item.type == "market" else { return }
|
|
2458
3451
|
let actionKey = item.data.string("pressInActionKey")
|
|
2459
3452
|
guard !actionKey.isEmpty else { return }
|
|
2460
3453
|
let origin = (collectionView.cellForItem(at: indexPath) as? NativeListRowHost)?.rowActionOrigin()
|
|
@@ -2462,7 +3455,7 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2462
3455
|
}
|
|
2463
3456
|
|
|
2464
3457
|
func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
|
2465
|
-
guard let item =
|
|
3458
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key) else { return false }
|
|
2466
3459
|
return item.isRowPressEnabled
|
|
2467
3460
|
}
|
|
2468
3461
|
|
|
@@ -2474,6 +3467,15 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2474
3467
|
}
|
|
2475
3468
|
|
|
2476
3469
|
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
|
|
3470
|
+
if structuralDisplayLink != nil {
|
|
3471
|
+
structuralScrollInterrupted = true
|
|
3472
|
+
if structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
3473
|
+
else {
|
|
3474
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
3475
|
+
object: collectionView, userInfo: ["phase": 2])
|
|
3476
|
+
structuralScrollPhaseActive = false
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
2477
3479
|
scrollViewDidEndScrollingAnimation(scrollView)
|
|
2478
3480
|
minimumDragOffset = 0
|
|
2479
3481
|
refreshEmittedForDrag = false
|
|
@@ -2512,7 +3514,7 @@ extension NativeListView: UICollectionViewDragDelegate, UICollectionViewDropDele
|
|
|
2512
3514
|
itemsForBeginning session: UIDragSession,
|
|
2513
3515
|
at indexPath: IndexPath
|
|
2514
3516
|
) -> [UIDragItem] {
|
|
2515
|
-
guard config?.reorderable == true,
|
|
3517
|
+
guard config?.reorderable == true, structuralDisplayLink == nil,
|
|
2516
3518
|
let item = config?.items[safe: indexPath.item],
|
|
2517
3519
|
item.isReorderable else { return [] }
|
|
2518
3520
|
let dragItem = UIDragItem(itemProvider: NSItemProvider(object: item.key as NSString))
|
|
@@ -2539,6 +3541,7 @@ extension NativeListView: UICollectionViewDragDelegate, UICollectionViewDropDele
|
|
|
2539
3541
|
guard sourceItem.isReorderable, targetItem.isReorderable, sourceItem.sectionKey == targetItem.sectionKey else { return }
|
|
2540
3542
|
current.items.remove(at: source.item)
|
|
2541
3543
|
current.items.insert(sourceItem, at: destination.item)
|
|
3544
|
+
acceptedRowIndex = AcceptedRowIndex(items: current.items)
|
|
2542
3545
|
config = current
|
|
2543
3546
|
itemsByKey = Dictionary(uniqueKeysWithValues: current.items.map { ($0.key, $0) })
|
|
2544
3547
|
var snapshot = NSDiffableDataSourceSnapshot<Int, String>()
|
|
@@ -2584,12 +3587,26 @@ private final class NativeListCollectionView: UICollectionView {
|
|
|
2584
3587
|
}
|
|
2585
3588
|
}
|
|
2586
3589
|
|
|
3590
|
+
private final class NativeListClippedSlotHost: UIView {
|
|
3591
|
+
var visibleTop: CGFloat = 0
|
|
3592
|
+
var visibleBottom: CGFloat?
|
|
3593
|
+
|
|
3594
|
+
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
|
3595
|
+
super.point(inside: point, with: event) && point.y >= visibleTop
|
|
3596
|
+
&& point.y < (visibleBottom ?? bounds.height)
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
|
|
2587
3600
|
final class NativeListFlowLayout: UICollectionViewFlowLayout {
|
|
2588
3601
|
var stickyItemIndexes: Set<Int> = []
|
|
2589
3602
|
var minimumContainerContentHeight: CGFloat = 0
|
|
3603
|
+
var animatedBodyContentHeight: CGFloat?
|
|
3604
|
+
var tailClip: (firstIndex: Int, endY: CGFloat)?
|
|
3605
|
+
var bodyContentHeight: CGFloat {
|
|
3606
|
+
animatedBodyContentHeight ?? super.collectionViewContentSize.height
|
|
3607
|
+
}
|
|
2590
3608
|
private var horizontalAttributes: [IndexPath: UICollectionViewLayoutAttributes] = [:]
|
|
2591
3609
|
private var horizontalContentSize: CGSize = .zero
|
|
2592
|
-
|
|
2593
3610
|
override func prepare() {
|
|
2594
3611
|
super.prepare()
|
|
2595
3612
|
horizontalAttributes.removeAll(keepingCapacity: true)
|
|
@@ -2617,7 +3634,7 @@ final class NativeListFlowLayout: UICollectionViewFlowLayout {
|
|
|
2617
3634
|
override var collectionViewContentSize: CGSize {
|
|
2618
3635
|
if scrollDirection == .horizontal { return horizontalContentSize }
|
|
2619
3636
|
let size = super.collectionViewContentSize
|
|
2620
|
-
return CGSize(width: size.width, height: max(
|
|
3637
|
+
return CGSize(width: size.width, height: max(bodyContentHeight, minimumContainerContentHeight))
|
|
2621
3638
|
}
|
|
2622
3639
|
|
|
2623
3640
|
override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
|
|
@@ -2654,10 +3671,17 @@ final class NativeListFlowLayout: UICollectionViewFlowLayout {
|
|
|
2654
3671
|
.filter { $0.frame.intersects(rect) }
|
|
2655
3672
|
.sorted { $0.indexPath.item < $1.indexPath.item }
|
|
2656
3673
|
}
|
|
2657
|
-
guard scrollDirection == .vertical,
|
|
2658
|
-
!stickyItemIndexes.isEmpty,
|
|
2659
|
-
let collectionView else { return super.layoutAttributesForElements(in: rect) }
|
|
2660
3674
|
let base = super.layoutAttributesForElements(in: rect)?.compactMap { $0.copy() as? UICollectionViewLayoutAttributes } ?? []
|
|
3675
|
+
guard scrollDirection == .vertical else { return base }
|
|
3676
|
+
let clipped = base.filter { attributes in
|
|
3677
|
+
guard let tailClip, attributes.representedElementCategory == .cell,
|
|
3678
|
+
attributes.indexPath.item >= tailClip.firstIndex else { return true }
|
|
3679
|
+
return attributes.frame.minY < tailClip.endY
|
|
3680
|
+
}
|
|
3681
|
+
guard !stickyItemIndexes.isEmpty,
|
|
3682
|
+
let collectionView else {
|
|
3683
|
+
return clipped
|
|
3684
|
+
}
|
|
2661
3685
|
let pinY = collectionView.contentOffset.y + collectionView.adjustedContentInset.top
|
|
2662
3686
|
// Visible cells can still describe the old viewport during an imperative
|
|
2663
3687
|
// scroll. Resolve the pinned header from unmodified layout positions.
|
|
@@ -2666,20 +3690,30 @@ final class NativeListFlowLayout: UICollectionViewFlowLayout {
|
|
|
2666
3690
|
return attributes.frame.minY <= pinY
|
|
2667
3691
|
}).max(),
|
|
2668
3692
|
let original = super.layoutAttributesForItem(at: IndexPath(item: stickyIndex, section: 0)),
|
|
2669
|
-
let sticky = original.copy() as? UICollectionViewLayoutAttributes else {
|
|
3693
|
+
let sticky = original.copy() as? UICollectionViewLayoutAttributes else {
|
|
3694
|
+
return clipped
|
|
3695
|
+
}
|
|
2670
3696
|
let nextHeaderY = stickyItemIndexes
|
|
2671
3697
|
.filter { $0 > stickyIndex }
|
|
2672
3698
|
.min()
|
|
2673
3699
|
.flatMap { super.layoutAttributesForItem(at: IndexPath(item: $0, section: 0))?.frame.minY }
|
|
2674
3700
|
sticky.frame.origin.y = min(max(pinY, original.frame.minY), (nextHeaderY ?? .greatestFiniteMagnitude) - sticky.frame.height)
|
|
2675
3701
|
sticky.zIndex = 10_000
|
|
2676
|
-
let filtered =
|
|
2677
|
-
|
|
3702
|
+
let filtered = clipped.filter { $0.indexPath != sticky.indexPath }
|
|
3703
|
+
let returned = filtered + [sticky]
|
|
3704
|
+
return returned
|
|
2678
3705
|
}
|
|
2679
3706
|
|
|
2680
3707
|
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
|
|
2681
3708
|
if scrollDirection == .horizontal { return horizontalAttributes[indexPath] }
|
|
2682
|
-
|
|
3709
|
+
guard let attributes = super.layoutAttributesForItem(at: indexPath) else {
|
|
3710
|
+
return nil
|
|
3711
|
+
}
|
|
3712
|
+
if let tailClip, indexPath.item >= tailClip.firstIndex,
|
|
3713
|
+
attributes.frame.minY >= tailClip.endY {
|
|
3714
|
+
return nil
|
|
3715
|
+
}
|
|
3716
|
+
return attributes
|
|
2683
3717
|
}
|
|
2684
3718
|
|
|
2685
3719
|
}
|