@onekeyfe/react-native-native-list 6.8.0-6 → 6.8.0-8
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/docs/SPEC.md +32 -0
- package/ios/RNCNativeListView.swift +79 -25
- package/ios/tests/NativeListLifecycleTests.swift +152 -2
- package/package.json +1 -1
package/docs/SPEC.md
CHANGED
|
@@ -553,6 +553,38 @@ image that already loaded. Common container styling clears what it wrote on the
|
|
|
553
553
|
next bind, including properties it set on template children. UI mutation remains on the platform
|
|
554
554
|
UI thread; [DESIGN.md](DESIGN.md) describes update and event ownership.
|
|
555
555
|
|
|
556
|
+
### iOS cell requests during snapshot replacement
|
|
557
|
+
|
|
558
|
+
Status: implemented, unreleased. On iOS 17.5 and 26.0, a focused UIKit fixture
|
|
559
|
+
reproduced the assertion on version 6.7.0-62 and completed the same layout
|
|
560
|
+
with the fix. Three focused UIKit tests passed on both runtimes, including
|
|
561
|
+
fixed-footer action routing. Consuming-app acceptance of the fix remains
|
|
562
|
+
pending.
|
|
563
|
+
|
|
564
|
+
When a snapshot removes rows, UIKit may request cells from its outgoing
|
|
565
|
+
snapshot while the new logical rows are already active. The iOS host MUST
|
|
566
|
+
provide a valid reusable cell for such requests. Until UIKit completes the
|
|
567
|
+
removal, the host retains only the removed row descriptors needed for pending
|
|
568
|
+
snapshot applications. These descriptors are presentation-only and cannot
|
|
569
|
+
emit actions, expose accessibility elements, or become selectable. Repeated
|
|
570
|
+
updates must preserve the descriptors still needed by in-flight applications
|
|
571
|
+
and must release them on completion or host disposal. A request with no
|
|
572
|
+
available descriptor receives an inert empty cell. The accepted snapshot,
|
|
573
|
+
patch validation, row identity, and structural-transition behavior retain
|
|
574
|
+
their existing contracts.
|
|
575
|
+
|
|
576
|
+
The action and interaction restrictions apply to the presenting collection
|
|
577
|
+
row. Its top-level key determines whether its actions can be delivered,
|
|
578
|
+
including actions whose payload comes from a child renderer. The fixed footer
|
|
579
|
+
is a separate host and retains its normal interaction, even when it shares a
|
|
580
|
+
key with a retiring row.
|
|
581
|
+
|
|
582
|
+
Conformance scrolls an unmaterialized outgoing row into UIKit's viewport
|
|
583
|
+
during removal and checks its renderer, inert state, and the binding of the
|
|
584
|
+
first filtered row. It also covers fixed-footer actions with a shared key
|
|
585
|
+
during a structural transition. A separate consuming-app check covers address
|
|
586
|
+
input in the Send recipient picker.
|
|
587
|
+
|
|
556
588
|
### Android vertical-drag React touch cancellation
|
|
557
589
|
|
|
558
590
|
Status: implemented; four real Android MotionEvent/JSTouchDispatcher regressions
|
|
@@ -199,8 +199,10 @@ final class NativeListView: UIView {
|
|
|
199
199
|
if !tail.retiringKeys.isEmpty {
|
|
200
200
|
var snapshot = dataSource.snapshot()
|
|
201
201
|
snapshot.deleteItems(Array(tail.retiringKeys))
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
let finishRetiringCells = replaceCellItems(
|
|
203
|
+
with: Dictionary(uniqueKeysWithValues: config.items.map { ($0.key, $0) }),
|
|
204
|
+
outgoingKeys: tail.retiringKeys)
|
|
205
|
+
dataSource.apply(snapshot, animatingDifferences: false, completion: finishRetiringCells)
|
|
204
206
|
}
|
|
205
207
|
clearStructuralTail()
|
|
206
208
|
structuralSpacerHeight = 0
|
|
@@ -701,6 +703,9 @@ final class NativeListView: UIView {
|
|
|
701
703
|
private var config: NativeListConfig?
|
|
702
704
|
private var acceptedRowIndex: AcceptedRowIndex?
|
|
703
705
|
private var itemsByKey: [String: NativeListItem] = [:]
|
|
706
|
+
private static let emptyCellReuseIdentifier = "NativeList.EmptyCell"
|
|
707
|
+
private var retiringCellItems: [String: (item: NativeListItem, update: UInt64)] = [:]
|
|
708
|
+
private var cellUpdate: UInt64 = 0
|
|
704
709
|
private var endReachedGeneration: Int?
|
|
705
710
|
private var lastVisibleRange: (first: Int, last: Int, firstKey: String?, lastKey: String?)?
|
|
706
711
|
private var visibleEventScheduled = false
|
|
@@ -777,6 +782,8 @@ final class NativeListView: UIView {
|
|
|
777
782
|
self.collectionView.setContentOffset(self.collectionView.contentOffset, animated: false)
|
|
778
783
|
}
|
|
779
784
|
NativeListRendererRegistry.register(in: collectionView)
|
|
785
|
+
collectionView.register(UICollectionViewCell.self,
|
|
786
|
+
forCellWithReuseIdentifier: Self.emptyCellReuseIdentifier)
|
|
780
787
|
collectionView.backgroundColor = .clear
|
|
781
788
|
collectionView.delegate = self
|
|
782
789
|
collectionView.dragDelegate = self
|
|
@@ -873,14 +880,30 @@ final class NativeListView: UIView {
|
|
|
873
880
|
footerCell.addGestureRecognizer(footerHighlight)
|
|
874
881
|
dataSource = UICollectionViewDiffableDataSource<Int, String>(collectionView: collectionView) {
|
|
875
882
|
[weak self] collectionView, indexPath, key in
|
|
876
|
-
guard let self,
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
883
|
+
guard let self, let item = self.itemsByKey[key] ?? self.retiringCellItems[key]?.item else {
|
|
884
|
+
let cell = collectionView.dequeueReusableCell(
|
|
885
|
+
withReuseIdentifier: NativeListView.emptyCellReuseIdentifier, for: indexPath)
|
|
886
|
+
cell.isUserInteractionEnabled = false
|
|
887
|
+
cell.accessibilityElementsHidden = true
|
|
888
|
+
return cell
|
|
889
|
+
}
|
|
890
|
+
let reusableCell = collectionView.dequeueReusableCell(
|
|
891
|
+
withReuseIdentifier: NativeListRendererRegistry.reuseIdentifier(for: item.rendererKey),
|
|
892
|
+
for: indexPath)
|
|
893
|
+
guard let cell = reusableCell as? NativeListRowHost else { return reusableCell }
|
|
894
|
+
if self.itemsByKey[key] == nil {
|
|
895
|
+
cell.onAction = nil
|
|
896
|
+
cell.onBindingInvalidated = nil
|
|
897
|
+
cell.isHidden = true
|
|
898
|
+
cell.isUserInteractionEnabled = false
|
|
899
|
+
cell.accessibilityElementsHidden = true
|
|
900
|
+
return cell
|
|
901
|
+
}
|
|
882
902
|
cell.onAction = { [weak self] item, action, target, origin in
|
|
883
|
-
|
|
903
|
+
// A child renderer can emit a different key than the collection row that owns it.
|
|
904
|
+
guard let self, self.itemsByKey[key] != nil,
|
|
905
|
+
!self.isInertPresentationKey(key) else { return }
|
|
906
|
+
self.handleAction(item: item, actionKey: action, target: target, origin: origin)
|
|
884
907
|
}
|
|
885
908
|
cell.onBindingInvalidated = { [weak self] cell, epoch in
|
|
886
909
|
self?.handleBindingInvalidated(cell: cell, epoch: epoch)
|
|
@@ -1054,6 +1077,29 @@ final class NativeListView: UIView {
|
|
|
1054
1077
|
acceptedRowIndex = AcceptedRowIndex(items: next.items)
|
|
1055
1078
|
}
|
|
1056
1079
|
|
|
1080
|
+
// Layout can ask UIKit's outgoing snapshot for cells before apply starts or while it settles.
|
|
1081
|
+
// Keep those descriptors outside the accepted row lookup and release each at its own commit.
|
|
1082
|
+
private func replaceCellItems(
|
|
1083
|
+
with nextItems: [String: NativeListItem], outgoingKeys: some Sequence<String>
|
|
1084
|
+
) -> (() -> Void)? {
|
|
1085
|
+
cellUpdate &+= 1
|
|
1086
|
+
let update = cellUpdate
|
|
1087
|
+
var retiringKeys: [String] = []
|
|
1088
|
+
for key in outgoingKeys where nextItems[key] == nil {
|
|
1089
|
+
guard let item = itemsByKey[key] ?? retiringCellItems[key]?.item else { continue }
|
|
1090
|
+
retiringCellItems[key] = (item, update)
|
|
1091
|
+
retiringKeys.append(key)
|
|
1092
|
+
}
|
|
1093
|
+
itemsByKey = nextItems
|
|
1094
|
+
guard !retiringKeys.isEmpty else { return nil }
|
|
1095
|
+
return { [weak self] in
|
|
1096
|
+
guard let self else { return }
|
|
1097
|
+
for key in retiringKeys where self.retiringCellItems[key]?.update == update {
|
|
1098
|
+
self.retiringCellItems.removeValue(forKey: key)
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1057
1103
|
func applySnapshotJson(_ json: String) {
|
|
1058
1104
|
guard let next = try? NativeListConfig.parse(json: json) else { return }
|
|
1059
1105
|
let transition = next.structuralTransition
|
|
@@ -1244,13 +1290,14 @@ final class NativeListView: UIView {
|
|
|
1244
1290
|
disclosureInset = next.disclosure?.expanded == true
|
|
1245
1291
|
? next.disclosure?.expandedTrailingInset ?? 0 : 0
|
|
1246
1292
|
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1293
|
+
var nextItemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
|
|
1294
|
+
nextItemsByKey.merge(structuralRemovedItems) { current, _ in current }
|
|
1249
1295
|
if let tail = structuralTail, !tail.retiringKeys.isEmpty {
|
|
1250
|
-
|
|
1296
|
+
nextItemsByKey.merge(presentationItems.filter { tail.retiringKeys.contains($0.key) }) {
|
|
1251
1297
|
current, _ in current
|
|
1252
1298
|
}
|
|
1253
1299
|
}
|
|
1300
|
+
let finishRetiringCells = replaceCellItems(with: nextItemsByKey, outgoingKeys: oldKeys)
|
|
1254
1301
|
if !animateStructure, let tail = structuralTail {
|
|
1255
1302
|
if themeChanged || tailGeometryChanged {
|
|
1256
1303
|
if !newDisclosureCommand { interruptedPendingID = activePendingID }
|
|
@@ -1341,7 +1388,8 @@ final class NativeListView: UIView {
|
|
|
1341
1388
|
let explicitScrollPendingAtApply = pendingScrollRequest != nil
|
|
1342
1389
|
dataSource.apply(snapshot, animatingDifferences: animateStructure && structuralRemovedItems.isEmpty
|
|
1343
1390
|
&& structuralTail == nil) { [weak self] in
|
|
1344
|
-
|
|
1391
|
+
finishRetiringCells?()
|
|
1392
|
+
guard let self, !self.disposed else { return }
|
|
1345
1393
|
self.collectionView.layoutIfNeeded()
|
|
1346
1394
|
self.updateStructuralTailWindow()
|
|
1347
1395
|
self.layoutContainerSlots()
|
|
@@ -1510,11 +1558,14 @@ final class NativeListView: UIView {
|
|
|
1510
1558
|
if progress >= 1 {
|
|
1511
1559
|
if !structuralRemovedItems.isEmpty {
|
|
1512
1560
|
var snapshot = dataSource.snapshot()
|
|
1513
|
-
|
|
1561
|
+
let outgoingKeys = Array(structuralRemovedItems.keys)
|
|
1562
|
+
snapshot.deleteItems(outgoingKeys)
|
|
1514
1563
|
structuralRemovedItems.removeAll()
|
|
1515
1564
|
structuralRemovedHeights.removeAll()
|
|
1516
|
-
|
|
1517
|
-
|
|
1565
|
+
let finishRetiringCells = replaceCellItems(
|
|
1566
|
+
with: Dictionary(uniqueKeysWithValues: config.items.map { ($0.key, $0) }),
|
|
1567
|
+
outgoingKeys: outgoingKeys)
|
|
1568
|
+
dataSource.apply(snapshot, animatingDifferences: false, completion: finishRetiringCells)
|
|
1518
1569
|
collectionView.layoutIfNeeded()
|
|
1519
1570
|
if !structuralScrollInterrupted && !collectionView.isTracking
|
|
1520
1571
|
&& !collectionView.isDragging && !collectionView.isDecelerating {
|
|
@@ -2280,7 +2331,9 @@ final class NativeListView: UIView {
|
|
|
2280
2331
|
// while the diffable snapshot and cell index paths keep the pre-drag order until
|
|
2281
2332
|
// the move commits. Resolving sizes from the snapshot swaps row heights.
|
|
2282
2333
|
private func layoutItem(at indexPath: IndexPath) -> NativeListItem? {
|
|
2283
|
-
guard let keys = interactiveMovementKeys else {
|
|
2334
|
+
guard let keys = interactiveMovementKeys else {
|
|
2335
|
+
return item(at: indexPath, includeRetiringCell: true)
|
|
2336
|
+
}
|
|
2284
2337
|
return keys[safe: indexPath.item].flatMap { itemsByKey[$0] }
|
|
2285
2338
|
}
|
|
2286
2339
|
|
|
@@ -2293,15 +2346,16 @@ final class NativeListView: UIView {
|
|
|
2293
2346
|
interactiveMovementKeys = keys
|
|
2294
2347
|
}
|
|
2295
2348
|
|
|
2296
|
-
private func item(at indexPath: IndexPath) -> NativeListItem? {
|
|
2297
|
-
if let key = dataSource.itemIdentifier(for: indexPath)
|
|
2298
|
-
return item
|
|
2349
|
+
private func item(at indexPath: IndexPath, includeRetiringCell: Bool = false) -> NativeListItem? {
|
|
2350
|
+
if let key = dataSource.itemIdentifier(for: indexPath) {
|
|
2351
|
+
return itemsByKey[key] ?? (includeRetiringCell ? retiringCellItems[key]?.item : nil)
|
|
2299
2352
|
}
|
|
2300
2353
|
return config?.items[safe: indexPath.item]
|
|
2301
2354
|
}
|
|
2302
2355
|
|
|
2303
2356
|
private func isInertPresentationKey(_ key: String) -> Bool {
|
|
2304
2357
|
structuralTail?.indexByKey[key] != nil || structuralRemovedItems[key] != nil
|
|
2358
|
+
|| (itemsByKey[key] == nil && retiringCellItems[key] != nil)
|
|
2305
2359
|
}
|
|
2306
2360
|
|
|
2307
2361
|
private func updateAtomicReorderTarget(to targetIndex: Int, key targetKey: String, animated: Bool) {
|
|
@@ -2647,7 +2701,7 @@ final class NativeListView: UIView {
|
|
|
2647
2701
|
if item.key == interactiveReorderCompactKey {
|
|
2648
2702
|
cell.setWalletGroupReorderCompact(true)
|
|
2649
2703
|
}
|
|
2650
|
-
let retiring = structuralRemovedItems[item.key] != nil
|
|
2704
|
+
let retiring = cell !== footerCell && structuralRemovedItems[item.key] != nil
|
|
2651
2705
|
cell.structuralContentHeight = retiring
|
|
2652
2706
|
? rowHeight(item, allocatedWidth: cell.bounds.width) : nil
|
|
2653
2707
|
if retiring { cell.clipsToBounds = true }
|
|
@@ -2663,7 +2717,7 @@ final class NativeListView: UIView {
|
|
|
2663
2717
|
|
|
2664
2718
|
private func handleRowPress(_ item: NativeListItem, origin: NativeListActionOrigin?) {
|
|
2665
2719
|
// OneKey patch: missing-address rows keep accessory actions available.
|
|
2666
|
-
guard let config, item.isRowPressEnabled
|
|
2720
|
+
guard let config, item.isRowPressEnabled else { return }
|
|
2667
2721
|
if config.rowPressToggles && item.isSelectable && config.selectionMode != "none" {
|
|
2668
2722
|
updateSelection(target: NativeSelectionTarget(scope: "row", key: item.key), sourceKey: item.key)
|
|
2669
2723
|
return
|
|
@@ -2699,7 +2753,7 @@ final class NativeListView: UIView {
|
|
|
2699
2753
|
target: NativeSelectionTarget?,
|
|
2700
2754
|
origin: NativeListActionOrigin?
|
|
2701
2755
|
) {
|
|
2702
|
-
guard !item.data.bool("disabled")
|
|
2756
|
+
guard !item.data.bool("disabled") else { return }
|
|
2703
2757
|
if let target, config?.selectionMode != "none" {
|
|
2704
2758
|
updateSelection(target: target, sourceKey: item.key)
|
|
2705
2759
|
return
|
|
@@ -2708,8 +2762,7 @@ final class NativeListView: UIView {
|
|
|
2708
2762
|
}
|
|
2709
2763
|
|
|
2710
2764
|
private func updateSelection(target: NativeSelectionTarget, sourceKey: String) {
|
|
2711
|
-
guard var current = config, current.selectionMode != "none"
|
|
2712
|
-
!isInertPresentationKey(sourceKey) else { return }
|
|
2765
|
+
guard var current = config, current.selectionMode != "none" else { return }
|
|
2713
2766
|
let keys = selectionKeys(target: target, items: current.items)
|
|
2714
2767
|
guard !keys.isEmpty else { return }
|
|
2715
2768
|
let before = current.selectedKeys
|
|
@@ -3133,6 +3186,7 @@ final class NativeListView: UIView {
|
|
|
3133
3186
|
structuralSpacerHeight = 0
|
|
3134
3187
|
structuralFooterStartY = nil
|
|
3135
3188
|
itemsByKey.removeAll()
|
|
3189
|
+
retiringCellItems.removeAll()
|
|
3136
3190
|
sectionIndexEntries.removeAll()
|
|
3137
3191
|
if let pagerCommandCancelObserver {
|
|
3138
3192
|
NotificationCenter.default.removeObserver(pagerCommandCancelObserver)
|
|
@@ -1,9 +1,97 @@
|
|
|
1
|
+
import ObjectiveC
|
|
1
2
|
import UIKit
|
|
2
3
|
import XCTest
|
|
3
4
|
@testable import NativeListModule
|
|
4
5
|
|
|
5
6
|
@MainActor
|
|
6
7
|
final class NativeListLifecycleTests: XCTestCase {
|
|
8
|
+
func testFilteredSnapshotSuppliesCellsDuringOutgoingUIKitLayout() throws {
|
|
9
|
+
let view = NativeListView(frame: CGRect(x: 0, y: 0, width: 390, height: 697))
|
|
10
|
+
let window = UIWindow(frame: view.frame)
|
|
11
|
+
let controller = UIViewController()
|
|
12
|
+
window.rootViewController = controller
|
|
13
|
+
window.makeKeyAndVisible()
|
|
14
|
+
controller.view.addSubview(view)
|
|
15
|
+
defer {
|
|
16
|
+
view.dispose()
|
|
17
|
+
window.isHidden = true
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let collection = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
21
|
+
let dataSource = try XCTUnwrap(collection.dataSource as? UICollectionViewDiffableDataSource<Int, String>)
|
|
22
|
+
collection.isPrefetchingEnabled = false
|
|
23
|
+
collection.contentInsetAdjustmentBehavior = .never
|
|
24
|
+
collection.contentInset = UIEdgeInsets(top: 190, left: 0, bottom: 449, right: 0)
|
|
25
|
+
func snapshot(_ indices: Range<Int>) throws -> String {
|
|
26
|
+
let rows: [[String: Any]] = indices.map { index in
|
|
27
|
+
["key": "account-\(index)", "type": "identity", "title": "Account \(index)",
|
|
28
|
+
"testID": "recipient-\(index)", "height": 64,
|
|
29
|
+
"leading": ["kind": "icon", "name": "Circle"]]
|
|
30
|
+
}
|
|
31
|
+
let value: [String: Any] = ["schemaVersion": 1, "generation": 1,
|
|
32
|
+
"layout": ["kind": "linear"], "rows": rows]
|
|
33
|
+
return String(decoding: try JSONSerialization.data(withJSONObject: value), as: UTF8.self)
|
|
34
|
+
}
|
|
35
|
+
view.applySnapshotJson(try snapshot(0..<18))
|
|
36
|
+
view.layoutIfNeeded()
|
|
37
|
+
let initialOffset = CGPoint(x: 0, y: -190)
|
|
38
|
+
collection.contentOffset = initialOffset
|
|
39
|
+
collection.layoutIfNeeded()
|
|
40
|
+
XCTAssertEqual(dataSource.snapshot().numberOfItems, 18)
|
|
41
|
+
let outgoingIndexPath = IndexPath(item: 8, section: 0)
|
|
42
|
+
let outgoingFrame = try XCTUnwrap(collection.layoutAttributesForItem(at: outgoingIndexPath)).frame
|
|
43
|
+
XCTAssertFalse(collection.bounds.intersects(outgoingFrame))
|
|
44
|
+
XCTAssertNil(collection.cellForItem(at: outgoingIndexPath))
|
|
45
|
+
|
|
46
|
+
// Force a real UIKit layout at the invalidation inside applySnapshotJson,
|
|
47
|
+
// while UIKit still owns the old snapshot. Scope the hook to this layout.
|
|
48
|
+
let layout = collection.collectionViewLayout
|
|
49
|
+
let layoutClass: AnyClass = type(of: layout)
|
|
50
|
+
let selector = NSSelectorFromString("invalidateLayout")
|
|
51
|
+
let method = try XCTUnwrap(class_getInstanceMethod(layoutClass, selector))
|
|
52
|
+
let encoding = try XCTUnwrap(method_getTypeEncoding(method))
|
|
53
|
+
let original = method_getImplementation(method)
|
|
54
|
+
let callOriginal = unsafeBitCast(original, to: (@convention(c) (AnyObject, Selector) -> Void).self)
|
|
55
|
+
var didLayoutOutgoingSnapshot = false
|
|
56
|
+
let invalidate: @convention(block) (UICollectionViewLayout) -> Void = { current in
|
|
57
|
+
callOriginal(current, selector)
|
|
58
|
+
guard current === layout, !didLayoutOutgoingSnapshot,
|
|
59
|
+
dataSource.snapshot().numberOfItems == 18 else { return }
|
|
60
|
+
didLayoutOutgoingSnapshot = true
|
|
61
|
+
let size = view.collectionView(collection, layout: current, sizeForItemAt: outgoingIndexPath)
|
|
62
|
+
XCTAssertEqual(size.height, 64, "UIKit still needs the outgoing row’s geometry")
|
|
63
|
+
XCTAssertNil(collection.cellForItem(at: outgoingIndexPath))
|
|
64
|
+
collection.contentOffset.y = outgoingFrame.midY - collection.bounds.height / 2
|
|
65
|
+
collection.setNeedsLayout()
|
|
66
|
+
collection.layoutIfNeeded()
|
|
67
|
+
XCTAssertTrue(collection.bounds.intersects(outgoingFrame))
|
|
68
|
+
guard let outgoingCell = collection.cellForItem(at: outgoingIndexPath) else {
|
|
69
|
+
XCTFail("UIKit must request the previously offscreen outgoing cell")
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
XCTAssertEqual(outgoingCell.reuseIdentifier,
|
|
73
|
+
NativeListRendererRegistry.reuseIdentifier(for: .identity))
|
|
74
|
+
XCTAssertFalse(outgoingCell.isUserInteractionEnabled)
|
|
75
|
+
XCTAssertTrue(outgoingCell.accessibilityElementsHidden)
|
|
76
|
+
XCTAssertFalse(view.collectionView(collection, shouldSelectItemAt: outgoingIndexPath))
|
|
77
|
+
}
|
|
78
|
+
let replacement = imp_implementationWithBlock(invalidate)
|
|
79
|
+
class_replaceMethod(layoutClass, selector, replacement, encoding)
|
|
80
|
+
defer {
|
|
81
|
+
class_replaceMethod(layoutClass, selector, original, encoding)
|
|
82
|
+
imp_removeBlock(replacement)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
view.applySnapshotJson(try snapshot(12..<15))
|
|
86
|
+
collection.contentOffset = initialOffset
|
|
87
|
+
collection.layoutIfNeeded()
|
|
88
|
+
XCTAssertTrue(didLayoutOutgoingSnapshot)
|
|
89
|
+
XCTAssertEqual(dataSource.snapshot().itemIdentifiers, ["account-12", "account-13", "account-14"])
|
|
90
|
+
let first = try XCTUnwrap(collection.cellForItem(at: IndexPath(item: 0, section: 0)))
|
|
91
|
+
XCTAssertFalse(first.isHidden)
|
|
92
|
+
XCTAssertEqual(first.accessibilityIdentifier, "recipient-12")
|
|
93
|
+
}
|
|
94
|
+
|
|
7
95
|
func testCanonicalNullPatchRemovesStoredOptionalFields() throws {
|
|
8
96
|
let view = NativeListView(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
|
|
9
97
|
let row: [String: Any] = ["key": "token", "type": "identity", "title": "Token",
|
|
@@ -1053,6 +1141,68 @@ final class NativeListLifecycleTests: XCTestCase {
|
|
|
1053
1141
|
XCTAssertTrue(second.isHidden)
|
|
1054
1142
|
}
|
|
1055
1143
|
|
|
1144
|
+
func testFixedFooterSharesRetiringRowKeyDuringStructuralTransition() throws {
|
|
1145
|
+
try requireStructuralAnimation()
|
|
1146
|
+
let footerData: [String: Any] = [
|
|
1147
|
+
"key": "a", "type": "action", "title": "Continue", "actionKey": "continue",
|
|
1148
|
+
]
|
|
1149
|
+
func snapshot(_ keys: [String], animate: Bool) throws -> String {
|
|
1150
|
+
let rows: [[String: Any]] = keys.map {
|
|
1151
|
+
["key": $0, "type": "action", "title": $0, "actionKey": "row-\($0)"]
|
|
1152
|
+
}
|
|
1153
|
+
var value: [String: Any] = ["schemaVersion": 1, "generation": animate ? 2 : 1,
|
|
1154
|
+
"layout": ["kind": "linear"], "rows": rows, "fixedFooter": footerData]
|
|
1155
|
+
if animate { value["structuralTransition"] = ["id": "remove-a", "durationMs": 800] }
|
|
1156
|
+
return String(decoding: try JSONSerialization.data(withJSONObject: value), as: UTF8.self)
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
|
|
1160
|
+
let controller = UIViewController()
|
|
1161
|
+
window.rootViewController = controller
|
|
1162
|
+
let view = NativeListView(frame: window.bounds)
|
|
1163
|
+
controller.view.addSubview(view)
|
|
1164
|
+
window.isHidden = false
|
|
1165
|
+
defer {
|
|
1166
|
+
view.dispose()
|
|
1167
|
+
window.isHidden = true
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
let collection = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
1171
|
+
let dataSource = try XCTUnwrap(collection.dataSource as? UICollectionViewDiffableDataSource<Int, String>)
|
|
1172
|
+
var actions: [String] = []
|
|
1173
|
+
view.onRowAction = { payload in
|
|
1174
|
+
if let action = (try? JSONSerialization.jsonObject(with: Data(payload.utf8))) as? [String: Any],
|
|
1175
|
+
let key = action["actionKey"] as? String { actions.append(key) }
|
|
1176
|
+
}
|
|
1177
|
+
view.applySnapshotJson(try snapshot(["a", "b", "c"], animate: false))
|
|
1178
|
+
view.layoutIfNeeded()
|
|
1179
|
+
collection.layoutIfNeeded()
|
|
1180
|
+
let outgoingIndex = IndexPath(item: 0, section: 0)
|
|
1181
|
+
let outgoing = try XCTUnwrap(collection.cellForItem(at: outgoingIndex) as? NativeListRowHost)
|
|
1182
|
+
let outgoingAction = try XCTUnwrap(outgoing.onAction)
|
|
1183
|
+
|
|
1184
|
+
view.applySnapshotJson(try snapshot(["b", "c"], animate: true))
|
|
1185
|
+
XCTAssertEqual(dataSource.itemIdentifier(for: outgoingIndex), "a")
|
|
1186
|
+
XCTAssertFalse(view.collectionView(collection, shouldSelectItemAt: outgoingIndex))
|
|
1187
|
+
view.collectionView(collection, didSelectItemAt: outgoingIndex)
|
|
1188
|
+
// Child renderers can emit a different key than the enclosing collection row.
|
|
1189
|
+
let child = try NativeListItem(data: ["key": "child", "type": "action", "title": "Child"])
|
|
1190
|
+
outgoingAction(child, "child-press", nil, outgoing.rowActionOrigin())
|
|
1191
|
+
XCTAssertTrue(actions.isEmpty)
|
|
1192
|
+
|
|
1193
|
+
let footer = try XCTUnwrap(footerCell(in: view))
|
|
1194
|
+
XCTAssertEqual(footer.accessibilityLabel, "Continue")
|
|
1195
|
+
XCTAssertEqual(footer.alpha, 1)
|
|
1196
|
+
XCTAssertTrue(footer.isUserInteractionEnabled)
|
|
1197
|
+
XCTAssertFalse(footer.accessibilityElementsHidden)
|
|
1198
|
+
// Dispatch the gesture's target directly in this hostless XCTest.
|
|
1199
|
+
let footerPress = NSSelectorFromString("footerPressed")
|
|
1200
|
+
XCTAssertTrue(view.responds(to: footerPress))
|
|
1201
|
+
_ = view.perform(footerPress)
|
|
1202
|
+
footer.onAction?(try NativeListItem(data: footerData), "footer-accessory", nil, footer.rowActionOrigin())
|
|
1203
|
+
XCTAssertEqual(actions, ["continue", "footer-accessory"])
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1056
1206
|
func testFontResolversMeasureBindResetAndKeepIndependentInstances() throws {
|
|
1057
1207
|
let first = NativeListFontFamilies(names: ["regular": "Courier", "bold": "Courier-Bold"])
|
|
1058
1208
|
let second = NativeListFontFamilies(names: ["regular": "Georgia", "bold": "Georgia-Bold"])
|
|
@@ -3368,8 +3518,8 @@ final class NativeListLifecycleTests: XCTestCase {
|
|
|
3368
3518
|
}
|
|
3369
3519
|
|
|
3370
3520
|
private func footerCell(in view: NativeListView) -> NativeListRowHost? {
|
|
3371
|
-
view.subviews.lazy.compactMap { container in
|
|
3372
|
-
container.subviews.
|
|
3521
|
+
view.subviews.lazy.filter { !($0 is UICollectionView) }.compactMap { container in
|
|
3522
|
+
container.subviews.first { $0 is NativeListRowHost } as? NativeListRowHost
|
|
3373
3523
|
}.first
|
|
3374
3524
|
}
|
|
3375
3525
|
}
|
package/package.json
CHANGED