@onekeyfe/react-native-native-list 6.7.0-alpha.354 → 6.7.0-alpha.359
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.
|
@@ -18,6 +18,8 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
18
18
|
private let columns = UIStackView()
|
|
19
19
|
private let cells = (0..<4).map { _ in NativeListTableColumnView() }
|
|
20
20
|
private var rowConstraints: [NSLayoutConstraint] = []
|
|
21
|
+
private var columnWidthConstraints: [NSLayoutConstraint] = []
|
|
22
|
+
private var columnWeights: [Int]?
|
|
21
23
|
override func unselectedBackground(
|
|
22
24
|
_ item: NativeListItem, theme: [String: Any]?, layout: String, itemIndex: Int?
|
|
23
25
|
) -> UIColor {
|
|
@@ -109,8 +111,20 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
109
111
|
trailingAccessories.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).width))
|
|
110
112
|
}
|
|
111
113
|
let values = Array(data.dictionaries("columns").prefix(4))
|
|
114
|
+
let weights = values.map { max(1, $0.int("weight", default: 1)) }
|
|
115
|
+
var divisor = weights.first ?? 1
|
|
116
|
+
for weight in weights.dropFirst() {
|
|
117
|
+
var a = divisor
|
|
118
|
+
var b = weight
|
|
119
|
+
while b != 0 { (a, b) = (b, a % b) }
|
|
120
|
+
divisor = a
|
|
121
|
+
}
|
|
122
|
+
let normalizedWeights = weights.map { $0 / divisor }
|
|
123
|
+
let columnsChanged = columnWeights != normalizedWeights
|
|
124
|
+
if columnsChanged { NSLayoutConstraint.deactivate(columnWidthConstraints) }
|
|
112
125
|
for (index, cell) in cells.enumerated() {
|
|
113
|
-
|
|
126
|
+
let hidden = index >= values.count
|
|
127
|
+
if cell.isHidden != hidden { cell.isHidden = hidden }
|
|
114
128
|
guard index < values.count else {
|
|
115
129
|
cell.reset()
|
|
116
130
|
continue
|
|
@@ -126,15 +140,16 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
126
140
|
}
|
|
127
141
|
cell.applySegments(values[index])
|
|
128
142
|
cell.bindTitleIcons(values[index], theme: theme)
|
|
129
|
-
if index > 0 {
|
|
130
|
-
rowConstraints.append(
|
|
131
|
-
cell.widthAnchor.constraint(
|
|
132
|
-
equalTo: cells[0].widthAnchor,
|
|
133
|
-
multiplier: CGFloat(max(1, values[index].int("weight", default: 1)))
|
|
134
|
-
/ CGFloat(max(1, values[0].int("weight", default: 1)))))
|
|
135
|
-
}
|
|
136
143
|
}
|
|
137
144
|
NSLayoutConstraint.activate(rowConstraints)
|
|
145
|
+
if columnsChanged {
|
|
146
|
+
columnWidthConstraints = values.count > 1 ? (1..<values.count).map { index in
|
|
147
|
+
cells[index].widthAnchor.constraint(equalTo: cells[0].widthAnchor,
|
|
148
|
+
multiplier: CGFloat(weights[index]) / CGFloat(weights[0]))
|
|
149
|
+
} : []
|
|
150
|
+
NSLayoutConstraint.activate(columnWidthConstraints)
|
|
151
|
+
columnWeights = normalizedWeights
|
|
152
|
+
}
|
|
138
153
|
}
|
|
139
154
|
override func bindSelectionContent(
|
|
140
155
|
_ item: NativeListItem,
|
|
@@ -667,7 +667,10 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
667
667
|
trailingStack.spacing = 12
|
|
668
668
|
} else if accessories.count == 2,
|
|
669
669
|
accessories[0].string("kind") == "valuePair",
|
|
670
|
-
accessories[1].string("kind") == "menu"
|
|
670
|
+
(accessories[1].string("kind") == "menu"
|
|
671
|
+
|| (accessories[1].string("kind") == "icon"
|
|
672
|
+
&& accessories[1].string("name") == "DotVerSolid"
|
|
673
|
+
&& accessories[1].string("actionKey") == "menu"))
|
|
671
674
|
{
|
|
672
675
|
trailingStack.axis = .horizontal
|
|
673
676
|
trailingStack.alignment = .center
|
|
@@ -364,6 +364,7 @@ final class NativeListView: UIView {
|
|
|
364
364
|
private var sectionIndexHapticsEnabled = true
|
|
365
365
|
private var lastLayoutDirection: UIUserInterfaceLayoutDirection?
|
|
366
366
|
private var lastLayoutSize: CGSize?
|
|
367
|
+
private var lastConfiguredCollectionWidth: CGFloat?
|
|
367
368
|
private var commandAcceptedForPendingScroll = false
|
|
368
369
|
private var performingExplicitScrollCommand = false
|
|
369
370
|
private var animatedExplicitScrollCommand = false
|
|
@@ -635,7 +636,9 @@ final class NativeListView: UIView {
|
|
|
635
636
|
invalidateActionAnchor(reason: "layout")
|
|
636
637
|
}
|
|
637
638
|
lastLayoutSize = bounds.size
|
|
638
|
-
|
|
639
|
+
let collectionWidthChanged = collectionView.bounds.width > 0
|
|
640
|
+
&& lastConfiguredCollectionWidth != collectionView.bounds.width
|
|
641
|
+
if (lastLayoutDirection != direction || collectionWidthChanged), let config {
|
|
639
642
|
configureLayout(config)
|
|
640
643
|
if lastLayoutDirection != direction { rebindRowsForLayoutDirection(config) }
|
|
641
644
|
}
|
|
@@ -1296,6 +1299,7 @@ final class NativeListView: UIView {
|
|
|
1296
1299
|
listBodyGestureGuard.isEnabled = !isHorizontal
|
|
1297
1300
|
collectionView.showsVerticalScrollIndicator = sectionIndexEntries.isEmpty
|
|
1298
1301
|
collectionView.dragInteractionEnabled = false
|
|
1302
|
+
lastConfiguredCollectionWidth = collectionView.bounds.width
|
|
1299
1303
|
lastLayoutDirection = effectiveUserInterfaceLayoutDirection
|
|
1300
1304
|
}
|
|
1301
1305
|
|
|
@@ -576,6 +576,63 @@ final class NativeListLifecycleTests: XCTestCase {
|
|
|
576
576
|
XCTAssertTrue(remainingConstraints.isEmpty)
|
|
577
577
|
}
|
|
578
578
|
|
|
579
|
+
func testSwapValuePairAndTertiaryMenuIconFitAndKeepActionState() throws {
|
|
580
|
+
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 386, height: 60))
|
|
581
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 386, height: 120))
|
|
582
|
+
window.addSubview(cell)
|
|
583
|
+
defer { cell.removeFromSuperview() }
|
|
584
|
+
let trailing = try XCTUnwrap(Mirror(reflecting: cell).children.first {
|
|
585
|
+
$0.label == "trailingStack"
|
|
586
|
+
}?.value as? NativeListAccessoryStack)
|
|
587
|
+
var actions: [(String, Int?)] = []
|
|
588
|
+
cell.onAction = { _, action, _, origin in actions.append((action, origin?.slot)) }
|
|
589
|
+
func bind(disabled: Bool) throws {
|
|
590
|
+
let item = try NativeListItem(data: [
|
|
591
|
+
"key": "swap-token", "type": "identity", "height": 60,
|
|
592
|
+
"title": "ETH", "subtitle": "Ethereum",
|
|
593
|
+
"leading": ["kind": "token", "fallbackIcon": ["name": "CryptoCoinOutline"]],
|
|
594
|
+
"trailing": [
|
|
595
|
+
["kind": "valuePair", "primary": "0.001328", "secondary": "$3.08"],
|
|
596
|
+
["kind": "icon", "name": "DotVerSolid", "buttonStyle": "tertiary",
|
|
597
|
+
"actionKey": "menu", "disabled": disabled],
|
|
598
|
+
],
|
|
599
|
+
"style": ["horizontalPadding": 20, "verticalPadding": 8,
|
|
600
|
+
"leadingGap": 12, "trailingGap": 8,
|
|
601
|
+
"image": ["width": 40, "height": 40]],
|
|
602
|
+
])
|
|
603
|
+
cell.bind(item: item, theme: nil, layout: "linear", selected: false,
|
|
604
|
+
checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
|
|
605
|
+
window.layoutIfNeeded()
|
|
606
|
+
cell.layoutIfNeeded()
|
|
607
|
+
}
|
|
608
|
+
try bind(disabled: false)
|
|
609
|
+
XCTAssertEqual(trailing.axis, .horizontal)
|
|
610
|
+
let controls = trailing.arrangedSubviews.compactMap { !$0.isHidden ? $0 as? UIButton : nil }
|
|
611
|
+
XCTAssertEqual(controls.count, 2)
|
|
612
|
+
let rects = controls.map { $0.convert($0.bounds, to: cell) }
|
|
613
|
+
XCTAssertTrue(rects.allSatisfy { $0.minY >= 0 && $0.maxY <= cell.bounds.height })
|
|
614
|
+
let amountLabel = try XCTUnwrap(controls[0].titleLabel)
|
|
615
|
+
let amountRect = amountLabel.convert(amountLabel.bounds, to: cell)
|
|
616
|
+
XCTAssertEqual(amountLabel.numberOfLines, 2)
|
|
617
|
+
XCTAssertGreaterThan(amountRect.height, 30)
|
|
618
|
+
XCTAssertGreaterThanOrEqual(amountRect.minY, 0)
|
|
619
|
+
XCTAssertLessThanOrEqual(amountRect.maxY, cell.bounds.height)
|
|
620
|
+
XCTAssertEqual(rects[0].midY, rects[1].midY, accuracy: 1)
|
|
621
|
+
XCTAssertEqual(rects[1].minX - rects[0].maxX, 8, accuracy: 0.5)
|
|
622
|
+
XCTAssertEqual(controls[1].bounds.height, 38, accuracy: 0.5)
|
|
623
|
+
XCTAssertTrue(controls[1].isEnabled)
|
|
624
|
+
controls[1].sendActions(for: .touchUpInside)
|
|
625
|
+
XCTAssertEqual(actions.count, 1)
|
|
626
|
+
XCTAssertEqual(actions[0].0, "menu")
|
|
627
|
+
XCTAssertEqual(actions[0].1, 1)
|
|
628
|
+
|
|
629
|
+
try bind(disabled: true)
|
|
630
|
+
let disabledIcon = try XCTUnwrap(trailing.arrangedSubviews.filter { !$0.isHidden }.last as? UIButton)
|
|
631
|
+
XCTAssertFalse(disabledIcon.isEnabled)
|
|
632
|
+
disabledIcon.sendActions(for: .touchUpInside)
|
|
633
|
+
XCTAssertEqual(actions.count, 1)
|
|
634
|
+
}
|
|
635
|
+
|
|
579
636
|
func testRiskIdentityRatioKeepsTitleVisibleWithAndWithoutButton() throws {
|
|
580
637
|
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 386, height: 56))
|
|
581
638
|
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 386, height: 200))
|
|
@@ -900,6 +957,239 @@ final class NativeListLifecycleTests: XCTestCase {
|
|
|
900
957
|
XCTAssertNil(slots[2].superview)
|
|
901
958
|
}
|
|
902
959
|
|
|
960
|
+
func testSidecarCentersRowsWhenConfiguredBeforeFirstWidth() throws {
|
|
961
|
+
try assertHomeSidecarGeometry(sidecarBeforeFirstLayout: true)
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
func testSidecarCentersRowsWhenConfiguredAfterFirstWidth() throws {
|
|
965
|
+
try assertHomeSidecarGeometry(sidecarBeforeFirstLayout: false)
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
func testHomeLinearColumnsStayInsideTheirStackAcrossEmptyMiddleAndReuse() throws {
|
|
969
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 1376, height: 900))
|
|
970
|
+
let controller = UIViewController()
|
|
971
|
+
window.rootViewController = controller
|
|
972
|
+
let view = NativeListView(frame: window.bounds)
|
|
973
|
+
controller.view.addSubview(view)
|
|
974
|
+
window.isHidden = false
|
|
975
|
+
defer {
|
|
976
|
+
view.dispose()
|
|
977
|
+
view.removeFromSuperview()
|
|
978
|
+
window.isHidden = true
|
|
979
|
+
window.rootViewController = nil
|
|
980
|
+
}
|
|
981
|
+
for index in 0..<4 { view.mountContainerSlot(UIView(), atIndex: index) }
|
|
982
|
+
view.setContainerSlotHeightsJson("[0,0,0,1200]")
|
|
983
|
+
let sidecar = "{\"width\":400,\"gap\":24,\"maxContentWidth\":1140}"
|
|
984
|
+
view.setSidecarLayoutJson(sidecar)
|
|
985
|
+
|
|
986
|
+
func columns(middle: String?, two: Bool = false) -> [[String: Any]] {
|
|
987
|
+
let first: [String: Any] = ["key": "asset", "text": "USD1",
|
|
988
|
+
"secondaryText": "Public fixture", "weight": 1]
|
|
989
|
+
let balance: [String: Any] = ["key": "balance", "text": middle ?? "",
|
|
990
|
+
"secondaryText": middle == nil ? "" : "$0.01", "alignment": "end", "weight": 1]
|
|
991
|
+
let price: [String: Any] = ["key": "price", "text": "$1.00",
|
|
992
|
+
"secondaryText": "0.01%", "alignment": "end", "weight": 1]
|
|
993
|
+
return two ? [first, price] : [first, balance, price]
|
|
994
|
+
}
|
|
995
|
+
let rows: [[String: Any]] = (0..<30).map { index in
|
|
996
|
+
["key": "row-\(index)", "type": "dataRow", "height": 60,
|
|
997
|
+
"leading": ["kind": "token", "fallbackIcon": ["name": "CryptoCoinOutline"]],
|
|
998
|
+
"columns": index == 20 ? columns(middle: "0.01") : homeSidecarColumns(index, updated: false),
|
|
999
|
+
"trailing": [["kind": "button", "label": "Swap", "actionKey": "swap"]],
|
|
1000
|
+
"style": ["horizontalPadding": 12, "verticalPadding": 8, "leadingGap": 12,
|
|
1001
|
+
"columns": ["token": "$bodyLg", "fontWeight": "medium", "lines": 1],
|
|
1002
|
+
"columnSecondary": ["token": "$bodyMd", "lines": 1],
|
|
1003
|
+
"image": ["width": 32, "height": 32]]]
|
|
1004
|
+
}
|
|
1005
|
+
let snapshot: [String: Any] = ["schemaVersion": 1, "generation": 1,
|
|
1006
|
+
"layout": ["kind": "linear", "contentPaddingHorizontal": 8], "rows": rows]
|
|
1007
|
+
view.applySnapshotJson(String(decoding: try JSONSerialization.data(withJSONObject: snapshot),
|
|
1008
|
+
as: UTF8.self))
|
|
1009
|
+
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
1010
|
+
list.contentInsetAdjustmentBehavior = .never
|
|
1011
|
+
func layout() {
|
|
1012
|
+
window.layoutIfNeeded()
|
|
1013
|
+
view.layoutIfNeeded()
|
|
1014
|
+
list.layoutIfNeeded()
|
|
1015
|
+
}
|
|
1016
|
+
func check(_ phase: String, count: Int, width: CGFloat, weights: [Int]? = nil) throws {
|
|
1017
|
+
layout()
|
|
1018
|
+
let cell = try XCTUnwrap(list.cellForItem(at: IndexPath(item: 20, section: 0))
|
|
1019
|
+
as? NativeListDataRowCell, phase)
|
|
1020
|
+
let stack = try XCTUnwrap(cell.root.arrangedSubviews[3] as? UIStackView, phase)
|
|
1021
|
+
let visible = stack.arrangedSubviews.filter { !$0.isHidden }
|
|
1022
|
+
XCTAssertEqual(stack.arrangedSubviews.count, 4, phase)
|
|
1023
|
+
XCTAssertEqual(stack.arrangedSubviews.map(\.isHidden),
|
|
1024
|
+
(0..<4).map { $0 >= count }, phase)
|
|
1025
|
+
XCTAssertEqual(visible.count, count, phase)
|
|
1026
|
+
let cellFrame = cell.convert(cell.bounds, to: list)
|
|
1027
|
+
let stackFrame = stack.convert(stack.bounds, to: list)
|
|
1028
|
+
let attributes = try XCTUnwrap(list.layoutAttributesForItem(
|
|
1029
|
+
at: IndexPath(item: 20, section: 0)), phase)
|
|
1030
|
+
XCTAssertEqual(attributes.frame.width, width, accuracy: 1, phase)
|
|
1031
|
+
XCTAssertEqual(cellFrame.width, width, accuracy: 1,
|
|
1032
|
+
"\(phase) window=\(window.frame) controller=\(controller.view.frame) view=\(view.frame) list=\(list.frame) bounds=\(list.bounds) attributes=\(attributes.frame)")
|
|
1033
|
+
let rowConstraints = Mirror(reflecting: cell).children.first {
|
|
1034
|
+
$0.label == "rowConstraints"
|
|
1035
|
+
}?.value as? [NSLayoutConstraint] ?? []
|
|
1036
|
+
let columnWidthConstraints = Mirror(reflecting: cell).children.first {
|
|
1037
|
+
$0.label == "columnWidthConstraints"
|
|
1038
|
+
}?.value as? [NSLayoutConstraint] ?? []
|
|
1039
|
+
let constraints = rowConstraints + columnWidthConstraints
|
|
1040
|
+
let constraintState = constraints.map { constraint in
|
|
1041
|
+
let first = stack.arrangedSubviews.firstIndex {
|
|
1042
|
+
$0 === constraint.firstItem as? UIView
|
|
1043
|
+
} ?? -1
|
|
1044
|
+
let second = stack.arrangedSubviews.firstIndex {
|
|
1045
|
+
$0 === constraint.secondItem as? UIView
|
|
1046
|
+
} ?? -1
|
|
1047
|
+
return "\(first):\(second):\(constraint.multiplier):\(constraint.isActive)"
|
|
1048
|
+
}.joined(separator: ",")
|
|
1049
|
+
let hidingState = stack.arrangedSubviews.enumerated().map { index, column in
|
|
1050
|
+
let hiding = (stack.constraints + column.constraints).filter {
|
|
1051
|
+
$0.isActive && $0.identifier == "UISV-hiding"
|
|
1052
|
+
}.map { "\($0.constant)" }.joined(separator: ",")
|
|
1053
|
+
return "\(index):\(column.isHidden):\(hiding)"
|
|
1054
|
+
}.joined(separator: ",")
|
|
1055
|
+
let geometry = "\(phase) model=\(count) cell=\(cellFrame) stack=\(stackFrame) "
|
|
1056
|
+
+ "columns=\(stack.arrangedSubviews.map { "\($0.isHidden):\($0.convert($0.bounds, to: list))" }) "
|
|
1057
|
+
+ "constraints=\(constraintState) hiding=\(hidingState)"
|
|
1058
|
+
XCTAssertGreaterThanOrEqual(stackFrame.minX, cellFrame.minX - 0.5, geometry)
|
|
1059
|
+
XCTAssertLessThanOrEqual(stackFrame.maxX, cellFrame.maxX + 0.5, geometry)
|
|
1060
|
+
for column in visible {
|
|
1061
|
+
let columnFrame = column.convert(column.bounds, to: list)
|
|
1062
|
+
XCTAssertGreaterThan(columnFrame.width, 0, geometry)
|
|
1063
|
+
XCTAssertGreaterThanOrEqual(columnFrame.minX, stackFrame.minX - 0.5, geometry)
|
|
1064
|
+
XCTAssertLessThanOrEqual(columnFrame.maxX, stackFrame.maxX + 0.5, geometry)
|
|
1065
|
+
let primaryLine = (column as? UIStackView)?.arrangedSubviews.first
|
|
1066
|
+
if let primaryLine {
|
|
1067
|
+
let lineFrame = primaryLine.convert(primaryLine.bounds, to: list)
|
|
1068
|
+
XCTAssertGreaterThanOrEqual(lineFrame.minX, columnFrame.minX - 0.5, geometry)
|
|
1069
|
+
XCTAssertLessThanOrEqual(lineFrame.maxX, columnFrame.maxX + 0.5, geometry)
|
|
1070
|
+
}
|
|
1071
|
+
for label in labels(in: column) where !label.isHidden {
|
|
1072
|
+
let labelFrame = label.convert(label.bounds, to: list)
|
|
1073
|
+
XCTAssertGreaterThanOrEqual(labelFrame.minX, columnFrame.minX - 0.5,
|
|
1074
|
+
"\(geometry) label=\(labelFrame)")
|
|
1075
|
+
XCTAssertLessThanOrEqual(labelFrame.maxX, columnFrame.maxX + 0.5,
|
|
1076
|
+
"\(geometry) label=\(labelFrame)")
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
if count >= 2 {
|
|
1080
|
+
let expectedWeights = weights ?? Array(repeating: 1, count: count)
|
|
1081
|
+
XCTAssertEqual(expectedWeights.count, count, geometry)
|
|
1082
|
+
for index in 1..<count {
|
|
1083
|
+
XCTAssertEqual(visible[index].bounds.width,
|
|
1084
|
+
visible[0].bounds.width * CGFloat(expectedWeights[index])
|
|
1085
|
+
/ CGFloat(expectedWeights[0]),
|
|
1086
|
+
accuracy: 1, geometry)
|
|
1087
|
+
let previous = visible[index - 1].convert(visible[index - 1].bounds, to: stack)
|
|
1088
|
+
let current = visible[index].convert(visible[index].bounds, to: stack)
|
|
1089
|
+
XCTAssertGreaterThanOrEqual(current.minX, previous.maxX - 0.5, geometry)
|
|
1090
|
+
XCTAssertEqual(current.minX - previous.maxX, stack.spacing,
|
|
1091
|
+
accuracy: 0.5, geometry)
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
func patch(_ next: [[String: Any]]) throws {
|
|
1096
|
+
let patches: [[String: Any]] = [["key": "row-20", "type": "dataRow",
|
|
1097
|
+
"changes": ["columns": next]]]
|
|
1098
|
+
view.applyPatchesJson(String(decoding: try JSONSerialization.data(withJSONObject: patches),
|
|
1099
|
+
as: UTF8.self))
|
|
1100
|
+
}
|
|
1101
|
+
func widthConstraints() throws -> [NSLayoutConstraint] {
|
|
1102
|
+
let cell = try XCTUnwrap(list.cellForItem(at: IndexPath(item: 20, section: 0))
|
|
1103
|
+
as? NativeListDataRowCell)
|
|
1104
|
+
return try XCTUnwrap(Mirror(reflecting: cell).children.first {
|
|
1105
|
+
$0.label == "columnWidthConstraints"
|
|
1106
|
+
}?.value as? [NSLayoutConstraint])
|
|
1107
|
+
}
|
|
1108
|
+
layout()
|
|
1109
|
+
list.setContentOffset(CGPoint(x: 0, y: 18 * 60), animated: false)
|
|
1110
|
+
try check("three populated", count: 3, width: 700)
|
|
1111
|
+
try patch(columns(middle: nil))
|
|
1112
|
+
try check("three empty middle", count: 3, width: 700)
|
|
1113
|
+
try patch(columns(middle: "0.02"))
|
|
1114
|
+
try check("three restored", count: 3, width: 700)
|
|
1115
|
+
try patch(columns(middle: nil, two: true))
|
|
1116
|
+
try check("two columns", count: 2, width: 700)
|
|
1117
|
+
try patch(columns(middle: nil))
|
|
1118
|
+
try check("three after two", count: 3, width: 700)
|
|
1119
|
+
let stableConstraints = try widthConstraints()
|
|
1120
|
+
XCTAssertEqual(stableConstraints.count, 2)
|
|
1121
|
+
for update in 0..<10 {
|
|
1122
|
+
var next = columns(middle: nil)
|
|
1123
|
+
next[2]["text"] = "$1.\(update)"
|
|
1124
|
+
try patch(next)
|
|
1125
|
+
try check("same-shape price \(update)", count: 3, width: 700)
|
|
1126
|
+
let retained = try widthConstraints()
|
|
1127
|
+
XCTAssertEqual(retained.count, stableConstraints.count)
|
|
1128
|
+
XCTAssertTrue(zip(stableConstraints, retained).allSatisfy { $0 === $1 })
|
|
1129
|
+
XCTAssertTrue(retained.allSatisfy(\.isActive))
|
|
1130
|
+
}
|
|
1131
|
+
var equivalentWeights = columns(middle: nil)
|
|
1132
|
+
for index in equivalentWeights.indices { equivalentWeights[index]["weight"] = 2 }
|
|
1133
|
+
try patch(equivalentWeights)
|
|
1134
|
+
try check("equivalent weights", count: 3, width: 700, weights: [2, 2, 2])
|
|
1135
|
+
let equivalentConstraints = try widthConstraints()
|
|
1136
|
+
XCTAssertEqual(equivalentConstraints.count, stableConstraints.count)
|
|
1137
|
+
XCTAssertTrue(zip(stableConstraints, equivalentConstraints).allSatisfy { $0 === $1 })
|
|
1138
|
+
var unequalWeights = columns(middle: nil)
|
|
1139
|
+
unequalWeights[0]["weight"] = 2
|
|
1140
|
+
try patch(unequalWeights)
|
|
1141
|
+
try check("unequal weights", count: 3, width: 700, weights: [2, 1, 1])
|
|
1142
|
+
let unequalConstraints = try widthConstraints()
|
|
1143
|
+
XCTAssertEqual(unequalConstraints.count, 2)
|
|
1144
|
+
XCTAssertTrue(stableConstraints.allSatisfy { !$0.isActive })
|
|
1145
|
+
try patch(columns(middle: nil, two: true))
|
|
1146
|
+
try check("two after weights", count: 2, width: 700)
|
|
1147
|
+
let twoConstraints = try widthConstraints()
|
|
1148
|
+
XCTAssertEqual(twoConstraints.count, 1)
|
|
1149
|
+
XCTAssertTrue(unequalConstraints.allSatisfy { !$0.isActive })
|
|
1150
|
+
try patch([])
|
|
1151
|
+
try check("zero columns", count: 0, width: 700)
|
|
1152
|
+
XCTAssertTrue((try widthConstraints()).isEmpty)
|
|
1153
|
+
XCTAssertTrue(twoConstraints.allSatisfy { !$0.isActive })
|
|
1154
|
+
try patch(columns(middle: nil))
|
|
1155
|
+
try check("three after zero", count: 3, width: 700)
|
|
1156
|
+
list.setContentOffset(.zero, animated: false)
|
|
1157
|
+
layout()
|
|
1158
|
+
XCTAssertNil(list.cellForItem(at: IndexPath(item: 20, section: 0)))
|
|
1159
|
+
list.setContentOffset(CGPoint(x: 0, y: 18 * 60), animated: false)
|
|
1160
|
+
try check("after scroll reuse", count: 3, width: 700)
|
|
1161
|
+
window.frame.size.width = 1032
|
|
1162
|
+
controller.view.frame = window.bounds
|
|
1163
|
+
view.frame = window.bounds
|
|
1164
|
+
view.setSidecarLayoutJson("")
|
|
1165
|
+
drainMainQueue()
|
|
1166
|
+
try check("narrow no sidecar", count: 3, width: 1016)
|
|
1167
|
+
window.frame.size.width = 1376
|
|
1168
|
+
controller.view.frame = window.bounds
|
|
1169
|
+
view.frame = window.bounds
|
|
1170
|
+
view.setSidecarLayoutJson(sidecar)
|
|
1171
|
+
drainMainQueue()
|
|
1172
|
+
try check("wide sidecar restored", count: 3, width: 700)
|
|
1173
|
+
func animatedPatch(_ next: [[String: Any]], phase: String, count: Int) throws {
|
|
1174
|
+
let patches: [[String: Any]] = [["key": "row-20", "type": "dataRow",
|
|
1175
|
+
"changes": ["columns": next]]]
|
|
1176
|
+
let json = String(decoding: try JSONSerialization.data(withJSONObject: patches), as: UTF8.self)
|
|
1177
|
+
let finished = expectation(description: "Home column animation: \(phase)")
|
|
1178
|
+
UIView.animate(withDuration: 0.2, delay: 0, options: .beginFromCurrentState) {
|
|
1179
|
+
view.applyPatchesJson(json)
|
|
1180
|
+
view.layoutIfNeeded()
|
|
1181
|
+
list.layoutIfNeeded()
|
|
1182
|
+
} completion: { _ in finished.fulfill() }
|
|
1183
|
+
wait(for: [finished], timeout: 1)
|
|
1184
|
+
try check(phase, count: count, width: 700)
|
|
1185
|
+
waitForStructuralFrames(0.1)
|
|
1186
|
+
try check("\(phase) stable", count: count, width: 700)
|
|
1187
|
+
}
|
|
1188
|
+
try animatedPatch(columns(middle: nil, two: true), phase: "animated two", count: 2)
|
|
1189
|
+
try animatedPatch(columns(middle: nil), phase: "animated three", count: 3)
|
|
1190
|
+
try animatedPatch(columns(middle: "0.06"), phase: "animated nonempty", count: 3)
|
|
1191
|
+
}
|
|
1192
|
+
|
|
903
1193
|
func testStructuralShrinkUsesTheTallerFinalColumnForOffsetClamping() throws {
|
|
904
1194
|
let cases: [(name: String, sidecar: Int, offset: CGFloat, height: CGFloat,
|
|
905
1195
|
zeroInset: Bool)] = [
|
|
@@ -1250,6 +1540,109 @@ final class NativeListLifecycleTests: XCTestCase {
|
|
|
1250
1540
|
return String(decoding: try JSONSerialization.data(withJSONObject: value), as: UTF8.self)
|
|
1251
1541
|
}
|
|
1252
1542
|
|
|
1543
|
+
private func assertHomeSidecarGeometry(sidecarBeforeFirstLayout: Bool) throws {
|
|
1544
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 1376, height: 900))
|
|
1545
|
+
let controller = UIViewController()
|
|
1546
|
+
window.rootViewController = controller
|
|
1547
|
+
let view = NativeListView(frame: window.bounds)
|
|
1548
|
+
controller.view.addSubview(view)
|
|
1549
|
+
window.isHidden = false
|
|
1550
|
+
defer {
|
|
1551
|
+
view.dispose()
|
|
1552
|
+
view.removeFromSuperview()
|
|
1553
|
+
window.isHidden = true
|
|
1554
|
+
window.rootViewController = nil
|
|
1555
|
+
}
|
|
1556
|
+
for index in 0..<4 { view.mountContainerSlot(UIView(), atIndex: index) }
|
|
1557
|
+
view.setContainerSlotHeightsJson("[0,0,0,1200]")
|
|
1558
|
+
let sidecar = "{\"width\":400,\"gap\":24,\"maxContentWidth\":1140}"
|
|
1559
|
+
if sidecarBeforeFirstLayout { view.setSidecarLayoutJson(sidecar) }
|
|
1560
|
+
view.applySnapshotJson(try homeSidecarSnapshot())
|
|
1561
|
+
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
1562
|
+
list.contentInsetAdjustmentBehavior = .never
|
|
1563
|
+
func layout() {
|
|
1564
|
+
window.layoutIfNeeded()
|
|
1565
|
+
view.layoutIfNeeded()
|
|
1566
|
+
list.layoutIfNeeded()
|
|
1567
|
+
}
|
|
1568
|
+
func assertRows(x: CGFloat, width: CGFloat) {
|
|
1569
|
+
let cells = list.visibleCells.compactMap { $0 as? NativeListDataRowCell }
|
|
1570
|
+
XCTAssertFalse(cells.isEmpty)
|
|
1571
|
+
for cell in cells {
|
|
1572
|
+
let frame = cell.convert(cell.bounds, to: list)
|
|
1573
|
+
XCTAssertEqual(frame.minX, x, accuracy: 1)
|
|
1574
|
+
XCTAssertEqual(frame.width, width, accuracy: 1)
|
|
1575
|
+
if let path = list.indexPath(for: cell),
|
|
1576
|
+
let attributes = list.layoutAttributesForItem(at: path)
|
|
1577
|
+
{
|
|
1578
|
+
XCTAssertEqual(attributes.frame.minX, x, accuracy: 1)
|
|
1579
|
+
XCTAssertEqual(attributes.frame.width, width, accuracy: 1)
|
|
1580
|
+
}
|
|
1581
|
+
let root = cell.root.convert(cell.root.bounds, to: list)
|
|
1582
|
+
XCTAssertGreaterThanOrEqual(root.minX, frame.minX - 1)
|
|
1583
|
+
XCTAssertLessThanOrEqual(root.maxX, frame.maxX + 1)
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
layout()
|
|
1587
|
+
if !sidecarBeforeFirstLayout {
|
|
1588
|
+
assertRows(x: 8, width: 1360)
|
|
1589
|
+
view.setSidecarLayoutJson(sidecar)
|
|
1590
|
+
layout()
|
|
1591
|
+
}
|
|
1592
|
+
assertRows(x: 126, width: 700)
|
|
1593
|
+
list.contentOffset.y = 18 * 60
|
|
1594
|
+
layout()
|
|
1595
|
+
assertRows(x: 126, width: 700)
|
|
1596
|
+
let patch: [[String: Any]] = [[
|
|
1597
|
+
"key": "row-20", "type": "dataRow",
|
|
1598
|
+
"changes": ["columns": homeSidecarColumns(20, updated: true),
|
|
1599
|
+
"trailing": [["kind": "button", "label": "Swap", "actionKey": "swap"]]],
|
|
1600
|
+
]]
|
|
1601
|
+
view.applyPatchesJson(String(decoding: try JSONSerialization.data(withJSONObject: patch),
|
|
1602
|
+
as: UTF8.self))
|
|
1603
|
+
layout()
|
|
1604
|
+
assertRows(x: 126, width: 700)
|
|
1605
|
+
window.frame.size.width = 1024
|
|
1606
|
+
controller.view.frame = window.bounds
|
|
1607
|
+
view.frame = window.bounds
|
|
1608
|
+
layout()
|
|
1609
|
+
assertRows(x: 8, width: 584)
|
|
1610
|
+
window.frame.size.width = 1376
|
|
1611
|
+
controller.view.frame = window.bounds
|
|
1612
|
+
view.frame = window.bounds
|
|
1613
|
+
layout()
|
|
1614
|
+
assertRows(x: 126, width: 700)
|
|
1615
|
+
view.setSidecarLayoutJson("")
|
|
1616
|
+
layout()
|
|
1617
|
+
assertRows(x: 8, width: 1360)
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
private func homeSidecarSnapshot() throws -> String {
|
|
1621
|
+
let rows: [[String: Any]] = (0..<30).map { index in
|
|
1622
|
+
["key": "row-\(index)", "type": "dataRow", "height": 60,
|
|
1623
|
+
"leading": ["kind": "token", "fallbackIcon": ["name": "CryptoCoinOutline"]],
|
|
1624
|
+
"columns": homeSidecarColumns(index, updated: false),
|
|
1625
|
+
"trailing": [["kind": "button", "label": "Swap", "actionKey": "swap"]],
|
|
1626
|
+
"style": ["horizontalPadding": 12, "verticalPadding": 8, "leadingGap": 12,
|
|
1627
|
+
"image": ["width": 32, "height": 32]]]
|
|
1628
|
+
}
|
|
1629
|
+
let snapshot: [String: Any] = [
|
|
1630
|
+
"schemaVersion": 1, "generation": 1,
|
|
1631
|
+
"layout": ["kind": "linear", "contentPaddingHorizontal": 8], "rows": rows,
|
|
1632
|
+
]
|
|
1633
|
+
return String(decoding: try JSONSerialization.data(withJSONObject: snapshot), as: UTF8.self)
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
private func homeSidecarColumns(_ index: Int, updated: Bool) -> [[String: Any]] {
|
|
1637
|
+
[
|
|
1638
|
+
["key": "asset", "text": "Asset \(index)", "secondaryText": "Public fixture", "weight": 1],
|
|
1639
|
+
["key": "balance", "text": updated ? "0.2966" : "0.000175",
|
|
1640
|
+
"secondaryText": "$0.13", "alignment": "end", "weight": 1],
|
|
1641
|
+
["key": "price", "text": updated ? "$739.22" : "$0.9989",
|
|
1642
|
+
"secondaryText": "-0.04%", "alignment": "end", "weight": 1],
|
|
1643
|
+
]
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1253
1646
|
private func makeScrollingList() throws -> NativeListView {
|
|
1254
1647
|
let view = NativeListView(frame: CGRect(x: 0, y: 0, width: 320, height: 708))
|
|
1255
1648
|
for index in 0..<3 { view.mountContainerSlot(UIView(), atIndex: index) }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-native-list",
|
|
3
|
-
"version": "6.7.0-alpha.
|
|
3
|
+
"version": "6.7.0-alpha.359",
|
|
4
4
|
"description": "Template-driven native RecyclerView and UICollectionView for React Native",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/module/index.js",
|
|
@@ -86,8 +86,8 @@
|
|
|
86
86
|
"typescript": "^5.9.2"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
|
-
"@onekeyfe/react-native-image": "6.7.0-alpha.
|
|
90
|
-
"@onekeyfe/react-native-native-logger": "6.7.0-alpha.
|
|
89
|
+
"@onekeyfe/react-native-image": "6.7.0-alpha.359",
|
|
90
|
+
"@onekeyfe/react-native-native-logger": "6.7.0-alpha.359",
|
|
91
91
|
"react": "*",
|
|
92
92
|
"react-native": "*",
|
|
93
93
|
"react-native-nitro-modules": "0.37.0"
|