@onekeyfe/react-native-native-list 6.7.0-alpha.343 → 6.7.0-alpha.354
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 +7 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +240 -7
- 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 +135 -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 +17 -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 +585 -21
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +1 -0
- package/docs/ROW_TEMPLATES.md +60 -9
- package/docs/SPEC.md +361 -8
- package/docs/STYLE_SPEC.md +6 -0
- package/ios/HybridNativeList.swift +10 -0
- package/ios/NativeListAccessoryStack.swift +220 -37
- package/ios/NativeListActivityDetailsView.swift +18 -8
- package/ios/NativeListActivityRenderer.swift +8 -2
- package/ios/NativeListButtonGroupRenderer.swift +89 -0
- package/ios/NativeListDataRowRenderer.swift +105 -8
- package/ios/NativeListDesignAssets.swift +3 -0
- package/ios/NativeListIdentityRenderer.swift +119 -4
- package/ios/NativeListLeadingVisual.swift +49 -14
- package/ios/NativeListMessageRenderer.swift +34 -1
- package/ios/NativeListModels.swift +16 -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 +331 -29
- 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 +890 -3
- package/lib/module/NativeList.js +64 -27
- package/lib/module/NativeList.web.js +84 -17
- package/lib/module/models.js +1 -0
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +532 -18
- package/lib/module/web/NativeListWebEngine.js +391 -24
- 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 +9 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
- package/lib/typescript/src/NativeList.d.ts +2 -2
- package/lib/typescript/src/NativeList.nitro.d.ts +1 -0
- package/lib/typescript/src/NativeList.types.d.ts +8 -0
- package/lib/typescript/src/models.d.ts +101 -9
- package/lib/typescript/src/validation.d.ts +13 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -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 +9 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
- package/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
- package/package.json +3 -3
- package/react-native-native-list.podspec +1 -0
- package/src/NativeList.nitro.ts +1 -0
- package/src/NativeList.tsx +155 -69
- package/src/NativeList.types.ts +9 -0
- package/src/NativeList.web.tsx +159 -49
- package/src/models.ts +113 -3
- package/src/selection.ts +1 -0
- package/src/validation.ts +1156 -18
- package/src/web/NativeListWebEngine.ts +594 -28
- 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
|
@@ -15,7 +15,7 @@ final class NativeListLifecycleTests: XCTestCase {
|
|
|
15
15
|
let originalStyle = list.topEdgeEffect.style
|
|
16
16
|
let originalInset = list.contentInset.top
|
|
17
17
|
let overlay = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 64))
|
|
18
|
-
view.mountContainerSlot(overlay, atIndex:
|
|
18
|
+
view.mountContainerSlot(overlay, atIndex: 4)
|
|
19
19
|
view.setTopScrollEdge(effect: .hard, overlayHeight: 64)
|
|
20
20
|
XCTAssertEqual(list.topEdgeEffect.style, .hard)
|
|
21
21
|
XCTAssertEqual(list.contentInset.top, originalInset + 64, accuracy: 0.01)
|
|
@@ -153,6 +153,514 @@ final class NativeListLifecycleTests: XCTestCase {
|
|
|
153
153
|
XCTAssertNotEqual(cell.bindingEpoch, changedEpoch)
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
+
func testRiskIdentityTitleIconAndButtonResetOnProductionCellBind() throws {
|
|
157
|
+
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 320, height: 56))
|
|
158
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 200))
|
|
159
|
+
window.addSubview(cell)
|
|
160
|
+
let titleIcon = try XCTUnwrap(
|
|
161
|
+
Mirror(reflecting: cell).children.first { $0.label == "titleIconView" }?.value as? UIImageView)
|
|
162
|
+
let titleStack = try XCTUnwrap(
|
|
163
|
+
Mirror(reflecting: cell).children.first { $0.label == "titleRowStack" }?.value as? UIStackView)
|
|
164
|
+
let titleLabel = try XCTUnwrap(
|
|
165
|
+
Mirror(reflecting: cell).children.first { $0.label == "titleLabel" }?.value as? UILabel)
|
|
166
|
+
let trailing = try XCTUnwrap(
|
|
167
|
+
Mirror(reflecting: cell).children.first { $0.label == "trailingStack" }?.value
|
|
168
|
+
as? NativeListAccessoryStack)
|
|
169
|
+
func bind(_ data: [String: Any]) throws {
|
|
170
|
+
let item = try NativeListItem(data: data)
|
|
171
|
+
cell.bind(item: item, theme: nil, layout: "linear", selected: false,
|
|
172
|
+
checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
|
|
173
|
+
cell.layoutIfNeeded()
|
|
174
|
+
}
|
|
175
|
+
let base: [String: Any] = ["key": "risk", "type": "identity", "title": "Risk",
|
|
176
|
+
"height": 56, "leading": ["kind": "token",
|
|
177
|
+
"fallbackIcon": ["name": "CryptoCoinOutline"]]]
|
|
178
|
+
try bind(base)
|
|
179
|
+
XCTAssertTrue(titleIcon.isHidden)
|
|
180
|
+
XCTAssertLessThanOrEqual(titleIcon.bounds.width, 0.5)
|
|
181
|
+
try bind(base.merging(["titleIcon": ["name": "GasSolid"],
|
|
182
|
+
"trailing": [["kind": "button", "label": "Show", "actionKey": "show",
|
|
183
|
+
"backgroundColor": "#DDDDDD", "pressedBackgroundColor": "#AAAAAA"]]]) { _, newer in newer })
|
|
184
|
+
XCTAssertFalse(titleIcon.isHidden)
|
|
185
|
+
XCTAssertNotNil(titleIcon.image)
|
|
186
|
+
XCTAssertEqual(titleIcon.bounds.width, 20, accuracy: 0.5)
|
|
187
|
+
XCTAssertEqual(titleStack.customSpacing(after: titleLabel), 4, accuracy: 0.1)
|
|
188
|
+
let button = try XCTUnwrap(trailing.arrangedSubviews.compactMap { $0 as? NativeListAccessoryButton }
|
|
189
|
+
.first { !$0.isHidden })
|
|
190
|
+
XCTAssertEqual(button.intrinsicContentSize.height, 30, accuracy: 0.5)
|
|
191
|
+
let normal = button.backgroundColor
|
|
192
|
+
button.isHighlighted = true
|
|
193
|
+
XCTAssertNotEqual(button.backgroundColor, normal)
|
|
194
|
+
button.isHighlighted = false
|
|
195
|
+
XCTAssertEqual(button.backgroundColor, normal)
|
|
196
|
+
try bind(base)
|
|
197
|
+
XCTAssertTrue(titleIcon.isHidden)
|
|
198
|
+
XCTAssertLessThanOrEqual(titleIcon.bounds.width, 0.5)
|
|
199
|
+
XCTAssertTrue(trailing.arrangedSubviews.compactMap { $0 as? NativeListAccessoryButton }
|
|
200
|
+
.allSatisfy { $0.isHidden })
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
func testIdentityTitleSuffixesUsePlainLabelsAndClearOnRebind() throws {
|
|
204
|
+
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 320, height: 60))
|
|
205
|
+
let titleStack = try XCTUnwrap(
|
|
206
|
+
Mirror(reflecting: cell).children.first { $0.label == "titleRowStack" }?.value as? UIStackView)
|
|
207
|
+
func bind(_ suffixes: [[String: Any]]?) throws {
|
|
208
|
+
var data: [String: Any] = [
|
|
209
|
+
"key": "recent", "type": "identity", "title": "Alice",
|
|
210
|
+
"leading": ["kind": "account", "fallbackText": "A"],
|
|
211
|
+
]
|
|
212
|
+
if let suffixes { data["titleSuffixes"] = suffixes }
|
|
213
|
+
let item = try NativeListItem(data: data)
|
|
214
|
+
cell.bind(item: item, theme: nil, layout: "linear", selected: false,
|
|
215
|
+
checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
|
|
216
|
+
cell.layoutIfNeeded()
|
|
217
|
+
}
|
|
218
|
+
try bind([
|
|
219
|
+
["text": "EVM", "tone": "secondary", "maxWidth": 128],
|
|
220
|
+
["text": "2 days ago", "tone": "disabled"],
|
|
221
|
+
])
|
|
222
|
+
let suffixes = titleStack.arrangedSubviews.compactMap { $0 as? UILabel }
|
|
223
|
+
.filter { ["EVM", "2 days ago"].contains($0.text ?? "") }
|
|
224
|
+
XCTAssertEqual(suffixes.map(\.text), ["EVM", "2 days ago"])
|
|
225
|
+
XCTAssertTrue(suffixes.allSatisfy { $0.font.pointSize == 12 && $0.numberOfLines == 1 })
|
|
226
|
+
XCTAssertFalse(suffixes.contains { $0 is NativeListInsetLabel })
|
|
227
|
+
try bind(nil)
|
|
228
|
+
XCTAssertFalse(titleStack.arrangedSubviews.compactMap { $0 as? UILabel }
|
|
229
|
+
.contains { ["EVM", "2 days ago"].contains($0.text ?? "") })
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
func testDataRowTitleIconsClearWhenCellIsRebound() throws {
|
|
233
|
+
let cell = NativeListDataRowCell(frame: CGRect(x: 0, y: 0, width: 380, height: 60))
|
|
234
|
+
func bind(_ column: [String: Any]) throws {
|
|
235
|
+
let item = try NativeListItem(data: [
|
|
236
|
+
"key": "asset", "type": "dataRow", "columns": [column],
|
|
237
|
+
])
|
|
238
|
+
cell.bind(item: item, theme: nil, layout: "table", selected: false,
|
|
239
|
+
checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
|
|
240
|
+
cell.layoutIfNeeded()
|
|
241
|
+
}
|
|
242
|
+
func titleIcons(in view: UIView) -> [UIImageView] {
|
|
243
|
+
let current = (view as? UIImageView).map { [$0] } ?? []
|
|
244
|
+
return current + view.subviews.flatMap(titleIcons)
|
|
245
|
+
}
|
|
246
|
+
try bind([
|
|
247
|
+
"key": "asset", "text": "ETH",
|
|
248
|
+
"titleIcon": ["name": "GasSolid", "accessibilityLabel": "Gas help"],
|
|
249
|
+
"secondaryTitleIcon": ["name": "InfoCircleOutline", "accessibilityLabel": "Info help"],
|
|
250
|
+
])
|
|
251
|
+
let visible = titleIcons(in: cell).filter { !$0.isHidden && $0.accessibilityLabel != nil }
|
|
252
|
+
XCTAssertEqual(visible.compactMap(\.accessibilityLabel), ["Gas help", "Info help"])
|
|
253
|
+
XCTAssertTrue(visible.allSatisfy { $0.image != nil })
|
|
254
|
+
|
|
255
|
+
try bind(["key": "asset", "text": "USDC"])
|
|
256
|
+
XCTAssertTrue(titleIcons(in: cell).allSatisfy {
|
|
257
|
+
$0.accessibilityLabel != "Gas help" && $0.accessibilityLabel != "Info help"
|
|
258
|
+
})
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
func testIdentityTrailingActionUsesDescriptorSlotAfterCheckboxAndRebind() throws {
|
|
262
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 386, height: 200))
|
|
263
|
+
let controller = UIViewController()
|
|
264
|
+
window.rootViewController = controller
|
|
265
|
+
window.isHidden = false
|
|
266
|
+
defer { window.isHidden = true }
|
|
267
|
+
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 386, height: 56))
|
|
268
|
+
controller.view.addSubview(cell)
|
|
269
|
+
let trailing = try XCTUnwrap(
|
|
270
|
+
Mirror(reflecting: cell).children.first { $0.label == "trailingStack" }?.value
|
|
271
|
+
as? NativeListAccessoryStack)
|
|
272
|
+
var actions: [(rowKey: String, key: String, source: String, slot: Int?)] = []
|
|
273
|
+
cell.onAction = { item, key, _, origin in
|
|
274
|
+
actions.append((item.key, key, origin?.source ?? "", origin?.slot))
|
|
275
|
+
}
|
|
276
|
+
func bind(_ trailingData: [[String: Any]], key: String = "row") throws {
|
|
277
|
+
let item = try NativeListItem(data: [
|
|
278
|
+
"key": key, "type": "identity", "title": "Row", "trailing": trailingData,
|
|
279
|
+
])
|
|
280
|
+
cell.bind(item: item, theme: nil, layout: "linear", selected: false,
|
|
281
|
+
checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
|
|
282
|
+
window.layoutIfNeeded()
|
|
283
|
+
cell.layoutIfNeeded()
|
|
284
|
+
}
|
|
285
|
+
func visibleButtons() -> [NativeListAccessoryButton] {
|
|
286
|
+
trailing.arrangedSubviews.compactMap { $0 as? NativeListAccessoryButton }
|
|
287
|
+
.filter { !$0.isHidden }
|
|
288
|
+
}
|
|
289
|
+
let checkbox: [String: Any] = [
|
|
290
|
+
"kind": "checkbox", "state": "unchecked", "actionKey": "selection",
|
|
291
|
+
]
|
|
292
|
+
let first: [String: Any] = ["kind": "button", "label": "First", "actionKey": "first"]
|
|
293
|
+
let second: [String: Any] = ["kind": "button", "label": "Second", "actionKey": "second"]
|
|
294
|
+
|
|
295
|
+
try bind([checkbox, second])
|
|
296
|
+
XCTAssertEqual(visibleButtons().count, 1)
|
|
297
|
+
XCTAssertTrue(visibleButtons()[0].isEnabled)
|
|
298
|
+
XCTAssertTrue(visibleButtons()[0].isUserInteractionEnabled)
|
|
299
|
+
XCTAssertTrue(visibleButtons()[0].allTargets.contains(trailing))
|
|
300
|
+
XCTAssertNotNil(trailing.onAction)
|
|
301
|
+
visibleButtons()[0].sendActions(for: .touchUpInside)
|
|
302
|
+
XCTAssertEqual(actions.last?.rowKey, "row")
|
|
303
|
+
XCTAssertEqual(actions.last?.key, "second")
|
|
304
|
+
XCTAssertEqual(actions.last?.source, "trailingAccessory")
|
|
305
|
+
XCTAssertEqual(actions.last?.slot, 1)
|
|
306
|
+
let selection = try XCTUnwrap(trailing.arrangedSubviews.compactMap { $0 as? UIButton }
|
|
307
|
+
.first { !($0 is NativeListAccessoryButton) && !$0.isHidden })
|
|
308
|
+
selection.sendActions(for: .touchUpInside)
|
|
309
|
+
XCTAssertEqual(actions.last?.key, "selection")
|
|
310
|
+
XCTAssertNil(actions.last?.slot)
|
|
311
|
+
|
|
312
|
+
try bind([first, second])
|
|
313
|
+
XCTAssertEqual(visibleButtons().count, 2)
|
|
314
|
+
visibleButtons()[0].sendActions(for: .touchUpInside)
|
|
315
|
+
XCTAssertEqual(actions.last?.key, "first")
|
|
316
|
+
XCTAssertEqual(actions.last?.slot, 0)
|
|
317
|
+
visibleButtons()[1].sendActions(for: .touchUpInside)
|
|
318
|
+
XCTAssertEqual(actions.last?.key, "second")
|
|
319
|
+
XCTAssertEqual(actions.last?.slot, 1)
|
|
320
|
+
|
|
321
|
+
try bind([second], key: "replacement")
|
|
322
|
+
XCTAssertEqual(visibleButtons().count, 1)
|
|
323
|
+
visibleButtons()[0].sendActions(for: .touchUpInside)
|
|
324
|
+
XCTAssertEqual(actions.last?.rowKey, "replacement")
|
|
325
|
+
XCTAssertEqual(actions.last?.key, "second")
|
|
326
|
+
XCTAssertEqual(actions.last?.slot, 0)
|
|
327
|
+
XCTAssertEqual(actions.count, 5)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
func testIdentityTertiaryIconAnchorInsetSurvivesAccessoryRebind() throws {
|
|
331
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 386, height: 200))
|
|
332
|
+
let controller = UIViewController()
|
|
333
|
+
window.rootViewController = controller
|
|
334
|
+
window.isHidden = false
|
|
335
|
+
defer { window.isHidden = true }
|
|
336
|
+
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 386, height: 88))
|
|
337
|
+
controller.view.addSubview(cell)
|
|
338
|
+
let trailing = try XCTUnwrap(
|
|
339
|
+
Mirror(reflecting: cell).children.first { $0.label == "trailingStack" }?.value
|
|
340
|
+
as? NativeListAccessoryStack)
|
|
341
|
+
var actions: [(rowKey: String, source: String, slot: Int?, inset: CGFloat,
|
|
342
|
+
width: CGFloat)] = []
|
|
343
|
+
cell.onAction = { item, _, _, origin in
|
|
344
|
+
actions.append((item.key, origin?.source ?? "", origin?.slot, origin?.anchorInset ?? -1,
|
|
345
|
+
origin?.sourceView?.bounds.width ?? -1))
|
|
346
|
+
}
|
|
347
|
+
func bind(_ descriptors: [[String: Any]], key: String,
|
|
348
|
+
presentation: String? = nil) throws -> NativeListAccessoryButton {
|
|
349
|
+
var data: [String: Any] = [
|
|
350
|
+
"key": key, "type": "identity", "title": "Row", "height": 88,
|
|
351
|
+
"trailing": descriptors,
|
|
352
|
+
]
|
|
353
|
+
if let presentation { data["presentation"] = presentation }
|
|
354
|
+
cell.bind(item: try NativeListItem(data: data), theme: nil, layout: "linear",
|
|
355
|
+
selected: false, checkboxState: { _, _, fallback in fallback },
|
|
356
|
+
fonts: NativeListFontFamilies())
|
|
357
|
+
window.layoutIfNeeded()
|
|
358
|
+
cell.layoutIfNeeded()
|
|
359
|
+
return try XCTUnwrap(trailing.firstVisibleControl as? NativeListAccessoryButton)
|
|
360
|
+
}
|
|
361
|
+
let tertiary: [String: Any] = [
|
|
362
|
+
"kind": "icon", "name": "CryptoCoinOutline", "buttonStyle": "tertiary",
|
|
363
|
+
"actionKey": "menu",
|
|
364
|
+
]
|
|
365
|
+
let ordinary: [String: Any] = [
|
|
366
|
+
"kind": "icon", "name": "CryptoCoinOutline", "actionKey": "menu",
|
|
367
|
+
]
|
|
368
|
+
|
|
369
|
+
let first = try bind([
|
|
370
|
+
["kind": "checkbox", "state": "unchecked", "actionKey": "selection"], tertiary,
|
|
371
|
+
], key: "tertiary-first")
|
|
372
|
+
XCTAssertEqual(first.bounds.width, 38, accuracy: 0.5)
|
|
373
|
+
first.sendActions(for: .touchUpInside)
|
|
374
|
+
XCTAssertEqual(actions.last?.rowKey, "tertiary-first")
|
|
375
|
+
XCTAssertEqual(actions.last?.source, "trailingAccessory")
|
|
376
|
+
XCTAssertEqual(actions.last?.slot, 1)
|
|
377
|
+
XCTAssertEqual(actions.last?.inset, 7)
|
|
378
|
+
let firstOrigin = try XCTUnwrap(actions.last)
|
|
379
|
+
XCTAssertEqual(firstOrigin.width - 2 * firstOrigin.inset, 24, accuracy: 0.5)
|
|
380
|
+
|
|
381
|
+
let normal = try bind([ordinary], key: "ordinary")
|
|
382
|
+
XCTAssertEqual(normal.bounds.width, 36, accuracy: 0.5)
|
|
383
|
+
normal.sendActions(for: .touchUpInside)
|
|
384
|
+
XCTAssertEqual(actions.last?.rowKey, "ordinary")
|
|
385
|
+
XCTAssertEqual(actions.last?.slot, 0)
|
|
386
|
+
XCTAssertEqual(actions.last?.inset, 0)
|
|
387
|
+
XCTAssertEqual(actions.last?.width, 36)
|
|
388
|
+
|
|
389
|
+
let value = try bind([["kind": "value", "text": "Value"]], key: "value")
|
|
390
|
+
value.bounds.size.width = 38
|
|
391
|
+
XCTAssertEqual(trailing.anchorInset(for: value), 0)
|
|
392
|
+
|
|
393
|
+
let rebound = try bind([tertiary], key: "tertiary-again")
|
|
394
|
+
rebound.sendActions(for: .touchUpInside)
|
|
395
|
+
XCTAssertEqual(actions.last?.rowKey, "tertiary-again")
|
|
396
|
+
XCTAssertEqual(actions.last?.slot, 0)
|
|
397
|
+
XCTAssertEqual(actions.last?.inset, 7)
|
|
398
|
+
let reboundOrigin = try XCTUnwrap(actions.last)
|
|
399
|
+
XCTAssertEqual(reboundOrigin.width - 2 * reboundOrigin.inset, 24, accuracy: 0.5)
|
|
400
|
+
|
|
401
|
+
let account = try bind([ordinary], key: "account", presentation: "accountSelector")
|
|
402
|
+
XCTAssertEqual(account.bounds.width, 38, accuracy: 0.5)
|
|
403
|
+
account.sendActions(for: .touchUpInside)
|
|
404
|
+
XCTAssertEqual(actions.last?.rowKey, "account")
|
|
405
|
+
XCTAssertEqual(actions.last?.slot, 0)
|
|
406
|
+
XCTAssertEqual(actions.last?.inset, 7)
|
|
407
|
+
let accountOrigin = try XCTUnwrap(actions.last)
|
|
408
|
+
XCTAssertEqual(accountOrigin.width - 2 * accountOrigin.inset, 24, accuracy: 0.5)
|
|
409
|
+
|
|
410
|
+
let finalOrdinary = try bind([ordinary], key: "ordinary-again")
|
|
411
|
+
finalOrdinary.sendActions(for: .touchUpInside)
|
|
412
|
+
XCTAssertEqual(actions.last?.rowKey, "ordinary-again")
|
|
413
|
+
XCTAssertEqual(actions.last?.inset, 0)
|
|
414
|
+
XCTAssertEqual(actions.count, 5)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
func testValuePairSegmentsStyleAndPlainRebindOnProductionAccessoryStack() throws {
|
|
418
|
+
let stack = NativeListAccessoryStack(frame: CGRect(x: 0, y: 0, width: 180, height: 48))
|
|
419
|
+
let item = try NativeListItem(data: [
|
|
420
|
+
"key": "pair", "type": "identity", "title": "Pair",
|
|
421
|
+
"leading": ["kind": "icon", "name": "coin"],
|
|
422
|
+
])
|
|
423
|
+
let pair: [String: Any] = [
|
|
424
|
+
"kind": "valuePair", "primary": "0.001", "secondary": "$0.01",
|
|
425
|
+
"primaryTextSegments": [["text": "0.00"], ["text": "1", "style": "subscript"]],
|
|
426
|
+
"secondaryTextSegments": [["text": "$0.0"], ["text": "1", "style": "subscript"]],
|
|
427
|
+
]
|
|
428
|
+
func bind(_ descriptor: [String: Any], size: Int? = nil) {
|
|
429
|
+
let style: [String: Any] = size.map { ["value": ["fontSize": $0]] } ?? [:]
|
|
430
|
+
stack.bind(item, descriptors: [descriptor], theme: nil, style: style,
|
|
431
|
+
checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
|
|
432
|
+
}
|
|
433
|
+
func fontSize(_ title: NSAttributedString, at index: Int) throws -> CGFloat {
|
|
434
|
+
try XCTUnwrap(title.attribute(.font, at: index, effectiveRange: nil) as? UIFont).pointSize
|
|
435
|
+
}
|
|
436
|
+
bind(pair)
|
|
437
|
+
let button = try XCTUnwrap(stack.arrangedSubviews.compactMap { $0 as? UIButton }
|
|
438
|
+
.first { !$0.isHidden })
|
|
439
|
+
let rich = try XCTUnwrap(button.attributedTitle(for: .normal))
|
|
440
|
+
XCTAssertEqual(rich.string, "0.001\n$0.01")
|
|
441
|
+
XCTAssertEqual(try fontSize(rich, at: 0), 16)
|
|
442
|
+
XCTAssertEqual(try fontSize(rich, at: 4), 10)
|
|
443
|
+
XCTAssertEqual(try fontSize(rich, at: 6), 14)
|
|
444
|
+
XCTAssertEqual(try fontSize(rich, at: 10), 9)
|
|
445
|
+
bind(pair, size: 20)
|
|
446
|
+
let styled = try XCTUnwrap(button.attributedTitle(for: .normal))
|
|
447
|
+
XCTAssertEqual(try fontSize(styled, at: 0), 20)
|
|
448
|
+
XCTAssertEqual(try fontSize(styled, at: 4), 12)
|
|
449
|
+
XCTAssertEqual(try fontSize(styled, at: 10), 12)
|
|
450
|
+
bind(["kind": "valuePair", "primary": "10", "secondary": "$2"])
|
|
451
|
+
let plain = try XCTUnwrap(button.attributedTitle(for: .normal))
|
|
452
|
+
XCTAssertEqual(plain.string, "10\n$2")
|
|
453
|
+
XCTAssertEqual(try fontSize(plain, at: 0), 16)
|
|
454
|
+
XCTAssertEqual(try fontSize(plain, at: 3), 14)
|
|
455
|
+
bind(["kind": "valuePair", "primary": "10", "secondary": "$2",
|
|
456
|
+
"primaryTextSegments": [], "secondaryTextSegments": []])
|
|
457
|
+
XCTAssertEqual(button.attributedTitle(for: .normal)?.string, "10\n$2")
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
func testDecorativeRefreshKeepsSixteenPointFrameAcrossActionRebind() throws {
|
|
461
|
+
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 386, height: 56))
|
|
462
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 386, height: 80))
|
|
463
|
+
window.addSubview(cell)
|
|
464
|
+
let stack = try XCTUnwrap(Mirror(reflecting: cell).children.first {
|
|
465
|
+
$0.label == "trailingStack"
|
|
466
|
+
}?.value as? NativeListAccessoryStack)
|
|
467
|
+
func bind(actionKey: String? = nil) throws {
|
|
468
|
+
var icon: [String: Any] = ["kind": "icon", "name": "RefreshCcwOutline"]
|
|
469
|
+
if let actionKey { icon["actionKey"] = actionKey }
|
|
470
|
+
let item = try NativeListItem(data: [
|
|
471
|
+
"key": "refresh", "type": "identity", "title": "Network", "height": 56,
|
|
472
|
+
"leading": ["kind": "icon", "name": "coin"], "trailing": [icon],
|
|
473
|
+
])
|
|
474
|
+
cell.bind(item: item, theme: nil, layout: "linear", selected: false,
|
|
475
|
+
checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
|
|
476
|
+
window.layoutIfNeeded()
|
|
477
|
+
cell.layoutIfNeeded()
|
|
478
|
+
}
|
|
479
|
+
try bind()
|
|
480
|
+
let button = try XCTUnwrap(stack.firstVisibleControl as? UIButton)
|
|
481
|
+
XCTAssertEqual(button.bounds.width, 16, accuracy: 0.5)
|
|
482
|
+
XCTAssertEqual(button.bounds.height, 16, accuracy: 0.5)
|
|
483
|
+
XCTAssertNotNil(button.image(for: .normal))
|
|
484
|
+
XCTAssertEqual(button.image(for: .normal)?.size.width, 16)
|
|
485
|
+
XCTAssertEqual(button.image(for: .normal)?.size.height, 16)
|
|
486
|
+
XCTAssertFalse(button.isUserInteractionEnabled)
|
|
487
|
+
try bind(actionKey: "refresh")
|
|
488
|
+
XCTAssertEqual(button.bounds.width, 36, accuracy: 0.5)
|
|
489
|
+
XCTAssertEqual(button.bounds.height, 36, accuracy: 0.5)
|
|
490
|
+
XCTAssertTrue(button.isUserInteractionEnabled)
|
|
491
|
+
try bind()
|
|
492
|
+
XCTAssertEqual(button.bounds.width, 16, accuracy: 0.5)
|
|
493
|
+
XCTAssertEqual(button.bounds.height, 16, accuracy: 0.5)
|
|
494
|
+
XCTAssertEqual(button.image(for: .normal)?.size.width, 16)
|
|
495
|
+
XCTAssertEqual(button.image(for: .normal)?.size.height, 16)
|
|
496
|
+
XCTAssertFalse(button.isUserInteractionEnabled)
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
func testLowValueAndOverviewAccessoryLayoutsOnProductionIdentityCell() throws {
|
|
500
|
+
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 386, height: 60))
|
|
501
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 386, height: 180))
|
|
502
|
+
window.addSubview(cell)
|
|
503
|
+
let main = try XCTUnwrap(Mirror(reflecting: cell).children.first { $0.label == "mainStack" }?
|
|
504
|
+
.value as? UIStackView)
|
|
505
|
+
let trailing = try XCTUnwrap(Mirror(reflecting: cell).children.first {
|
|
506
|
+
$0.label == "trailingStack"
|
|
507
|
+
}?.value as? NativeListAccessoryStack)
|
|
508
|
+
func bind(_ data: [String: Any], height: CGFloat) throws {
|
|
509
|
+
cell.frame.size.height = height
|
|
510
|
+
cell.bind(item: try NativeListItem(data: data), theme: nil, layout: "linear",
|
|
511
|
+
selected: false, checkboxState: { _, _, fallback in fallback },
|
|
512
|
+
fonts: NativeListFontFamilies())
|
|
513
|
+
window.layoutIfNeeded()
|
|
514
|
+
cell.layoutIfNeeded()
|
|
515
|
+
}
|
|
516
|
+
let pair: [String: Any] = ["kind": "valuePair", "primary": "1.0193B",
|
|
517
|
+
"secondary": "$1,018,849,363.70"]
|
|
518
|
+
let lowValue: [String: Any] = ["key": "low", "type": "identity", "height": 60,
|
|
519
|
+
"title": "FRAX", "subtitleSegments": [
|
|
520
|
+
["text": "$0.9918", "tone": "secondary", "textSegments": [
|
|
521
|
+
["text": "$0.99"], ["text": "18", "style": "subscript"]]],
|
|
522
|
+
["text": "\u{00a0}+0.05%", "tone": "positive"]],
|
|
523
|
+
"leading": ["kind": "token", "fallbackIcon": ["name": "CryptoCoinOutline"]],
|
|
524
|
+
"trailing": [pair], "style": ["horizontalPadding": 12, "verticalPadding": 8,
|
|
525
|
+
"leadingGap": 12, "image": ["width": 40, "height": 40]]]
|
|
526
|
+
try bind(lowValue, height: 60)
|
|
527
|
+
let priceLabels = try XCTUnwrap(Mirror(reflecting: cell).children.first {
|
|
528
|
+
$0.label == "semanticSubtitleLabels"
|
|
529
|
+
}?.value as? [UILabel])
|
|
530
|
+
XCTAssertEqual(priceLabels.count, 2)
|
|
531
|
+
XCTAssertGreaterThan(main.bounds.width, 150)
|
|
532
|
+
XCTAssertTrue(priceLabels.allSatisfy { $0.bounds.width > 0 && !$0.isHidden })
|
|
533
|
+
XCTAssertLessThanOrEqual(priceLabels.last?.frame.maxX ?? .infinity, main.bounds.width + 0.5)
|
|
534
|
+
XCTAssertEqual(trailing.bounds.width, trailing.firstVisibleControl?.bounds.width ?? -1,
|
|
535
|
+
accuracy: 0.5)
|
|
536
|
+
let detail: [String: Any] = ["key": "detail", "type": "identity", "height": 60,
|
|
537
|
+
"title": "Ethereum", "subtitle": "100.0%",
|
|
538
|
+
"leading": ["kind": "network", "fallbackIcon": ["name": "GlobusOutline"]],
|
|
539
|
+
"trailing": [pair, ["kind": "chevron"]],
|
|
540
|
+
"style": ["horizontalPadding": 12, "verticalPadding": 8, "leadingGap": 12,
|
|
541
|
+
"trailingGap": 12, "image": ["width": 32, "height": 32]]]
|
|
542
|
+
try bind(detail, height: 60)
|
|
543
|
+
XCTAssertEqual(trailing.axis, .horizontal)
|
|
544
|
+
let detailControls = trailing.arrangedSubviews.filter { !$0.isHidden }
|
|
545
|
+
XCTAssertEqual(detailControls.count, 2)
|
|
546
|
+
let detailRects = detailControls.map { $0.convert($0.bounds, to: cell) }
|
|
547
|
+
XCTAssertTrue(detailRects.allSatisfy { $0.minY >= 0 && $0.maxY <= 60 })
|
|
548
|
+
XCTAssertEqual(detailRects[0].midY, detailRects[1].midY, accuracy: 1)
|
|
549
|
+
XCTAssertEqual(detailRects[1].minX - detailRects[0].maxX, 12, accuracy: 0.5)
|
|
550
|
+
XCTAssertEqual(detailRects[1].maxX, cell.bounds.maxX - 12, accuracy: 0.5)
|
|
551
|
+
let missing: [String: Any] = ["key": "missing", "type": "identity", "height": 48,
|
|
552
|
+
"title": "Ethereum", "leading": ["kind": "network",
|
|
553
|
+
"fallbackIcon": ["name": "GlobusOutline"]],
|
|
554
|
+
"trailing": [["kind": "icon", "name": "RefreshCcwOutline"], ["kind": "chevron"]],
|
|
555
|
+
"style": ["horizontalPadding": 12, "verticalPadding": 8, "leadingGap": 12,
|
|
556
|
+
"trailingGap": 12, "image": ["width": 32, "height": 32]]]
|
|
557
|
+
try bind(missing, height: 48)
|
|
558
|
+
XCTAssertEqual(trailing.axis, .horizontal)
|
|
559
|
+
let missingControls = trailing.arrangedSubviews.filter { !$0.isHidden }
|
|
560
|
+
XCTAssertEqual(missingControls.count, 2)
|
|
561
|
+
XCTAssertEqual(missingControls[0].bounds.width, 16, accuracy: 0.5)
|
|
562
|
+
XCTAssertEqual(missingControls[1].bounds.width, 24, accuracy: 0.5)
|
|
563
|
+
let missingRects = missingControls.map { $0.convert($0.bounds, to: cell) }
|
|
564
|
+
XCTAssertTrue(missingRects.allSatisfy { $0.minY >= 0 && $0.maxY <= 48 })
|
|
565
|
+
XCTAssertEqual(missingRects[0].midY, missingRects[1].midY, accuracy: 1)
|
|
566
|
+
XCTAssertEqual(missingRects[1].minX - missingRects[0].maxX, 12, accuracy: 0.5)
|
|
567
|
+
XCTAssertEqual(missingRects[1].maxX, cell.bounds.maxX - 12, accuracy: 0.5)
|
|
568
|
+
try bind(detail, height: 60)
|
|
569
|
+
XCTAssertEqual(trailing.axis, .horizontal)
|
|
570
|
+
try bind(["key": "plain", "type": "identity", "title": "Plain", "height": 56,
|
|
571
|
+
"leading": ["kind": "token", "fallbackIcon": ["name": "CryptoCoinOutline"]]],
|
|
572
|
+
height: 56)
|
|
573
|
+
let remainingConstraints = try XCTUnwrap(Mirror(reflecting: cell).children.first {
|
|
574
|
+
$0.label == "selectorConstraints"
|
|
575
|
+
}?.value as? [NSLayoutConstraint])
|
|
576
|
+
XCTAssertTrue(remainingConstraints.isEmpty)
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
func testRiskIdentityRatioKeepsTitleVisibleWithAndWithoutButton() throws {
|
|
580
|
+
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 386, height: 56))
|
|
581
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 386, height: 200))
|
|
582
|
+
window.addSubview(cell)
|
|
583
|
+
let titleLabel = try XCTUnwrap(
|
|
584
|
+
Mirror(reflecting: cell).children.first { $0.label == "titleLabel" }?.value as? UILabel)
|
|
585
|
+
let mainStack = try XCTUnwrap(
|
|
586
|
+
Mirror(reflecting: cell).children.first { $0.label == "mainStack" }?.value as? UIStackView)
|
|
587
|
+
let trailing = try XCTUnwrap(
|
|
588
|
+
Mirror(reflecting: cell).children.first { $0.label == "trailingStack" }?.value
|
|
589
|
+
as? NativeListAccessoryStack)
|
|
590
|
+
let base: [String: Any] = [
|
|
591
|
+
"key": "risk", "type": "identity", "title": "XSR", "height": 56,
|
|
592
|
+
"leading": ["kind": "token", "fallbackIcon": ["name": "CryptoCoinOutline"]],
|
|
593
|
+
"style": [
|
|
594
|
+
"horizontalPadding": 12, "verticalPadding": 8, "leadingGap": 12,
|
|
595
|
+
"leadingContentMaxWidthRatio": 0.6,
|
|
596
|
+
"image": ["width": 40, "height": 40, "shape": "circle"],
|
|
597
|
+
"title": ["fontSize": 16, "lineHeight": 24, "fontWeight": "medium", "lines": 1],
|
|
598
|
+
],
|
|
599
|
+
]
|
|
600
|
+
|
|
601
|
+
func bind(_ data: [String: Any], capped: Bool = true) throws {
|
|
602
|
+
cell.bind(item: try NativeListItem(data: data), theme: nil, layout: "linear",
|
|
603
|
+
selected: false, checkboxState: { _, _, fallback in fallback },
|
|
604
|
+
fonts: NativeListFontFamilies())
|
|
605
|
+
window.layoutIfNeeded()
|
|
606
|
+
cell.layoutIfNeeded()
|
|
607
|
+
XCTAssertFalse(titleLabel.isHidden)
|
|
608
|
+
XCTAssertGreaterThan(titleLabel.bounds.width, 0.5,
|
|
609
|
+
"A visible token title must not collapse when the row reserves trailing space")
|
|
610
|
+
XCTAssertEqual(titleLabel.bounds.height, 24, accuracy: 0.5)
|
|
611
|
+
let intrinsicWidth = titleLabel.intrinsicContentSize.width
|
|
612
|
+
let capWidth = cell.root.bounds.width * 0.6 - 52
|
|
613
|
+
let requiredTitleWidth = capped ? min(intrinsicWidth, capWidth) : intrinsicWidth
|
|
614
|
+
XCTAssertGreaterThanOrEqual(titleLabel.bounds.width, requiredTitleWidth - 0.5,
|
|
615
|
+
"title=\(data["title"] ?? "") intrinsic=\(intrinsicWidth) "
|
|
616
|
+
+ "rendered=\(titleLabel.bounds.width) root=\(cell.root.bounds.width) "
|
|
617
|
+
+ "trailing=\(trailing.bounds.width)")
|
|
618
|
+
XCTAssertGreaterThanOrEqual(mainStack.bounds.width, titleLabel.bounds.width - 0.5)
|
|
619
|
+
XCTAssertEqual(trailing.frame.maxX, cell.root.bounds.maxX, accuracy: 0.5)
|
|
620
|
+
if capped {
|
|
621
|
+
XCTAssertLessThanOrEqual(mainStack.bounds.width, cell.root.bounds.width * 0.6 - 52 + 0.5)
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
try bind(base)
|
|
626
|
+
XCTAssertNil(trailing.firstVisibleControl)
|
|
627
|
+
try bind(base.merging(["trailing": [[
|
|
628
|
+
"kind": "button", "label": "Show on home", "actionKey": "show",
|
|
629
|
+
]]]) { _, newer in newer })
|
|
630
|
+
let button = try XCTUnwrap(trailing.firstVisibleControl)
|
|
631
|
+
XCTAssertGreaterThan(button.bounds.width, 100)
|
|
632
|
+
XCTAssertEqual(trailing.frame.minX + button.frame.maxX, cell.root.bounds.maxX, accuracy: 0.5)
|
|
633
|
+
cell.frame.size.height = 88
|
|
634
|
+
try bind(base.merging(["trailing": [
|
|
635
|
+
["kind": "button", "label": "A", "actionKey": "first"],
|
|
636
|
+
["kind": "button", "label": "Longer action", "actionKey": "second"],
|
|
637
|
+
], "height": 88]) { _, newer in newer })
|
|
638
|
+
let visibleButtons = trailing.arrangedSubviews.compactMap { $0 as? NativeListAccessoryButton }
|
|
639
|
+
.filter { !$0.isHidden }
|
|
640
|
+
XCTAssertEqual(visibleButtons.count, 2)
|
|
641
|
+
XCTAssertGreaterThan(visibleButtons[1].bounds.width, visibleButtons[0].bounds.width)
|
|
642
|
+
XCTAssertEqual(trailing.frame.minX + visibleButtons[1].frame.maxX,
|
|
643
|
+
cell.root.bounds.maxX, accuracy: 0.5)
|
|
644
|
+
cell.frame.size.height = 56
|
|
645
|
+
try bind(base.merging(["title": "A very long token symbol that must truncate within the cap"])
|
|
646
|
+
{ _, newer in newer })
|
|
647
|
+
XCTAssertLessThan(titleLabel.bounds.width, titleLabel.intrinsicContentSize.width)
|
|
648
|
+
try bind(base)
|
|
649
|
+
XCTAssertNil(trailing.firstVisibleControl)
|
|
650
|
+
try bind(base.merging(["key": "searched-risk", "title": "rkl"]) { _, newer in newer })
|
|
651
|
+
XCTAssertNil(trailing.firstVisibleControl)
|
|
652
|
+
try bind(base)
|
|
653
|
+
var unrestricted = base
|
|
654
|
+
var unrestrictedStyle = try XCTUnwrap(base["style"] as? [String: Any])
|
|
655
|
+
unrestrictedStyle.removeValue(forKey: "leadingContentMaxWidthRatio")
|
|
656
|
+
unrestricted["style"] = unrestrictedStyle
|
|
657
|
+
try bind(unrestricted, capped: false)
|
|
658
|
+
XCTAssertEqual(cell.root.arrangedSubviews.count, 3)
|
|
659
|
+
XCTAssertEqual(mainStack.contentHuggingPriority(for: .horizontal).rawValue, 1, accuracy: 0.1)
|
|
660
|
+
let spacing = cell.root.customSpacing(after: mainStack)
|
|
661
|
+
XCTAssertTrue(spacing == UIStackView.spacingUseDefault || spacing == cell.root.spacing)
|
|
662
|
+
}
|
|
663
|
+
|
|
156
664
|
func testFixedFooterReplacesRendererAndKeepsActionRouting() throws {
|
|
157
665
|
let view = NativeListView(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
|
|
158
666
|
var actions: [[String: Any]] = []
|
|
@@ -246,6 +754,35 @@ final class NativeListLifecycleTests: XCTestCase {
|
|
|
246
754
|
XCTAssertEqual(footer.accessibilityLabel, "Continue")
|
|
247
755
|
}
|
|
248
756
|
|
|
757
|
+
func testPaddedSquareNetworkOverlayRoundsInnerImageAndResetsOnRebind() throws {
|
|
758
|
+
let visual = NativeListLeadingVisual(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
|
|
759
|
+
func bind(_ overlay: [String: Any]) {
|
|
760
|
+
visual.bind(["kind": "token", "overlays": [overlay]], style: [:], key: "overlay",
|
|
761
|
+
theme: nil, isUnread: false, fonts: NativeListFontFamilies())
|
|
762
|
+
visual.layoutIfNeeded()
|
|
763
|
+
}
|
|
764
|
+
let image: [String: Any] = ["uri": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Y9xvY0AAAAASUVORK5CYII="]
|
|
765
|
+
bind(["position": "bottomRight", "size": 20, "width": 20, "height": 20,
|
|
766
|
+
"padding": 2, "image": image, "fallbackIcon": ["name": "GlobusOutline"]])
|
|
767
|
+
let slots = try XCTUnwrap(Mirror(reflecting: visual).children.first {
|
|
768
|
+
$0.label == "overlaySlots"
|
|
769
|
+
}?.value as? [NativeListImageSlot])
|
|
770
|
+
let slot = try XCTUnwrap(slots.first?.view)
|
|
771
|
+
XCTAssertEqual(slot.bounds.size, CGSize(width: 16, height: 16))
|
|
772
|
+
XCTAssertEqual(slot.layer.cornerRadius, 8, accuracy: 0.5)
|
|
773
|
+
XCTAssertTrue(slot.clipsToBounds)
|
|
774
|
+
bind(["position": "bottomRight", "width": 20, "height": 14,
|
|
775
|
+
"padding": 2, "image": image])
|
|
776
|
+
XCTAssertEqual(slot.layer.cornerRadius, 0)
|
|
777
|
+
XCTAssertFalse(slot.clipsToBounds)
|
|
778
|
+
bind(["position": "bottomRight", "size": 20, "padding": 2, "text": "E"])
|
|
779
|
+
XCTAssertEqual(slot.layer.cornerRadius, 0)
|
|
780
|
+
XCTAssertFalse(slot.clipsToBounds)
|
|
781
|
+
bind(["position": "bottomRight", "size": 20, "padding": 2, "image": image])
|
|
782
|
+
XCTAssertEqual(slot.layer.cornerRadius, 8, accuracy: 0.5)
|
|
783
|
+
visual.recycle()
|
|
784
|
+
}
|
|
785
|
+
|
|
249
786
|
func testNestedWalletMembersAndDragBadgeFollowEachBindMapping() throws {
|
|
250
787
|
let group = NativeListWalletGroupCell(frame: CGRect(x: 0, y: 0, width: 320, height: 200))
|
|
251
788
|
let item = try NativeListItem(data: [
|
|
@@ -348,7 +885,7 @@ final class NativeListLifecycleTests: XCTestCase {
|
|
|
348
885
|
XCTAssertTrue(header.clipsToBounds)
|
|
349
886
|
XCTAssertEqual(header.bounds.height, 0, "An unmeasured header cannot draw over the first rows")
|
|
350
887
|
|
|
351
|
-
view.setContainerSlotHeightsJson("[44,44,60]")
|
|
888
|
+
view.setContainerSlotHeightsJson("[44,44,60,0]")
|
|
352
889
|
view.layoutIfNeeded()
|
|
353
890
|
list.layoutIfNeeded()
|
|
354
891
|
XCTAssertEqual(slots[0].convert(CGPoint.zero, to: list), CGPoint(x: 16, y: 0))
|
|
@@ -363,10 +900,360 @@ final class NativeListLifecycleTests: XCTestCase {
|
|
|
363
900
|
XCTAssertNil(slots[2].superview)
|
|
364
901
|
}
|
|
365
902
|
|
|
903
|
+
func testStructuralShrinkUsesTheTallerFinalColumnForOffsetClamping() throws {
|
|
904
|
+
let cases: [(name: String, sidecar: Int, offset: CGFloat, height: CGFloat,
|
|
905
|
+
zeroInset: Bool)] = [
|
|
906
|
+
("sidecar stays taller", 2200, 1450, 2200, false),
|
|
907
|
+
("left column stays taller", 1000, 1100, 1560, false),
|
|
908
|
+
("left column zero inset", 1000, 1100, 1560, true),
|
|
909
|
+
("sidecar becomes taller", 1700, 1050, 1700, false),
|
|
910
|
+
]
|
|
911
|
+
for testCase in cases {
|
|
912
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 1000, height: 600))
|
|
913
|
+
let controller = UIViewController()
|
|
914
|
+
window.rootViewController = controller
|
|
915
|
+
let view = NativeListView(frame: window.bounds)
|
|
916
|
+
controller.view.addSubview(view)
|
|
917
|
+
window.isHidden = false
|
|
918
|
+
defer {
|
|
919
|
+
view.dispose()
|
|
920
|
+
view.removeFromSuperview()
|
|
921
|
+
window.isHidden = true
|
|
922
|
+
window.rootViewController = nil
|
|
923
|
+
}
|
|
924
|
+
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
925
|
+
// Keep the viewport insets fixed while testing structural offset clamping.
|
|
926
|
+
let explicitInset = testCase.zeroInset ? UIEdgeInsets.zero :
|
|
927
|
+
UIEdgeInsets(top: 62, left: 0, bottom: 34, right: 0)
|
|
928
|
+
list.contentInsetAdjustmentBehavior = .never
|
|
929
|
+
list.contentInset = explicitInset
|
|
930
|
+
view.mountContainerSlot(UIView(), atIndex: 0)
|
|
931
|
+
view.mountContainerSlot(UIView(), atIndex: 1)
|
|
932
|
+
let footer = UIView()
|
|
933
|
+
view.mountContainerSlot(footer, atIndex: 2)
|
|
934
|
+
let sidecar = UIView()
|
|
935
|
+
view.mountContainerSlot(sidecar, atIndex: 3)
|
|
936
|
+
view.setContainerSlotHeightsJson("[0,0,60,\(testCase.sidecar)]")
|
|
937
|
+
view.setSidecarLayoutJson("{\"width\":300,\"gap\":24,\"maxContentWidth\":1000}")
|
|
938
|
+
view.applySnapshotJson(try structuralRowsSnapshot(count: 30))
|
|
939
|
+
view.layoutIfNeeded()
|
|
940
|
+
list.layoutIfNeeded()
|
|
941
|
+
drainMainQueue()
|
|
942
|
+
XCTAssertEqual(list.adjustedContentInset, explicitInset, testCase.name)
|
|
943
|
+
XCTAssertEqual(list.contentSize.height, max(1860, CGFloat(testCase.sidecar)),
|
|
944
|
+
accuracy: 1, testCase.name)
|
|
945
|
+
list.contentOffset.y = testCase.offset
|
|
946
|
+
list.layoutIfNeeded()
|
|
947
|
+
XCTAssertEqual(list.contentOffset.y, testCase.offset, accuracy: 1, testCase.name)
|
|
948
|
+
|
|
949
|
+
view.applySnapshotJson(try structuralRowsSnapshot(count: 25, transitionID: testCase.name))
|
|
950
|
+
let completed = expectation(description: "Native structural display link: \(testCase.name)")
|
|
951
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { completed.fulfill() }
|
|
952
|
+
wait(for: [completed], timeout: 1)
|
|
953
|
+
list.layoutIfNeeded()
|
|
954
|
+
XCTAssertEqual(list.adjustedContentInset, explicitInset, testCase.name)
|
|
955
|
+
XCTAssertEqual(list.contentSize.height, testCase.height, accuracy: 1, testCase.name)
|
|
956
|
+
let inset = list.adjustedContentInset
|
|
957
|
+
let finalMaximum = max(-inset.top, testCase.height - list.bounds.height + inset.bottom)
|
|
958
|
+
let expectedOffset = min(testCase.offset, finalMaximum)
|
|
959
|
+
XCTAssertEqual(list.contentOffset.y, expectedOffset, accuracy: 1, testCase.name)
|
|
960
|
+
XCTAssertNotNil(sidecar.superview, testCase.name)
|
|
961
|
+
XCTAssertEqual(footer.convert(.zero, to: list).y, 1500, accuracy: 1, testCase.name)
|
|
962
|
+
waitForStructuralFrames(0.1)
|
|
963
|
+
XCTAssertEqual(list.adjustedContentInset, explicitInset, testCase.name)
|
|
964
|
+
XCTAssertEqual(list.contentSize.height, testCase.height, accuracy: 1, testCase.name)
|
|
965
|
+
XCTAssertEqual(list.contentOffset.y, expectedOffset, accuracy: 1, testCase.name)
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
func testVisibleNativeCellsRemainBoundedAsRowsGrowTenfold() throws {
|
|
970
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 600))
|
|
971
|
+
let controller = UIViewController()
|
|
972
|
+
window.rootViewController = controller
|
|
973
|
+
let view = NativeListView(frame: window.bounds)
|
|
974
|
+
controller.view.addSubview(view)
|
|
975
|
+
window.isHidden = false
|
|
976
|
+
defer { window.isHidden = true }
|
|
977
|
+
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
978
|
+
func sampleCells(count: Int) throws -> [(visible: Int, attached: Int)] {
|
|
979
|
+
view.applySnapshotJson(try structuralRowsSnapshot(count: count))
|
|
980
|
+
view.layoutIfNeeded()
|
|
981
|
+
list.layoutIfNeeded()
|
|
982
|
+
let lastOffset = CGFloat(count * 60 - 600)
|
|
983
|
+
return [CGFloat(0), lastOffset / 2, lastOffset].map { offset in
|
|
984
|
+
list.setContentOffset(CGPoint(x: 0, y: offset), animated: false)
|
|
985
|
+
list.layoutIfNeeded()
|
|
986
|
+
return (list.visibleCells.count,
|
|
987
|
+
list.subviews.compactMap { $0 as? NativeListRowHost }.count)
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
let hundredCells = try sampleCells(count: 100)
|
|
991
|
+
let thousandCells = try sampleCells(count: 1000)
|
|
992
|
+
print("NativeList 100 visible/attached first/mid/tail: \(hundredCells)")
|
|
993
|
+
print("NativeList 1000 visible/attached first/mid/tail: \(thousandCells)")
|
|
994
|
+
XCTAssertTrue(hundredCells.allSatisfy {
|
|
995
|
+
$0.visible > 0 && $0.visible <= 24 && $0.attached > 0 && $0.attached <= 24
|
|
996
|
+
})
|
|
997
|
+
XCTAssertTrue(thousandCells.allSatisfy {
|
|
998
|
+
$0.visible > 0 && $0.visible <= 24 && $0.attached > 0 && $0.attached <= 24
|
|
999
|
+
})
|
|
1000
|
+
XCTAssertLessThanOrEqual(thousandCells.map(\.attached).max() ?? 0,
|
|
1001
|
+
(hundredCells.map(\.attached).max() ?? 0) + 4)
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
func testStructuralTransitionRapidReversalKeepsRetiringContentAtNaturalHeight() throws {
|
|
1005
|
+
try requireStructuralAnimation()
|
|
1006
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 600))
|
|
1007
|
+
let controller = UIViewController()
|
|
1008
|
+
window.rootViewController = controller
|
|
1009
|
+
let view = NativeListView(frame: window.bounds)
|
|
1010
|
+
controller.view.addSubview(view)
|
|
1011
|
+
window.isHidden = false
|
|
1012
|
+
defer { view.dispose(); view.removeFromSuperview(); window.isHidden = true }
|
|
1013
|
+
let footer = UIView()
|
|
1014
|
+
for index in 0..<2 { view.mountContainerSlot(UIView(), atIndex: index) }
|
|
1015
|
+
view.mountContainerSlot(footer, atIndex: 2)
|
|
1016
|
+
view.setContainerSlotHeightsJson("[0,0,60,0]")
|
|
1017
|
+
view.applySnapshotJson(try structuralRowsSnapshot(count: 25, generation: 1))
|
|
1018
|
+
view.layoutIfNeeded()
|
|
1019
|
+
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
1020
|
+
list.layoutIfNeeded()
|
|
1021
|
+
drainMainQueue()
|
|
1022
|
+
list.contentOffset.y = 900
|
|
1023
|
+
list.layoutIfNeeded()
|
|
1024
|
+
|
|
1025
|
+
view.applySnapshotJson(try structuralRowsSnapshot(count: 30, generation: 2,
|
|
1026
|
+
transitionID: "expand-first", durationMs: 400))
|
|
1027
|
+
waitForStructuralFrames(0.08)
|
|
1028
|
+
list.contentOffset.y = 1100
|
|
1029
|
+
list.layoutIfNeeded()
|
|
1030
|
+
view.applySnapshotJson(try structuralRowsSnapshot(count: 25, generation: 3,
|
|
1031
|
+
transitionID: "collapse-middle", durationMs: 400))
|
|
1032
|
+
waitForStructuralFrames(0.08)
|
|
1033
|
+
list.layoutIfNeeded()
|
|
1034
|
+
let source = try XCTUnwrap(list.dataSource as? UICollectionViewDiffableDataSource<Int, String>)
|
|
1035
|
+
let retiring = try XCTUnwrap(list.indexPathsForVisibleItems.compactMap { indexPath -> NativeListRowHost? in
|
|
1036
|
+
guard let key = source.itemIdentifier(for: indexPath),
|
|
1037
|
+
let index = Int(key.replacingOccurrences(of: "row-", with: "")), index >= 25 else {
|
|
1038
|
+
return nil
|
|
1039
|
+
}
|
|
1040
|
+
return list.cellForItem(at: indexPath) as? NativeListRowHost
|
|
1041
|
+
}.first)
|
|
1042
|
+
XCTAssertGreaterThan(retiring.bounds.height, 0)
|
|
1043
|
+
XCTAssertLessThan(retiring.bounds.height, 60)
|
|
1044
|
+
XCTAssertEqual(retiring.contentView.bounds.height, 60, accuracy: 1)
|
|
1045
|
+
XCTAssertNotNil(retiring.structuralContentHeight)
|
|
1046
|
+
|
|
1047
|
+
view.applySnapshotJson(try structuralRowsSnapshot(count: 30, generation: 4,
|
|
1048
|
+
transitionID: "expand-last", durationMs: 400))
|
|
1049
|
+
waitForStructuralFrames(0.5)
|
|
1050
|
+
list.layoutIfNeeded()
|
|
1051
|
+
let keys = source.snapshot().itemIdentifiers
|
|
1052
|
+
XCTAssertEqual(keys, (0..<30).map { "row-\($0)" })
|
|
1053
|
+
XCTAssertEqual(Set(keys).count, 30)
|
|
1054
|
+
XCTAssertEqual(list.contentSize.height, 1860, accuracy: 1)
|
|
1055
|
+
XCTAssertEqual(footer.convert(.zero, to: list).y, 1800, accuracy: 1)
|
|
1056
|
+
XCTAssertGreaterThanOrEqual(list.contentOffset.y, -list.adjustedContentInset.top - 1)
|
|
1057
|
+
XCTAssertLessThanOrEqual(list.contentOffset.y,
|
|
1058
|
+
list.contentSize.height - list.bounds.height + list.adjustedContentInset.bottom + 1)
|
|
1059
|
+
for case let cell as NativeListRowHost in list.visibleCells {
|
|
1060
|
+
XCTAssertEqual(cell.alpha, 1, accuracy: 0.01)
|
|
1061
|
+
XCTAssertNil(cell.structuralContentHeight)
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
func testStructuralTransitionSurvivesVisibleDataRowPatch() throws {
|
|
1066
|
+
try requireStructuralAnimation()
|
|
1067
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 600))
|
|
1068
|
+
let controller = UIViewController()
|
|
1069
|
+
window.rootViewController = controller
|
|
1070
|
+
let view = NativeListView(frame: window.bounds)
|
|
1071
|
+
controller.view.addSubview(view)
|
|
1072
|
+
window.isHidden = false
|
|
1073
|
+
defer { view.dispose(); view.removeFromSuperview(); window.isHidden = true }
|
|
1074
|
+
let footer = UIView()
|
|
1075
|
+
for index in 0..<2 { view.mountContainerSlot(UIView(), atIndex: index) }
|
|
1076
|
+
view.mountContainerSlot(footer, atIndex: 2)
|
|
1077
|
+
view.setContainerSlotHeightsJson("[0,0,60,0]")
|
|
1078
|
+
view.applySnapshotJson(try structuralRowsSnapshot(count: 30, generation: 1, dataRows: true))
|
|
1079
|
+
view.layoutIfNeeded()
|
|
1080
|
+
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
1081
|
+
list.layoutIfNeeded()
|
|
1082
|
+
drainMainQueue()
|
|
1083
|
+
list.contentOffset.y = 1100
|
|
1084
|
+
list.layoutIfNeeded()
|
|
1085
|
+
|
|
1086
|
+
view.applySnapshotJson(try structuralRowsSnapshot(count: 25, generation: 2,
|
|
1087
|
+
transitionID: "collapse-with-patch", durationMs: 800, dataRows: true))
|
|
1088
|
+
waitForStructuralFrames(0.3)
|
|
1089
|
+
let source = try XCTUnwrap(list.dataSource as? UICollectionViewDiffableDataSource<Int, String>)
|
|
1090
|
+
let tail = try XCTUnwrap(source.indexPath(for: "row-25"))
|
|
1091
|
+
let retiring = try XCTUnwrap(list.cellForItem(at: tail) as? NativeListRowHost)
|
|
1092
|
+
let heightBeforePatch = retiring.bounds.height
|
|
1093
|
+
XCTAssertGreaterThan(heightBeforePatch, 0)
|
|
1094
|
+
XCTAssertLessThan(heightBeforePatch, 60)
|
|
1095
|
+
let patch: [[String: Any]] = [[
|
|
1096
|
+
"key": "row-20", "type": "dataRow", "changes": [
|
|
1097
|
+
"revision": 2,
|
|
1098
|
+
"columns": [["key": "asset", "text": "Asset"],
|
|
1099
|
+
["key": "price", "text": "$123.45"]],
|
|
1100
|
+
],
|
|
1101
|
+
]]
|
|
1102
|
+
view.applyPatchesJson(String(decoding: try JSONSerialization.data(withJSONObject: patch),
|
|
1103
|
+
as: UTF8.self))
|
|
1104
|
+
list.layoutIfNeeded()
|
|
1105
|
+
let patched = try XCTUnwrap(list.cellForItem(at: IndexPath(item: 20, section: 0)))
|
|
1106
|
+
XCTAssertTrue(labels(in: patched).contains { $0.text == "$123.45" })
|
|
1107
|
+
waitForStructuralFrames(0.05)
|
|
1108
|
+
list.layoutIfNeeded()
|
|
1109
|
+
XCTAssertLessThan(retiring.bounds.height, heightBeforePatch)
|
|
1110
|
+
waitForStructuralFrames(0.55)
|
|
1111
|
+
list.layoutIfNeeded()
|
|
1112
|
+
XCTAssertEqual(source.snapshot().itemIdentifiers, (0..<25).map { "row-\($0)" })
|
|
1113
|
+
XCTAssertEqual(list.contentSize.height, 1560, accuracy: 1)
|
|
1114
|
+
XCTAssertEqual(footer.convert(.zero, to: list).y, 1500, accuracy: 1)
|
|
1115
|
+
let finalPatched = try XCTUnwrap(list.cellForItem(at: IndexPath(item: 20, section: 0)))
|
|
1116
|
+
XCTAssertTrue(labels(in: finalPatched).contains { $0.text == "$123.45" })
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
func testStructuralTransitionDoesNotOverrideUserDrag() throws {
|
|
1120
|
+
try requireStructuralAnimation()
|
|
1121
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 600))
|
|
1122
|
+
let controller = UIViewController()
|
|
1123
|
+
window.rootViewController = controller
|
|
1124
|
+
let view = NativeListView(frame: window.bounds)
|
|
1125
|
+
controller.view.addSubview(view)
|
|
1126
|
+
window.isHidden = false
|
|
1127
|
+
defer { view.dispose(); view.removeFromSuperview(); window.isHidden = true }
|
|
1128
|
+
for index in 0..<3 { view.mountContainerSlot(UIView(), atIndex: index) }
|
|
1129
|
+
view.setContainerSlotHeightsJson("[0,0,60,0]")
|
|
1130
|
+
view.applySnapshotJson(try structuralRowsSnapshot(count: 30, generation: 1))
|
|
1131
|
+
view.layoutIfNeeded()
|
|
1132
|
+
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
1133
|
+
list.layoutIfNeeded()
|
|
1134
|
+
drainMainQueue()
|
|
1135
|
+
list.contentOffset.y = 1100
|
|
1136
|
+
view.applySnapshotJson(try structuralRowsSnapshot(count: 25, generation: 2,
|
|
1137
|
+
transitionID: "collapse-drag", durationMs: 400))
|
|
1138
|
+
waitForStructuralFrames(0.08)
|
|
1139
|
+
view.scrollViewWillBeginDragging(list)
|
|
1140
|
+
list.contentOffset.y = 600
|
|
1141
|
+
list.layoutIfNeeded()
|
|
1142
|
+
waitForStructuralFrames(0.15)
|
|
1143
|
+
XCTAssertEqual(list.contentOffset.y, 600, accuracy: 1)
|
|
1144
|
+
waitForStructuralFrames(0.35)
|
|
1145
|
+
list.layoutIfNeeded()
|
|
1146
|
+
XCTAssertEqual(list.contentOffset.y, 600, accuracy: 1)
|
|
1147
|
+
let source = try XCTUnwrap(list.dataSource as? UICollectionViewDiffableDataSource<Int, String>)
|
|
1148
|
+
XCTAssertEqual(source.snapshot().itemIdentifiers, (0..<25).map { "row-\($0)" })
|
|
1149
|
+
XCTAssertEqual(list.contentSize.height, 1560, accuracy: 1)
|
|
1150
|
+
XCTAssertTrue(list.visibleCells.allSatisfy { abs($0.alpha - 1) < 0.01 })
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
func testStructuralTransitionDetachAndDisposeReleaseView() throws {
|
|
1154
|
+
try requireStructuralAnimation()
|
|
1155
|
+
for dispose in [false, true] {
|
|
1156
|
+
var callbacks = 0
|
|
1157
|
+
let reference = try detachStructuralTransition(dispose: dispose) { callbacks += 1 }
|
|
1158
|
+
if dispose {
|
|
1159
|
+
drainMainQueue()
|
|
1160
|
+
XCTAssertNil(reference.view)
|
|
1161
|
+
let countAtDispose = callbacks
|
|
1162
|
+
waitForStructuralFrames(0.5)
|
|
1163
|
+
XCTAssertEqual(callbacks, countAtDispose)
|
|
1164
|
+
} else {
|
|
1165
|
+
waitForStructuralFrames(0.5)
|
|
1166
|
+
XCTAssertNil(reference.view)
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
private final class WeakListReference {
|
|
1172
|
+
weak var view: NativeListView?
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
private func detachStructuralTransition(
|
|
1176
|
+
dispose: Bool, onCallback: @escaping () -> Void
|
|
1177
|
+
) throws -> WeakListReference {
|
|
1178
|
+
try autoreleasepool {
|
|
1179
|
+
let reference = WeakListReference()
|
|
1180
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 600))
|
|
1181
|
+
let controller = UIViewController()
|
|
1182
|
+
window.rootViewController = controller
|
|
1183
|
+
let view = NativeListView(frame: window.bounds)
|
|
1184
|
+
controller.view.addSubview(view)
|
|
1185
|
+
window.isHidden = false
|
|
1186
|
+
for index in 0..<3 { view.mountContainerSlot(UIView(), atIndex: index) }
|
|
1187
|
+
view.setContainerSlotHeightsJson("[0,0,60,0]")
|
|
1188
|
+
view.applySnapshotJson(try structuralRowsSnapshot(count: 30, generation: 1))
|
|
1189
|
+
view.layoutIfNeeded()
|
|
1190
|
+
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
1191
|
+
view.onVisibleRangeChanged = { _ in onCallback() }
|
|
1192
|
+
view.onEndReached = { _ in onCallback() }
|
|
1193
|
+
list.layoutIfNeeded()
|
|
1194
|
+
drainMainQueue()
|
|
1195
|
+
view.applySnapshotJson(try structuralRowsSnapshot(count: 25, generation: 2,
|
|
1196
|
+
transitionID: dispose ? "dispose-mid-transition" : "detach-mid-transition",
|
|
1197
|
+
durationMs: 400))
|
|
1198
|
+
waitForStructuralFrames(0.08)
|
|
1199
|
+
reference.view = view
|
|
1200
|
+
if dispose {
|
|
1201
|
+
view.dispose()
|
|
1202
|
+
XCTAssertNil(list.delegate)
|
|
1203
|
+
XCTAssertNil(list.dataSource)
|
|
1204
|
+
}
|
|
1205
|
+
view.removeFromSuperview()
|
|
1206
|
+
window.isHidden = true
|
|
1207
|
+
window.rootViewController = nil
|
|
1208
|
+
return reference
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
private func requireStructuralAnimation() throws {
|
|
1213
|
+
if UIAccessibility.isReduceMotionEnabled {
|
|
1214
|
+
throw XCTSkip("Structural animation is disabled by Reduce Motion")
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
private func waitForStructuralFrames(_ seconds: TimeInterval) {
|
|
1219
|
+
let completed = expectation(description: "Native structural display link ran for \(seconds)s")
|
|
1220
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + seconds) { completed.fulfill() }
|
|
1221
|
+
wait(for: [completed], timeout: seconds + 1)
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
private func labels(in view: UIView) -> [UILabel] {
|
|
1225
|
+
let current = (view as? UILabel).map { [$0] } ?? []
|
|
1226
|
+
return current + view.subviews.flatMap(labels(in:))
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
private func structuralRowsSnapshot(
|
|
1230
|
+
count: Int, generation: Int? = nil, transitionID: String? = nil,
|
|
1231
|
+
durationMs: Int = 80, dataRows: Bool = false
|
|
1232
|
+
) throws -> String {
|
|
1233
|
+
let rows: [[String: Any]] = (0..<count).map {
|
|
1234
|
+
if dataRows {
|
|
1235
|
+
return ["key": "row-\($0)", "type": "dataRow", "height": 60,
|
|
1236
|
+
"columns": [["key": "asset", "text": "Asset"],
|
|
1237
|
+
["key": "price", "text": "$1.00"]]]
|
|
1238
|
+
}
|
|
1239
|
+
return ["key": "row-\($0)", "type": "action", "title": "Row", "height": 60]
|
|
1240
|
+
}
|
|
1241
|
+
var value: [String: Any] = [
|
|
1242
|
+
"schemaVersion": 1, "generation": generation ?? count + 1,
|
|
1243
|
+
"layout": ["kind": "linear"], "rows": rows,
|
|
1244
|
+
]
|
|
1245
|
+
if let transitionID {
|
|
1246
|
+
value["structuralTransition"] = [
|
|
1247
|
+
"id": transitionID, "durationMs": durationMs, "anchorKey": "row-24",
|
|
1248
|
+
]
|
|
1249
|
+
}
|
|
1250
|
+
return String(decoding: try JSONSerialization.data(withJSONObject: value), as: UTF8.self)
|
|
1251
|
+
}
|
|
1252
|
+
|
|
366
1253
|
private func makeScrollingList() throws -> NativeListView {
|
|
367
1254
|
let view = NativeListView(frame: CGRect(x: 0, y: 0, width: 320, height: 708))
|
|
368
1255
|
for index in 0..<3 { view.mountContainerSlot(UIView(), atIndex: index) }
|
|
369
|
-
view.setContainerSlotHeightsJson("[44,44,44]")
|
|
1256
|
+
view.setContainerSlotHeightsJson("[44,44,44,0]")
|
|
370
1257
|
view.applySnapshotJson(try scrollingSnapshot(count: 40))
|
|
371
1258
|
view.layoutIfNeeded()
|
|
372
1259
|
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|