@onekeyfe/react-native-native-list 6.7.0-16 → 6.7.0-17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +240 -11
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +7 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +6 -3
- 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 +87 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +177 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +43 -14
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +33 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +22 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +2 -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 +1877 -41
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +1 -0
- package/docs/ROW_TEMPLATES.md +60 -9
- package/docs/SPEC.md +401 -5
- package/docs/STYLE_SPEC.md +6 -0
- package/ios/HybridNativeList.swift +17 -2
- package/ios/NativeListAccessoryStack.swift +227 -39
- package/ios/NativeListActivityDetailsView.swift +18 -8
- package/ios/NativeListActivityRenderer.swift +8 -2
- package/ios/NativeListButtonGroupRenderer.swift +89 -0
- package/ios/NativeListDataRowRenderer.swift +155 -27
- package/ios/NativeListDesignAssets.swift +3 -0
- package/ios/NativeListIdentityRenderer.swift +166 -30
- package/ios/NativeListLeadingVisual.swift +49 -14
- package/ios/NativeListMessageRenderer.swift +34 -1
- 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 +88 -0
- package/ios/RNCNativeListView.swift +984 -53
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +56 -0
- package/ios/tests/NativeListLifecycleTests.swift +2494 -3
- package/lib/module/NativeList.js +171 -28
- package/lib/module/NativeList.web.js +54 -4
- package/lib/module/models.js +1 -0
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +331 -8
- package/lib/module/web/NativeListWebEngine.js +503 -18
- package/lib/module/web/templates/ActivityRowRenderer.js +8 -7
- 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 +90 -4
- 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 +1 -1
- package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
- package/lib/typescript/src/NativeList.types.d.ts +18 -0
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/models.d.ts +105 -9
- package/lib/typescript/src/validation.d.ts +10 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +31 -0
- 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 +3 -3
- package/react-native-native-list.podspec +1 -0
- package/src/NativeList.nitro.ts +2 -0
- package/src/NativeList.tsx +307 -44
- package/src/NativeList.types.ts +22 -0
- package/src/NativeList.web.tsx +75 -8
- package/src/index.ts +1 -0
- package/src/models.ts +117 -3
- package/src/selection.ts +1 -0
- package/src/validation.ts +742 -6
- package/src/web/NativeListWebEngine.ts +798 -19
- package/src/web/templates/ActivityRowRenderer.ts +14 -6
- package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
- package/src/web/templates/DataRowRenderer.ts +93 -20
- package/src/web/templates/IdentityRowRenderer.ts +150 -5
- 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
|
@@ -30,11 +30,20 @@ final class NativeListView: UIView {
|
|
|
30
30
|
}
|
|
31
31
|
private var refreshEmittedForDrag = false
|
|
32
32
|
private var minimumDragOffset: CGFloat = 0
|
|
33
|
-
private var containerSlotHeights: [CGFloat] = [0, 0, 0]
|
|
33
|
+
private var containerSlotHeights: [CGFloat] = [0, 0, 0, 0, 0, 0]
|
|
34
|
+
private var disclosureCVisibleHeight: CGFloat = 0
|
|
35
|
+
private var disclosureInset: CGFloat = 0
|
|
36
|
+
private var disclosureStartCHeight: CGFloat = 0
|
|
37
|
+
private var disclosureStartInset: CGFloat = 0
|
|
38
|
+
private var disclosureSegmentStartEased: CFTimeInterval = 0
|
|
39
|
+
private var deferredDisclosureGeometryInvalid = false
|
|
40
|
+
private var pendingDisclosureSettlement: (id: String, expanded: Bool)?
|
|
34
41
|
// Fabric keeps assigning each slot root the frame React computed (inset, 0, width, height).
|
|
35
42
|
// Each root therefore lives in a list-owned host whose origin the list alone controls, so a
|
|
36
43
|
// React layout update can never move a slot out of its native position, even for a frame.
|
|
37
44
|
private var reactContainerSlots: [(content: UIView, host: UIView)] = []
|
|
45
|
+
private var sidecarLayout: (width: CGFloat, gap: CGFloat, maxContentWidth: CGFloat)?
|
|
46
|
+
private let pagerStickyHeights = NSMapTable<AnyObject, NSNumber>(keyOptions: .weakMemory, valueOptions: .strongMemory)
|
|
38
47
|
private let topOverlayHost = UIView()
|
|
39
48
|
private weak var topOverlayContent: UIView?
|
|
40
49
|
private var topEdgeInteraction: UIInteraction?
|
|
@@ -47,16 +56,239 @@ final class NativeListView: UIView {
|
|
|
47
56
|
private var lastLaidOutContentHeight: CGFloat?
|
|
48
57
|
private var needsContentShrinkCorrection = false
|
|
49
58
|
private var contentShrinkCorrectionScheduled = false
|
|
59
|
+
private var consumedStructuralTransitionID: String?
|
|
60
|
+
private var structuralDisplayLink: CADisplayLink?
|
|
61
|
+
private var structuralScrollPhaseActive = false
|
|
62
|
+
private var structuralSpacerHeight: CGFloat = 0
|
|
63
|
+
private var structuralAnimationStart: CFTimeInterval = 0
|
|
64
|
+
private var structuralAnimationDuration: CFTimeInterval = 0
|
|
65
|
+
private var structuralStartSpacer: CGFloat = 0
|
|
66
|
+
private var structuralStartOffset: CGFloat = 0
|
|
67
|
+
private var structuralTargetOffset: CGFloat = 0
|
|
68
|
+
private var structuralScrollInterrupted = false
|
|
69
|
+
private var structuralFooterStartY: CGFloat?
|
|
70
|
+
private var structuralFooterProgress: CGFloat = 0
|
|
71
|
+
private var structuralRemovedItems: [String: NativeListItem] = [:]
|
|
72
|
+
private var structuralRemovedHeights: [String: CGFloat] = [:]
|
|
73
|
+
private var structuralRemovalProgress: CGFloat = 0
|
|
74
|
+
private final class StructuralTail {
|
|
75
|
+
var items: [NativeListItem]
|
|
76
|
+
let starts: [CGFloat]
|
|
77
|
+
let heights: [CGFloat]
|
|
78
|
+
let indexByKey: [String: Int]
|
|
79
|
+
let extent: CGFloat
|
|
80
|
+
let prefixCount: Int
|
|
81
|
+
let finalExtent: CGFloat
|
|
82
|
+
let retiringKeys: Set<String>
|
|
83
|
+
init(items: [NativeListItem], heights: [CGFloat], spacing: CGFloat,
|
|
84
|
+
prefixCount: Int, finalExtent: CGFloat) {
|
|
85
|
+
self.items = items
|
|
86
|
+
self.heights = heights
|
|
87
|
+
self.indexByKey = Dictionary(uniqueKeysWithValues: items.enumerated().map { ($1.key, $0) })
|
|
88
|
+
self.prefixCount = prefixCount
|
|
89
|
+
self.finalExtent = finalExtent
|
|
90
|
+
self.retiringKeys = finalExtent == 0 ? Set(items.map(\.key)) : []
|
|
91
|
+
var edge: CGFloat = prefixCount == 0 ? 0 : spacing
|
|
92
|
+
var starts: [CGFloat] = []
|
|
93
|
+
for (index, height) in heights.enumerated() {
|
|
94
|
+
starts.append(edge)
|
|
95
|
+
edge += height + (index + 1 < heights.count ? spacing : 0)
|
|
96
|
+
}
|
|
97
|
+
self.starts = starts
|
|
98
|
+
self.extent = edge
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
private var structuralTail: StructuralTail?
|
|
102
|
+
private var structuralTailStartExtent: CGFloat = 0
|
|
103
|
+
private var structuralTailSegmentStartEased: CFTimeInterval = 0
|
|
104
|
+
private var structuralTailStartY: CGFloat = 0
|
|
105
|
+
private func prefixTailCount(from old: NativeListConfig, to next: NativeListConfig) -> Int? {
|
|
106
|
+
guard old.orientation == "vertical", next.orientation == "vertical",
|
|
107
|
+
old.layout == next.layout, next.layout == "linear" || next.layout == "table",
|
|
108
|
+
old.itemSpacing == next.itemSpacing,
|
|
109
|
+
old.contentPaddingTop == next.contentPaddingTop,
|
|
110
|
+
old.contentPaddingBottom == next.contentPaddingBottom,
|
|
111
|
+
old.contentPaddingHorizontal == next.contentPaddingHorizontal,
|
|
112
|
+
dictionariesEqual(old.theme, next.theme),
|
|
113
|
+
dictionariesEqual(old.listStyle, next.listStyle),
|
|
114
|
+
old.items.count != next.items.count,
|
|
115
|
+
structuralDisplayLink == nil || structuralTail != nil,
|
|
116
|
+
!old.items.contains(where: { $0.type == "sectionHeader" }),
|
|
117
|
+
!next.items.contains(where: { $0.type == "sectionHeader" }) else { return nil }
|
|
118
|
+
let prefix = min(old.items.count, next.items.count)
|
|
119
|
+
guard prefix > 0 else { return nil }
|
|
120
|
+
for index in 0..<prefix {
|
|
121
|
+
let before = old.items[index], after = next.items[index]
|
|
122
|
+
guard before.key == after.key, before.type == after.type,
|
|
123
|
+
rowHeight(before) == rowHeight(after) else { return nil }
|
|
124
|
+
}
|
|
125
|
+
return prefix
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private func tailExceedsHostLimit(_ tail: StructuralTail) -> Bool {
|
|
129
|
+
let window = max(0, collectionView.bounds.height) * 3
|
|
130
|
+
var end = 0
|
|
131
|
+
for first in tail.items.indices {
|
|
132
|
+
end = max(end, first)
|
|
133
|
+
while end < tail.items.count && tail.starts[end] <= tail.starts[first] + window {
|
|
134
|
+
end += 1
|
|
135
|
+
}
|
|
136
|
+
if end - first > 128 { return true }
|
|
137
|
+
}
|
|
138
|
+
return false
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private func clearStructuralTail() {
|
|
142
|
+
structuralTail = nil
|
|
143
|
+
flowLayout.animatedBodyContentHeight = nil
|
|
144
|
+
flowLayout.tailClip = nil
|
|
145
|
+
for case let cell as NativeListRowHost in collectionView.visibleCells {
|
|
146
|
+
let indexPath = collectionView.indexPath(for: cell)
|
|
147
|
+
let key = indexPath.flatMap { dataSource?.itemIdentifier(for: $0) }
|
|
148
|
+
let accepted = indexPath.flatMap { config?.items[safe: $0.item]?.key } == key && key != nil
|
|
149
|
+
cell.layer.mask = nil
|
|
150
|
+
cell.isHidden = !accepted
|
|
151
|
+
cell.accessibilityElementsHidden = !accepted
|
|
152
|
+
cell.isUserInteractionEnabled = accepted && !(key.flatMap { itemsByKey[$0] }?.data.bool("disabled") ?? false)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private func updateStructuralTailWindow() {
|
|
157
|
+
guard let tail = structuralTail else { return }
|
|
158
|
+
let clipEnd = structuralTailStartY + structuralSpacerHeight
|
|
159
|
+
flowLayout.animatedBodyContentHeight = clipEnd
|
|
160
|
+
+ (config?.contentPaddingBottom ?? 0) + containerSlotHeights[2]
|
|
161
|
+
+ (config?.disclosure == nil ? 0 : disclosureCVisibleHeight
|
|
162
|
+
+ containerSlotHeights[5] + disclosureInset)
|
|
163
|
+
flowLayout.tailClip = (tail.prefixCount, clipEnd)
|
|
164
|
+
for case let cell as NativeListRowHost in collectionView.visibleCells {
|
|
165
|
+
guard let indexPath = collectionView.indexPath(for: cell),
|
|
166
|
+
let key = dataSource.itemIdentifier(for: indexPath) else { continue }
|
|
167
|
+
presentTailCell(cell, key: key, index: indexPath.item, tail: tail)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private func presentTailCell(_ cell: NativeListRowHost, key: String, index: Int,
|
|
172
|
+
tail: StructuralTail) {
|
|
173
|
+
let clipEnd = structuralTailStartY + structuralSpacerHeight
|
|
174
|
+
let visibleHeight = index >= tail.prefixCount
|
|
175
|
+
? max(0, min(cell.bounds.height, clipEnd - cell.frame.minY)) : cell.bounds.height
|
|
176
|
+
let clipped = visibleHeight < cell.bounds.height
|
|
177
|
+
CATransaction.begin()
|
|
178
|
+
CATransaction.setDisableActions(true)
|
|
179
|
+
cell.isHidden = visibleHeight <= 0
|
|
180
|
+
if clipped && visibleHeight > 0 {
|
|
181
|
+
let mask = cell.layer.mask ?? CALayer()
|
|
182
|
+
mask.backgroundColor = UIColor.black.cgColor
|
|
183
|
+
mask.frame = CGRect(x: 0, y: 0, width: cell.bounds.width, height: visibleHeight)
|
|
184
|
+
cell.layer.mask = mask
|
|
185
|
+
} else {
|
|
186
|
+
cell.layer.mask = nil
|
|
187
|
+
}
|
|
188
|
+
CATransaction.commit()
|
|
189
|
+
let inert = index >= tail.prefixCount || clipped
|
|
190
|
+
cell.isUserInteractionEnabled = !inert && !(itemsByKey[key]?.data.bool("disabled") ?? false)
|
|
191
|
+
cell.accessibilityElementsHidden = inert
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private func finishStructuralTail(interrupted: Bool) {
|
|
195
|
+
guard let tail = structuralTail, let config else { return }
|
|
196
|
+
stopStructuralAnimation()
|
|
197
|
+
if !tail.retiringKeys.isEmpty {
|
|
198
|
+
var snapshot = dataSource.snapshot()
|
|
199
|
+
snapshot.deleteItems(Array(tail.retiringKeys))
|
|
200
|
+
dataSource.apply(snapshot, animatingDifferences: false)
|
|
201
|
+
itemsByKey = Dictionary(uniqueKeysWithValues: config.items.map { ($0.key, $0) })
|
|
202
|
+
}
|
|
203
|
+
clearStructuralTail()
|
|
204
|
+
structuralSpacerHeight = 0
|
|
205
|
+
disclosureCVisibleHeight = config.disclosure?.expanded == true ? containerSlotHeights[4] : 0
|
|
206
|
+
disclosureInset = config.disclosure?.expanded == true
|
|
207
|
+
? config.disclosure?.expandedTrailingInset ?? 0 : 0
|
|
208
|
+
structuralFooterStartY = nil
|
|
209
|
+
structuralFooterProgress = 0
|
|
210
|
+
configureLayout(config)
|
|
211
|
+
collectionView.layoutIfNeeded()
|
|
212
|
+
if interrupted {
|
|
213
|
+
// A diffable deletion can leave UIKit's content-shrink scroll animation active.
|
|
214
|
+
// Cancel it without choosing a new offset for the user's gesture.
|
|
215
|
+
collectionView.setContentOffset(collectionView.contentOffset, animated: false)
|
|
216
|
+
} else if !collectionView.isTracking && !collectionView.isDragging
|
|
217
|
+
&& !collectionView.isDecelerating {
|
|
218
|
+
let inset = collectionView.adjustedContentInset
|
|
219
|
+
let maximum = max(-inset.top,
|
|
220
|
+
collectionView.contentSize.height - collectionView.bounds.height + inset.bottom)
|
|
221
|
+
let target = min(max(-inset.top, structuralTargetOffset), maximum)
|
|
222
|
+
collectionView.setContentOffset(CGPoint(x: collectionView.contentOffset.x, y: target), animated: false)
|
|
223
|
+
}
|
|
224
|
+
layoutContainerSlots()
|
|
225
|
+
emitVisibleRangeIfNeeded()
|
|
226
|
+
checkEndReached()
|
|
227
|
+
settleDisclosure(interrupted ? "interrupted" : "completed")
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private func updateStructuralTailTarget() {
|
|
231
|
+
guard let tail = structuralTail, let config else { return }
|
|
232
|
+
let inset = collectionView.adjustedContentInset
|
|
233
|
+
let leftHeight = structuralTailStartY + tail.finalExtent
|
|
234
|
+
+ config.contentPaddingBottom + containerSlotHeights[2]
|
|
235
|
+
+ (config.disclosure == nil ? 0 :
|
|
236
|
+
(config.disclosure?.expanded == true ? containerSlotHeights[4] : 0)
|
|
237
|
+
+ containerSlotHeights[5]
|
|
238
|
+
+ (config.disclosure?.expanded == true
|
|
239
|
+
? config.disclosure?.expandedTrailingInset ?? 0 : 0))
|
|
240
|
+
let sidecarHeight = sidecarLayout == nil ? 0 :
|
|
241
|
+
config.contentPaddingTop + containerSlotHeights[3] + config.contentPaddingBottom
|
|
242
|
+
let finalHeight = max(leftHeight, sidecarHeight)
|
|
243
|
+
let maximum = max(-inset.top,
|
|
244
|
+
finalHeight - collectionView.bounds.height + inset.bottom)
|
|
245
|
+
var target = min(max(-inset.top, structuralStartOffset), maximum)
|
|
246
|
+
if tail.finalExtent == 0, config.disclosure != nil, containerSlotHeights[5] > 0 {
|
|
247
|
+
let toggleTop = structuralTailStartY
|
|
248
|
+
let toggleBottom = toggleTop + containerSlotHeights[5]
|
|
249
|
+
var sticky: CGFloat = 0
|
|
250
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
251
|
+
sticky += CGFloat(value.doubleValue)
|
|
252
|
+
}
|
|
253
|
+
let lower = toggleBottom - collectionView.bounds.height + inset.bottom
|
|
254
|
+
let upper = toggleTop - inset.top - sticky
|
|
255
|
+
target = lower <= upper ? min(max(target, lower), upper) : upper
|
|
256
|
+
} else if tail.finalExtent == 0, containerSlotHeights[2] > 0 {
|
|
257
|
+
let footerTop = structuralTailStartY
|
|
258
|
+
let footerBottom = footerTop + containerSlotHeights[2]
|
|
259
|
+
var sticky: CGFloat = 0
|
|
260
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
261
|
+
sticky += CGFloat(value.doubleValue)
|
|
262
|
+
}
|
|
263
|
+
let lower = footerBottom - collectionView.bounds.height + inset.bottom
|
|
264
|
+
let upper = footerTop - inset.top - sticky
|
|
265
|
+
target = lower <= upper ? min(max(target, lower), upper) : upper
|
|
266
|
+
}
|
|
267
|
+
structuralTargetOffset = min(max(-inset.top, target), maximum)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private func structuralTailSegmentProgress(_ eased: CFTimeInterval) -> CFTimeInterval {
|
|
271
|
+
if eased >= 1 { return 1 }
|
|
272
|
+
let remaining = max(0.001, 1 - structuralTailSegmentStartEased)
|
|
273
|
+
return min(1, max(0, (eased - structuralTailSegmentStartEased) / remaining))
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private func disclosureSegmentProgress(_ eased: CFTimeInterval) -> CFTimeInterval {
|
|
277
|
+
if eased >= 1 { return 1 }
|
|
278
|
+
let remaining = max(0.001, 1 - disclosureSegmentStartEased)
|
|
279
|
+
return min(1, max(0, (eased - disclosureSegmentStartEased) / remaining))
|
|
280
|
+
}
|
|
50
281
|
|
|
51
282
|
@objc func mountContainerSlot(_ view: UIView, atIndex index: Int) {
|
|
52
|
-
if index ==
|
|
283
|
+
if index == 6 {
|
|
53
284
|
topOverlayContent?.removeFromSuperview()
|
|
54
285
|
topOverlayContent = view
|
|
55
286
|
topOverlayHost.addSubview(view)
|
|
56
287
|
updateTopScrollEdge()
|
|
57
288
|
return
|
|
58
289
|
}
|
|
59
|
-
let host =
|
|
290
|
+
let host: UIView = index == 2 || index == 4 || index == 5
|
|
291
|
+
? NativeListClippedSlotHost() : UIView()
|
|
60
292
|
// Clipping to the reported height keeps new content from overlapping rows until the list
|
|
61
293
|
// has reserved space for it.
|
|
62
294
|
host.clipsToBounds = true
|
|
@@ -142,16 +374,113 @@ final class NativeListView: UIView {
|
|
|
142
374
|
}
|
|
143
375
|
}
|
|
144
376
|
|
|
145
|
-
func setContainerSlotHeightsJson(_ json: String) {
|
|
377
|
+
func setContainerSlotHeightsJson(_ json: String, followedBySnapshot: Bool = false) {
|
|
146
378
|
guard let data = json.data(using: .utf8),
|
|
147
379
|
let heights = try? JSONSerialization.jsonObject(with: data) as? [Double],
|
|
148
|
-
heights.count ==
|
|
149
|
-
|
|
380
|
+
(heights.count == 4 || heights.count == 6),
|
|
381
|
+
heights.allSatisfy({ $0.isFinite && $0 >= 0 }) else { return }
|
|
382
|
+
let previousHeights = containerSlotHeights
|
|
383
|
+
let footerDelta = containerSlotHeights[2] - CGFloat(heights[2])
|
|
384
|
+
containerSlotHeights = heights.map { CGFloat($0) } + (heights.count == 4 ? [0, 0] : [])
|
|
385
|
+
let contentHeightChanged = previousHeights[4] != containerSlotHeights[4]
|
|
386
|
+
let toggleHeightChanged = previousHeights[5] != containerSlotHeights[5]
|
|
387
|
+
let disclosureGeometryInvalid = structuralTail != nil && config?.disclosure != nil
|
|
388
|
+
&& (toggleHeightChanged || footerDelta != 0
|
|
389
|
+
|| containerSlotHeights[4] < disclosureCVisibleHeight - 0.5)
|
|
390
|
+
let surroundingSlotGeometryInvalid = structuralTail != nil
|
|
391
|
+
&& (previousHeights[0] != containerSlotHeights[0]
|
|
392
|
+
|| previousHeights[1] != containerSlotHeights[1]
|
|
393
|
+
|| previousHeights[3] != containerSlotHeights[3])
|
|
394
|
+
if surroundingSlotGeometryInvalid || disclosureGeometryInvalid {
|
|
395
|
+
if followedBySnapshot, config?.disclosure != nil {
|
|
396
|
+
deferredDisclosureGeometryInvalid = true
|
|
397
|
+
}
|
|
398
|
+
else { finishStructuralTail(interrupted: true) }
|
|
399
|
+
}
|
|
400
|
+
if structuralTail != nil, contentHeightChanged, !disclosureGeometryInvalid,
|
|
401
|
+
!surroundingSlotGeometryInvalid,
|
|
402
|
+
config?.disclosure != nil, structuralDisplayLink != nil {
|
|
403
|
+
let progress = min(1, max(0,
|
|
404
|
+
(CACurrentMediaTime() - structuralAnimationStart) / max(0.001, structuralAnimationDuration)))
|
|
405
|
+
let eased = progress * progress * (3 - 2 * progress)
|
|
406
|
+
disclosureStartCHeight = disclosureCVisibleHeight
|
|
407
|
+
disclosureSegmentStartEased = eased
|
|
408
|
+
}
|
|
409
|
+
if structuralTail != nil, structuralDisplayLink != nil, footerDelta != 0,
|
|
410
|
+
config?.disclosure == nil {
|
|
411
|
+
let progress = min(1, max(0,
|
|
412
|
+
(CACurrentMediaTime() - structuralAnimationStart) / max(0.001, structuralAnimationDuration)))
|
|
413
|
+
let eased = progress * progress * (3 - 2 * progress)
|
|
414
|
+
// Rebase from the last extent actually presented, not elapsed wall time.
|
|
415
|
+
structuralTailStartExtent = structuralSpacerHeight + footerDelta
|
|
416
|
+
structuralSpacerHeight = structuralTailStartExtent
|
|
417
|
+
structuralTailSegmentStartEased = eased
|
|
418
|
+
disclosureStartCHeight = disclosureCVisibleHeight
|
|
419
|
+
disclosureSegmentStartEased = eased
|
|
420
|
+
disclosureStartInset = disclosureInset
|
|
421
|
+
structuralStartOffset = collectionView.contentOffset.y
|
|
422
|
+
} else if structuralTail == nil, structuralDisplayLink != nil,
|
|
423
|
+
footerDelta != 0, config?.disclosure == nil {
|
|
424
|
+
let progress = min(1, max(0,
|
|
425
|
+
(CACurrentMediaTime() - structuralAnimationStart) / max(0.001, structuralAnimationDuration)))
|
|
426
|
+
let eased = progress * progress * (3 - 2 * progress)
|
|
427
|
+
structuralStartSpacer = max(0, structuralStartSpacer + footerDelta)
|
|
428
|
+
structuralSpacerHeight = structuralStartSpacer * (1 - eased)
|
|
429
|
+
if let startY = structuralFooterStartY { structuralFooterStartY = startY + footerDelta }
|
|
430
|
+
}
|
|
431
|
+
if structuralTail == nil, let disclosure = config?.disclosure {
|
|
432
|
+
disclosureCVisibleHeight = disclosure.expanded ? containerSlotHeights[4] : 0
|
|
433
|
+
disclosureInset = disclosure.expanded ? disclosure.expandedTrailingInset : 0
|
|
434
|
+
}
|
|
150
435
|
if let config { configureLayout(config) }
|
|
436
|
+
if structuralTail != nil {
|
|
437
|
+
updateStructuralTailTarget()
|
|
438
|
+
updateStructuralTailWindow()
|
|
439
|
+
flowLayout.invalidateLayout()
|
|
440
|
+
collectionView.layoutIfNeeded()
|
|
441
|
+
updateStructuralTailWindow()
|
|
442
|
+
} else if structuralDisplayLink != nil {
|
|
443
|
+
collectionView.layoutIfNeeded()
|
|
444
|
+
let inset = collectionView.adjustedContentInset
|
|
445
|
+
let finalMaximum = max(-inset.top,
|
|
446
|
+
collectionView.contentSize.height - structuralSpacerHeight
|
|
447
|
+
- collectionView.bounds.height + inset.bottom)
|
|
448
|
+
structuralTargetOffset = min(structuralTargetOffset, finalMaximum)
|
|
449
|
+
}
|
|
151
450
|
layoutContainerSlots()
|
|
152
451
|
setNeedsLayout()
|
|
153
452
|
}
|
|
154
453
|
|
|
454
|
+
func setSidecarLayoutJson(_ json: String) {
|
|
455
|
+
if json.isEmpty {
|
|
456
|
+
sidecarLayout = nil
|
|
457
|
+
} else if let data = json.data(using: .utf8),
|
|
458
|
+
let value = try? JSONSerialization.jsonObject(with: data) as? [String: Double],
|
|
459
|
+
let width = value["width"], let gap = value["gap"],
|
|
460
|
+
let maxWidth = value["maxContentWidth"],
|
|
461
|
+
width.isFinite, width > 0, gap.isFinite, gap >= 0,
|
|
462
|
+
maxWidth.isFinite, maxWidth > width + gap {
|
|
463
|
+
sidecarLayout = (CGFloat(width), CGFloat(gap), CGFloat(maxWidth))
|
|
464
|
+
} else { return }
|
|
465
|
+
if structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
466
|
+
if let config { configureLayout(config) }
|
|
467
|
+
layoutContainerSlots()
|
|
468
|
+
setNeedsLayout()
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
private func sidecarBaseInset(_ width: CGFloat) -> CGFloat {
|
|
472
|
+
guard let sidecarLayout else { return 0 }
|
|
473
|
+
return max(0, (width - min(width, sidecarLayout.maxContentWidth)) / 2)
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
@objc(setPagerStickyHeight:forOwner:)
|
|
477
|
+
func setPagerStickyHeight(_ height: CGFloat, forOwner owner: AnyObject) {
|
|
478
|
+
let next = height.isFinite ? max(0, height) : 0
|
|
479
|
+
if next == 0 { pagerStickyHeights.removeObject(forKey: owner) }
|
|
480
|
+
else { pagerStickyHeights.setObject(NSNumber(value: Double(next)), forKey: owner) }
|
|
481
|
+
layoutContainerSlots()
|
|
482
|
+
}
|
|
483
|
+
|
|
155
484
|
private func layoutContainerSlots() {
|
|
156
485
|
let empty = config?.items.isEmpty ?? true
|
|
157
486
|
let header = containerSlotHeights[0]
|
|
@@ -159,15 +488,76 @@ final class NativeListView: UIView {
|
|
|
159
488
|
let footer = containerSlotHeights[2]
|
|
160
489
|
let paddingTop = config?.contentPaddingTop ?? 0
|
|
161
490
|
let paddingBottom = config?.contentPaddingBottom ?? 0
|
|
162
|
-
let
|
|
163
|
-
|
|
164
|
-
|
|
491
|
+
let naturalFooterY = flowLayout.bodyContentHeight - paddingBottom - footer
|
|
492
|
+
let footerY = structuralTail == nil
|
|
493
|
+
? max(paddingTop + header + emptyHeight, naturalFooterY) : naturalFooterY
|
|
494
|
+
let footerPosition = structuralTail == nil && structuralRemovedItems.isEmpty ? structuralFooterStartY.map {
|
|
495
|
+
$0 + (footerY - $0) * structuralFooterProgress
|
|
496
|
+
} ?? footerY : footerY
|
|
497
|
+
let positions = [paddingTop, paddingTop + header, footerPosition]
|
|
165
498
|
for (index, slot) in reactContainerSlots.prefix(3).enumerated() {
|
|
166
499
|
slot.host.isHidden = index == 1 && !empty
|
|
167
500
|
// React places the root at the horizontal inset inside this full-width host.
|
|
168
501
|
slot.host.frame = CGRect(x: 0, y: positions[index],
|
|
169
502
|
width: collectionView.bounds.width, height: containerSlotHeights[index])
|
|
170
503
|
}
|
|
504
|
+
if reactContainerSlots.count > 3 {
|
|
505
|
+
let slot = reactContainerSlots[3]
|
|
506
|
+
let width = sidecarLayout?.width ?? 0
|
|
507
|
+
let base = sidecarBaseInset(collectionView.bounds.width)
|
|
508
|
+
slot.host.isHidden = sidecarLayout == nil || containerSlotHeights[3] <= 0
|
|
509
|
+
let x = effectiveUserInterfaceLayoutDirection == .rightToLeft
|
|
510
|
+
? base : collectionView.bounds.width - base - width
|
|
511
|
+
slot.host.frame = CGRect(x: x,
|
|
512
|
+
y: paddingTop, width: width, height: containerSlotHeights[3])
|
|
513
|
+
}
|
|
514
|
+
if reactContainerSlots.count > 5 {
|
|
515
|
+
let disclosureEnabled = config?.disclosure != nil
|
|
516
|
+
let content = reactContainerSlots[4].host
|
|
517
|
+
let toggle = reactContainerSlots[5].host
|
|
518
|
+
let toggleHeight = disclosureEnabled ? containerSlotHeights[5] : 0
|
|
519
|
+
let contentY = footerPosition - disclosureInset - toggleHeight
|
|
520
|
+
- disclosureCVisibleHeight
|
|
521
|
+
content.frame = CGRect(x: 0, y: contentY, width: collectionView.bounds.width,
|
|
522
|
+
height: containerSlotHeights[4])
|
|
523
|
+
toggle.frame = CGRect(x: 0, y: contentY + disclosureCVisibleHeight,
|
|
524
|
+
width: collectionView.bounds.width, height: containerSlotHeights[5])
|
|
525
|
+
content.isHidden = !disclosureEnabled || disclosureCVisibleHeight <= 0
|
|
526
|
+
toggle.isHidden = !disclosureEnabled || toggleHeight <= 0
|
|
527
|
+
let contentSettled = structuralDisplayLink == nil && structuralTail == nil
|
|
528
|
+
&& config?.disclosure?.expanded == true
|
|
529
|
+
&& disclosureCVisibleHeight >= containerSlotHeights[4] - 0.5
|
|
530
|
+
content.isUserInteractionEnabled = contentSettled
|
|
531
|
+
content.accessibilityElementsHidden = !contentSettled
|
|
532
|
+
toggle.isUserInteractionEnabled = disclosureEnabled && toggleHeight > 0
|
|
533
|
+
toggle.accessibilityElementsHidden = !disclosureEnabled || toggleHeight <= 0
|
|
534
|
+
}
|
|
535
|
+
var stickyHeight: CGFloat = 0
|
|
536
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
537
|
+
stickyHeight += CGFloat(value.doubleValue)
|
|
538
|
+
}
|
|
539
|
+
CATransaction.begin()
|
|
540
|
+
CATransaction.setDisableActions(true)
|
|
541
|
+
for (index, slot) in reactContainerSlots.enumerated() {
|
|
542
|
+
let stickyTop = max(0, collectionView.contentOffset.y + stickyHeight - slot.host.frame.minY)
|
|
543
|
+
let tailTop = index == 2 && structuralTail != nil ? max(0, -structuralSpacerHeight) : 0
|
|
544
|
+
let top = max(stickyHeight > 0 ? stickyTop : 0, tailTop)
|
|
545
|
+
let bottom = index == 4 && config?.disclosure != nil
|
|
546
|
+
? min(slot.host.bounds.height, max(0, disclosureCVisibleHeight))
|
|
547
|
+
: slot.host.bounds.height
|
|
548
|
+
(slot.host as? NativeListClippedSlotHost)?.visibleTop = top
|
|
549
|
+
(slot.host as? NativeListClippedSlotHost)?.visibleBottom = index == 4 ? bottom : nil
|
|
550
|
+
guard top > 0 || bottom < slot.host.bounds.height else {
|
|
551
|
+
slot.host.layer.mask = nil
|
|
552
|
+
continue
|
|
553
|
+
}
|
|
554
|
+
let mask = slot.host.layer.mask ?? CALayer()
|
|
555
|
+
mask.backgroundColor = UIColor.black.cgColor
|
|
556
|
+
mask.frame = CGRect(x: 0, y: top, width: slot.host.bounds.width,
|
|
557
|
+
height: max(0, bottom - top))
|
|
558
|
+
slot.host.layer.mask = mask
|
|
559
|
+
}
|
|
560
|
+
CATransaction.commit()
|
|
171
561
|
}
|
|
172
562
|
|
|
173
563
|
private final class ActionAnchorRecord {
|
|
@@ -238,6 +628,7 @@ final class NativeListView: UIView {
|
|
|
238
628
|
var onSelectionDelta: ((String) -> Void)?
|
|
239
629
|
var onReorder: ((String) -> Void)?
|
|
240
630
|
var onEndReached: ((String) -> Void)?
|
|
631
|
+
var onStructuralTransitionSettled: ((String) -> Void)?
|
|
241
632
|
var onVisibleRangeChanged: ((String) -> Void)? {
|
|
242
633
|
didSet {
|
|
243
634
|
lastVisibleRange = nil
|
|
@@ -273,9 +664,11 @@ final class NativeListView: UIView {
|
|
|
273
664
|
private var sectionIndexHapticsEnabled = true
|
|
274
665
|
private var lastLayoutDirection: UIUserInterfaceLayoutDirection?
|
|
275
666
|
private var lastLayoutSize: CGSize?
|
|
667
|
+
private var lastConfiguredCollectionWidth: CGFloat?
|
|
276
668
|
private var commandAcceptedForPendingScroll = false
|
|
277
669
|
private var performingExplicitScrollCommand = false
|
|
278
670
|
private var animatedExplicitScrollCommand = false
|
|
671
|
+
private var explicitScrollRevision = 0
|
|
279
672
|
private var pagerCommandCancelObserver: NSObjectProtocol?
|
|
280
673
|
private var pendingScrollRequest: ScrollRequest?
|
|
281
674
|
private let sectionIndexFeedback = UISelectionFeedbackGenerator()
|
|
@@ -452,7 +845,8 @@ final class NativeListView: UIView {
|
|
|
452
845
|
}
|
|
453
846
|
dataSource.reorderingHandlers.canReorderItem = { [weak self] key in
|
|
454
847
|
guard let self else { return false }
|
|
455
|
-
return self.config?.reorderable == true && self.
|
|
848
|
+
return self.config?.reorderable == true && !self.isInertPresentationKey(key)
|
|
849
|
+
&& self.itemsByKey[key]?.isReorderable == true
|
|
456
850
|
}
|
|
457
851
|
dataSource.reorderingHandlers.didReorder = { [weak self] transaction in
|
|
458
852
|
guard self?.interactiveReorderUsesAtomicTargeting != true else { return }
|
|
@@ -510,7 +904,7 @@ final class NativeListView: UIView {
|
|
|
510
904
|
let point = touch.location(in: collectionView)
|
|
511
905
|
guard collectionView.bounds.contains(point),
|
|
512
906
|
let indexPath = collectionView.indexPathForItem(at: point),
|
|
513
|
-
let item = item(at: indexPath) else { return false }
|
|
907
|
+
let item = item(at: indexPath), !isInertPresentationKey(item.key) else { return false }
|
|
514
908
|
return item.isRowPressEnabled
|
|
515
909
|
}
|
|
516
910
|
|
|
@@ -523,7 +917,10 @@ final class NativeListView: UIView {
|
|
|
523
917
|
}
|
|
524
918
|
|
|
525
919
|
override func willMove(toWindow newWindow: UIWindow?) {
|
|
526
|
-
if newWindow == nil {
|
|
920
|
+
if newWindow == nil {
|
|
921
|
+
attachSectionIndexToList()
|
|
922
|
+
if structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
923
|
+
}
|
|
527
924
|
super.willMove(toWindow: newWindow)
|
|
528
925
|
}
|
|
529
926
|
|
|
@@ -553,14 +950,17 @@ final class NativeListView: UIView {
|
|
|
553
950
|
height: requestedTopOverlayHeight)
|
|
554
951
|
updateSectionIndexAttachment()
|
|
555
952
|
let direction = effectiveUserInterfaceLayoutDirection
|
|
556
|
-
|
|
557
|
-
|
|
953
|
+
let sizeChanged = lastLayoutSize != nil && lastLayoutSize != bounds.size
|
|
954
|
+
if sizeChanged && structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
955
|
+
if sizeChanged || lastLayoutDirection != nil && lastLayoutDirection != direction {
|
|
558
956
|
invalidateActionAnchor(reason: "layout")
|
|
559
957
|
}
|
|
560
958
|
lastLayoutSize = bounds.size
|
|
561
|
-
|
|
959
|
+
let collectionWidthChanged = collectionView.bounds.width > 0
|
|
960
|
+
&& lastConfiguredCollectionWidth != collectionView.bounds.width
|
|
961
|
+
if (lastLayoutDirection != direction || collectionWidthChanged), let config {
|
|
562
962
|
configureLayout(config)
|
|
563
|
-
rebindRowsForLayoutDirection(config)
|
|
963
|
+
if lastLayoutDirection != direction { rebindRowsForLayoutDirection(config) }
|
|
564
964
|
}
|
|
565
965
|
performPendingScrollIfNeeded()
|
|
566
966
|
layoutContainerSlots()
|
|
@@ -598,8 +998,148 @@ final class NativeListView: UIView {
|
|
|
598
998
|
|
|
599
999
|
func applySnapshotJson(_ json: String) {
|
|
600
1000
|
guard let next = try? NativeListConfig.parse(json: json) else { return }
|
|
1001
|
+
let transition = next.structuralTransition
|
|
1002
|
+
let isNewTransition = transition != nil && transition?.id != consumedStructuralTransitionID
|
|
1003
|
+
let disclosureGeometryInvalid = deferredDisclosureGeometryInvalid
|
|
1004
|
+
deferredDisclosureGeometryInvalid = false
|
|
1005
|
+
let disclosureTargetChanged = config?.disclosure?.expanded != next.disclosure?.expanded
|
|
1006
|
+
let disclosureInsetChanged = config?.disclosure?.expandedTrailingInset
|
|
1007
|
+
!= next.disclosure?.expandedTrailingInset
|
|
1008
|
+
let disclosureStateChanged = disclosureTargetChanged || disclosureInsetChanged
|
|
1009
|
+
let activePendingID = structuralTail == nil ? nil : pendingDisclosureSettlement?.id
|
|
1010
|
+
let oldKeys = dataSource.snapshot().itemIdentifiers
|
|
1011
|
+
let logicalOldKeys = config?.items.map(\.key) ?? []
|
|
1012
|
+
let presentationItems = itemsByKey
|
|
1013
|
+
let newKeys = next.items.map(\.key)
|
|
1014
|
+
let newDisclosureCommand = config != nil && next.disclosure != nil && isNewTransition
|
|
1015
|
+
if let transition { consumedStructuralTransitionID = transition.id }
|
|
1016
|
+
if newDisclosureCommand, let transition, let disclosure = next.disclosure {
|
|
1017
|
+
pendingDisclosureSettlement = (transition.id, disclosure.expanded)
|
|
1018
|
+
} else if next.disclosure == nil || disclosureTargetChanged {
|
|
1019
|
+
// A target change without a new command cannot settle the previous target.
|
|
1020
|
+
pendingDisclosureSettlement = nil
|
|
1021
|
+
}
|
|
1022
|
+
let wantsStructure = config?.orientation == "vertical"
|
|
1023
|
+
&& (config?.layout == "linear" || config?.layout == "table")
|
|
1024
|
+
&& isNewTransition && logicalOldKeys != newKeys
|
|
1025
|
+
&& next.orientation == "vertical" && (next.layout == "linear" || next.layout == "table")
|
|
1026
|
+
&& !UIAccessibility.isReduceMotionEnabled
|
|
1027
|
+
&& (transition?.duration ?? 0) > 0
|
|
1028
|
+
let tailPrefix = wantsStructure ? config.flatMap { prefixTailCount(from: $0, to: next) } : nil
|
|
1029
|
+
// A carried tail extent belongs to its original prefix boundary.
|
|
1030
|
+
// Commit a new boundary atomically instead of starting a legacy row animation.
|
|
1031
|
+
let prefixChangedDuringTail = structuralTail != nil && tailPrefix != nil
|
|
1032
|
+
&& structuralTail?.prefixCount != tailPrefix
|
|
1033
|
+
let rawTailCandidate: StructuralTail? = tailPrefix.flatMap { prefix in
|
|
1034
|
+
guard let previous = config else { return nil }
|
|
1035
|
+
let items = previous.items.count > next.items.count
|
|
1036
|
+
? Array(previous.items.dropFirst(prefix)) : Array(next.items.dropFirst(prefix))
|
|
1037
|
+
let heights = items.map { rowHeight($0) }
|
|
1038
|
+
let tail = StructuralTail(items: items, heights: heights,
|
|
1039
|
+
spacing: next.itemSpacing, prefixCount: prefix,
|
|
1040
|
+
finalExtent: previous.items.count > next.items.count ? 0 :
|
|
1041
|
+
heights.reduce(0, +) + CGFloat(max(0, items.count - 1)) * next.itemSpacing
|
|
1042
|
+
+ (prefix == 0 ? 0 : next.itemSpacing))
|
|
1043
|
+
return tail
|
|
1044
|
+
}
|
|
1045
|
+
let tailOverCap = rawTailCandidate.map(tailExceedsHostLimit) ?? false
|
|
1046
|
+
let animateStructure = wantsStructure && !tailOverCap && !prefixChangedDuringTail
|
|
1047
|
+
&& !disclosureGeometryInvalid
|
|
1048
|
+
&& (next.disclosure == nil ||
|
|
1049
|
+
(rawTailCandidate != nil && reactContainerSlots.count > 5))
|
|
1050
|
+
let directDisclosureStatus: String? = newDisclosureCommand && !animateStructure
|
|
1051
|
+
? (disclosureGeometryInvalid || logicalOldKeys != newKeys && (transition?.duration ?? 0) > 0
|
|
1052
|
+
&& !UIAccessibility.isReduceMotionEnabled ? "interrupted" : "completed")
|
|
1053
|
+
: nil
|
|
1054
|
+
var interruptedPendingID: String?
|
|
1055
|
+
let tailCandidate = animateStructure ? rawTailCandidate : nil
|
|
1056
|
+
let presentationHeights: [String: CGFloat] = animateStructure ? Dictionary(uniqueKeysWithValues: oldKeys.compactMap { key -> (String, CGFloat)? in
|
|
1057
|
+
guard let item = presentationItems[key] else { return nil }
|
|
1058
|
+
let height = structuralRemovedHeights[key].map { $0 * (1 - structuralRemovalProgress) }
|
|
1059
|
+
?? rowHeight(item)
|
|
1060
|
+
return (key, height)
|
|
1061
|
+
}) : [:]
|
|
1062
|
+
let previousOffset = collectionView.contentOffset.y
|
|
1063
|
+
let oldLeftContentHeight = animateStructure ? flowLayout.bodyContentHeight : 0
|
|
1064
|
+
let oldSpacerHeight = structuralSpacerHeight
|
|
1065
|
+
let oldRowsHeight = animateStructure
|
|
1066
|
+
? presentationHeights.values.reduce(CGFloat(0), +)
|
|
1067
|
+
+ CGFloat(max(0, oldKeys.count - 1)) * (config?.itemSpacing ?? 0)
|
|
1068
|
+
: 0
|
|
1069
|
+
let newRowsHeight = animateStructure
|
|
1070
|
+
? next.items.reduce(CGFloat(0)) { $0 + rowHeight($1) }
|
|
1071
|
+
+ CGFloat(max(0, newKeys.count - 1)) * next.itemSpacing
|
|
1072
|
+
: 0
|
|
1073
|
+
let survivingKeys = animateStructure ? Set(newKeys) : Set<String>()
|
|
1074
|
+
let visibleAnchor = animateStructure
|
|
1075
|
+
? collectionView.indexPathsForVisibleItems.sorted().first {
|
|
1076
|
+
oldKeys.indices.contains($0.item) && survivingKeys.contains(oldKeys[$0.item])
|
|
1077
|
+
}
|
|
1078
|
+
: nil
|
|
1079
|
+
let anchorKey = visibleAnchor.map { oldKeys[$0.item] }
|
|
1080
|
+
let oldPrefix = (animateStructure ? anchorKey : nil).flatMap { key -> CGFloat? in
|
|
1081
|
+
guard let index = oldKeys.firstIndex(of: key) else { return nil }
|
|
1082
|
+
return oldKeys.prefix(index).reduce(CGFloat(0)) { $0 + (presentationHeights[$1] ?? 0) }
|
|
1083
|
+
+ CGFloat(index) * (config?.itemSpacing ?? 0)
|
|
1084
|
+
} ?? 0
|
|
1085
|
+
let newPrefix = (animateStructure ? anchorKey : nil).flatMap { key -> CGFloat? in
|
|
1086
|
+
guard let index = newKeys.firstIndex(of: key) else { return nil }
|
|
1087
|
+
return next.items.prefix(index).reduce(CGFloat(0)) { $0 + rowHeight($1) }
|
|
1088
|
+
+ CGFloat(index) * next.itemSpacing
|
|
1089
|
+
} ?? 0
|
|
1090
|
+
if animateStructure {
|
|
1091
|
+
let carriedExtent = structuralTail == nil ? nil : structuralSpacerHeight
|
|
1092
|
+
stopStructuralAnimation()
|
|
1093
|
+
clearStructuralTail()
|
|
1094
|
+
structuralScrollInterrupted = false
|
|
1095
|
+
structuralFooterStartY = reactContainerSlots.count > 2
|
|
1096
|
+
? reactContainerSlots[2].host.frame.minY : nil
|
|
1097
|
+
structuralFooterProgress = 0
|
|
1098
|
+
let removedKeys = Set(oldKeys).subtracting(newKeys)
|
|
1099
|
+
let retainsOrder = oldKeys.filter { survivingKeys.contains($0) } == newKeys
|
|
1100
|
+
structuralRemovedItems = tailCandidate == nil && retainsOrder
|
|
1101
|
+
? presentationItems.filter { removedKeys.contains($0.key) } : [:]
|
|
1102
|
+
structuralRemovedHeights = tailCandidate == nil && retainsOrder
|
|
1103
|
+
? presentationHeights.filter { removedKeys.contains($0.key) } : [:]
|
|
1104
|
+
structuralRemovalProgress = 0
|
|
1105
|
+
if let tail = tailCandidate {
|
|
1106
|
+
structuralTail = tail
|
|
1107
|
+
structuralTailStartExtent = carriedExtent ?? (tail.finalExtent == 0 ? tail.extent : 0)
|
|
1108
|
+
structuralTailSegmentStartEased = 0
|
|
1109
|
+
structuralSpacerHeight = structuralTailStartExtent
|
|
1110
|
+
let prefixHeights = next.items.prefix(tail.prefixCount).reduce(CGFloat(0)) {
|
|
1111
|
+
$0 + rowHeight($1)
|
|
1112
|
+
}
|
|
1113
|
+
structuralTailStartY = next.contentPaddingTop + containerSlotHeights[0]
|
|
1114
|
+
+ prefixHeights + CGFloat(max(0, tail.prefixCount - 1)) * next.itemSpacing
|
|
1115
|
+
disclosureStartCHeight = disclosureCVisibleHeight
|
|
1116
|
+
disclosureStartInset = disclosureInset
|
|
1117
|
+
disclosureSegmentStartEased = 0
|
|
1118
|
+
} else {
|
|
1119
|
+
structuralSpacerHeight = structuralRemovedItems.isEmpty
|
|
1120
|
+
? max(0, structuralSpacerHeight + oldRowsHeight - newRowsHeight) : 0
|
|
1121
|
+
}
|
|
1122
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1123
|
+
object: collectionView, userInfo: ["phase": 0])
|
|
1124
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1125
|
+
object: collectionView, userInfo: ["phase": 1])
|
|
1126
|
+
structuralScrollPhaseActive = true
|
|
1127
|
+
needsContentShrinkCorrection = false
|
|
1128
|
+
} else if logicalOldKeys != newKeys
|
|
1129
|
+
|| (newDisclosureCommand || disclosureGeometryInvalid || disclosureStateChanged)
|
|
1130
|
+
&& structuralTail != nil {
|
|
1131
|
+
if !newDisclosureCommand && !disclosureTargetChanged { interruptedPendingID = activePendingID }
|
|
1132
|
+
stopStructuralAnimation()
|
|
1133
|
+
clearStructuralTail()
|
|
1134
|
+
structuralSpacerHeight = 0
|
|
1135
|
+
structuralFooterStartY = nil
|
|
1136
|
+
structuralRemovedItems.removeAll()
|
|
1137
|
+
structuralRemovedHeights.removeAll()
|
|
1138
|
+
}
|
|
601
1139
|
invalidateActionAnchor(reason: "snapshot")
|
|
602
|
-
if let current = config,
|
|
1140
|
+
if let current = config, !newDisclosureCommand,
|
|
1141
|
+
structuralRemovedItems.isEmpty, structuralTail == nil,
|
|
1142
|
+
isControlledSelectionSnapshotUpdate(from: current, to: next) {
|
|
603
1143
|
config = next
|
|
604
1144
|
itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
|
|
605
1145
|
// OneKey patch: A controlled selection echo is fully handled by the
|
|
@@ -608,7 +1148,7 @@ final class NativeListView: UIView {
|
|
|
608
1148
|
return
|
|
609
1149
|
}
|
|
610
1150
|
if let current = config, interactiveReorderSource != nil {
|
|
611
|
-
if canDeferSnapshotDuringInteractiveReorder(from: current, to: next) {
|
|
1151
|
+
if !newDisclosureCommand && canDeferSnapshotDuringInteractiveReorder(from: current, to: next) {
|
|
612
1152
|
deferSnapshotDuringInteractiveReorder(from: current, to: next)
|
|
613
1153
|
return
|
|
614
1154
|
}
|
|
@@ -619,17 +1159,110 @@ final class NativeListView: UIView {
|
|
|
619
1159
|
// rows whose own content is unchanged.
|
|
620
1160
|
let themeChanged = !dictionariesEqual(config?.theme, next.theme)
|
|
621
1161
|
|| !dictionariesEqual(config?.listStyle, next.listStyle)
|
|
1162
|
+
|| config?.layout != next.layout
|
|
1163
|
+
let tailGeometryChanged = config.map { current in
|
|
1164
|
+
current.disclosure?.expanded != next.disclosure?.expanded
|
|
1165
|
+
|| current.disclosure?.expandedTrailingInset != next.disclosure?.expandedTrailingInset
|
|
1166
|
+
|| current.orientation != next.orientation
|
|
1167
|
+
|| current.stickyHeaders != next.stickyHeaders
|
|
1168
|
+
|| current.sectionIndexEnabled != next.sectionIndexEnabled
|
|
1169
|
+
|| current.contentPadding != next.contentPadding
|
|
1170
|
+
|| current.itemSpacing != next.itemSpacing
|
|
1171
|
+
|| current.contentPaddingTop != next.contentPaddingTop
|
|
1172
|
+
|| current.contentPaddingBottom != next.contentPaddingBottom
|
|
1173
|
+
|| current.contentPaddingHorizontal != next.contentPaddingHorizontal
|
|
1174
|
+
|| current.items.count != next.items.count
|
|
1175
|
+
|| zip(current.items, next.items).contains { old, new in
|
|
1176
|
+
old.key != new.key || old.rendererKey != new.rendererKey
|
|
1177
|
+
|| rowHeight(old) != rowHeight(new)
|
|
1178
|
+
}
|
|
1179
|
+
} ?? false
|
|
622
1180
|
if config?.generation != next.generation { endReachedGeneration = nil }
|
|
623
1181
|
config = next
|
|
1182
|
+
if structuralTail == nil {
|
|
1183
|
+
disclosureCVisibleHeight = next.disclosure?.expanded == true ? containerSlotHeights[4] : 0
|
|
1184
|
+
disclosureInset = next.disclosure?.expanded == true
|
|
1185
|
+
? next.disclosure?.expandedTrailingInset ?? 0 : 0
|
|
1186
|
+
}
|
|
624
1187
|
itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
|
|
1188
|
+
itemsByKey.merge(structuralRemovedItems) { current, _ in current }
|
|
1189
|
+
if let tail = structuralTail, !tail.retiringKeys.isEmpty {
|
|
1190
|
+
itemsByKey.merge(presentationItems.filter { tail.retiringKeys.contains($0.key) }) {
|
|
1191
|
+
current, _ in current
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
if !animateStructure, let tail = structuralTail {
|
|
1195
|
+
if themeChanged || tailGeometryChanged {
|
|
1196
|
+
if !newDisclosureCommand { interruptedPendingID = activePendingID }
|
|
1197
|
+
stopStructuralAnimation()
|
|
1198
|
+
clearStructuralTail()
|
|
1199
|
+
structuralSpacerHeight = 0
|
|
1200
|
+
structuralFooterStartY = nil
|
|
1201
|
+
disclosureCVisibleHeight = next.disclosure?.expanded == true ? containerSlotHeights[4] : 0
|
|
1202
|
+
disclosureInset = next.disclosure?.expanded == true
|
|
1203
|
+
? next.disclosure?.expandedTrailingInset ?? 0 : 0
|
|
1204
|
+
} else {
|
|
1205
|
+
for (index, previous) in tail.items.enumerated() {
|
|
1206
|
+
guard let item = itemsByKey[previous.key], item.content != previous.content else { continue }
|
|
1207
|
+
tail.items[index] = item
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
625
1211
|
configureSectionIndex(next)
|
|
626
1212
|
configureLayout(next)
|
|
627
1213
|
configureRefresh(next)
|
|
628
1214
|
configureFooter(next)
|
|
1215
|
+
if structuralTail != nil { updateStructuralTailWindow() }
|
|
1216
|
+
|
|
1217
|
+
if animateStructure, let transition {
|
|
1218
|
+
let inset = collectionView.adjustedContentInset
|
|
1219
|
+
let finalLeftHeight = structuralTail.map { tail in
|
|
1220
|
+
structuralTailStartY + tail.finalExtent + next.contentPaddingBottom + containerSlotHeights[2]
|
|
1221
|
+
+ (next.disclosure == nil ? 0 :
|
|
1222
|
+
(next.disclosure?.expanded == true ? containerSlotHeights[4] : 0)
|
|
1223
|
+
+ containerSlotHeights[5]
|
|
1224
|
+
+ (next.disclosure?.expanded == true
|
|
1225
|
+
? next.disclosure?.expandedTrailingInset ?? 0 : 0))
|
|
1226
|
+
} ?? max(0, oldLeftContentHeight + newRowsHeight - oldRowsHeight - oldSpacerHeight)
|
|
1227
|
+
let sidecarHeight = sidecarLayout == nil ? 0 :
|
|
1228
|
+
next.contentPaddingTop + containerSlotHeights[3] + next.contentPaddingBottom
|
|
1229
|
+
let finalHeight = max(finalLeftHeight, sidecarHeight)
|
|
1230
|
+
let finalMaximum = max(-inset.top, finalHeight - collectionView.bounds.height + inset.bottom)
|
|
1231
|
+
structuralStartSpacer = structuralSpacerHeight
|
|
1232
|
+
structuralStartOffset = previousOffset
|
|
1233
|
+
var targetOffset = structuralTail == nil
|
|
1234
|
+
? min(max(-inset.top, previousOffset + newPrefix - oldPrefix), finalMaximum)
|
|
1235
|
+
: min(max(-inset.top, previousOffset), finalMaximum)
|
|
1236
|
+
if let tail = structuralTail, tail.finalExtent == 0,
|
|
1237
|
+
(next.disclosure != nil ? containerSlotHeights[5] : containerSlotHeights[2]) > 0 {
|
|
1238
|
+
let targetTop = structuralTailStartY
|
|
1239
|
+
let targetBottom = targetTop + (next.disclosure != nil
|
|
1240
|
+
? containerSlotHeights[5] : containerSlotHeights[2])
|
|
1241
|
+
var sticky: CGFloat = 0
|
|
1242
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
1243
|
+
sticky += CGFloat(value.doubleValue)
|
|
1244
|
+
}
|
|
1245
|
+
let lower = targetBottom - collectionView.bounds.height + inset.bottom
|
|
1246
|
+
let upper = targetTop - inset.top - sticky
|
|
1247
|
+
targetOffset = lower <= upper
|
|
1248
|
+
? min(max(targetOffset, lower), upper) : upper
|
|
1249
|
+
targetOffset = min(max(-inset.top, targetOffset), finalMaximum)
|
|
1250
|
+
} else if structuralTail == nil, visibleAnchor == nil, let fallbackKey = transition.anchorKey,
|
|
1251
|
+
let fallbackIndex = newKeys.firstIndex(of: fallbackKey) {
|
|
1252
|
+
let fallbackY = next.contentPaddingTop + containerSlotHeights[0]
|
|
1253
|
+
+ next.items.prefix(fallbackIndex).reduce(CGFloat(0)) { $0 + rowHeight($1) }
|
|
1254
|
+
+ CGFloat(fallbackIndex) * next.itemSpacing
|
|
1255
|
+
targetOffset = min(targetOffset, max(-inset.top, fallbackY - inset.top))
|
|
1256
|
+
}
|
|
1257
|
+
structuralTargetOffset = targetOffset
|
|
1258
|
+
if structuralTail != nil { updateStructuralTailTarget() }
|
|
1259
|
+
structuralAnimationDuration = transition.duration
|
|
1260
|
+
}
|
|
629
1261
|
|
|
630
1262
|
var snapshot = NSDiffableDataSourceSnapshot<Int, String>()
|
|
631
1263
|
snapshot.appendSections([0])
|
|
632
|
-
let keys =
|
|
1264
|
+
let keys = structuralTail.map { $0.retiringKeys.isEmpty ? newKeys : oldKeys }
|
|
1265
|
+
?? (structuralRemovedItems.isEmpty ? newKeys : oldKeys)
|
|
633
1266
|
snapshot.appendItems(keys, toSection: 0)
|
|
634
1267
|
var changedKeys = Set(keys.filter { key in
|
|
635
1268
|
guard let old = oldItems[key], let new = itemsByKey[key] else { return false }
|
|
@@ -644,14 +1277,203 @@ final class NativeListView: UIView {
|
|
|
644
1277
|
let replacedKeys = changedRetainedKeys.filter { oldItems[$0]?.rendererKey != itemsByKey[$0]?.rendererKey }
|
|
645
1278
|
snapshot.reloadItems(Array(replacedKeys))
|
|
646
1279
|
snapshot.reconfigureItems(Array(changedRetainedKeys.subtracting(replacedKeys)))
|
|
647
|
-
|
|
1280
|
+
let scrollRevisionAtApply = explicitScrollRevision
|
|
1281
|
+
let explicitScrollPendingAtApply = pendingScrollRequest != nil
|
|
1282
|
+
dataSource.apply(snapshot, animatingDifferences: animateStructure && structuralRemovedItems.isEmpty
|
|
1283
|
+
&& structuralTail == nil) { [weak self] in
|
|
648
1284
|
guard let self else { return }
|
|
649
1285
|
self.collectionView.layoutIfNeeded()
|
|
1286
|
+
self.updateStructuralTailWindow()
|
|
1287
|
+
self.layoutContainerSlots()
|
|
650
1288
|
self.notifyPagerScrollViewReadyIfNeeded()
|
|
651
1289
|
self.performPendingScrollIfNeeded()
|
|
1290
|
+
if directDisclosureStatus == "completed", let transition {
|
|
1291
|
+
self.revealDirectCollapsedToggle(expectedID: transition.id,
|
|
1292
|
+
scrollRevision: scrollRevisionAtApply,
|
|
1293
|
+
explicitScrollPendingAtApply: explicitScrollPendingAtApply)
|
|
1294
|
+
}
|
|
652
1295
|
self.emitVisibleRangeIfNeeded()
|
|
653
1296
|
self.checkEndReached()
|
|
654
1297
|
self.syncSectionIndexToVisibleRows()
|
|
1298
|
+
if let directDisclosureStatus, let transition {
|
|
1299
|
+
self.settleDisclosure(directDisclosureStatus, expectedID: transition.id)
|
|
1300
|
+
} else if let interruptedPendingID {
|
|
1301
|
+
self.settleDisclosure("interrupted", expectedID: interruptedPendingID)
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
if animateStructure && (structuralTail != nil || tailCandidate == nil) {
|
|
1305
|
+
updateStructuralTailWindow()
|
|
1306
|
+
if tailCandidate != nil && structuralTail == nil { return }
|
|
1307
|
+
structuralAnimationStart = CACurrentMediaTime()
|
|
1308
|
+
let displayLink = CADisplayLink(target: self, selector: #selector(advanceStructuralAnimation(_:)))
|
|
1309
|
+
structuralDisplayLink = displayLink
|
|
1310
|
+
displayLink.add(to: .main, forMode: .common)
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
private func stopStructuralAnimation() {
|
|
1315
|
+
if structuralScrollPhaseActive {
|
|
1316
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1317
|
+
object: collectionView, userInfo: ["phase": 2])
|
|
1318
|
+
structuralScrollPhaseActive = false
|
|
1319
|
+
}
|
|
1320
|
+
structuralDisplayLink?.invalidate()
|
|
1321
|
+
structuralDisplayLink = nil
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
private func revealDirectCollapsedToggle(expectedID: String, scrollRevision: Int,
|
|
1325
|
+
explicitScrollPendingAtApply: Bool) {
|
|
1326
|
+
guard !disposed, let pending = pendingDisclosureSettlement,
|
|
1327
|
+
pending.id == expectedID, !pending.expanded,
|
|
1328
|
+
consumedStructuralTransitionID == expectedID,
|
|
1329
|
+
config?.disclosure?.expanded == false,
|
|
1330
|
+
structuralTail == nil, structuralDisplayLink == nil,
|
|
1331
|
+
!structuralScrollPhaseActive, scrollRevision == explicitScrollRevision,
|
|
1332
|
+
!explicitScrollPendingAtApply,
|
|
1333
|
+
pendingScrollRequest == nil, !animatedExplicitScrollCommand,
|
|
1334
|
+
!collectionView.isTracking, !collectionView.isDragging,
|
|
1335
|
+
!collectionView.isDecelerating,
|
|
1336
|
+
collectionView.bounds.height > 0, reactContainerSlots.count > 5 else { return }
|
|
1337
|
+
let toggle = reactContainerSlots[5].host
|
|
1338
|
+
guard !toggle.isHidden, toggle.bounds.height > 0 else { return }
|
|
1339
|
+
let inset = collectionView.adjustedContentInset
|
|
1340
|
+
let maximum = max(-inset.top,
|
|
1341
|
+
collectionView.contentSize.height - collectionView.bounds.height + inset.bottom)
|
|
1342
|
+
var sticky: CGFloat = 0
|
|
1343
|
+
for case let value as NSNumber in pagerStickyHeights.objectEnumerator()?.allObjects ?? [] {
|
|
1344
|
+
sticky += CGFloat(value.doubleValue)
|
|
1345
|
+
}
|
|
1346
|
+
let lower = toggle.frame.maxY - collectionView.bounds.height + inset.bottom
|
|
1347
|
+
let upper = toggle.frame.minY - inset.top - sticky
|
|
1348
|
+
let current = collectionView.contentOffset.y
|
|
1349
|
+
let visibleTarget = lower <= upper ? min(max(current, lower), upper) : upper
|
|
1350
|
+
let target = min(max(-inset.top, visibleTarget), maximum)
|
|
1351
|
+
guard abs(target - current) > 0.5 else { return }
|
|
1352
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1353
|
+
object: collectionView, userInfo: ["phase": 0])
|
|
1354
|
+
defer {
|
|
1355
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1356
|
+
object: collectionView, userInfo: ["phase": 2])
|
|
1357
|
+
}
|
|
1358
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
1359
|
+
object: collectionView, userInfo: ["phase": 1])
|
|
1360
|
+
collectionView.setContentOffset(CGPoint(x: collectionView.contentOffset.x, y: target), animated: false)
|
|
1361
|
+
layoutContainerSlots()
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
private func settleDisclosure(_ status: String, expectedID: String? = nil) {
|
|
1365
|
+
guard let pending = pendingDisclosureSettlement,
|
|
1366
|
+
expectedID == nil || pending.id == expectedID,
|
|
1367
|
+
consumedStructuralTransitionID == pending.id,
|
|
1368
|
+
config?.disclosure?.expanded == pending.expanded else { return }
|
|
1369
|
+
pendingDisclosureSettlement = nil
|
|
1370
|
+
emit(onStructuralTransitionSettled, [
|
|
1371
|
+
"transitionId": pending.id,
|
|
1372
|
+
"status": status,
|
|
1373
|
+
"settledExpanded": pending.expanded,
|
|
1374
|
+
])
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
@objc private func advanceStructuralAnimation(_ link: CADisplayLink) {
|
|
1378
|
+
guard let config else { stopStructuralAnimation(); return }
|
|
1379
|
+
if structuralTail != nil && UIAccessibility.isReduceMotionEnabled {
|
|
1380
|
+
finishStructuralTail(interrupted: false)
|
|
1381
|
+
return
|
|
1382
|
+
}
|
|
1383
|
+
let elapsed = CACurrentMediaTime() - structuralAnimationStart
|
|
1384
|
+
let progress = min(1, max(0, elapsed / max(0.001, structuralAnimationDuration)))
|
|
1385
|
+
let eased = progress * progress * (3 - 2 * progress)
|
|
1386
|
+
if let tail = structuralTail {
|
|
1387
|
+
// Commit cell clipping, viewport movement, and slots together for this tick.
|
|
1388
|
+
CATransaction.begin()
|
|
1389
|
+
CATransaction.setDisableActions(true)
|
|
1390
|
+
defer { CATransaction.commit() }
|
|
1391
|
+
let segment = structuralTailSegmentProgress(eased)
|
|
1392
|
+
structuralSpacerHeight = structuralTailStartExtent
|
|
1393
|
+
+ (tail.finalExtent - structuralTailStartExtent) * segment
|
|
1394
|
+
if let disclosure = config.disclosure {
|
|
1395
|
+
let targetC = disclosure.expanded ? containerSlotHeights[4] : 0
|
|
1396
|
+
let targetInset = disclosure.expanded ? disclosure.expandedTrailingInset : 0
|
|
1397
|
+
let contentSegment = disclosureSegmentProgress(eased)
|
|
1398
|
+
disclosureCVisibleHeight = disclosureStartCHeight
|
|
1399
|
+
+ (targetC - disclosureStartCHeight) * contentSegment
|
|
1400
|
+
disclosureInset = disclosureStartInset
|
|
1401
|
+
+ (targetInset - disclosureStartInset) * segment
|
|
1402
|
+
}
|
|
1403
|
+
structuralFooterProgress = CGFloat(eased)
|
|
1404
|
+
updateStructuralTailWindow()
|
|
1405
|
+
flowLayout.invalidateLayout()
|
|
1406
|
+
collectionView.layoutIfNeeded()
|
|
1407
|
+
if !structuralScrollInterrupted && !collectionView.isTracking
|
|
1408
|
+
&& !collectionView.isDragging && !collectionView.isDecelerating {
|
|
1409
|
+
collectionView.contentOffset.y = structuralStartOffset
|
|
1410
|
+
+ (structuralTargetOffset - structuralStartOffset) * segment
|
|
1411
|
+
collectionView.layoutIfNeeded()
|
|
1412
|
+
}
|
|
1413
|
+
updateStructuralTailWindow()
|
|
1414
|
+
layoutContainerSlots()
|
|
1415
|
+
if progress >= 1 { finishStructuralTail(interrupted: structuralScrollInterrupted) }
|
|
1416
|
+
return
|
|
1417
|
+
}
|
|
1418
|
+
structuralSpacerHeight = structuralStartSpacer * (1 - eased)
|
|
1419
|
+
structuralFooterProgress = CGFloat(eased)
|
|
1420
|
+
structuralRemovalProgress = CGFloat(eased)
|
|
1421
|
+
for case let cell as NativeListRowHost in collectionView.visibleCells {
|
|
1422
|
+
guard let indexPath = collectionView.indexPath(for: cell),
|
|
1423
|
+
let key = dataSource.itemIdentifier(for: indexPath) else { continue }
|
|
1424
|
+
cell.structuralContentHeight = structuralRemovedItems[key].map {
|
|
1425
|
+
rowHeight($0, allocatedWidth: cell.bounds.width)
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
var inset = flowLayout.sectionInset
|
|
1429
|
+
inset.bottom = config.contentPaddingBottom + containerSlotHeights[2] + structuralSpacerHeight
|
|
1430
|
+
flowLayout.sectionInset = inset
|
|
1431
|
+
flowLayout.invalidateLayout()
|
|
1432
|
+
collectionView.layoutIfNeeded()
|
|
1433
|
+
if !structuralScrollInterrupted && !collectionView.isTracking
|
|
1434
|
+
&& !collectionView.isDragging && !collectionView.isDecelerating {
|
|
1435
|
+
collectionView.contentOffset.y = structuralStartOffset
|
|
1436
|
+
+ (structuralTargetOffset - structuralStartOffset) * eased
|
|
1437
|
+
// Materialize the new viewport before updating presentation cells.
|
|
1438
|
+
collectionView.layoutIfNeeded()
|
|
1439
|
+
}
|
|
1440
|
+
for cell in collectionView.visibleCells {
|
|
1441
|
+
guard let indexPath = collectionView.indexPath(for: cell),
|
|
1442
|
+
let key = dataSource.itemIdentifier(for: indexPath) else { continue }
|
|
1443
|
+
let retiring = structuralRemovedItems[key] != nil
|
|
1444
|
+
if retiring { cell.clipsToBounds = true }
|
|
1445
|
+
cell.alpha = retiring ? 1 - structuralRemovalProgress : 1
|
|
1446
|
+
cell.isUserInteractionEnabled = !retiring && !(itemsByKey[key]?.data.bool("disabled") ?? false)
|
|
1447
|
+
}
|
|
1448
|
+
layoutContainerSlots()
|
|
1449
|
+
if progress >= 1 {
|
|
1450
|
+
if !structuralRemovedItems.isEmpty {
|
|
1451
|
+
var snapshot = dataSource.snapshot()
|
|
1452
|
+
snapshot.deleteItems(Array(structuralRemovedItems.keys))
|
|
1453
|
+
structuralRemovedItems.removeAll()
|
|
1454
|
+
structuralRemovedHeights.removeAll()
|
|
1455
|
+
dataSource.apply(snapshot, animatingDifferences: false)
|
|
1456
|
+
itemsByKey = Dictionary(uniqueKeysWithValues: config.items.map { ($0.key, $0) })
|
|
1457
|
+
collectionView.layoutIfNeeded()
|
|
1458
|
+
if !structuralScrollInterrupted && !collectionView.isTracking
|
|
1459
|
+
&& !collectionView.isDragging && !collectionView.isDecelerating {
|
|
1460
|
+
let inset = collectionView.adjustedContentInset
|
|
1461
|
+
let maximum = max(-inset.top,
|
|
1462
|
+
collectionView.contentSize.height - collectionView.bounds.height + inset.bottom)
|
|
1463
|
+
let target = min(max(-inset.top, structuralTargetOffset), maximum)
|
|
1464
|
+
// Cancel UIKit's residual content-shrink scroll animation after deleting retired rows.
|
|
1465
|
+
collectionView.setContentOffset(
|
|
1466
|
+
CGPoint(x: collectionView.contentOffset.x, y: target), animated: false)
|
|
1467
|
+
collectionView.layoutIfNeeded()
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
stopStructuralAnimation()
|
|
1471
|
+
structuralSpacerHeight = 0
|
|
1472
|
+
structuralFooterStartY = nil
|
|
1473
|
+
layoutContainerSlots()
|
|
1474
|
+
emitVisibleRangeIfNeeded()
|
|
1475
|
+
checkEndReached()
|
|
1476
|
+
scheduleContentShrinkCorrection()
|
|
655
1477
|
}
|
|
656
1478
|
}
|
|
657
1479
|
|
|
@@ -714,6 +1536,19 @@ final class NativeListView: UIView {
|
|
|
714
1536
|
}
|
|
715
1537
|
config = current
|
|
716
1538
|
itemsByKey = Dictionary(uniqueKeysWithValues: current.items.map { ($0.key, $0) })
|
|
1539
|
+
itemsByKey.merge(structuralRemovedItems) { current, _ in current }
|
|
1540
|
+
if let tail = structuralTail, !tail.retiringKeys.isEmpty {
|
|
1541
|
+
itemsByKey.merge(Dictionary(uniqueKeysWithValues: tail.items.map { ($0.key, $0) })) {
|
|
1542
|
+
current, _ in current
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
if let tail = structuralTail {
|
|
1546
|
+
for key in changedKeys.union(marketQuoteKeys) {
|
|
1547
|
+
guard let index = tail.indexByKey[key], let item = itemsByKey[key] else { continue }
|
|
1548
|
+
tail.items[index] = item
|
|
1549
|
+
}
|
|
1550
|
+
if sizeChanged { finishStructuralTail(interrupted: true) }
|
|
1551
|
+
}
|
|
717
1552
|
for indexPath in collectionView.indexPathsForVisibleItems {
|
|
718
1553
|
guard let item = item(at: indexPath),
|
|
719
1554
|
marketQuoteKeys.contains(item.key),
|
|
@@ -814,6 +1649,8 @@ final class NativeListView: UIView {
|
|
|
814
1649
|
|
|
815
1650
|
private func requestScroll(_ request: ScrollRequest) {
|
|
816
1651
|
if config != nil && explicitTopForScrollCommand(request) == nil { return }
|
|
1652
|
+
explicitScrollRevision &+= 1
|
|
1653
|
+
if structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
817
1654
|
animatedExplicitScrollCommand = false
|
|
818
1655
|
commandAcceptedForPendingScroll = false
|
|
819
1656
|
acceptScrollCommand(request)
|
|
@@ -977,6 +1814,7 @@ final class NativeListView: UIView {
|
|
|
977
1814
|
guard let self else { return }
|
|
978
1815
|
self.contentShrinkCorrectionScheduled = false
|
|
979
1816
|
guard !self.disposed, self.needsContentShrinkCorrection,
|
|
1817
|
+
self.structuralDisplayLink == nil,
|
|
980
1818
|
!self.collectionView.isTracking, !self.collectionView.isDragging,
|
|
981
1819
|
!self.collectionView.isDecelerating,
|
|
982
1820
|
self.collectionView.refreshControl?.isRefreshing != true,
|
|
@@ -1012,15 +1850,25 @@ final class NativeListView: UIView {
|
|
|
1012
1850
|
flowLayout.scrollDirection = isHorizontal ? .horizontal : .vertical
|
|
1013
1851
|
flowLayout.minimumLineSpacing = config.itemSpacing
|
|
1014
1852
|
flowLayout.minimumInteritemSpacing = config.itemSpacing
|
|
1853
|
+
let sidecarInset = sidecarBaseInset(collectionView.bounds.width)
|
|
1854
|
+
let sidecarSpace = sidecarLayout.map { $0.width + $0.gap } ?? 0
|
|
1855
|
+
let horizontalInset = config.contentPaddingHorizontal + sidecarInset
|
|
1856
|
+
let disclosureHeight = config.disclosure == nil ? 0 :
|
|
1857
|
+
disclosureCVisibleHeight + containerSlotHeights[5] + disclosureInset
|
|
1015
1858
|
flowLayout.sectionInset = UIEdgeInsets(
|
|
1016
1859
|
top: config.contentPaddingTop + containerSlotHeights[0],
|
|
1017
|
-
left:
|
|
1018
|
-
bottom: config.contentPaddingBottom + containerSlotHeights[2]
|
|
1019
|
-
|
|
1860
|
+
left: horizontalInset + (isRightToLeft ? sidecarSpace + indexGutter : 0),
|
|
1861
|
+
bottom: config.contentPaddingBottom + containerSlotHeights[2] + disclosureHeight
|
|
1862
|
+
+ (structuralTail == nil ? structuralSpacerHeight : 0),
|
|
1863
|
+
right: horizontalInset + (isRightToLeft ? 0 : sidecarSpace + indexGutter)
|
|
1020
1864
|
)
|
|
1021
|
-
|
|
1022
|
-
? config.contentPaddingTop + config.contentPaddingBottom
|
|
1865
|
+
let emptyMinimum = config.items.isEmpty
|
|
1866
|
+
? config.contentPaddingTop + config.contentPaddingBottom
|
|
1867
|
+
+ containerSlotHeights.prefix(3).reduce(0, +) + disclosureHeight
|
|
1023
1868
|
: 0
|
|
1869
|
+
let sidecarMinimum = sidecarLayout == nil ? 0 :
|
|
1870
|
+
config.contentPaddingTop + containerSlotHeights[3] + config.contentPaddingBottom
|
|
1871
|
+
flowLayout.minimumContainerContentHeight = max(emptyMinimum, sidecarMinimum)
|
|
1024
1872
|
flowLayout.stickyItemIndexes = config.stickyHeaders
|
|
1025
1873
|
? Set(config.items.enumerated().compactMap {
|
|
1026
1874
|
$0.element.type == "sectionHeader" && $0.element.data.bool("sticky", default: true) && $0.element.data.string("variant") != "summary"
|
|
@@ -1034,6 +1882,7 @@ final class NativeListView: UIView {
|
|
|
1034
1882
|
listBodyGestureGuard.isEnabled = !isHorizontal
|
|
1035
1883
|
collectionView.showsVerticalScrollIndicator = sectionIndexEntries.isEmpty
|
|
1036
1884
|
collectionView.dragInteractionEnabled = false
|
|
1885
|
+
lastConfiguredCollectionWidth = collectionView.bounds.width
|
|
1037
1886
|
lastLayoutDirection = effectiveUserInterfaceLayoutDirection
|
|
1038
1887
|
}
|
|
1039
1888
|
|
|
@@ -1371,6 +2220,10 @@ final class NativeListView: UIView {
|
|
|
1371
2220
|
return config?.items[safe: indexPath.item]
|
|
1372
2221
|
}
|
|
1373
2222
|
|
|
2223
|
+
private func isInertPresentationKey(_ key: String) -> Bool {
|
|
2224
|
+
structuralTail?.indexByKey[key] != nil || structuralRemovedItems[key] != nil
|
|
2225
|
+
}
|
|
2226
|
+
|
|
1374
2227
|
private func updateAtomicReorderTarget(to targetIndex: Int, key targetKey: String, animated: Bool) {
|
|
1375
2228
|
guard let source = interactiveReorderSource else { return }
|
|
1376
2229
|
interactiveReorderTargetIndex = targetIndex
|
|
@@ -1714,11 +2567,23 @@ final class NativeListView: UIView {
|
|
|
1714
2567
|
if item.key == interactiveReorderCompactKey {
|
|
1715
2568
|
cell.setWalletGroupReorderCompact(true)
|
|
1716
2569
|
}
|
|
2570
|
+
let retiring = structuralRemovedItems[item.key] != nil
|
|
2571
|
+
cell.structuralContentHeight = retiring
|
|
2572
|
+
? rowHeight(item, allocatedWidth: cell.bounds.width) : nil
|
|
2573
|
+
if retiring { cell.clipsToBounds = true }
|
|
2574
|
+
cell.alpha = retiring ? 1 - structuralRemovalProgress : 1
|
|
2575
|
+
cell.isUserInteractionEnabled = !retiring && !item.data.bool("disabled")
|
|
2576
|
+
cell.layer.mask = nil
|
|
2577
|
+
cell.isHidden = false
|
|
2578
|
+
cell.accessibilityElementsHidden = false
|
|
2579
|
+
if let structuralTail, let itemIndex {
|
|
2580
|
+
presentTailCell(cell, key: item.key, index: itemIndex, tail: structuralTail)
|
|
2581
|
+
}
|
|
1717
2582
|
}
|
|
1718
2583
|
|
|
1719
2584
|
private func handleRowPress(_ item: NativeListItem, origin: NativeListActionOrigin?) {
|
|
1720
2585
|
// OneKey patch: missing-address rows keep accessory actions available.
|
|
1721
|
-
guard let config, item.isRowPressEnabled else { return }
|
|
2586
|
+
guard let config, item.isRowPressEnabled, !isInertPresentationKey(item.key) else { return }
|
|
1722
2587
|
if config.rowPressToggles && item.isSelectable && config.selectionMode != "none" {
|
|
1723
2588
|
updateSelection(target: NativeSelectionTarget(scope: "row", key: item.key), sourceKey: item.key)
|
|
1724
2589
|
return
|
|
@@ -1738,8 +2603,8 @@ final class NativeListView: UIView {
|
|
|
1738
2603
|
guard gesture.state == .began else { return }
|
|
1739
2604
|
let point = gesture.location(in: collectionView)
|
|
1740
2605
|
guard let indexPath = collectionView.indexPathForItem(at: point),
|
|
1741
|
-
let item =
|
|
1742
|
-
item.type == "market",
|
|
2606
|
+
let item = item(at: indexPath), !isInertPresentationKey(item.key),
|
|
2607
|
+
(item.type == "market" || item.type == "identity"),
|
|
1743
2608
|
item.isRowPressEnabled else { return }
|
|
1744
2609
|
let actionKey = item.data.string("longPressActionKey")
|
|
1745
2610
|
guard !actionKey.isEmpty else { return }
|
|
@@ -1754,7 +2619,7 @@ final class NativeListView: UIView {
|
|
|
1754
2619
|
target: NativeSelectionTarget?,
|
|
1755
2620
|
origin: NativeListActionOrigin?
|
|
1756
2621
|
) {
|
|
1757
|
-
guard !item.data.bool("disabled") else { return }
|
|
2622
|
+
guard !item.data.bool("disabled"), !isInertPresentationKey(item.key) else { return }
|
|
1758
2623
|
if let target, config?.selectionMode != "none" {
|
|
1759
2624
|
updateSelection(target: target, sourceKey: item.key)
|
|
1760
2625
|
return
|
|
@@ -1763,7 +2628,8 @@ final class NativeListView: UIView {
|
|
|
1763
2628
|
}
|
|
1764
2629
|
|
|
1765
2630
|
private func updateSelection(target: NativeSelectionTarget, sourceKey: String) {
|
|
1766
|
-
guard var current = config, current.selectionMode != "none"
|
|
2631
|
+
guard var current = config, current.selectionMode != "none",
|
|
2632
|
+
!isInertPresentationKey(sourceKey) else { return }
|
|
1767
2633
|
let keys = selectionKeys(target: target, items: current.items)
|
|
1768
2634
|
guard !keys.isEmpty else { return }
|
|
1769
2635
|
let before = current.selectedKeys
|
|
@@ -1824,7 +2690,7 @@ final class NativeListView: UIView {
|
|
|
1824
2690
|
self?.resolveCheckboxState(item: item, target: target, fallback: fallback) ?? fallback
|
|
1825
2691
|
}
|
|
1826
2692
|
for indexPath in collectionView.indexPathsForVisibleItems {
|
|
1827
|
-
guard let item = item(at: indexPath),
|
|
2693
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key),
|
|
1828
2694
|
let cell = collectionView.cellForItem(at: indexPath) as? NativeListRowHost else { continue }
|
|
1829
2695
|
if changedSummaryKeys.contains(item.key) {
|
|
1830
2696
|
bind(cell: cell, item: item, itemIndex: indexPath.item)
|
|
@@ -2175,6 +3041,12 @@ final class NativeListView: UIView {
|
|
|
2175
3041
|
dataSource = nil
|
|
2176
3042
|
|
|
2177
3043
|
config = nil
|
|
3044
|
+
pagerStickyHeights.removeAllObjects()
|
|
3045
|
+
for slot in reactContainerSlots { slot.host.layer.mask = nil }
|
|
3046
|
+
stopStructuralAnimation()
|
|
3047
|
+
clearStructuralTail()
|
|
3048
|
+
structuralSpacerHeight = 0
|
|
3049
|
+
structuralFooterStartY = nil
|
|
2178
3050
|
itemsByKey.removeAll()
|
|
2179
3051
|
sectionIndexEntries.removeAll()
|
|
2180
3052
|
if let pagerCommandCancelObserver {
|
|
@@ -2193,8 +3065,10 @@ final class NativeListView: UIView {
|
|
|
2193
3065
|
onSelectionDelta = nil
|
|
2194
3066
|
onReorder = nil
|
|
2195
3067
|
onEndReached = nil
|
|
3068
|
+
onStructuralTransitionSettled = nil
|
|
2196
3069
|
onVisibleRangeChanged = nil
|
|
2197
3070
|
onScrollPositionThresholdChange = nil
|
|
3071
|
+
pendingDisclosureSettlement = nil
|
|
2198
3072
|
}
|
|
2199
3073
|
|
|
2200
3074
|
private func createActionAnchor(origin: NativeListActionOrigin) -> [String: Any]? {
|
|
@@ -2290,8 +3164,9 @@ final class NativeListView: UIView {
|
|
|
2290
3164
|
DispatchQueue.main.async { [weak self] in
|
|
2291
3165
|
guard let self else { return }
|
|
2292
3166
|
self.visibleEventScheduled = false
|
|
2293
|
-
guard
|
|
2294
|
-
|
|
3167
|
+
guard self.structuralRemovedItems.isEmpty,
|
|
3168
|
+
let onVisibleRangeChanged = self.onVisibleRangeChanged else { return }
|
|
3169
|
+
let indexes = self.acceptedVisibleIndexes()
|
|
2295
3170
|
let first = indexes.first ?? -1
|
|
2296
3171
|
let last = indexes.last ?? -1
|
|
2297
3172
|
let firstKey = self.config?.items[safe: first]?.key
|
|
@@ -2309,11 +3184,11 @@ final class NativeListView: UIView {
|
|
|
2309
3184
|
}
|
|
2310
3185
|
|
|
2311
3186
|
private func checkEndReached() {
|
|
2312
|
-
guard let config,
|
|
3187
|
+
guard let config, structuralRemovedItems.isEmpty,
|
|
2313
3188
|
config.loadMore,
|
|
2314
3189
|
endReachedGeneration != config.generation,
|
|
2315
3190
|
!config.items.isEmpty else { return }
|
|
2316
|
-
let lastVisible =
|
|
3191
|
+
let lastVisible = acceptedVisibleIndexes().last ?? -1
|
|
2317
3192
|
let threshold = max(1, Int(ceil(Double(config.items.count) * config.endReachedThreshold)))
|
|
2318
3193
|
guard lastVisible >= config.items.count - threshold else { return }
|
|
2319
3194
|
endReachedGeneration = config.generation
|
|
@@ -2322,6 +3197,18 @@ final class NativeListView: UIView {
|
|
|
2322
3197
|
emit(onEndReached, payload)
|
|
2323
3198
|
}
|
|
2324
3199
|
|
|
3200
|
+
private func acceptedVisibleIndexes() -> [Int] {
|
|
3201
|
+
guard let config else { return [] }
|
|
3202
|
+
let presentedPrefix = structuralTail?.prefixCount
|
|
3203
|
+
return collectionView.indexPathsForVisibleItems.compactMap { indexPath in
|
|
3204
|
+
guard presentedPrefix.map({ indexPath.item < $0 }) ?? true,
|
|
3205
|
+
let item = config.items[safe: indexPath.item],
|
|
3206
|
+
dataSource.itemIdentifier(for: indexPath) == item.key,
|
|
3207
|
+
let cell = collectionView.cellForItem(at: indexPath), !cell.isHidden else { return nil }
|
|
3208
|
+
return indexPath.item
|
|
3209
|
+
}.sorted()
|
|
3210
|
+
}
|
|
3211
|
+
|
|
2325
3212
|
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
|
|
2326
3213
|
if gestureRecognizer === keyboardDragRecognizer {
|
|
2327
3214
|
return keyboardDismissMode == .onDrag && focusedTextInput(in: window) != nil
|
|
@@ -2329,12 +3216,13 @@ final class NativeListView: UIView {
|
|
|
2329
3216
|
if gestureRecognizer === reorderLongPress || gestureRecognizer === marketLongPress {
|
|
2330
3217
|
let point = gestureRecognizer.location(in: collectionView)
|
|
2331
3218
|
guard let indexPath = collectionView.indexPathForItem(at: point),
|
|
2332
|
-
let item = item(at: indexPath),
|
|
3219
|
+
let item = item(at: indexPath), !isInertPresentationKey(item.key),
|
|
2333
3220
|
!item.data.bool("disabled") else { return false }
|
|
2334
3221
|
if gestureRecognizer === reorderLongPress {
|
|
2335
3222
|
return config?.reorderable == true && item.isReorderable
|
|
2336
3223
|
}
|
|
2337
|
-
return item.type == "market"
|
|
3224
|
+
return (item.type == "market" || item.type == "identity")
|
|
3225
|
+
&& item.isRowPressEnabled && !item.data.string("longPressActionKey").isEmpty
|
|
2338
3226
|
}
|
|
2339
3227
|
guard gestureRecognizer === listBodyGestureGuard,
|
|
2340
3228
|
let pan = gestureRecognizer as? UIPanGestureRecognizer else { return true }
|
|
@@ -2445,14 +3333,16 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2445
3333
|
return CGSize(width: width, height: height)
|
|
2446
3334
|
}
|
|
2447
3335
|
let available = max(0, collectionView.bounds.width - insets.left - insets.right)
|
|
2448
|
-
let structural = item.type == "sectionHeader" || item.type == "system" || item.type == "action"
|
|
3336
|
+
let structural = item.type == "sectionHeader" || item.type == "system" || item.type == "action" || item.type == "buttonGroup"
|
|
2449
3337
|
if config.layout == "grid", !structural {
|
|
2450
3338
|
let spacing = CGFloat(config.gridColumns - 1) * config.itemSpacing
|
|
2451
3339
|
let width = floor((available - spacing) / CGFloat(config.gridColumns))
|
|
2452
3340
|
let height = item.styledHeight ?? (item.type == "mediaTile" && item.data["height"] == nil ? width + 48 : rowHeight(item, allocatedWidth: width))
|
|
2453
3341
|
return CGSize(width: width, height: height)
|
|
2454
3342
|
}
|
|
2455
|
-
|
|
3343
|
+
let height = structuralRemovedHeights[item.key].map { $0 * (1 - structuralRemovalProgress) }
|
|
3344
|
+
?? rowHeight(item, allocatedWidth: available)
|
|
3345
|
+
return CGSize(width: available, height: max(0.01, height))
|
|
2456
3346
|
}
|
|
2457
3347
|
|
|
2458
3348
|
private func railWidth(_ item: NativeListItem) -> CGFloat {
|
|
@@ -2460,19 +3350,20 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2460
3350
|
}
|
|
2461
3351
|
|
|
2462
3352
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
2463
|
-
guard let item =
|
|
3353
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key) else { return }
|
|
2464
3354
|
if item.type == "walletGroup" { return }
|
|
2465
3355
|
let origin = (collectionView.cellForItem(at: indexPath) as? NativeListRowHost)?.rowActionOrigin()
|
|
2466
3356
|
handleRowPress(item, origin: origin)
|
|
2467
3357
|
}
|
|
2468
3358
|
|
|
2469
3359
|
func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool {
|
|
2470
|
-
guard let item =
|
|
3360
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key) else { return false }
|
|
2471
3361
|
return item.isRowPressEnabled
|
|
2472
3362
|
}
|
|
2473
3363
|
|
|
2474
3364
|
func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
|
|
2475
|
-
guard let item =
|
|
3365
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key),
|
|
3366
|
+
item.type == "market" else { return }
|
|
2476
3367
|
let actionKey = item.data.string("pressInActionKey")
|
|
2477
3368
|
guard !actionKey.isEmpty else { return }
|
|
2478
3369
|
let origin = (collectionView.cellForItem(at: indexPath) as? NativeListRowHost)?.rowActionOrigin()
|
|
@@ -2480,7 +3371,7 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2480
3371
|
}
|
|
2481
3372
|
|
|
2482
3373
|
func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
|
2483
|
-
guard let item =
|
|
3374
|
+
guard let item = item(at: indexPath), !isInertPresentationKey(item.key) else { return false }
|
|
2484
3375
|
return item.isRowPressEnabled
|
|
2485
3376
|
}
|
|
2486
3377
|
|
|
@@ -2492,6 +3383,15 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
|
|
|
2492
3383
|
}
|
|
2493
3384
|
|
|
2494
3385
|
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
|
|
3386
|
+
if structuralDisplayLink != nil {
|
|
3387
|
+
structuralScrollInterrupted = true
|
|
3388
|
+
if structuralTail != nil { finishStructuralTail(interrupted: true) }
|
|
3389
|
+
else {
|
|
3390
|
+
NotificationCenter.default.post(name: Notification.Name("OneKeyNativeListScrollCommandAccepted"),
|
|
3391
|
+
object: collectionView, userInfo: ["phase": 2])
|
|
3392
|
+
structuralScrollPhaseActive = false
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
2495
3395
|
scrollViewDidEndScrollingAnimation(scrollView)
|
|
2496
3396
|
minimumDragOffset = 0
|
|
2497
3397
|
refreshEmittedForDrag = false
|
|
@@ -2530,7 +3430,7 @@ extension NativeListView: UICollectionViewDragDelegate, UICollectionViewDropDele
|
|
|
2530
3430
|
itemsForBeginning session: UIDragSession,
|
|
2531
3431
|
at indexPath: IndexPath
|
|
2532
3432
|
) -> [UIDragItem] {
|
|
2533
|
-
guard config?.reorderable == true,
|
|
3433
|
+
guard config?.reorderable == true, structuralDisplayLink == nil,
|
|
2534
3434
|
let item = config?.items[safe: indexPath.item],
|
|
2535
3435
|
item.isReorderable else { return [] }
|
|
2536
3436
|
let dragItem = UIDragItem(itemProvider: NSItemProvider(object: item.key as NSString))
|
|
@@ -2602,12 +3502,26 @@ private final class NativeListCollectionView: UICollectionView {
|
|
|
2602
3502
|
}
|
|
2603
3503
|
}
|
|
2604
3504
|
|
|
3505
|
+
private final class NativeListClippedSlotHost: UIView {
|
|
3506
|
+
var visibleTop: CGFloat = 0
|
|
3507
|
+
var visibleBottom: CGFloat?
|
|
3508
|
+
|
|
3509
|
+
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
|
3510
|
+
super.point(inside: point, with: event) && point.y >= visibleTop
|
|
3511
|
+
&& point.y < (visibleBottom ?? bounds.height)
|
|
3512
|
+
}
|
|
3513
|
+
}
|
|
3514
|
+
|
|
2605
3515
|
final class NativeListFlowLayout: UICollectionViewFlowLayout {
|
|
2606
3516
|
var stickyItemIndexes: Set<Int> = []
|
|
2607
3517
|
var minimumContainerContentHeight: CGFloat = 0
|
|
3518
|
+
var animatedBodyContentHeight: CGFloat?
|
|
3519
|
+
var tailClip: (firstIndex: Int, endY: CGFloat)?
|
|
3520
|
+
var bodyContentHeight: CGFloat {
|
|
3521
|
+
animatedBodyContentHeight ?? super.collectionViewContentSize.height
|
|
3522
|
+
}
|
|
2608
3523
|
private var horizontalAttributes: [IndexPath: UICollectionViewLayoutAttributes] = [:]
|
|
2609
3524
|
private var horizontalContentSize: CGSize = .zero
|
|
2610
|
-
|
|
2611
3525
|
override func prepare() {
|
|
2612
3526
|
super.prepare()
|
|
2613
3527
|
horizontalAttributes.removeAll(keepingCapacity: true)
|
|
@@ -2635,7 +3549,7 @@ final class NativeListFlowLayout: UICollectionViewFlowLayout {
|
|
|
2635
3549
|
override var collectionViewContentSize: CGSize {
|
|
2636
3550
|
if scrollDirection == .horizontal { return horizontalContentSize }
|
|
2637
3551
|
let size = super.collectionViewContentSize
|
|
2638
|
-
return CGSize(width: size.width, height: max(
|
|
3552
|
+
return CGSize(width: size.width, height: max(bodyContentHeight, minimumContainerContentHeight))
|
|
2639
3553
|
}
|
|
2640
3554
|
|
|
2641
3555
|
override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
|
|
@@ -2672,10 +3586,17 @@ final class NativeListFlowLayout: UICollectionViewFlowLayout {
|
|
|
2672
3586
|
.filter { $0.frame.intersects(rect) }
|
|
2673
3587
|
.sorted { $0.indexPath.item < $1.indexPath.item }
|
|
2674
3588
|
}
|
|
2675
|
-
guard scrollDirection == .vertical,
|
|
2676
|
-
!stickyItemIndexes.isEmpty,
|
|
2677
|
-
let collectionView else { return super.layoutAttributesForElements(in: rect) }
|
|
2678
3589
|
let base = super.layoutAttributesForElements(in: rect)?.compactMap { $0.copy() as? UICollectionViewLayoutAttributes } ?? []
|
|
3590
|
+
guard scrollDirection == .vertical else { return base }
|
|
3591
|
+
let clipped = base.filter { attributes in
|
|
3592
|
+
guard let tailClip, attributes.representedElementCategory == .cell,
|
|
3593
|
+
attributes.indexPath.item >= tailClip.firstIndex else { return true }
|
|
3594
|
+
return attributes.frame.minY < tailClip.endY
|
|
3595
|
+
}
|
|
3596
|
+
guard !stickyItemIndexes.isEmpty,
|
|
3597
|
+
let collectionView else {
|
|
3598
|
+
return clipped
|
|
3599
|
+
}
|
|
2679
3600
|
let pinY = collectionView.contentOffset.y + collectionView.adjustedContentInset.top
|
|
2680
3601
|
// Visible cells can still describe the old viewport during an imperative
|
|
2681
3602
|
// scroll. Resolve the pinned header from unmodified layout positions.
|
|
@@ -2684,20 +3605,30 @@ final class NativeListFlowLayout: UICollectionViewFlowLayout {
|
|
|
2684
3605
|
return attributes.frame.minY <= pinY
|
|
2685
3606
|
}).max(),
|
|
2686
3607
|
let original = super.layoutAttributesForItem(at: IndexPath(item: stickyIndex, section: 0)),
|
|
2687
|
-
let sticky = original.copy() as? UICollectionViewLayoutAttributes else {
|
|
3608
|
+
let sticky = original.copy() as? UICollectionViewLayoutAttributes else {
|
|
3609
|
+
return clipped
|
|
3610
|
+
}
|
|
2688
3611
|
let nextHeaderY = stickyItemIndexes
|
|
2689
3612
|
.filter { $0 > stickyIndex }
|
|
2690
3613
|
.min()
|
|
2691
3614
|
.flatMap { super.layoutAttributesForItem(at: IndexPath(item: $0, section: 0))?.frame.minY }
|
|
2692
3615
|
sticky.frame.origin.y = min(max(pinY, original.frame.minY), (nextHeaderY ?? .greatestFiniteMagnitude) - sticky.frame.height)
|
|
2693
3616
|
sticky.zIndex = 10_000
|
|
2694
|
-
let filtered =
|
|
2695
|
-
|
|
3617
|
+
let filtered = clipped.filter { $0.indexPath != sticky.indexPath }
|
|
3618
|
+
let returned = filtered + [sticky]
|
|
3619
|
+
return returned
|
|
2696
3620
|
}
|
|
2697
3621
|
|
|
2698
3622
|
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
|
|
2699
3623
|
if scrollDirection == .horizontal { return horizontalAttributes[indexPath] }
|
|
2700
|
-
|
|
3624
|
+
guard let attributes = super.layoutAttributesForItem(at: indexPath) else {
|
|
3625
|
+
return nil
|
|
3626
|
+
}
|
|
3627
|
+
if let tailClip, indexPath.item >= tailClip.firstIndex,
|
|
3628
|
+
attributes.frame.minY >= tailClip.endY {
|
|
3629
|
+
return nil
|
|
3630
|
+
}
|
|
3631
|
+
return attributes
|
|
2701
3632
|
}
|
|
2702
3633
|
|
|
2703
3634
|
}
|