@onekeyfe/react-native-native-list 6.7.0-4 → 6.7.0-41
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 +4 -0
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +250 -9
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +35 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +25 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
- 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 +102 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListGeneratedIcons.kt +47 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +225 -11
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +152 -33
- package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaPlaceholderView.kt +244 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +66 -31
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +32 -11
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +149 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +120 -287
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +7 -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 +1953 -117
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +35 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
- package/docs/ROW_TEMPLATES.md +74 -13
- package/docs/SPEC.md +1206 -15
- package/docs/STYLE_SPEC.md +14 -0
- package/ios/HybridNativeList.swift +21 -2
- package/ios/NativeListAccessoryStack.swift +237 -51
- package/ios/NativeListActivityDetailsView.swift +30 -11
- package/ios/NativeListActivityRenderer.swift +8 -2
- package/ios/NativeListButtonGroupRenderer.swift +89 -0
- package/ios/NativeListDataRowRenderer.swift +167 -30
- package/ios/NativeListDesignAssets.swift +13 -75
- package/ios/NativeListGeneratedIcons.swift +55 -0
- package/ios/NativeListIconBinding.swift +171 -0
- package/ios/NativeListIdentityRenderer.swift +256 -39
- package/ios/NativeListLeadingVisual.swift +127 -28
- package/ios/NativeListMarketRenderer.swift +120 -31
- package/ios/NativeListMediaPlaceholderView.swift +189 -0
- package/ios/NativeListMediaPreviewSlot.swift +122 -61
- package/ios/NativeListMediaTileRenderer.swift +15 -11
- package/ios/NativeListMessageRenderer.swift +34 -1
- package/ios/NativeListMetricCardRenderer.swift +4 -2
- package/ios/NativeListModels.swift +42 -2
- package/ios/NativeListRendererRegistry.swift +1 -0
- package/ios/NativeListResolvedText.swift +2 -1
- package/ios/NativeListRowHost.swift +14 -0
- package/ios/NativeListSectionHeaderRenderer.swift +100 -4
- package/ios/RNCNativeListView.swift +1053 -58
- package/ios/tests/NativeListAccessoryStackTests.swift +101 -0
- package/ios/tests/NativeListAccountSelectorLayoutTests.swift +96 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +153 -0
- package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
- package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
- package/ios/tests/NativeListLifecycleTests.swift +2819 -3
- package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
- package/ios/tests/NativeListMediaVisibilityTests.swift +26 -1
- package/ios/tests/NativeListSharedIconTests.swift +236 -0
- package/lib/module/NativeList.js +221 -36
- package/lib/module/NativeList.web.js +167 -46
- package/lib/module/index.js +1 -1
- package/lib/module/models.js +3 -0
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +1246 -48
- package/lib/module/web/NativeListGeneratedIcons.js +31 -0
- package/lib/module/web/NativeListWebEngine.js +513 -275
- package/lib/module/web/templates/ActivityRowRenderer.js +120 -87
- 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 +158 -6
- package/lib/module/web/templates/MarketTableRowRenderer.js +36 -19
- package/lib/module/web/templates/MediaTileRowRenderer.js +84 -25
- package/lib/module/web/templates/MessageRowRenderer.js +18 -2
- package/lib/module/web/templates/RowContainerStyle.js +1 -0
- package/lib/module/web/templates/RowRendererRegistry.js +3 -0
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +36 -2
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
- package/lib/typescript/src/NativeList.d.ts +3 -3
- package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
- package/lib/typescript/src/NativeList.types.d.ts +20 -2
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/models.d.ts +126 -17
- package/lib/typescript/src/validation.d.ts +20 -0
- package/lib/typescript/src/web/NativeListGeneratedIcons.d.ts +2 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +32 -1
- package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
- package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +9 -3
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
- package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
- package/package.json +16 -10
- package/react-native-native-list.podspec +2 -6
- package/scripts/generate-icons.mjs +150 -0
- package/scripts/generate-icons.test.mjs +288 -0
- package/scripts/native-list-icons.json +260 -0
- package/src/NativeList.nitro.ts +2 -0
- package/src/NativeList.tsx +416 -89
- package/src/NativeList.types.ts +24 -2
- package/src/NativeList.web.tsx +295 -89
- package/src/index.ts +2 -0
- package/src/models.ts +263 -144
- package/src/selection.ts +1 -0
- package/src/validation.ts +3013 -152
- package/src/web/NativeListGeneratedIcons.ts +28 -0
- package/src/web/NativeListWebEngine.ts +818 -343
- package/src/web/templates/ActivityRowRenderer.ts +178 -141
- package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
- package/src/web/templates/DataRowRenderer.ts +93 -20
- package/src/web/templates/IdentityRowRenderer.ts +231 -6
- package/src/web/templates/MarketTableRowRenderer.ts +53 -33
- package/src/web/templates/MediaTileRowRenderer.ts +90 -28
- 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
- package/ios/Resources/NativeListIcons.xcassets/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/icon.svg +0 -14
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/icon.svg +0 -12
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/icon.svg +0 -6
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/icon.svg +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/icon.svg +0 -3
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/icon.svg +0 -7
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/icon.svg +0 -18
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/icon.svg +0 -7
- package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/icon.svg +0 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
import XCTest
|
|
3
|
+
@testable import NativeListModule
|
|
4
|
+
|
|
5
|
+
@MainActor
|
|
6
|
+
final class NativeListAccessoryStackTests: XCTestCase {
|
|
7
|
+
private func makeStack(trailing: [[String: Any]]) throws -> NativeListAccessoryStack {
|
|
8
|
+
let stack = NativeListAccessoryStack(frame: CGRect(x: 0, y: 0, width: 160, height: 48))
|
|
9
|
+
let item = try NativeListItem(data: [
|
|
10
|
+
"key": "doge--0",
|
|
11
|
+
"type": "identity",
|
|
12
|
+
"presentation": "networkSelector",
|
|
13
|
+
"height": 48,
|
|
14
|
+
"title": "Dogecoin",
|
|
15
|
+
"trailing": trailing,
|
|
16
|
+
])
|
|
17
|
+
stack.bind(
|
|
18
|
+
item,
|
|
19
|
+
descriptors: trailing,
|
|
20
|
+
theme: nil,
|
|
21
|
+
style: [:],
|
|
22
|
+
checkboxState: { _, _, fallback in fallback },
|
|
23
|
+
fonts: NativeListFontFamilies()
|
|
24
|
+
)
|
|
25
|
+
stack.layoutIfNeeded()
|
|
26
|
+
return stack
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private func visibleControl(_ stack: NativeListAccessoryStack) throws -> UIView {
|
|
30
|
+
let control = try XCTUnwrap(stack.firstVisibleControl)
|
|
31
|
+
XCTAssertGreaterThan(control.bounds.width, 0)
|
|
32
|
+
XCTAssertGreaterThan(control.bounds.height, 0)
|
|
33
|
+
return control
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// OK-65494: a network balance is display only, so a tap on it must reach the
|
|
37
|
+
// cell and select the row instead of stopping at the accessory button.
|
|
38
|
+
func testValueAccessoryLeavesTouchesToTheRow() throws {
|
|
39
|
+
let stack = try makeStack(trailing: [["kind": "value", "text": "¥110.42"]])
|
|
40
|
+
let value = try visibleControl(stack)
|
|
41
|
+
XCTAssertFalse(value.isUserInteractionEnabled)
|
|
42
|
+
XCTAssertTrue(stack.hitTest(value.center, with: nil) === stack)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
func testSwapMenuUsesTheDotVerSolidImage() throws {
|
|
46
|
+
let metadata = try XCTUnwrap(nativeListIconMetadata(named: "DotVerSolid"))
|
|
47
|
+
XCTAssertGreaterThan(metadata.size.width, 0)
|
|
48
|
+
XCTAssertGreaterThan(metadata.size.height, 0)
|
|
49
|
+
let stack = try makeStack(trailing: [[
|
|
50
|
+
"kind": "icon", "name": "DotVerSolid", "buttonStyle": "tertiary",
|
|
51
|
+
"actionKey": "menu",
|
|
52
|
+
]])
|
|
53
|
+
let button = try XCTUnwrap(try visibleControl(stack) as? UIButton)
|
|
54
|
+
XCTAssertNotNil(button.image(for: .normal))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
func testValuePairAccessoryLeavesTouchesToTheRow() throws {
|
|
58
|
+
let stack = try makeStack(trailing: [
|
|
59
|
+
["kind": "valuePair", "primary": "$15.60", "secondary": "0.002 BTC"],
|
|
60
|
+
])
|
|
61
|
+
let value = try visibleControl(stack)
|
|
62
|
+
XCTAssertFalse(value.isUserInteractionEnabled)
|
|
63
|
+
XCTAssertTrue(stack.hitTest(value.center, with: nil) === stack)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
func testTextAccessoryWithActionKeepsItsOwnTouches() throws {
|
|
67
|
+
let stack = try makeStack(trailing: [
|
|
68
|
+
["kind": "radio", "checked": true, "actionKey": "network.select"],
|
|
69
|
+
])
|
|
70
|
+
let radio = try visibleControl(stack)
|
|
71
|
+
XCTAssertTrue(radio.isUserInteractionEnabled)
|
|
72
|
+
XCTAssertTrue(stack.hitTest(radio.center, with: nil) === radio)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
func testRebindRestoresTouchOwnershipOfTheReusedButton() throws {
|
|
76
|
+
let stack = try makeStack(trailing: [["kind": "value", "text": "¥110.42"]])
|
|
77
|
+
let value = try visibleControl(stack)
|
|
78
|
+
XCTAssertFalse(value.isUserInteractionEnabled)
|
|
79
|
+
let radioItem = try NativeListItem(data: [
|
|
80
|
+
"key": "doge--0",
|
|
81
|
+
"type": "identity",
|
|
82
|
+
"presentation": "networkSelector",
|
|
83
|
+
"height": 48,
|
|
84
|
+
"title": "Dogecoin",
|
|
85
|
+
])
|
|
86
|
+
let radio: [[String: Any]] = [["kind": "radio", "checked": false, "actionKey": "network.select"]]
|
|
87
|
+
stack.bind(
|
|
88
|
+
radioItem,
|
|
89
|
+
descriptors: radio,
|
|
90
|
+
theme: nil,
|
|
91
|
+
style: [:],
|
|
92
|
+
checkboxState: { _, _, fallback in fallback },
|
|
93
|
+
fonts: NativeListFontFamilies()
|
|
94
|
+
)
|
|
95
|
+
stack.layoutIfNeeded()
|
|
96
|
+
let reused = try visibleControl(stack)
|
|
97
|
+
XCTAssertTrue(reused === value)
|
|
98
|
+
XCTAssertTrue(reused.isUserInteractionEnabled)
|
|
99
|
+
XCTAssertTrue(stack.hitTest(reused.center, with: nil) === reused)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
import XCTest
|
|
3
|
+
@testable import NativeListModule
|
|
4
|
+
|
|
5
|
+
@MainActor
|
|
6
|
+
final class NativeListAccountSelectorLayoutTests: XCTestCase {
|
|
7
|
+
private func child<T>(_ cell: NativeListIdentityCell, _ label: String, as type: T.Type) throws -> T {
|
|
8
|
+
try XCTUnwrap(Mirror(reflecting: cell).children.first { $0.label == label }?.value as? T)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
private func bind(
|
|
12
|
+
_ cell: NativeListIdentityCell, title: String = "A", balance: String = "$16.30",
|
|
13
|
+
trailing: [[String: Any]] = []
|
|
14
|
+
) throws {
|
|
15
|
+
let item = try NativeListItem(data: [
|
|
16
|
+
"key": "account", "type": "identity", "presentation": "accountSelector",
|
|
17
|
+
"title": title, "height": 60,
|
|
18
|
+
"leading": ["kind": "account", "fallbackText": "A"],
|
|
19
|
+
"subtitleSegments": [
|
|
20
|
+
["text": balance, "tone": "secondary"],
|
|
21
|
+
["text": "0x1234...5678", "tone": "secondary", "separatorBefore": true],
|
|
22
|
+
],
|
|
23
|
+
"trailing": trailing,
|
|
24
|
+
])
|
|
25
|
+
cell.bind(item: item, theme: nil, layout: "linear", selected: false,
|
|
26
|
+
checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
|
|
27
|
+
cell.setNeedsLayout()
|
|
28
|
+
cell.layoutIfNeeded()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private func assertSubtitleFits(
|
|
32
|
+
_ cell: NativeListIdentityCell, file: StaticString = #filePath, line: UInt = #line
|
|
33
|
+
) throws {
|
|
34
|
+
let labels = try child(cell, "semanticSubtitleLabels", as: [UILabel].self)
|
|
35
|
+
XCTAssertEqual(labels.count, 2, file: file, line: line)
|
|
36
|
+
for label in labels {
|
|
37
|
+
XCTAssertGreaterThanOrEqual(
|
|
38
|
+
label.bounds.width + 0.5, label.intrinsicContentSize.width,
|
|
39
|
+
"The balance and address must fit when the row has spare width", file: file, line: line)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
func testEmptyTrailingDoesNotCollapseBalanceToShortTitleWidth() throws {
|
|
44
|
+
for width: CGFloat in [320, 390] {
|
|
45
|
+
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: width, height: 60))
|
|
46
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: width, height: 200))
|
|
47
|
+
window.addSubview(cell)
|
|
48
|
+
for title in ["A", "返佣5", "Pendle account"] {
|
|
49
|
+
for balance in ["$16.30", "$0", "****"] {
|
|
50
|
+
try bind(cell, title: title, balance: balance)
|
|
51
|
+
window.layoutIfNeeded()
|
|
52
|
+
try assertSubtitleFits(cell)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
func testSpinnerPreservesItsIntrinsicWidthAndSubtitleSpace() throws {
|
|
59
|
+
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 320, height: 60))
|
|
60
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 200))
|
|
61
|
+
window.addSubview(cell)
|
|
62
|
+
try bind(cell, trailing: [["kind": "spinner"]])
|
|
63
|
+
window.layoutIfNeeded()
|
|
64
|
+
|
|
65
|
+
try assertSubtitleFits(cell)
|
|
66
|
+
let trailing = try child(cell, "trailingStack", as: NativeListAccessoryStack.self)
|
|
67
|
+
let spinner = try XCTUnwrap(trailing.arrangedSubviews.compactMap { $0 as? UIActivityIndicatorView }.first)
|
|
68
|
+
XCTAssertTrue(spinner.isAnimating)
|
|
69
|
+
XCTAssertFalse(spinner.isHidden)
|
|
70
|
+
XCTAssertGreaterThanOrEqual(spinner.bounds.width + 0.5, spinner.intrinsicContentSize.width)
|
|
71
|
+
XCTAssertGreaterThanOrEqual(trailing.bounds.width + 0.5, spinner.bounds.width)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
func testRebindingBetweenIconEmptyAndSpinnerKeepsControlAndSubtitleWidths() throws {
|
|
75
|
+
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 320, height: 60))
|
|
76
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 200))
|
|
77
|
+
window.addSubview(cell)
|
|
78
|
+
for icon in ["DotHorOutline", "PlusSmallOutline"] {
|
|
79
|
+
let descriptor: [String: Any] = ["kind": "icon", "name": icon, "actionKey": "action"]
|
|
80
|
+
let states: [[[String: Any]]] = [[descriptor], [], [["kind": "spinner"]], [descriptor], []]
|
|
81
|
+
for accessories in states {
|
|
82
|
+
try bind(cell, trailing: accessories)
|
|
83
|
+
window.layoutIfNeeded()
|
|
84
|
+
try assertSubtitleFits(cell)
|
|
85
|
+
let trailing = try child(cell, "trailingStack", as: NativeListAccessoryStack.self)
|
|
86
|
+
if accessories.first?["kind"] as? String == "icon" {
|
|
87
|
+
let control = try XCTUnwrap(trailing.firstVisibleControl)
|
|
88
|
+
XCTAssertGreaterThan(control.bounds.width, 0)
|
|
89
|
+
XCTAssertEqual(trailing.bounds.width, control.bounds.width, accuracy: 0.5)
|
|
90
|
+
} else {
|
|
91
|
+
XCTAssertNil(trailing.firstVisibleControl)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -4,6 +4,62 @@ import XCTest
|
|
|
4
4
|
|
|
5
5
|
@MainActor
|
|
6
6
|
final class NativeListActivityPresentationTests: XCTestCase {
|
|
7
|
+
func testActivityLeadingVisibilityAndFooterAlignmentRestoreOnRebind() throws {
|
|
8
|
+
func item(rich: Bool, hidden: Bool) throws -> NativeListItem {
|
|
9
|
+
var data: [String: Any] = [
|
|
10
|
+
"type": "activity", "key": "tx", "title": "Send", "description": "To Alice",
|
|
11
|
+
"leading": ["kind": "icon", "name": "ArrowTopOutline"],
|
|
12
|
+
"hideLeading": hidden,
|
|
13
|
+
"footerActions": [["key": "speed-up", "label": "Speed up"]],
|
|
14
|
+
]
|
|
15
|
+
if rich { data["amounts"] = [["key": "send", "text": "••••"]] }
|
|
16
|
+
else { data["primaryAmount"] = "••••" }
|
|
17
|
+
return try NativeListItem(data: data)
|
|
18
|
+
}
|
|
19
|
+
let details = NativeListActivityDetailsView()
|
|
20
|
+
let main = try XCTUnwrap(details.arrangedSubviews.first as? UIStackView)
|
|
21
|
+
let richVisual = try XCTUnwrap(main.arrangedSubviews.first)
|
|
22
|
+
let richActions = try XCTUnwrap(details.arrangedSubviews.last as? UIStackView)
|
|
23
|
+
let container = UIView(frame: CGRect(x: 0, y: 0, width: 366, height: 300))
|
|
24
|
+
details.translatesAutoresizingMaskIntoConstraints = false
|
|
25
|
+
container.addSubview(details)
|
|
26
|
+
NSLayoutConstraint.activate([
|
|
27
|
+
details.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
|
28
|
+
details.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
|
29
|
+
details.topAnchor.constraint(equalTo: container.topAnchor),
|
|
30
|
+
])
|
|
31
|
+
for hidden in [false, true, false] {
|
|
32
|
+
let current = try item(rich: true, hidden: hidden)
|
|
33
|
+
details.bind(current, theme: nil, fonts: NativeListFontFamilies())
|
|
34
|
+
container.layoutIfNeeded()
|
|
35
|
+
XCTAssertEqual(richVisual.isHidden, hidden)
|
|
36
|
+
XCTAssertEqual(richActions.directionalLayoutMargins.leading, hidden ? 0 : 52)
|
|
37
|
+
XCTAssertEqual(
|
|
38
|
+
NativeListActivityDetailsView.measure(
|
|
39
|
+
current.data, width: 390,
|
|
40
|
+
fonts: NativeListFontFamilies()),
|
|
41
|
+
ceil(details.frame.height) + 16, accuracy: 1)
|
|
42
|
+
func hasAmount(_ view: UIView) -> Bool {
|
|
43
|
+
if (view as? UILabel)?.text == "••••" { return true }
|
|
44
|
+
return view.subviews.contains(where: hasAmount)
|
|
45
|
+
}
|
|
46
|
+
XCTAssertTrue(hasAmount(details))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let cell = NativeListActivityCell(frame: CGRect(x: 0, y: 0, width: 390, height: 100))
|
|
50
|
+
let legacyVisual = try XCTUnwrap(cell.root.arrangedSubviews.first)
|
|
51
|
+
let column = try XCTUnwrap(cell.root.arrangedSubviews[1] as? UIStackView)
|
|
52
|
+
let legacyActions = try XCTUnwrap(column.arrangedSubviews.last as? UIStackView)
|
|
53
|
+
for hidden in [false, true, false] {
|
|
54
|
+
cell.bind(item: try item(rich: false, hidden: hidden), theme: nil,
|
|
55
|
+
layout: "linear", selected: false, checkboxState: { _, _, fallback in fallback },
|
|
56
|
+
fonts: NativeListFontFamilies())
|
|
57
|
+
XCTAssertEqual(legacyVisual.isHidden, hidden)
|
|
58
|
+
XCTAssertFalse(legacyActions.isHidden)
|
|
59
|
+
XCTAssertEqual((legacyActions.arrangedSubviews.first as? UIButton)?.currentTitle, "Speed up")
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
7
63
|
func testSmallNumberRunsPreserveBaselineAcrossAmountsFiatAndFee() throws {
|
|
8
64
|
func segments(_ prefix: String, _ suffix: String) -> [[String: Any]] {
|
|
9
65
|
[["text": prefix], ["text": "5", "style": "subscript"], ["text": suffix]]
|
|
@@ -41,6 +97,103 @@ final class NativeListActivityPresentationTests: XCTestCase {
|
|
|
41
97
|
}
|
|
42
98
|
}
|
|
43
99
|
|
|
100
|
+
func testTableColumnsStayStableAcrossFeeLeadingAndAmountReuseWithForcedRendererDirection() throws {
|
|
101
|
+
let width: CGFloat = 900
|
|
102
|
+
let horizontal: CGFloat = 16
|
|
103
|
+
let contentWidth = width - horizontal * 2
|
|
104
|
+
let gap: CGFloat = 12
|
|
105
|
+
let container = UIView(frame: CGRect(x: 0, y: 0, width: contentWidth, height: 4000))
|
|
106
|
+
let details = NativeListActivityDetailsView()
|
|
107
|
+
details.translatesAutoresizingMaskIntoConstraints = false
|
|
108
|
+
container.addSubview(details)
|
|
109
|
+
NSLayoutConstraint.activate([
|
|
110
|
+
details.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
|
111
|
+
details.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
|
112
|
+
details.topAnchor.constraint(equalTo: container.topAnchor),
|
|
113
|
+
])
|
|
114
|
+
let main = try XCTUnwrap(details.arrangedSubviews.first as? UIStackView)
|
|
115
|
+
let amounts = try XCTUnwrap(main.arrangedSubviews[2] as? UIStackView)
|
|
116
|
+
let fee = try XCTUnwrap(main.arrangedSubviews[3] as? UIStackView)
|
|
117
|
+
for rtl in [false, true] {
|
|
118
|
+
let direction: UIUserInterfaceLayoutDirection = rtl ? .rightToLeft : .leftToRight
|
|
119
|
+
// This fixture covers renderer geometry; App-level RTL propagation is separate.
|
|
120
|
+
func applyDirection(_ view: UIView) {
|
|
121
|
+
view.semanticContentAttribute = rtl ? .forceRightToLeft : .forceLeftToRight
|
|
122
|
+
view.subviews.forEach(applyDirection)
|
|
123
|
+
}
|
|
124
|
+
for hasFee in [true, false, true] {
|
|
125
|
+
var previousHeight: CGFloat = 0
|
|
126
|
+
for count in [1, 2, 6, 32] {
|
|
127
|
+
for hideLeading in [false, true, false] {
|
|
128
|
+
for feeKind in 0...2 {
|
|
129
|
+
var data: [String: Any] = [
|
|
130
|
+
"type": "activity", "key": "table", "title": "Send",
|
|
131
|
+
"description": "Contract interaction with a long description that wraps",
|
|
132
|
+
"leading": ["kind": "icon", "name": "ArrowTopOutline"],
|
|
133
|
+
"hideLeading": hideLeading,
|
|
134
|
+
"amounts": (0..<count).map { index in [
|
|
135
|
+
"key": "amount-\(index)", "text": index % 2 == 0 ? "-123456789012345678901234567890.123456789 ETH" : "+1 USDC",
|
|
136
|
+
"secondaryText": "$1,000.00",
|
|
137
|
+
"leading": ["kind": "icon", "name": "ArrowTopOutline"],
|
|
138
|
+
] as [String: Any] },
|
|
139
|
+
]
|
|
140
|
+
if hasFee {
|
|
141
|
+
data["fee"] = ["label": "Network fee",
|
|
142
|
+
"primary": feeKind == 1 ? "0.000000012345678 ETH" : "1 ETH",
|
|
143
|
+
"secondary": "$0.20", "hidden": feeKind == 2]
|
|
144
|
+
}
|
|
145
|
+
// Create amount views before applying the fixture direction; each transition binds once.
|
|
146
|
+
details.bind(try NativeListItem(data: data), theme: nil, fonts: NativeListFontFamilies())
|
|
147
|
+
applyDirection(details)
|
|
148
|
+
for presentation in ["table", "stacked", "table"] {
|
|
149
|
+
data["presentation"] = presentation
|
|
150
|
+
details.bind(try NativeListItem(data: data), theme: nil, fonts: NativeListFontFamilies())
|
|
151
|
+
XCTAssertEqual(main.effectiveUserInterfaceLayoutDirection, direction)
|
|
152
|
+
XCTAssertEqual(amounts.effectiveUserInterfaceLayoutDirection, direction)
|
|
153
|
+
XCTAssertEqual(fee.effectiveUserInterfaceLayoutDirection, direction)
|
|
154
|
+
container.setNeedsLayout()
|
|
155
|
+
container.layoutIfNeeded()
|
|
156
|
+
guard presentation == "table" else { continue }
|
|
157
|
+
let expected = (contentWidth - gap * (hasFee ? 2 : 1)) / (hasFee ? 2.6 : 2)
|
|
158
|
+
XCTAssertEqual(amounts.frame.width, expected, accuracy: 1)
|
|
159
|
+
let start = rtl ? contentWidth - expected * 2 - gap : expected + gap
|
|
160
|
+
XCTAssertEqual(amounts.frame.minX, start, accuracy: 1)
|
|
161
|
+
XCTAssertEqual(amounts.frame.midX, start + expected / 2, accuracy: 1)
|
|
162
|
+
XCTAssertEqual(amounts.arrangedSubviews.count, count)
|
|
163
|
+
for amount in amounts.arrangedSubviews {
|
|
164
|
+
XCTAssertEqual(amount.frame.minX, 0, accuracy: 1)
|
|
165
|
+
XCTAssertEqual(amount.frame.width, expected, accuracy: 1)
|
|
166
|
+
let row = try XCTUnwrap(amount as? UIStackView)
|
|
167
|
+
let leading = row.arrangedSubviews[0]
|
|
168
|
+
let labels = row.arrangedSubviews[1]
|
|
169
|
+
if rtl { XCTAssertLessThanOrEqual(labels.frame.maxX, leading.frame.minX) }
|
|
170
|
+
else { XCTAssertLessThanOrEqual(leading.frame.maxX, labels.frame.minX) }
|
|
171
|
+
XCTAssertGreaterThanOrEqual(labels.frame.minX, 0)
|
|
172
|
+
XCTAssertLessThanOrEqual(labels.frame.maxX, amount.frame.width + 1)
|
|
173
|
+
}
|
|
174
|
+
if hasFee {
|
|
175
|
+
XCTAssertEqual(fee.frame.width, expected * 0.6, accuracy: 1)
|
|
176
|
+
XCTAssertEqual(fee.alpha, feeKind == 2 ? 0 : 1)
|
|
177
|
+
for child in fee.arrangedSubviews {
|
|
178
|
+
XCTAssertGreaterThanOrEqual(child.frame.minX, -1)
|
|
179
|
+
XCTAssertLessThanOrEqual(child.frame.maxX, fee.frame.width + 1)
|
|
180
|
+
if rtl { XCTAssertEqual(child.frame.minX, 0, accuracy: 1) }
|
|
181
|
+
else { XCTAssertEqual(child.frame.maxX, fee.frame.width, accuracy: 1) }
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
XCTAssertEqual(
|
|
185
|
+
NativeListActivityDetailsView.measure(data, width: width, fonts: NativeListFontFamilies()),
|
|
186
|
+
ceil(details.frame.height) + 16, accuracy: 1)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
XCTAssertGreaterThan(details.frame.height, previousHeight)
|
|
191
|
+
previousHeight = details.frame.height
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
44
197
|
func testAutomaticHeightMatchesRenderedStacks() throws {
|
|
45
198
|
let amount: [String: Any] = ["key": "send", "text": "-0.5 ETH", "secondaryText": "$1,000.00"]
|
|
46
199
|
let cases: [(String, [String: Any])] = [
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
import XCTest
|
|
3
|
+
@testable import NativeListModule
|
|
4
|
+
|
|
5
|
+
@MainActor
|
|
6
|
+
final class NativeListIdentityTitleIconLayoutTests: XCTestCase {
|
|
7
|
+
private func child<T>(_ cell: NativeListIdentityCell, _ label: String, as type: T.Type) throws -> T {
|
|
8
|
+
try XCTUnwrap(Mirror(reflecting: cell).children.first { $0.label == label }?.value as? T)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// OK-66041: the Home native-token row carries a GasSolid `titleIcon`. The
|
|
12
|
+
// glyph must sit right after the title text (4pt gap), as Android's
|
|
13
|
+
// PackedTitleLineLayout and the Web flex row already do. iOS let the title
|
|
14
|
+
// label stretch across the whole title row, so the icon landed next to the
|
|
15
|
+
// trailing value column instead of beside "ETH".
|
|
16
|
+
func testTitleIconFollowsTheTitleTextInsteadOfTheRowEnd() throws {
|
|
17
|
+
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 390, height: 60))
|
|
18
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 390, height: 200))
|
|
19
|
+
window.addSubview(cell)
|
|
20
|
+
let titleIcon = try child(cell, "titleIconView", as: UIImageView.self)
|
|
21
|
+
let titleLabel = try child(cell, "titleLabel", as: UILabel.self)
|
|
22
|
+
let titleStack = try child(cell, "titleRowStack", as: UIStackView.self)
|
|
23
|
+
let item = try NativeListItem(data: [
|
|
24
|
+
"key": "eth", "type": "identity", "title": "ETH", "height": 60,
|
|
25
|
+
"leading": ["kind": "token", "fallbackIcon": ["name": "CryptoCoinOutline"]],
|
|
26
|
+
"titleIcon": ["name": "GasSolid"],
|
|
27
|
+
"subtitleSegments": [
|
|
28
|
+
["text": "$2,330.23", "tone": "secondary"],
|
|
29
|
+
["text": "+0.23%", "tone": "positive", "separatorBefore": true],
|
|
30
|
+
],
|
|
31
|
+
"trailing": [["kind": "valuePair", "primary": "0.00001417", "secondary": "$0.03"]],
|
|
32
|
+
])
|
|
33
|
+
cell.bind(item: item, theme: nil, layout: "linear", selected: false,
|
|
34
|
+
checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
|
|
35
|
+
cell.layoutIfNeeded()
|
|
36
|
+
|
|
37
|
+
XCTAssertFalse(titleIcon.isHidden)
|
|
38
|
+
// The title keeps its intrinsic width; the slack goes to the end of the row.
|
|
39
|
+
XCTAssertEqual(
|
|
40
|
+
titleLabel.bounds.width, titleLabel.intrinsicContentSize.width, accuracy: 1,
|
|
41
|
+
"title label must not stretch across the title row")
|
|
42
|
+
let labelFrame = titleLabel.convert(titleLabel.bounds, to: cell)
|
|
43
|
+
let iconFrame = titleIcon.convert(titleIcon.bounds, to: cell)
|
|
44
|
+
XCTAssertEqual(iconFrame.minX, labelFrame.maxX + 4, accuracy: 1,
|
|
45
|
+
"gas icon must follow the title text with the 4pt gap")
|
|
46
|
+
let iconInRow = titleIcon.convert(titleIcon.bounds, to: titleStack)
|
|
47
|
+
XCTAssertLessThan(iconInRow.maxX, titleStack.bounds.width / 2,
|
|
48
|
+
"gas icon must stay in the leading half of the title row, not at the value column")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// A long title still truncates in front of the icon instead of pushing it
|
|
52
|
+
// out of the row, and the badge keeps following the icon.
|
|
53
|
+
func testLongTitleTruncatesAndKeepsIconAndBadgeAdjacent() throws {
|
|
54
|
+
let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 320, height: 60))
|
|
55
|
+
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 200))
|
|
56
|
+
window.addSubview(cell)
|
|
57
|
+
let titleIcon = try child(cell, "titleIconView", as: UIImageView.self)
|
|
58
|
+
let titleLabel = try child(cell, "titleLabel", as: UILabel.self)
|
|
59
|
+
let badge = try child(cell, "badgeLabel", as: UILabel.self)
|
|
60
|
+
let item = try NativeListItem(data: [
|
|
61
|
+
"key": "long", "type": "identity",
|
|
62
|
+
"title": "A very long token name that cannot possibly fit on one line", "height": 60,
|
|
63
|
+
"leading": ["kind": "token", "fallbackIcon": ["name": "CryptoCoinOutline"]],
|
|
64
|
+
"titleIcon": ["name": "GasSolid"],
|
|
65
|
+
"badges": [["key": "native", "text": "Native"]],
|
|
66
|
+
"trailing": [["kind": "valuePair", "primary": "1.00", "secondary": "$1.00"]],
|
|
67
|
+
])
|
|
68
|
+
cell.bind(item: item, theme: nil, layout: "linear", selected: false,
|
|
69
|
+
checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
|
|
70
|
+
cell.layoutIfNeeded()
|
|
71
|
+
|
|
72
|
+
let labelFrame = titleLabel.convert(titleLabel.bounds, to: cell)
|
|
73
|
+
let iconFrame = titleIcon.convert(titleIcon.bounds, to: cell)
|
|
74
|
+
let badgeFrame = badge.convert(badge.bounds, to: cell)
|
|
75
|
+
XCTAssertEqual(titleIcon.bounds.width, 20, accuracy: 0.5)
|
|
76
|
+
XCTAssertEqual(iconFrame.minX, labelFrame.maxX + 4, accuracy: 1)
|
|
77
|
+
XCTAssertFalse(badge.isHidden)
|
|
78
|
+
XCTAssertGreaterThan(badgeFrame.minX, iconFrame.maxX)
|
|
79
|
+
XCTAssertLessThanOrEqual(badgeFrame.maxX, cell.bounds.width)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
import XCTest
|
|
3
|
+
@testable import NativeListModule
|
|
4
|
+
|
|
5
|
+
@MainActor
|
|
6
|
+
final class NativeListLeadingVisualPairBackdropTests: XCTestCase {
|
|
7
|
+
private func child<T>(_ visual: NativeListLeadingVisual, _ label: String, as type: T.Type) throws -> T {
|
|
8
|
+
try XCTUnwrap(Mirror(reflecting: visual).children.first { $0.label == label }?.value as? T)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
private func token(_ uri: String) -> [String: Any] {
|
|
12
|
+
[
|
|
13
|
+
"kind": "token", "shape": "circle",
|
|
14
|
+
"image": ["uri": uri, "width": 40, "height": 40],
|
|
15
|
+
"fallbackIcon": ["name": "CryptoCoinOutline"],
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// PR #185 review: the pair ring sits above the primary token. While the
|
|
20
|
+
// secondary image has not loaded (or failed), its slot is hidden, so the ring
|
|
21
|
+
// must be hidden too; otherwise a blank row-background disc covers the
|
|
22
|
+
// primary's lower-right corner.
|
|
23
|
+
func testPairRingStaysHiddenWhileTheSecondaryImageIsNotDisplayed() throws {
|
|
24
|
+
let visual = NativeListLeadingVisual(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
|
|
25
|
+
let ring = try child(visual, "pairBackdrop", as: UIView.self)
|
|
26
|
+
visual.bind(
|
|
27
|
+
token("https://example.invalid/primary.png"), style: [:], key: "pair", theme: nil,
|
|
28
|
+
isUnread: false, secondaryVisual: token("https://example.invalid/secondary.png"),
|
|
29
|
+
fonts: NativeListFontFamilies())
|
|
30
|
+
visual.layoutIfNeeded()
|
|
31
|
+
// `slots` is a value-type array: read it after bind has created the slots.
|
|
32
|
+
let slots = try child(visual, "slots", as: [NativeListImageSlot].self)
|
|
33
|
+
XCTAssertEqual(slots.count, 2)
|
|
34
|
+
XCTAssertTrue(slots[1].view.isHidden, "secondary slot is hidden until its image loads")
|
|
35
|
+
XCTAssertTrue(ring.isHidden, "ring must follow the hidden secondary slot")
|
|
36
|
+
|
|
37
|
+
visual.recycle()
|
|
38
|
+
XCTAssertTrue(ring.isHidden)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
func testNoPairMeansNoRing() throws {
|
|
42
|
+
let visual = NativeListLeadingVisual(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
|
|
43
|
+
let ring = try child(visual, "pairBackdrop", as: UIView.self)
|
|
44
|
+
visual.bind(
|
|
45
|
+
token("https://example.invalid/primary.png"), style: [:], key: "single", theme: nil,
|
|
46
|
+
isUnread: false, fonts: NativeListFontFamilies())
|
|
47
|
+
visual.layoutIfNeeded()
|
|
48
|
+
XCTAssertTrue(ring.isHidden)
|
|
49
|
+
}
|
|
50
|
+
}
|