@onekeyfe/react-native-native-list 3.0.158 → 3.0.159
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -5
- package/android/build.gradle +7 -0
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +20 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +711 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListActionRenderer.kt +169 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +179 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +264 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +20 -6
- package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +53 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +487 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListEndAlignment.kt +5 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +820 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListImageSlot.kt +147 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +453 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +997 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +268 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +243 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +232 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMetricCardRenderer.kt +551 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +27 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +475 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRailRenderer.kt +143 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +42 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +415 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +163 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRowHost.kt +70 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListScrollPositionTracker.kt +59 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +763 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListSystemRenderer.kt +464 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +432 -124
- package/android/src/main/java/com/onekey/nativelist/NativeListWalletGroupRenderer.kt +407 -0
- package/android/src/main/res/values/native_scroll_coordinator_ids.xml +5 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListEndAlignmentTest.kt +34 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListScrollPositionTrackerTest.kt +44 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListSelectorBackgroundColorTest.kt +34 -0
- package/docs/DESIGN.md +520 -9
- package/docs/MIGRATION_BASELINE.md +117 -0
- package/docs/ROW_TEMPLATES.md +404 -0
- package/docs/SPEC.md +621 -0
- package/docs/STYLE_SPEC.md +988 -0
- package/docs/images/list-capabilities.svg +39 -0
- package/docs/images/row-action.svg +17 -0
- package/docs/images/row-activity.svg +24 -0
- package/docs/images/row-data.svg +24 -0
- package/docs/images/row-identity.svg +25 -0
- package/docs/images/row-market.svg +23 -0
- package/docs/images/row-media-tile.svg +26 -0
- package/docs/images/row-message.svg +20 -0
- package/docs/images/row-metric-card.svg +33 -0
- package/docs/images/row-rail.svg +18 -0
- package/docs/images/row-section-header.svg +19 -0
- package/docs/images/row-style-regions.svg +30 -0
- package/docs/images/row-system.svg +30 -0
- package/docs/images/row-wallet-group.svg +26 -0
- package/ios/HybridNativeList.swift +30 -0
- package/ios/NativeListAccessoryStack.swift +680 -0
- package/ios/NativeListActionRenderer.swift +108 -0
- package/ios/NativeListActivityDetailsView.swift +291 -0
- package/ios/NativeListActivityRenderer.swift +201 -0
- package/ios/NativeListDataRowRenderer.swift +444 -0
- package/ios/NativeListIdentityRenderer.swift +685 -0
- package/ios/NativeListImageSlot.swift +140 -0
- package/ios/NativeListLeadingVisual.swift +372 -0
- package/ios/NativeListMarketRenderer.swift +698 -0
- package/ios/NativeListMediaPreviewSlot.swift +259 -0
- package/ios/NativeListMediaTileRenderer.swift +190 -0
- package/ios/NativeListMessageRenderer.swift +168 -0
- package/ios/NativeListMetricCardRenderer.swift +420 -0
- package/ios/NativeListModels.swift +36 -1
- package/ios/NativeListRailRenderer.swift +152 -0
- package/ios/NativeListRendererCell.swift +311 -0
- package/ios/NativeListRendererRegistry.swift +50 -0
- package/ios/NativeListResolvedText.swift +130 -0
- package/ios/NativeListRowHost.swift +63 -0
- package/ios/NativeListScrollPositionTracker.swift +30 -0
- package/ios/NativeListSectionHeaderRenderer.swift +734 -0
- package/ios/NativeListSystemRenderer.swift +568 -0
- package/ios/NativeListTextLabel.swift +42 -0
- package/ios/NativeListTextStyles.swift +236 -0
- package/ios/NativeListWalletGroupRenderer.swift +255 -0
- package/ios/RNCNativeListView.swift +282 -184
- package/ios/tests/NativeListActivityPresentationTests.swift +97 -0
- package/ios/tests/NativeListLifecycleTests.swift +241 -0
- package/ios/tests/NativeListMediaVisibilityTests.swift +109 -0
- package/ios/tests/NativeListScrollPositionTrackerTests.swift +25 -0
- package/lib/module/NativeList.js +56 -3
- package/lib/module/NativeList.web.js +5 -0
- package/lib/module/models.js +54 -0
- package/lib/module/validation.js +386 -28
- package/lib/module/web/NativeListWebEngine.js +148 -936
- package/lib/module/web/templates/ActionRowRenderer.js +97 -0
- package/lib/module/web/templates/ActivityRowRenderer.js +95 -0
- package/lib/module/web/templates/DataRowRenderer.js +145 -0
- package/lib/module/web/templates/IdentityRowRenderer.js +289 -0
- package/lib/module/web/templates/MarketRowRenderer.js +310 -0
- package/lib/module/web/templates/MediaTileRowRenderer.js +132 -0
- package/lib/module/web/templates/MessageRowRenderer.js +165 -0
- package/lib/module/web/templates/MetricCardRowRenderer.js +172 -0
- package/lib/module/web/templates/RailRowRenderer.js +98 -0
- package/lib/module/web/templates/RowContainerStyle.js +100 -0
- package/lib/module/web/templates/RowElements.js +93 -0
- package/lib/module/web/templates/RowRendererRegistry.js +70 -0
- package/lib/module/web/templates/RowText.js +121 -0
- package/lib/module/web/templates/RowVisual.js +43 -0
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +146 -0
- package/lib/module/web/templates/SystemRowRenderer.js +161 -0
- package/lib/module/web/templates/WalletGroupRowRenderer.js +96 -0
- package/lib/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +39 -3
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +6 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +15 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/Func_void_bool.kt +78 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +26 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListManager.kt +24 -9
- package/lib/nitrogen/generated/android/nativelistOnLoad.cpp +2 -0
- package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.cpp +8 -0
- package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.hpp +37 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +23 -2
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +32 -0
- package/lib/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +3 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +54 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +6 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +8 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +6 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +11 -2
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +3 -0
- package/lib/typescript/src/NativeList.nitro.d.ts +3 -0
- package/lib/typescript/src/NativeList.types.d.ts +14 -1
- package/lib/typescript/src/models.d.ts +199 -18
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +18 -16
- package/lib/typescript/src/web/templates/ActionRowRenderer.d.ts +15 -0
- package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +15 -0
- package/lib/typescript/src/web/templates/DataRowRenderer.d.ts +15 -0
- package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +16 -0
- package/lib/typescript/src/web/templates/MarketRowRenderer.d.ts +30 -0
- package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +15 -0
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +44 -0
- package/lib/typescript/src/web/templates/MetricCardRowRenderer.d.ts +15 -0
- package/lib/typescript/src/web/templates/RailRowRenderer.d.ts +28 -0
- package/lib/typescript/src/web/templates/RowContainerStyle.d.ts +9 -0
- package/lib/typescript/src/web/templates/RowElements.d.ts +38 -0
- package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +83 -0
- package/lib/typescript/src/web/templates/RowText.d.ts +9 -0
- package/lib/typescript/src/web/templates/RowVisual.d.ts +20 -0
- package/lib/typescript/src/web/templates/SectionHeaderRowRenderer.d.ts +15 -0
- package/lib/typescript/src/web/templates/SystemRowRenderer.d.ts +16 -0
- package/lib/typescript/src/web/templates/WalletGroupRowRenderer.d.ts +20 -0
- package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +39 -3
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +6 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +15 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/Func_void_bool.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListManager.kt +24 -9
- package/nitrogen/generated/android/nativelistOnLoad.cpp +2 -0
- package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.cpp +8 -0
- package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.hpp +37 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +23 -2
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +32 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +3 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +54 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +6 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +8 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +6 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +11 -2
- package/nitrogen/generated/shared/json/NativeListConfig.json +3 -0
- package/package.json +7 -6
- package/react-native-native-list.podspec +6 -0
- package/scripts/enable-container-slots.mjs +58 -0
- package/scripts/enable-container-slots.test.mjs +58 -0
- package/src/NativeList.nitro.ts +3 -0
- package/src/NativeList.tsx +84 -2
- package/src/NativeList.types.ts +14 -1
- package/src/NativeList.web.tsx +5 -0
- package/src/models.ts +320 -20
- package/src/validation.ts +641 -49
- package/src/web/NativeListWebEngine.ts +361 -1932
- package/src/web/templates/ActionRowRenderer.ts +123 -0
- package/src/web/templates/ActivityRowRenderer.ts +159 -0
- package/src/web/templates/DataRowRenderer.ts +212 -0
- package/src/web/templates/IdentityRowRenderer.ts +527 -0
- package/src/web/templates/MarketRowRenderer.ts +467 -0
- package/src/web/templates/MediaTileRowRenderer.ts +182 -0
- package/src/web/templates/MessageRowRenderer.ts +306 -0
- package/src/web/templates/MetricCardRowRenderer.ts +337 -0
- package/src/web/templates/RailRowRenderer.ts +136 -0
- package/src/web/templates/RowContainerStyle.ts +131 -0
- package/src/web/templates/RowElements.ts +160 -0
- package/src/web/templates/RowRendererRegistry.ts +111 -0
- package/src/web/templates/RowText.ts +181 -0
- package/src/web/templates/RowVisual.ts +115 -0
- package/src/web/templates/SectionHeaderRowRenderer.ts +243 -0
- package/src/web/templates/SystemRowRenderer.ts +282 -0
- package/src/web/templates/WalletGroupRowRenderer.ts +131 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRowView.kt +0 -4538
- package/ios/NativeListCell.swift +0 -4300
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
import XCTest
|
|
3
|
+
@testable import NativeListModule
|
|
4
|
+
|
|
5
|
+
@MainActor
|
|
6
|
+
final class NativeListActivityPresentationTests: XCTestCase {
|
|
7
|
+
func testSmallNumberRunsPreserveBaselineAcrossAmountsFiatAndFee() throws {
|
|
8
|
+
func segments(_ prefix: String, _ suffix: String) -> [[String: Any]] {
|
|
9
|
+
[["text": prefix], ["text": "5", "style": "subscript"], ["text": suffix]]
|
|
10
|
+
}
|
|
11
|
+
let item = try NativeListItem(data: [
|
|
12
|
+
"type": "activity", "key": "transfer", "title": "Transfer",
|
|
13
|
+
"leading": ["kind": "icon", "name": "ArrowTopOutline"],
|
|
14
|
+
"amounts": [[
|
|
15
|
+
"key": "receive", "text": "0.051 ETH", "textSegments": segments("0.0", "1 ETH"),
|
|
16
|
+
"secondaryText": "$0.051", "secondaryTextSegments": segments("$0.0", "1"),
|
|
17
|
+
]],
|
|
18
|
+
"fee": [
|
|
19
|
+
"primary": "0.051 GAS", "primaryTextSegments": segments("0.0", "1 GAS"),
|
|
20
|
+
"secondary": "€0.051", "secondaryTextSegments": segments("€0.0", "1"),
|
|
21
|
+
],
|
|
22
|
+
])
|
|
23
|
+
let view = NativeListActivityDetailsView()
|
|
24
|
+
view.bind(item, theme: nil)
|
|
25
|
+
func labels(in view: UIView) -> [UILabel] {
|
|
26
|
+
(view as? UILabel).map { [$0] } ?? view.subviews.flatMap { labels(in: $0) }
|
|
27
|
+
}
|
|
28
|
+
let cases: [(String, Int, CGFloat)] = [
|
|
29
|
+
("0.051 ETH", 3, 16), ("$0.051", 4, 14),
|
|
30
|
+
("0.051 GAS", 3, 14), ("€0.051", 4, 12),
|
|
31
|
+
]
|
|
32
|
+
let rendered = labels(in: view)
|
|
33
|
+
for (text, countIndex, parentSize) in cases {
|
|
34
|
+
let label = try XCTUnwrap(rendered.first { $0.attributedText?.string == text })
|
|
35
|
+
let value = try XCTUnwrap(label.attributedText)
|
|
36
|
+
let font = try XCTUnwrap(value.attribute(.font, at: countIndex, effectiveRange: nil) as? UIFont)
|
|
37
|
+
XCTAssertEqual(font.pointSize, ceil(parentSize * 0.6))
|
|
38
|
+
let baseline = value.attribute(.baselineOffset, at: 0, effectiveRange: nil) as? NSNumber
|
|
39
|
+
let countBaseline = value.attribute(.baselineOffset, at: countIndex, effectiveRange: nil) as? NSNumber
|
|
40
|
+
XCTAssertEqual(countBaseline?.doubleValue ?? 0, baseline?.doubleValue ?? 0)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func testAutomaticHeightMatchesRenderedStacks() throws {
|
|
45
|
+
let amount: [String: Any] = ["key": "send", "text": "-0.5 ETH", "secondaryText": "$1,000.00"]
|
|
46
|
+
let cases: [(String, [String: Any])] = [
|
|
47
|
+
("stacked single-line", [
|
|
48
|
+
"presentation": "stacked", "description": "Jan 1 • 0x1234…abcd", "amounts": [amount],
|
|
49
|
+
"style": ["horizontalPadding": 20, "verticalPadding": 12, "lineGap": 0,
|
|
50
|
+
"title": ["fontSize": 16, "lineHeight": 24, "fontWeight": "medium", "lines": 1],
|
|
51
|
+
"description": ["fontSize": 14, "lineHeight": 20, "lines": 1]],
|
|
52
|
+
]),
|
|
53
|
+
("table line gap without secondary amount", [
|
|
54
|
+
"presentation": "table", "description": "0x1234…abcd",
|
|
55
|
+
"amounts": [["key": "approve", "text": "Unlimited USDC"]],
|
|
56
|
+
"fee": ["label": "Network fee", "primary": "0.0001 ETH", "secondary": "$0.20"],
|
|
57
|
+
"badges": [["key": "risk", "text": "Scam", "tone": "danger"]],
|
|
58
|
+
"style": ["horizontalPadding": 20, "verticalPadding": 12, "lineGap": 4,
|
|
59
|
+
"title": ["fontSize": 14, "lineHeight": 20, "fontWeight": "medium", "lines": 1],
|
|
60
|
+
"description": ["fontSize": 14, "lineHeight": 20, "lines": 1]],
|
|
61
|
+
]),
|
|
62
|
+
("wrapped description, status and actions", [
|
|
63
|
+
"description": String(repeating: "Contract interaction with a long label ", count: 3),
|
|
64
|
+
"status": "Pending", "amounts": [amount, ["key": "receive", "text": "+1 USDC"]],
|
|
65
|
+
"footerActions": [["key": "speedUp", "label": "Speed up"], ["key": "cancel", "label": "Cancel"]],
|
|
66
|
+
"style": ["lineGap": 6],
|
|
67
|
+
]),
|
|
68
|
+
]
|
|
69
|
+
for (name, fields) in cases {
|
|
70
|
+
var data: [String: Any] = [
|
|
71
|
+
"type": "activity", "key": name, "title": "Send",
|
|
72
|
+
"leading": ["kind": "icon", "name": "ArrowTopOutline"],
|
|
73
|
+
]
|
|
74
|
+
fields.forEach { data[$0.key] = $0.value }
|
|
75
|
+
let item = try NativeListItem(data: data)
|
|
76
|
+
let width: CGFloat = 390
|
|
77
|
+
let style = data["style"] as? [String: Any] ?? [:]
|
|
78
|
+
let table = data["presentation"] as? String == "table"
|
|
79
|
+
let horizontal = CGFloat(style.double("horizontalPadding", default: table ? 16 : 12))
|
|
80
|
+
let vertical = CGFloat(style.double("verticalPadding", default: 8))
|
|
81
|
+
let container = UIView(frame: CGRect(x: 0, y: 0, width: width - horizontal * 2, height: 1000))
|
|
82
|
+
let view = NativeListActivityDetailsView()
|
|
83
|
+
view.translatesAutoresizingMaskIntoConstraints = false
|
|
84
|
+
container.addSubview(view)
|
|
85
|
+
NSLayoutConstraint.activate([
|
|
86
|
+
view.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
|
87
|
+
view.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
|
88
|
+
view.topAnchor.constraint(equalTo: container.topAnchor),
|
|
89
|
+
])
|
|
90
|
+
view.bind(item, theme: nil)
|
|
91
|
+
container.layoutIfNeeded()
|
|
92
|
+
container.layoutIfNeeded()
|
|
93
|
+
let rendered = ceil(view.frame.height) + vertical * 2
|
|
94
|
+
XCTAssertEqual(NativeListActivityDetailsView.measure(data, width: width), rendered, accuracy: 1, name)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
import XCTest
|
|
3
|
+
@testable import NativeListModule
|
|
4
|
+
|
|
5
|
+
@MainActor
|
|
6
|
+
final class NativeListLifecycleTests: XCTestCase {
|
|
7
|
+
func testSectionLoadingStopsOnRebindReuseAndDetach() throws {
|
|
8
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
|
|
9
|
+
let controller = UIViewController()
|
|
10
|
+
window.rootViewController = controller
|
|
11
|
+
window.isHidden = false
|
|
12
|
+
defer { window.isHidden = true }
|
|
13
|
+
let cell = NativeListSectionHeaderCell(frame: CGRect(x: 0, y: 0, width: 320, height: 40))
|
|
14
|
+
controller.view.addSubview(cell)
|
|
15
|
+
func bind(loading: Bool) throws {
|
|
16
|
+
let item = try NativeListItem(data: [
|
|
17
|
+
"key": "section", "type": "sectionHeader", "sectionKey": "pending",
|
|
18
|
+
"title": "Confirming", "variant": "history", "titleLoading": loading,
|
|
19
|
+
"style": ["title": ["color": "#FFAA00"]],
|
|
20
|
+
])
|
|
21
|
+
cell.bind(item: item, theme: nil, layout: "sectioned", selected: false,
|
|
22
|
+
checkboxState: { _, _, fallback in fallback })
|
|
23
|
+
}
|
|
24
|
+
try bind(loading: true)
|
|
25
|
+
let spinner = try XCTUnwrap(cell.root.arrangedSubviews.first as? UIActivityIndicatorView)
|
|
26
|
+
XCTAssertTrue(spinner.isAnimating)
|
|
27
|
+
XCTAssertFalse(spinner.isAccessibilityElement)
|
|
28
|
+
XCTAssertEqual(spinner.color, UIColor(nativeListHex: "#FFAA00", fallback: .clear))
|
|
29
|
+
|
|
30
|
+
try bind(loading: false)
|
|
31
|
+
XCTAssertFalse(spinner.isAnimating)
|
|
32
|
+
XCTAssertNil(spinner.superview)
|
|
33
|
+
try bind(loading: true)
|
|
34
|
+
XCTAssertTrue(spinner.isAnimating)
|
|
35
|
+
cell.removeFromSuperview()
|
|
36
|
+
XCTAssertFalse(spinner.isAnimating)
|
|
37
|
+
controller.view.addSubview(cell)
|
|
38
|
+
XCTAssertTrue(spinner.isAnimating)
|
|
39
|
+
cell.prepareForReuse()
|
|
40
|
+
XCTAssertFalse(spinner.isAnimating)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
func testRebindingAndReuseInvalidateThePreviousActionEpoch() throws {
|
|
44
|
+
let cell = NativeListActionCell(frame: CGRect(x: 0, y: 0, width: 320, height: 60))
|
|
45
|
+
let first = try NativeListItem(data: ["key": "row", "type": "action", "title": "First"])
|
|
46
|
+
let changed = try NativeListItem(data: ["key": "row", "type": "action", "title": "Changed"])
|
|
47
|
+
var invalidatedEpochs: [Int] = []
|
|
48
|
+
cell.onBindingInvalidated = { _, epoch in invalidatedEpochs.append(epoch) }
|
|
49
|
+
|
|
50
|
+
func bind(_ item: NativeListItem) {
|
|
51
|
+
cell.bind(item: item, theme: nil, layout: "linear", selected: false,
|
|
52
|
+
checkboxState: { _, _, fallback in fallback })
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
bind(first)
|
|
56
|
+
let originalEpoch = cell.rowActionOrigin().bindingEpoch
|
|
57
|
+
bind(first)
|
|
58
|
+
XCTAssertEqual(cell.bindingEpoch, originalEpoch, "Identical content should retain its action origin")
|
|
59
|
+
XCTAssertTrue(invalidatedEpochs.isEmpty)
|
|
60
|
+
|
|
61
|
+
bind(changed)
|
|
62
|
+
XCTAssertEqual(invalidatedEpochs, [originalEpoch])
|
|
63
|
+
XCTAssertNotEqual(cell.rowActionOrigin().bindingEpoch, originalEpoch)
|
|
64
|
+
|
|
65
|
+
let changedEpoch = cell.bindingEpoch
|
|
66
|
+
cell.prepareForReuse()
|
|
67
|
+
XCTAssertEqual(invalidatedEpochs, [originalEpoch, changedEpoch])
|
|
68
|
+
XCTAssertNotEqual(cell.bindingEpoch, changedEpoch)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
func testFixedFooterReplacesRendererAndKeepsActionRouting() throws {
|
|
72
|
+
let view = NativeListView(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
|
|
73
|
+
var actions: [[String: Any]] = []
|
|
74
|
+
view.onRowAction = { payload in
|
|
75
|
+
let data = Data(payload.utf8)
|
|
76
|
+
if let action = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any] {
|
|
77
|
+
actions.append(action)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
view.applySnapshotJson(try snapshot(footer: [
|
|
82
|
+
"key": "footer", "type": "action", "title": "Continue", "actionKey": "continue",
|
|
83
|
+
]))
|
|
84
|
+
let first = try XCTUnwrap(footerCell(in: view))
|
|
85
|
+
XCTAssertTrue(first is NativeListActionCell)
|
|
86
|
+
XCTAssertFalse(first.isHidden)
|
|
87
|
+
XCTAssertEqual(first.accessibilityLabel, "Continue")
|
|
88
|
+
let gestureCount = first.gestureRecognizers?.count
|
|
89
|
+
|
|
90
|
+
view.applySnapshotJson(try snapshot(footer: [
|
|
91
|
+
"key": "footer", "type": "system", "variant": "retry", "title": "Retry",
|
|
92
|
+
"actionKey": "retry",
|
|
93
|
+
]))
|
|
94
|
+
let second = try XCTUnwrap(footerCell(in: view))
|
|
95
|
+
XCTAssertTrue(second is NativeListSystemCell)
|
|
96
|
+
XCTAssertFalse(second === first)
|
|
97
|
+
XCTAssertNil(first.superview)
|
|
98
|
+
XCTAssertFalse(second.isHidden)
|
|
99
|
+
XCTAssertEqual(second.accessibilityLabel, "Retry")
|
|
100
|
+
XCTAssertEqual(second.gestureRecognizers?.count, gestureCount)
|
|
101
|
+
|
|
102
|
+
second.onAction?(try NativeListItem(data: [
|
|
103
|
+
"key": "footer", "type": "system", "variant": "retry", "title": "Retry",
|
|
104
|
+
"actionKey": "retry",
|
|
105
|
+
]), "retry", nil, nil)
|
|
106
|
+
XCTAssertEqual(actions.last?["actionKey"] as? String, "retry")
|
|
107
|
+
|
|
108
|
+
view.applySnapshotJson(try snapshot(footer: nil))
|
|
109
|
+
XCTAssertTrue(second.isHidden)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private func snapshot(footer: [String: Any]?) throws -> String {
|
|
113
|
+
var value: [String: Any] = [
|
|
114
|
+
"schemaVersion": 1, "generation": 1, "layout": ["kind": "linear"], "rows": [],
|
|
115
|
+
]
|
|
116
|
+
if let footer { value["fixedFooter"] = footer }
|
|
117
|
+
let data = try JSONSerialization.data(withJSONObject: value, options: [.sortedKeys])
|
|
118
|
+
return String(decoding: data, as: UTF8.self)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
func testContentShrinkCorrectsRestoredOffsetAfterPagerInsetsAndUpdatesObserver() throws {
|
|
122
|
+
let view = try makeScrollingList()
|
|
123
|
+
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
124
|
+
list.contentInset = UIEdgeInsets(top: 108, left: 0, bottom: 0, right: 0)
|
|
125
|
+
list.contentOffset.y = 600
|
|
126
|
+
var savedLogicalOffset = list.contentOffset.y + list.contentInset.top
|
|
127
|
+
let offsetObserver = list.observe(\.contentOffset, options: [.new]) { list, _ in
|
|
128
|
+
savedLogicalOffset = list.contentOffset.y + list.contentInset.top
|
|
129
|
+
}
|
|
130
|
+
// Model the pager's synchronous content-size observer and cached-offset restoration.
|
|
131
|
+
let sizeObserver = list.observe(\.contentSize, options: [.old, .new]) { list, change in
|
|
132
|
+
if change.oldValue != change.newValue, list.contentSize.height < 200 {
|
|
133
|
+
list.contentInset.bottom = max(0, list.bounds.height - 44 - list.contentSize.height)
|
|
134
|
+
list.contentOffset.y = 600
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
view.applySnapshotJson(try scrollingSnapshot(count: 0))
|
|
138
|
+
view.layoutIfNeeded()
|
|
139
|
+
list.layoutIfNeeded()
|
|
140
|
+
drainMainQueue()
|
|
141
|
+
XCTAssertEqual(list.contentSize.height, 132, accuracy: 0.5)
|
|
142
|
+
XCTAssertEqual(list.contentOffset.y, -44, accuracy: 0.5)
|
|
143
|
+
XCTAssertEqual(savedLogicalOffset, 64, accuracy: 0.5)
|
|
144
|
+
withExtendedLifetime((offsetObserver, sizeObserver)) {}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
func testContentShrinkPreservesInRangeAndNegativePullOffsets() throws {
|
|
148
|
+
for offset in [CGFloat(120), CGFloat(-160)] {
|
|
149
|
+
let view = try makeScrollingList()
|
|
150
|
+
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
151
|
+
list.contentInset.top = 108
|
|
152
|
+
view.applySnapshotJson(try scrollingSnapshot(count: 20))
|
|
153
|
+
view.layoutIfNeeded()
|
|
154
|
+
list.layoutIfNeeded()
|
|
155
|
+
// Preserve a valid offset or a refresh pull while shrink correction is queued.
|
|
156
|
+
list.contentOffset.y = offset
|
|
157
|
+
drainMainQueue()
|
|
158
|
+
XCTAssertEqual(list.contentOffset.y, offset, accuracy: 0.5)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
func testContentShrinkWaitsForRefreshCompletion() throws {
|
|
163
|
+
let view = try makeScrollingList()
|
|
164
|
+
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
165
|
+
view.applySnapshotJson(try scrollingSnapshot(count: 0, refreshing: true))
|
|
166
|
+
view.layoutIfNeeded()
|
|
167
|
+
list.layoutIfNeeded()
|
|
168
|
+
list.contentOffset.y = 600
|
|
169
|
+
drainMainQueue()
|
|
170
|
+
XCTAssertEqual(list.contentOffset.y, 600, accuracy: 0.5)
|
|
171
|
+
view.setRefreshing(false)
|
|
172
|
+
drainMainQueue()
|
|
173
|
+
let inset = list.adjustedContentInset
|
|
174
|
+
let maximum = max(-inset.top, list.contentSize.height - list.bounds.height + inset.bottom)
|
|
175
|
+
XCTAssertEqual(list.contentOffset.y, maximum, accuracy: 0.5)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
func testReactSlotFramesCannotMoveSlotsOutOfNativePlacement() throws {
|
|
179
|
+
let view = NativeListView(frame: CGRect(x: 0, y: 0, width: 320, height: 708))
|
|
180
|
+
// Fabric assigns each root the frame React computed: horizontal inset, top 0.
|
|
181
|
+
let slots = (0..<3).map { _ in UIView(frame: CGRect(x: 16, y: 0, width: 288, height: 44)) }
|
|
182
|
+
for (index, slot) in slots.enumerated() { view.mountContainerSlot(slot, atIndex: index) }
|
|
183
|
+
view.applySnapshotJson(try scrollingSnapshot(count: 3))
|
|
184
|
+
view.layoutIfNeeded()
|
|
185
|
+
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
186
|
+
list.layoutIfNeeded()
|
|
187
|
+
let header = try XCTUnwrap(slots[0].superview)
|
|
188
|
+
XCTAssertTrue(header.clipsToBounds)
|
|
189
|
+
XCTAssertEqual(header.bounds.height, 0, "An unmeasured header cannot draw over the first rows")
|
|
190
|
+
|
|
191
|
+
view.setContainerSlotHeightsJson("[44,44,60]")
|
|
192
|
+
view.layoutIfNeeded()
|
|
193
|
+
list.layoutIfNeeded()
|
|
194
|
+
XCTAssertEqual(slots[0].convert(CGPoint.zero, to: list), CGPoint(x: 16, y: 0))
|
|
195
|
+
let footerY = 44 + 3 * 80 as CGFloat
|
|
196
|
+
XCTAssertEqual(slots[2].convert(CGPoint.zero, to: list).y, footerY)
|
|
197
|
+
// A React height update rewrites the root frame before the new height reaches native.
|
|
198
|
+
slots[2].frame = CGRect(x: 16, y: 0, width: 288, height: 90)
|
|
199
|
+
XCTAssertEqual(slots[2].convert(CGPoint.zero, to: list), CGPoint(x: 16, y: footerY))
|
|
200
|
+
XCTAssertTrue(slots[1].superview?.isHidden == true, "The empty slot stays hidden with rows")
|
|
201
|
+
|
|
202
|
+
view.unmountContainerSlot(slots[2])
|
|
203
|
+
XCTAssertNil(slots[2].superview)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private func makeScrollingList() throws -> NativeListView {
|
|
207
|
+
let view = NativeListView(frame: CGRect(x: 0, y: 0, width: 320, height: 708))
|
|
208
|
+
for index in 0..<3 { view.mountContainerSlot(UIView(), atIndex: index) }
|
|
209
|
+
view.setContainerSlotHeightsJson("[44,44,44]")
|
|
210
|
+
view.applySnapshotJson(try scrollingSnapshot(count: 40))
|
|
211
|
+
view.layoutIfNeeded()
|
|
212
|
+
let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
|
|
213
|
+
list.layoutIfNeeded()
|
|
214
|
+
drainMainQueue()
|
|
215
|
+
return view
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private func scrollingSnapshot(count: Int, refreshing: Bool = false) throws -> String {
|
|
219
|
+
let rows: [[String: Any]] = (0..<count).map {
|
|
220
|
+
["key": "row-\($0)", "type": "action", "title": "Row", "height": 80]
|
|
221
|
+
}
|
|
222
|
+
let value: [String: Any] = [
|
|
223
|
+
"schemaVersion": 1, "generation": count + 1,
|
|
224
|
+
"layout": ["kind": "linear"], "rows": rows,
|
|
225
|
+
"capabilities": ["pullToRefresh": true, "refreshing": refreshing],
|
|
226
|
+
]
|
|
227
|
+
return String(decoding: try JSONSerialization.data(withJSONObject: value), as: UTF8.self)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private func drainMainQueue() {
|
|
231
|
+
let settled = expectation(description: "Deferred content shrink correction")
|
|
232
|
+
DispatchQueue.main.async { settled.fulfill() }
|
|
233
|
+
wait(for: [settled], timeout: 1)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private func footerCell(in view: NativeListView) -> NativeListRowHost? {
|
|
237
|
+
view.subviews.lazy.compactMap { container in
|
|
238
|
+
container.subviews.compactMap { $0 as? NativeListRowHost }.first
|
|
239
|
+
}.first
|
|
240
|
+
}
|
|
241
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
import XCTest
|
|
3
|
+
@testable import NativeListModule
|
|
4
|
+
|
|
5
|
+
@MainActor
|
|
6
|
+
final class NativeListMediaVisibilityTests: XCTestCase {
|
|
7
|
+
func testRetainedPagerAndListCellsRequireViewportIntersection() {
|
|
8
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
|
|
9
|
+
let controller = UIViewController()
|
|
10
|
+
window.rootViewController = controller
|
|
11
|
+
window.isHidden = false
|
|
12
|
+
defer { window.isHidden = true }
|
|
13
|
+
let pager = UIScrollView(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
|
|
14
|
+
pager.contentSize = CGSize(width: 640, height: 480)
|
|
15
|
+
controller.view.addSubview(pager)
|
|
16
|
+
let list = UIScrollView(frame: CGRect(x: 320, y: 0, width: 320, height: 480))
|
|
17
|
+
list.contentSize = CGSize(width: 320, height: 960)
|
|
18
|
+
pager.addSubview(list)
|
|
19
|
+
let tile = UIView(frame: CGRect(x: 10, y: 10, width: 100, height: 100))
|
|
20
|
+
list.addSubview(tile)
|
|
21
|
+
|
|
22
|
+
XCTAssertNotNil(tile.window, "Pager retains the offscreen cell in the window")
|
|
23
|
+
XCTAssertFalse(NativeListMediaPreviewSlot.intersectsViewport(tile))
|
|
24
|
+
pager.contentOffset.x = 320
|
|
25
|
+
XCTAssertTrue(NativeListMediaPreviewSlot.intersectsViewport(tile))
|
|
26
|
+
list.contentOffset.y = 110
|
|
27
|
+
XCTAssertFalse(NativeListMediaPreviewSlot.intersectsViewport(tile))
|
|
28
|
+
list.contentOffset.y = 100
|
|
29
|
+
XCTAssertTrue(NativeListMediaPreviewSlot.intersectsViewport(tile), "Partially visible previews remain eligible")
|
|
30
|
+
list.transform = CGAffineTransform(translationX: 320, y: 0)
|
|
31
|
+
XCTAssertFalse(NativeListMediaPreviewSlot.intersectsViewport(tile))
|
|
32
|
+
list.transform = .identity
|
|
33
|
+
XCTAssertTrue(NativeListMediaPreviewSlot.intersectsViewport(tile))
|
|
34
|
+
list.isHidden = true
|
|
35
|
+
XCTAssertFalse(NativeListMediaPreviewSlot.intersectsViewport(tile))
|
|
36
|
+
list.isHidden = false
|
|
37
|
+
list.alpha = 0
|
|
38
|
+
XCTAssertFalse(NativeListMediaPreviewSlot.intersectsViewport(tile))
|
|
39
|
+
tile.removeFromSuperview()
|
|
40
|
+
XCTAssertFalse(NativeListMediaPreviewSlot.intersectsViewport(tile))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@MainActor
|
|
45
|
+
final class NativeListMediaFrameCaptureTests: XCTestCase {
|
|
46
|
+
func testVisibleVideoReleasesPlayerAfterCapturingFirstFrame() throws {
|
|
47
|
+
let url = try writeVideo()
|
|
48
|
+
defer { try? FileManager.default.removeItem(at: url) }
|
|
49
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
|
|
50
|
+
window.rootViewController = UIViewController()
|
|
51
|
+
window.isHidden = false
|
|
52
|
+
defer { window.isHidden = true }
|
|
53
|
+
let slot = NativeListMediaPreviewSlot()
|
|
54
|
+
slot.view.frame = CGRect(x: 0, y: 0, width: 120, height: 120)
|
|
55
|
+
window.rootViewController?.view.addSubview(slot.view)
|
|
56
|
+
slot.view.layoutIfNeeded()
|
|
57
|
+
|
|
58
|
+
var loaded: Bool?
|
|
59
|
+
slot.bind(["uri": url.absoluteString], key: "video", probeOrder: ["video"]) { loaded = $0 }
|
|
60
|
+
XCTAssertTrue(slot.hasLivePlayer, "A visible tile starts one paused player")
|
|
61
|
+
let deadline = Date().addingTimeInterval(10)
|
|
62
|
+
while slot.capturedFrame == nil, Date() < deadline {
|
|
63
|
+
RunLoop.main.run(until: Date().addingTimeInterval(0.05))
|
|
64
|
+
}
|
|
65
|
+
XCTAssertEqual(loaded, true)
|
|
66
|
+
let frame = try XCTUnwrap(slot.capturedFrame, "The first frame replaces the live player")
|
|
67
|
+
XCTAssertEqual(frame.size, CGSize(width: 64, height: 48))
|
|
68
|
+
XCTAssertFalse(slot.hasLivePlayer)
|
|
69
|
+
|
|
70
|
+
// Leaving and re-entering the viewport keeps the still without rebuilding a player.
|
|
71
|
+
slot.view.removeFromSuperview()
|
|
72
|
+
window.rootViewController?.view.addSubview(slot.view)
|
|
73
|
+
slot.bind(["uri": url.absoluteString], key: "video", probeOrder: ["video"])
|
|
74
|
+
XCTAssertFalse(slot.hasLivePlayer)
|
|
75
|
+
XCTAssertNotNil(slot.capturedFrame)
|
|
76
|
+
slot.recycle()
|
|
77
|
+
XCTAssertNil(slot.capturedFrame)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/// A 64×48, ten-frame H.264 MP4 (generated with AVAssetWriter on macOS); the simulator
|
|
81
|
+
/// has no reliable H.264 encoder for writing one at test time.
|
|
82
|
+
private static let videoBase64 = [
|
|
83
|
+
"AAAAHGZ0eXBtcDQyAAAAAWlzb21tcDQxbXA0MgAAAAFtZGF0AAAAAAAAAXQAAAA1BgUtR1ZK3FxMQz+U78URPNFDqAEAAAMA",
|
|
84
|
+
"AQMAAAMAAQIAAeYACwAAAwAAAwAArDoMA5ErAYAAAAA8JbggH94I5Uz/gak9b71ouT+PwABUezojLMLPpBfbqJ15oD1BM5L2",
|
|
85
|
+
"vvLSFvvy+AABSCrnn2hX8nKgIiU0AAAAHSHhEF/Eku94/c0JBdrVAqcS2Y43GYAJD/p9QzWAAAAAGSGogoS/nFT7cZbZ8xnp",
|
|
86
|
+
"PB3mw6AB/xojtyEAAAAXAajBj/+nyteRkHQKsy3f1gAFJajGDXAAAAAVAajDj/9TDF3o0LWPJnRoAJ7STV8lAAAAGSHjIaIl",
|
|
87
|
+
"/wHKBDW4y227MDl54AH+VxDvqGgAAAAUIakGhL9JSwD9lXLr+gAf8c7Z0iAAAAATAalFiT9cnuAKgJxY0AGV0YL85AAAABEB",
|
|
88
|
+
"qUeJP1ye5zMOKAAol0Uv0AAAABQh5SWiJf8BygQQ1yj2ACX52k6mwAAAA0xtb292AAAAbG12aGQAAAAA5uAsIObgLCAAAAJY",
|
|
89
|
+
"AAACWAABAAABAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAA",
|
|
90
|
+
"AAAAAAAAAAAAAAACAAAC2HRyYWsAAABcdGtoZAAAAAHm4Cwg5uAsIAAAAAEAAAAAAAACWAAAAAAAAAAAAAAAAAAAAAAAAQAA",
|
|
91
|
+
"AAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAEAAAAAAQAAAADAAAAAAACRlZHRzAAAAHGVsc3QAAAAAAAAAAQAAAlgAAAB4",
|
|
92
|
+
"AAEAAAAAAlBtZGlhAAAAIG1kaGQAAAAA5uAsIObgLCAAAAJYAAACWFXEAAAAAAAxaGRscgAAAAAAAAAAdmlkZQAAAAAAAAAA",
|
|
93
|
+
"AAAAAENvcmUgTWVkaWEgVmlkZW8AAAAB921pbmYAAAAUdm1oZAAAAAEAAAAAAAAAAAAAACRkaW5mAAAAHGRyZWYAAAAAAAAA",
|
|
94
|
+
"AQAAAAx1cmwgAAAAAQAAAbdzdGJsAAAAoXN0c2QAAAAAAAAAAQAAAJFhdmMxAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAEAA",
|
|
95
|
+
"MABIAAAASAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGP//AAAAJ2F2Y0MBZAAL/+EADCdkAAus",
|
|
96
|
+
"VlDDeBBhlAEABCjuPLD9+PgAAAAACmZpZWwBAAAAAApjaHJtAAAAAAAYc3R0cwAAAAAAAAABAAAACgAAADwAAABgY3R0cwAA",
|
|
97
|
+
"AAAAAAAKAAAAAQAAAHgAAAABAAABLAAAAAEAAAB4AAAAAQAAAAAAAAABAAAAPAAAAAEAAAEsAAAAAQAAAHgAAAABAAAAAAAA",
|
|
98
|
+
"AAEAAAA8AAAAAQAAAHgAAAAUc3RzcwAAAAAAAAABAAAAAQAAABZzZHRwAAAAACAQEBgYEBAYGBAAAAAcc3RzYwAAAAAAAAAB",
|
|
99
|
+
"AAAAAQAAAAoAAAABAAAAPHN0c3oAAAAAAAAAAAAAAAoAAAB5AAAAIQAAAB0AAAAbAAAAGQAAAB0AAAAYAAAAFwAAABUAAAAY",
|
|
100
|
+
"AAAAFHN0Y28AAAAAAAAAAQAAACw=",
|
|
101
|
+
].joined()
|
|
102
|
+
|
|
103
|
+
private func writeVideo() throws -> URL {
|
|
104
|
+
let url = FileManager.default.temporaryDirectory
|
|
105
|
+
.appendingPathComponent("native-list-frame-\(UUID().uuidString).mp4")
|
|
106
|
+
try XCTUnwrap(Data(base64Encoded: Self.videoBase64)).write(to: url)
|
|
107
|
+
return url
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import NativeListModule
|
|
3
|
+
|
|
4
|
+
final class NativeListScrollPositionTrackerTests: XCTestCase {
|
|
5
|
+
func testHysteresisAndDisabledLifecycle() {
|
|
6
|
+
var tracker = NativeListScrollPositionTracker()
|
|
7
|
+
XCTAssertNil(tracker.update(offset: 200))
|
|
8
|
+
tracker.configure(json: "{\"start\":48,\"end\":160}")
|
|
9
|
+
XCTAssertEqual(tracker.update(offset: 0), false)
|
|
10
|
+
XCTAssertNil(tracker.update(offset: 159))
|
|
11
|
+
XCTAssertEqual(tracker.update(offset: 160), true)
|
|
12
|
+
XCTAssertNil(tracker.update(offset: 100))
|
|
13
|
+
XCTAssertEqual(tracker.update(offset: 48), false)
|
|
14
|
+
XCTAssertNil(tracker.update(offset: 49))
|
|
15
|
+
tracker.configure(json: "")
|
|
16
|
+
XCTAssertNil(tracker.update(offset: 200))
|
|
17
|
+
tracker.configure(json: "{\"start\":48,\"end\":160}")
|
|
18
|
+
XCTAssertEqual(tracker.update(offset: 200), true)
|
|
19
|
+
tracker.resetDelivery()
|
|
20
|
+
XCTAssertEqual(tracker.update(offset: 200), true)
|
|
21
|
+
XCTAssertNil(tracker.update(offset: .nan))
|
|
22
|
+
tracker.configure(json: "{\"start\":48,\"end\":48}")
|
|
23
|
+
XCTAssertNil(tracker.update(offset: 48))
|
|
24
|
+
}
|
|
25
|
+
}
|
package/lib/module/NativeList.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
3
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { OneKeyImageCache, OneKeyImageCachePolicy } from '@onekeyfe/react-native-image';
|
|
5
5
|
import { NativeAvatarPrefetchModel, NativeAvatarPrefetchQueue } from "./avatarPrefetch.js";
|
|
6
|
+
import { View } from 'react-native';
|
|
6
7
|
import { callback, getHostComponent } from 'react-native-nitro-modules';
|
|
7
8
|
import { isSelectableRow } from "./selection.js";
|
|
8
9
|
import { normalizeIndexScroll, normalizeKeyScroll, normalizePositionScroll, resolveLocationIndex, scrollFailure, validateOffset } from "./scrolling.js";
|
|
@@ -26,6 +27,10 @@ function parsePayload(payloadJson) {
|
|
|
26
27
|
}
|
|
27
28
|
export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
28
29
|
snapshot,
|
|
30
|
+
listHeader,
|
|
31
|
+
listFooter,
|
|
32
|
+
listEmpty,
|
|
33
|
+
scrollPositionThresholds,
|
|
29
34
|
webVirtualizationEnabled: _webVirtualizationEnabled,
|
|
30
35
|
webSectionIndexContainerRef: _webSectionIndexContainerRef,
|
|
31
36
|
keyboardDismissMode = 'none',
|
|
@@ -36,6 +41,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
36
41
|
onReorder,
|
|
37
42
|
onEndReached,
|
|
38
43
|
onVisibleRangeChanged,
|
|
44
|
+
onScrollPositionThresholdChange,
|
|
39
45
|
onRefresh,
|
|
40
46
|
onScrollToIndexFailed,
|
|
41
47
|
initialScrollIndex,
|
|
@@ -44,6 +50,13 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
44
50
|
initialScrollViewOffset,
|
|
45
51
|
...viewProps
|
|
46
52
|
}, forwardedRef) {
|
|
53
|
+
const [slotHeights, setSlotHeights] = useState([0, 0, 0]);
|
|
54
|
+
const containerSlotHeightsJson = JSON.stringify(slotHeights);
|
|
55
|
+
const slotInset = snapshot.layout.contentPaddingHorizontal ?? snapshot.layout.contentPadding ?? 0;
|
|
56
|
+
if (snapshot.layout.orientation === 'horizontal' && (listHeader || listEmpty || listFooter)) {
|
|
57
|
+
throw new Error('NativeList container slots require vertical orientation');
|
|
58
|
+
}
|
|
59
|
+
const slotContents = [listHeader, listEmpty, listFooter];
|
|
47
60
|
const normalizedKeyboardShouldPersistTaps = keyboardShouldPersistTaps === true ? 'always' : keyboardShouldPersistTaps === false ? 'never' : keyboardShouldPersistTaps;
|
|
48
61
|
const nativeRef = useRef(null);
|
|
49
62
|
const callbacksRef = useRef({
|
|
@@ -53,6 +66,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
53
66
|
onReorder,
|
|
54
67
|
onEndReached,
|
|
55
68
|
onVisibleRangeChanged,
|
|
69
|
+
onScrollPositionThresholdChange,
|
|
56
70
|
onRefresh,
|
|
57
71
|
onScrollToIndexFailed
|
|
58
72
|
});
|
|
@@ -63,9 +77,24 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
63
77
|
onReorder,
|
|
64
78
|
onEndReached,
|
|
65
79
|
onVisibleRangeChanged,
|
|
80
|
+
onScrollPositionThresholdChange,
|
|
66
81
|
onRefresh,
|
|
67
82
|
onScrollToIndexFailed
|
|
68
83
|
};
|
|
84
|
+
const scrollPositionThresholdsJson = useMemo(() => {
|
|
85
|
+
if (!scrollPositionThresholds || scrollPositionThresholds.enabled === false) return '';
|
|
86
|
+
const {
|
|
87
|
+
start,
|
|
88
|
+
end
|
|
89
|
+
} = scrollPositionThresholds;
|
|
90
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || start < 0 || end <= start) {
|
|
91
|
+
throw new Error('scrollPositionThresholds requires 0 <= start < end and finite values');
|
|
92
|
+
}
|
|
93
|
+
return JSON.stringify({
|
|
94
|
+
start,
|
|
95
|
+
end
|
|
96
|
+
});
|
|
97
|
+
}, [scrollPositionThresholds]);
|
|
69
98
|
const snapshotJson = useMemo(() => serializeSnapshot(snapshot), [snapshot]);
|
|
70
99
|
const snapshotRef = useRef(snapshot);
|
|
71
100
|
const previousSnapshotJsonRef = useRef(snapshotJson);
|
|
@@ -235,7 +264,10 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
235
264
|
}),
|
|
236
265
|
onRowAction: callback(payloadJson => {
|
|
237
266
|
const payload = parsePayload(payloadJson);
|
|
238
|
-
if (payload.actionKey === 'nativeList.refresh'
|
|
267
|
+
if (payload.actionKey === 'nativeList.refresh' && payload.rowKey === undefined) {
|
|
268
|
+
callbacksRef.current.onRefresh?.();
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
239
271
|
callbacksRef.current.onRowAction?.(payload);
|
|
240
272
|
}),
|
|
241
273
|
onActionAnchorInvalidated: callback(payloadJson => {
|
|
@@ -264,6 +296,11 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
264
296
|
onEndReached: callback(payloadJson => {
|
|
265
297
|
callbacksRef.current.onEndReached?.(parsePayload(payloadJson));
|
|
266
298
|
}),
|
|
299
|
+
onScrollPositionThresholdChange: callback(isBeyondThreshold => {
|
|
300
|
+
callbacksRef.current.onScrollPositionThresholdChange?.({
|
|
301
|
+
isBeyondThreshold
|
|
302
|
+
});
|
|
303
|
+
}),
|
|
267
304
|
onVisibleRangeChanged: callback(payloadJson => {
|
|
268
305
|
const payload = parsePayload(payloadJson);
|
|
269
306
|
const previous = avatarRangeRef.current;
|
|
@@ -280,8 +317,24 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
280
317
|
...viewProps,
|
|
281
318
|
...nativeCallbacks,
|
|
282
319
|
snapshotJson: snapshotJson,
|
|
320
|
+
containerSlotHeightsJson: containerSlotHeightsJson,
|
|
321
|
+
scrollPositionThresholdsJson: scrollPositionThresholdsJson,
|
|
283
322
|
keyboardDismissMode: keyboardDismissMode,
|
|
284
|
-
keyboardShouldPersistTaps: normalizedKeyboardShouldPersistTaps
|
|
323
|
+
keyboardShouldPersistTaps: normalizedKeyboardShouldPersistTaps,
|
|
324
|
+
children: slotContents.map((content, index) => /*#__PURE__*/_jsx(View, {
|
|
325
|
+
collapsable: false,
|
|
326
|
+
style: {
|
|
327
|
+
position: 'absolute',
|
|
328
|
+
left: slotInset,
|
|
329
|
+
right: slotInset,
|
|
330
|
+
top: 0
|
|
331
|
+
},
|
|
332
|
+
onLayout: event => {
|
|
333
|
+
const height = Math.ceil(event.nativeEvent.layout.height);
|
|
334
|
+
setSlotHeights(previous => previous[index] === height ? previous : previous.map((value, slot) => slot === index ? height : value));
|
|
335
|
+
},
|
|
336
|
+
children: content
|
|
337
|
+
}, index))
|
|
285
338
|
});
|
|
286
339
|
});
|
|
287
340
|
//# sourceMappingURL=NativeList.js.map
|
|
@@ -22,6 +22,11 @@ export function preloadNativeListAvatarImages(sources) {
|
|
|
22
22
|
}
|
|
23
23
|
export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
24
24
|
snapshot,
|
|
25
|
+
listHeader: _listHeader,
|
|
26
|
+
listEmpty: _listEmpty,
|
|
27
|
+
listFooter: _listFooter,
|
|
28
|
+
scrollPositionThresholds: _scrollPositionThresholds,
|
|
29
|
+
onScrollPositionThresholdChange: _onScrollPositionThresholdChange,
|
|
25
30
|
webVirtualizationEnabled = true,
|
|
26
31
|
webSectionIndexContainerRef,
|
|
27
32
|
keyboardDismissMode: _keyboardDismissMode,
|
package/lib/module/models.js
CHANGED
|
@@ -1,2 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Named typography steps, shared with the application's design scale. Resolved
|
|
5
|
+
* to fontSize/lineHeight/fontWeight in JavaScript before the snapshot is
|
|
6
|
+
* serialized, so no native renderer needs to know the vocabulary.
|
|
7
|
+
* See docs/STYLE_SPEC.md §3.2.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Retained alias: Market shipped this name before the style surface was shared. */
|
|
11
|
+
|
|
12
|
+
/** Local box vocabulary. Each template exposes only parameters for its own slots. */
|
|
13
|
+
|
|
14
|
+
/** Template-owned slots determine which local box parameters exist, on every platform. */
|
|
15
|
+
export const ROW_BOX_STYLE_KEYS_BY_TYPE = {
|
|
16
|
+
identity: ['horizontalPadding', 'verticalPadding', 'leadingGap', 'lineGap', 'titleBadgeGap', 'trailingGap', 'image'],
|
|
17
|
+
walletGroup: ['horizontalPadding', 'verticalPadding'],
|
|
18
|
+
rail: ['horizontalPadding', 'verticalPadding', 'leadingGap', 'titleBadgeGap', 'trailingGap', 'image'],
|
|
19
|
+
activity: ['horizontalPadding', 'verticalPadding', 'leadingGap', 'lineGap', 'titleBadgeGap', 'trailingGap', 'image'],
|
|
20
|
+
message: ['horizontalPadding', 'verticalPadding', 'leadingGap', 'lineGap', 'image'],
|
|
21
|
+
dataRow: ['horizontalPadding', 'verticalPadding', 'leadingGap', 'lineGap', 'titleBadgeGap', 'image'],
|
|
22
|
+
market: ['horizontalPadding', 'verticalPadding', 'leadingGap', 'lineGap', 'titleBadgeGap', 'trailingGap', 'image'],
|
|
23
|
+
mediaTile: ['horizontalPadding', 'verticalPadding', 'leadingGap', 'lineGap', 'image'],
|
|
24
|
+
metricCard: ['horizontalPadding', 'verticalPadding', 'leadingGap', 'lineGap', 'image'],
|
|
25
|
+
sectionHeader: ['horizontalPadding', 'verticalPadding', 'lineGap', 'trailingGap'],
|
|
26
|
+
action: ['horizontalPadding', 'verticalPadding', 'leadingGap', 'trailingGap', 'image'],
|
|
27
|
+
system: ['horizontalPadding', 'verticalPadding', 'lineGap']
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A style key names the model field it modifies, never the view that carries
|
|
32
|
+
* it. Each template renderer owns its views and maps the key to whichever view
|
|
33
|
+
* renders that field (for example metricCard `value` is its large number), so
|
|
34
|
+
* the same key name keeps one meaning across platforms. See docs/STYLE_SPEC.md §4.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
// OneKey patch: keep selector decoration and text data serializable.
|
|
38
|
+
|
|
39
|
+
// OneKey patch: preserve compact very-small-balance digit runs.
|
|
40
|
+
|
|
41
|
+
/** Native Market quote row. All values are already localized/formatted strings. */
|
|
42
|
+
|
|
43
|
+
/** Compact KPI card for dashboards and grids. */
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* List chrome that every platform can honour. Pull to refresh, the section index
|
|
47
|
+
* rail and the reorder preview are deliberately absent: the first two are system
|
|
48
|
+
* controls or three independent constant sets, and the third is drawn with
|
|
49
|
+
* platform-specific primitives. See docs/STYLE_SPEC.md §5.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
// OneKey patch: include selector-only mutable presentation fields.
|
|
53
|
+
// type CommonPatchFields = 'revision' | 'disabled' | 'selected' | 'separator';
|
|
54
|
+
// OneKey patch: balance patches also refresh the existing row's spoken content.
|
|
55
|
+
// type CommonPatchFields = 'revision' | 'disabled' | 'selected' | 'separator' | 'height' | 'heightRounding' | 'opacity' | 'pressDisabled';
|
|
2
56
|
//# sourceMappingURL=models.js.map
|