@onekeyfe/react-native-native-list 6.7.0-6 → 6.7.0-60
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 +312 -375
- 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 +50 -13
- 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 +209 -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 +8 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +130 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1978 -136
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +35 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListDescriptionTouchPolicyTest.kt +153 -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 +78 -14
- package/docs/SPEC.md +1318 -16
- package/docs/STYLE_SPEC.md +18 -0
- package/ios/HybridNativeList.swift +21 -2
- package/ios/NativeListAccessoryStack.swift +237 -51
- package/ios/NativeListActivityDetailsView.swift +43 -16
- 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 +17 -5
- package/ios/NativeListRowHost.swift +14 -0
- package/ios/NativeListSectionHeaderRenderer.swift +100 -4
- package/ios/NativeListTextLabel.swift +106 -0
- package/ios/RNCNativeListView.swift +1097 -60
- package/ios/tests/NativeListAccessoryStackTests.swift +101 -0
- package/ios/tests/NativeListAccountSelectorLayoutTests.swift +96 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +423 -0
- package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
- package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
- package/ios/tests/NativeListLifecycleTests.swift +2959 -4
- package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
- package/ios/tests/NativeListMediaVisibilityTests.swift +27 -1
- package/ios/tests/NativeListSharedIconTests.swift +236 -0
- package/lib/module/NativeList.js +236 -38
- package/lib/module/NativeList.web.js +163 -45
- 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 +1263 -48
- package/lib/module/web/NativeListGeneratedIcons.js +31 -0
- package/lib/module/web/NativeListWebEngine.js +513 -275
- package/lib/module/web/templates/ActivityRowRenderer.js +41 -54
- package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
- package/lib/module/web/templates/DataRowRenderer.js +56 -5
- package/lib/module/web/templates/IdentityRowRenderer.js +161 -7
- 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 +134 -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 +439 -91
- package/src/NativeList.types.ts +24 -2
- package/src/NativeList.web.tsx +286 -88
- package/src/index.ts +2 -0
- package/src/models.ts +272 -144
- package/src/selection.ts +1 -0
- package/src/validation.ts +3041 -146
- package/src/web/NativeListGeneratedIcons.ts +28 -0
- package/src/web/NativeListWebEngine.ts +818 -343
- package/src/web/templates/ActivityRowRenderer.ts +71 -91
- package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
- package/src/web/templates/DataRowRenderer.ts +121 -20
- package/src/web/templates/IdentityRowRenderer.ts +234 -9
- 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,332 @@ 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
|
+
|
|
63
|
+
// The description label spans the identity column, so a tap anywhere on its
|
|
64
|
+
// line used to open the description action. Only the action text opens it
|
|
65
|
+
// now; the blank rest of the line belongs to the row press (OK-67219). Where
|
|
66
|
+
// that text starts is the caller's `descriptionActionStart`, never something
|
|
67
|
+
// read out of the string.
|
|
68
|
+
func testDescriptionActionTakesTouchesOnItsTextOnly() throws {
|
|
69
|
+
let details = NativeListActivityDetailsView()
|
|
70
|
+
// Wide enough that the label keeps blank space beside its text even when
|
|
71
|
+
// the amounts take their full half of the row.
|
|
72
|
+
let container = UIView(frame: CGRect(x: 0, y: 0, width: 600, height: 300))
|
|
73
|
+
details.translatesAutoresizingMaskIntoConstraints = false
|
|
74
|
+
container.addSubview(details)
|
|
75
|
+
NSLayoutConstraint.activate([
|
|
76
|
+
details.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
|
77
|
+
details.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
|
78
|
+
details.topAnchor.constraint(equalTo: container.topAnchor),
|
|
79
|
+
])
|
|
80
|
+
func bind(description: String, actionKey: String?, actionStart: Int? = nil) throws -> NativeListTextLabel {
|
|
81
|
+
var data: [String: Any] = [
|
|
82
|
+
"type": "activity", "key": "tx", "title": "Swap", "description": description,
|
|
83
|
+
"leading": ["kind": "icon", "name": "ArrowTopOutline"],
|
|
84
|
+
"amounts": [["key": "send", "text": "-1"]],
|
|
85
|
+
]
|
|
86
|
+
if let actionKey { data["descriptionActionKey"] = actionKey }
|
|
87
|
+
if let actionStart { data["descriptionActionStart"] = actionStart }
|
|
88
|
+
details.bind(try NativeListItem(data: data), theme: nil, fonts: NativeListFontFamilies())
|
|
89
|
+
container.layoutIfNeeded()
|
|
90
|
+
func find(_ view: UIView) -> NativeListTextLabel? {
|
|
91
|
+
if let label = view as? NativeListTextLabel, label.text == description { return label }
|
|
92
|
+
return view.subviews.lazy.compactMap(find).first
|
|
93
|
+
}
|
|
94
|
+
return try XCTUnwrap(find(details))
|
|
95
|
+
}
|
|
96
|
+
func hit(_ label: NativeListTextLabel, x: CGFloat) -> Bool {
|
|
97
|
+
label.point(inside: CGPoint(x: x, y: label.bounds.midY), with: nil)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Without a start the whole text is the action, also a label holding the
|
|
101
|
+
// separator a time prefix would use.
|
|
102
|
+
let label = try bind(description: "Router • V2", actionKey: "address-info")
|
|
103
|
+
let labelText = try XCTUnwrap(label.touchableTextRegions.first)
|
|
104
|
+
XCTAssertEqual(label.touchableTextStart, 0)
|
|
105
|
+
XCTAssertEqual(label.touchableTextRegions.count, 1)
|
|
106
|
+
XCTAssertGreaterThan(label.bounds.width, labelText.maxX + 40)
|
|
107
|
+
XCTAssertTrue(hit(label, x: 4))
|
|
108
|
+
XCTAssertTrue(hit(label, x: labelText.maxX - 12))
|
|
109
|
+
XCTAssertFalse(hit(label, x: label.bounds.maxX - 4))
|
|
110
|
+
|
|
111
|
+
// With a start only the text from there on is the action: the time is
|
|
112
|
+
// not, the complete label behind it is.
|
|
113
|
+
let prefix = "08:48 • "
|
|
114
|
+
let timed = try bind(
|
|
115
|
+
description: prefix + "Router • V2", actionKey: "address-info",
|
|
116
|
+
actionStart: (prefix as NSString).length)
|
|
117
|
+
let timedText = try XCTUnwrap(timed.touchableTextRegions.first)
|
|
118
|
+
XCTAssertEqual(timed.touchableTextRegions.count, 1)
|
|
119
|
+
XCTAssertGreaterThan(timed.bounds.width, timedText.maxX + 40)
|
|
120
|
+
// The same label, less the slop on the side where the time is.
|
|
121
|
+
XCTAssertEqual(timedText.width, labelText.width - 8, accuracy: 1)
|
|
122
|
+
XCTAssertFalse(hit(timed, x: 4))
|
|
123
|
+
XCTAssertFalse(hit(timed, x: timedText.minX - 2))
|
|
124
|
+
XCTAssertTrue(hit(timed, x: timedText.minX + 2))
|
|
125
|
+
XCTAssertTrue(hit(timed, x: timedText.maxX - 12))
|
|
126
|
+
XCTAssertFalse(hit(timed, x: timed.bounds.maxX - 4))
|
|
127
|
+
|
|
128
|
+
// The start counts UTF-16 units: the emoji takes two.
|
|
129
|
+
let emojiPrefix = "🕘 08:48 • "
|
|
130
|
+
XCTAssertEqual((emojiPrefix as NSString).length, 11)
|
|
131
|
+
let emoji = try bind(
|
|
132
|
+
description: emojiPrefix + "Router • V2", actionKey: "address-info", actionStart: 11)
|
|
133
|
+
let emojiText = try XCTUnwrap(emoji.touchableTextRegions.first)
|
|
134
|
+
XCTAssertEqual(emojiText.width, labelText.width - 8, accuracy: 1)
|
|
135
|
+
XCTAssertFalse(hit(emoji, x: 4))
|
|
136
|
+
XCTAssertFalse(hit(emoji, x: emojiText.minX - 2))
|
|
137
|
+
XCTAssertTrue(hit(emoji, x: emojiText.minX + 2))
|
|
138
|
+
XCTAssertTrue(hit(emoji, x: emojiText.maxX - 12))
|
|
139
|
+
|
|
140
|
+
// A start at the end of the text, or clamped to it, leaves nothing to tap.
|
|
141
|
+
// 4294967296 is a safe integer past 32 bits; it must clamp, not wrap to 0.
|
|
142
|
+
for start in [(prefix as NSString).length, 99, 4_294_967_296] {
|
|
143
|
+
let ended = try bind(description: prefix, actionKey: "address-info", actionStart: start)
|
|
144
|
+
XCTAssertTrue(ended.touchableTextRegions.isEmpty)
|
|
145
|
+
XCTAssertFalse(ended.isUserInteractionEnabled)
|
|
146
|
+
XCTAssertFalse(hit(ended, x: 4))
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// The reused view keeps no state: a rebind without a start covers the
|
|
150
|
+
// whole text again, one without the action restores the label's own hit
|
|
151
|
+
// testing even when a start is still supplied, and so does recycling.
|
|
152
|
+
let rebound = try bind(description: "Router • V2", actionKey: "address-info")
|
|
153
|
+
XCTAssertEqual(rebound.touchableTextStart, 0)
|
|
154
|
+
XCTAssertTrue(rebound.isUserInteractionEnabled)
|
|
155
|
+
XCTAssertTrue(hit(rebound, x: 4))
|
|
156
|
+
let plain = try bind(description: "Router • V2", actionKey: nil, actionStart: 3)
|
|
157
|
+
XCTAssertNil(plain.touchableTextStart)
|
|
158
|
+
XCTAssertFalse(plain.isUserInteractionEnabled)
|
|
159
|
+
XCTAssertTrue(hit(plain, x: plain.bounds.maxX - 4))
|
|
160
|
+
let recycled = try bind(
|
|
161
|
+
description: prefix + "Router", actionKey: "address-info",
|
|
162
|
+
actionStart: (prefix as NSString).length)
|
|
163
|
+
XCTAssertEqual(recycled.touchableTextStart, (prefix as NSString).length)
|
|
164
|
+
details.recycle()
|
|
165
|
+
XCTAssertNil(recycled.touchableTextStart)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// A narrow column wraps "time • address". The time stays outside the action
|
|
169
|
+
// on its line, while the address is hit on both lines, also at the x the
|
|
170
|
+
// time occupies one line above. The label is sized directly so the wrap does
|
|
171
|
+
// not depend on how the row shares its width.
|
|
172
|
+
func testWrappedDescriptionKeepsTheTimeOutsideTheAction() throws {
|
|
173
|
+
let description = "08:48 • Uniswap Router"
|
|
174
|
+
let label = NativeListTextLabel()
|
|
175
|
+
NativeListResolvedText(
|
|
176
|
+
description, style: nil, size: 14, color: .label, lineHeight: 20, lines: 2,
|
|
177
|
+
fonts: NativeListFontFamilies()
|
|
178
|
+
).bind(label)
|
|
179
|
+
label.frame = CGRect(x: 0, y: 0, width: 142, height: 40)
|
|
180
|
+
label.touchableTextStart = ("08:48 • " as NSString).length
|
|
181
|
+
func hit(_ x: CGFloat, _ y: CGFloat) -> Bool {
|
|
182
|
+
label.point(inside: CGPoint(x: x, y: y), with: nil)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
let lines = label.touchableTextRegions
|
|
186
|
+
XCTAssertEqual(lines.count, 2)
|
|
187
|
+
guard lines.count == 2 else { return }
|
|
188
|
+
XCTAssertFalse(hit(4, lines[0].midY))
|
|
189
|
+
XCTAssertTrue(hit(lines[0].maxX - 12, lines[0].midY))
|
|
190
|
+
XCTAssertTrue(hit(4, lines[1].midY))
|
|
191
|
+
XCTAssertFalse(hit(label.bounds.maxX - 2, lines[1].midY))
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// The first line holds only the time, so it takes no touches, and the slop
|
|
195
|
+
// of the address line below it must not reach up into the time.
|
|
196
|
+
func testAddressStartingOnTheSecondLineLeavesTheTimeLineAlone() throws {
|
|
197
|
+
let prefix = "08:48 • "
|
|
198
|
+
let address = "UniswapUniversalRouter"
|
|
199
|
+
func text(_ value: String) -> NativeListResolvedText {
|
|
200
|
+
NativeListResolvedText(
|
|
201
|
+
value, style: nil, size: 14, color: .label, lineHeight: 20, lines: 2,
|
|
202
|
+
fonts: NativeListFontFamilies())
|
|
203
|
+
}
|
|
204
|
+
let label = NativeListTextLabel()
|
|
205
|
+
text(prefix + address).bind(label)
|
|
206
|
+
// Wide enough for the address alone, too narrow for the time beside it.
|
|
207
|
+
label.frame = CGRect(x: 0, y: 0, width: text(address).measureWidth() + 4, height: 40)
|
|
208
|
+
label.touchableTextStart = (prefix as NSString).length
|
|
209
|
+
func hit(y: CGFloat) -> Bool { label.point(inside: CGPoint(x: 4, y: y), with: nil) }
|
|
210
|
+
|
|
211
|
+
let line = try XCTUnwrap(label.touchableTextRegions.first)
|
|
212
|
+
XCTAssertEqual(label.touchableTextRegions.count, 1)
|
|
213
|
+
XCTAssertEqual(line.minY, 20, accuracy: 0.5)
|
|
214
|
+
XCTAssertFalse(hit(y: 10))
|
|
215
|
+
XCTAssertFalse(hit(y: line.minY - 2))
|
|
216
|
+
XCTAssertTrue(hit(y: line.minY + 2))
|
|
217
|
+
// The last line of the layout still takes its slop below the text.
|
|
218
|
+
XCTAssertTrue(hit(y: label.bounds.maxY + 4))
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private func descriptionText(_ value: String, style: [String: Any]? = nil) -> NativeListResolvedText {
|
|
222
|
+
NativeListResolvedText(
|
|
223
|
+
value, style: style, size: 14, color: .label, lineHeight: 20, lines: 1,
|
|
224
|
+
fonts: NativeListFontFamilies())
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/// Width the description font gives `value` on its own.
|
|
228
|
+
private func descriptionWidth(_ value: String) -> CGFloat {
|
|
229
|
+
descriptionText(value).attributed(direction: .leftToRight).size().width
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private func descriptionLabel(
|
|
233
|
+
_ value: String, start: Int, width: CGFloat = 300, style: [String: Any]? = nil
|
|
234
|
+
) -> NativeListTextLabel {
|
|
235
|
+
let label = NativeListTextLabel()
|
|
236
|
+
descriptionText(value, style: style).bind(label)
|
|
237
|
+
label.frame = CGRect(x: 0, y: 0, width: width, height: 20)
|
|
238
|
+
label.touchableTextStart = start
|
|
239
|
+
return label
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private func hit(_ label: NativeListTextLabel, x: CGFloat) -> Bool {
|
|
243
|
+
label.point(inside: CGPoint(x: x, y: label.bounds.midY), with: nil)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// The slop is for blank space. It stops at plain text beside the action
|
|
247
|
+
// text, or a prefix narrower than the slop, like the "i" of "iRouter", would
|
|
248
|
+
// open an action it is not part of.
|
|
249
|
+
func testSlopStopsAtPlainTextBesideTheActionText() throws {
|
|
250
|
+
let short = descriptionLabel("iRouter", start: 1)
|
|
251
|
+
let i = descriptionWidth("i")
|
|
252
|
+
XCTAssertLessThan(i, 8)
|
|
253
|
+
let region = try XCTUnwrap(short.touchableTextRegions.first)
|
|
254
|
+
XCTAssertEqual(short.touchableTextRegions.count, 1)
|
|
255
|
+
XCTAssertEqual(region.minX, i, accuracy: 0.5)
|
|
256
|
+
XCTAssertFalse(hit(short, x: i / 2))
|
|
257
|
+
XCTAssertFalse(hit(short, x: -3))
|
|
258
|
+
XCTAssertTrue(hit(short, x: i + 2))
|
|
259
|
+
// Into the blank after the text the slop still reaches.
|
|
260
|
+
XCTAssertTrue(hit(short, x: descriptionWidth("iRouter") + 6))
|
|
261
|
+
XCTAssertFalse(hit(short, x: descriptionWidth("iRouter") + 10))
|
|
262
|
+
// And into the blank before a line that starts with the action text.
|
|
263
|
+
XCTAssertTrue(hit(descriptionLabel("Router", start: 0), x: -6))
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Mixed-direction text can split one logical suffix into several visual
|
|
267
|
+
// runs. From offset 6 of "ABC אבג XYZ" the suffix is the last Hebrew letter
|
|
268
|
+
// and " XYZ"; the Hebrew run is drawn right to left, so that letter sits
|
|
269
|
+
// left of the two plain ones. Each run is its own region and the plain text
|
|
270
|
+
// between them takes no touches.
|
|
271
|
+
func testMixedDirectionSuffixFollowsTheLaidOutRuns() {
|
|
272
|
+
let label = descriptionLabel("ABC \u{05D0}\u{05D1}\u{05D2} XYZ", start: 6)
|
|
273
|
+
let abc = descriptionWidth("ABC ")
|
|
274
|
+
let last = descriptionWidth("\u{05D2}")
|
|
275
|
+
let plain = descriptionWidth("\u{05D1}\u{05D0}")
|
|
276
|
+
let xyz = descriptionWidth(" XYZ")
|
|
277
|
+
let regions = label.touchableTextRegions.sorted { $0.minX < $1.minX }
|
|
278
|
+
XCTAssertEqual(regions.count, 2)
|
|
279
|
+
guard regions.count == 2 else { return }
|
|
280
|
+
XCTAssertEqual(regions[0].minX, abc, accuracy: 1)
|
|
281
|
+
XCTAssertEqual(regions[0].maxX, abc + last, accuracy: 1)
|
|
282
|
+
XCTAssertEqual(regions[1].minX, abc + last + plain, accuracy: 1)
|
|
283
|
+
XCTAssertFalse(hit(label, x: abc / 2))
|
|
284
|
+
XCTAssertTrue(hit(label, x: abc + last / 2))
|
|
285
|
+
XCTAssertFalse(hit(label, x: abc + last + plain / 2))
|
|
286
|
+
XCTAssertTrue(hit(label, x: abc + last + plain + xyz / 2))
|
|
287
|
+
// Only the outer edge of the last run faces blank space.
|
|
288
|
+
XCTAssertTrue(hit(label, x: abc + last + plain + xyz + 5))
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// A one-line description that does not fit ends in an ellipsis. Action text
|
|
292
|
+
// it only shortens stays touchable up to and including the ellipsis. Once it
|
|
293
|
+
// hides the action text altogether the ellipsis also stands for plain text,
|
|
294
|
+
// and nothing is left to touch.
|
|
295
|
+
func testTruncationCanHideTheActionText() throws {
|
|
296
|
+
let cut = descriptionLabel(
|
|
297
|
+
"08:48 • UniswapUniversalRouterWithAVeryLongName", start: 8, width: 150,
|
|
298
|
+
style: ["lines": 1])
|
|
299
|
+
let region = try XCTUnwrap(cut.touchableTextRegions.first)
|
|
300
|
+
XCTAssertEqual(cut.touchableTextRegions.count, 1)
|
|
301
|
+
XCTAssertEqual(region.minX, descriptionWidth("08:48 • "), accuracy: 1)
|
|
302
|
+
XCTAssertFalse(hit(cut, x: 20))
|
|
303
|
+
XCTAssertTrue(hit(cut, x: 100))
|
|
304
|
+
XCTAssertTrue(hit(cut, x: 145))
|
|
305
|
+
|
|
306
|
+
let prefix = "A very long plain prefix that fills the row • "
|
|
307
|
+
let hidden = descriptionLabel(
|
|
308
|
+
prefix + "Router", start: (prefix as NSString).length, width: 150, style: ["lines": 1])
|
|
309
|
+
XCTAssertTrue(hidden.touchableTextRegions.isEmpty)
|
|
310
|
+
XCTAssertFalse(hit(hidden, x: 145))
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// A one-line description folds each line break into one space, so the
|
|
314
|
+
// caller's offset is mapped onto the displayed text and kept inside it.
|
|
315
|
+
func testDescriptionActionStartFollowsTheDisplayedText() {
|
|
316
|
+
let source = "08:48\r\n• Router"
|
|
317
|
+
func text(_ style: [String: Any]?) -> NativeListResolvedText {
|
|
318
|
+
NativeListResolvedText(
|
|
319
|
+
source, style: style, size: 14, color: .label, lineHeight: 20, lines: 2,
|
|
320
|
+
fonts: NativeListFontFamilies())
|
|
321
|
+
}
|
|
322
|
+
let oneLine = text(["lines": 1])
|
|
323
|
+
XCTAssertEqual(oneLine.text, "08:48 • Router")
|
|
324
|
+
XCTAssertEqual(oneLine.displayOffset(9, in: source), 8)
|
|
325
|
+
XCTAssertEqual(oneLine.displayOffset(-3, in: source), 0)
|
|
326
|
+
XCTAssertEqual(oneLine.displayOffset(99, in: source), 14)
|
|
327
|
+
let wrapping = text(nil)
|
|
328
|
+
XCTAssertEqual(wrapping.text, source)
|
|
329
|
+
XCTAssertEqual(wrapping.displayOffset(9, in: source), 9)
|
|
330
|
+
XCTAssertEqual(wrapping.displayOffset(99, in: source), 15)
|
|
331
|
+
}
|
|
332
|
+
|
|
7
333
|
func testSmallNumberRunsPreserveBaselineAcrossAmountsFiatAndFee() throws {
|
|
8
334
|
func segments(_ prefix: String, _ suffix: String) -> [[String: Any]] {
|
|
9
335
|
[["text": prefix], ["text": "5", "style": "subscript"], ["text": suffix]]
|
|
@@ -41,6 +367,103 @@ final class NativeListActivityPresentationTests: XCTestCase {
|
|
|
41
367
|
}
|
|
42
368
|
}
|
|
43
369
|
|
|
370
|
+
func testTableColumnsStayStableAcrossFeeLeadingAndAmountReuseWithForcedRendererDirection() throws {
|
|
371
|
+
let width: CGFloat = 900
|
|
372
|
+
let horizontal: CGFloat = 16
|
|
373
|
+
let contentWidth = width - horizontal * 2
|
|
374
|
+
let gap: CGFloat = 12
|
|
375
|
+
let container = UIView(frame: CGRect(x: 0, y: 0, width: contentWidth, height: 4000))
|
|
376
|
+
let details = NativeListActivityDetailsView()
|
|
377
|
+
details.translatesAutoresizingMaskIntoConstraints = false
|
|
378
|
+
container.addSubview(details)
|
|
379
|
+
NSLayoutConstraint.activate([
|
|
380
|
+
details.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
|
381
|
+
details.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
|
382
|
+
details.topAnchor.constraint(equalTo: container.topAnchor),
|
|
383
|
+
])
|
|
384
|
+
let main = try XCTUnwrap(details.arrangedSubviews.first as? UIStackView)
|
|
385
|
+
let amounts = try XCTUnwrap(main.arrangedSubviews[2] as? UIStackView)
|
|
386
|
+
let fee = try XCTUnwrap(main.arrangedSubviews[3] as? UIStackView)
|
|
387
|
+
for rtl in [false, true] {
|
|
388
|
+
let direction: UIUserInterfaceLayoutDirection = rtl ? .rightToLeft : .leftToRight
|
|
389
|
+
// This fixture covers renderer geometry; App-level RTL propagation is separate.
|
|
390
|
+
func applyDirection(_ view: UIView) {
|
|
391
|
+
view.semanticContentAttribute = rtl ? .forceRightToLeft : .forceLeftToRight
|
|
392
|
+
view.subviews.forEach(applyDirection)
|
|
393
|
+
}
|
|
394
|
+
for hasFee in [true, false, true] {
|
|
395
|
+
var previousHeight: CGFloat = 0
|
|
396
|
+
for count in [1, 2, 6, 32] {
|
|
397
|
+
for hideLeading in [false, true, false] {
|
|
398
|
+
for feeKind in 0...2 {
|
|
399
|
+
var data: [String: Any] = [
|
|
400
|
+
"type": "activity", "key": "table", "title": "Send",
|
|
401
|
+
"description": "Contract interaction with a long description that wraps",
|
|
402
|
+
"leading": ["kind": "icon", "name": "ArrowTopOutline"],
|
|
403
|
+
"hideLeading": hideLeading,
|
|
404
|
+
"amounts": (0..<count).map { index in [
|
|
405
|
+
"key": "amount-\(index)", "text": index % 2 == 0 ? "-123456789012345678901234567890.123456789 ETH" : "+1 USDC",
|
|
406
|
+
"secondaryText": "$1,000.00",
|
|
407
|
+
"leading": ["kind": "icon", "name": "ArrowTopOutline"],
|
|
408
|
+
] as [String: Any] },
|
|
409
|
+
]
|
|
410
|
+
if hasFee {
|
|
411
|
+
data["fee"] = ["label": "Network fee",
|
|
412
|
+
"primary": feeKind == 1 ? "0.000000012345678 ETH" : "1 ETH",
|
|
413
|
+
"secondary": "$0.20", "hidden": feeKind == 2]
|
|
414
|
+
}
|
|
415
|
+
// Create amount views before applying the fixture direction; each transition binds once.
|
|
416
|
+
details.bind(try NativeListItem(data: data), theme: nil, fonts: NativeListFontFamilies())
|
|
417
|
+
applyDirection(details)
|
|
418
|
+
for presentation in ["table", "stacked", "table"] {
|
|
419
|
+
data["presentation"] = presentation
|
|
420
|
+
details.bind(try NativeListItem(data: data), theme: nil, fonts: NativeListFontFamilies())
|
|
421
|
+
XCTAssertEqual(main.effectiveUserInterfaceLayoutDirection, direction)
|
|
422
|
+
XCTAssertEqual(amounts.effectiveUserInterfaceLayoutDirection, direction)
|
|
423
|
+
XCTAssertEqual(fee.effectiveUserInterfaceLayoutDirection, direction)
|
|
424
|
+
container.setNeedsLayout()
|
|
425
|
+
container.layoutIfNeeded()
|
|
426
|
+
guard presentation == "table" else { continue }
|
|
427
|
+
let expected = (contentWidth - gap * (hasFee ? 2 : 1)) / (hasFee ? 2.6 : 2)
|
|
428
|
+
XCTAssertEqual(amounts.frame.width, expected, accuracy: 1)
|
|
429
|
+
let start = rtl ? contentWidth - expected * 2 - gap : expected + gap
|
|
430
|
+
XCTAssertEqual(amounts.frame.minX, start, accuracy: 1)
|
|
431
|
+
XCTAssertEqual(amounts.frame.midX, start + expected / 2, accuracy: 1)
|
|
432
|
+
XCTAssertEqual(amounts.arrangedSubviews.count, count)
|
|
433
|
+
for amount in amounts.arrangedSubviews {
|
|
434
|
+
XCTAssertEqual(amount.frame.minX, 0, accuracy: 1)
|
|
435
|
+
XCTAssertEqual(amount.frame.width, expected, accuracy: 1)
|
|
436
|
+
let row = try XCTUnwrap(amount as? UIStackView)
|
|
437
|
+
let leading = row.arrangedSubviews[0]
|
|
438
|
+
let labels = row.arrangedSubviews[1]
|
|
439
|
+
if rtl { XCTAssertLessThanOrEqual(labels.frame.maxX, leading.frame.minX) }
|
|
440
|
+
else { XCTAssertLessThanOrEqual(leading.frame.maxX, labels.frame.minX) }
|
|
441
|
+
XCTAssertGreaterThanOrEqual(labels.frame.minX, 0)
|
|
442
|
+
XCTAssertLessThanOrEqual(labels.frame.maxX, amount.frame.width + 1)
|
|
443
|
+
}
|
|
444
|
+
if hasFee {
|
|
445
|
+
XCTAssertEqual(fee.frame.width, expected * 0.6, accuracy: 1)
|
|
446
|
+
XCTAssertEqual(fee.alpha, feeKind == 2 ? 0 : 1)
|
|
447
|
+
for child in fee.arrangedSubviews {
|
|
448
|
+
XCTAssertGreaterThanOrEqual(child.frame.minX, -1)
|
|
449
|
+
XCTAssertLessThanOrEqual(child.frame.maxX, fee.frame.width + 1)
|
|
450
|
+
if rtl { XCTAssertEqual(child.frame.minX, 0, accuracy: 1) }
|
|
451
|
+
else { XCTAssertEqual(child.frame.maxX, fee.frame.width, accuracy: 1) }
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
XCTAssertEqual(
|
|
455
|
+
NativeListActivityDetailsView.measure(data, width: width, fonts: NativeListFontFamilies()),
|
|
456
|
+
ceil(details.frame.height) + 16, accuracy: 1)
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
XCTAssertGreaterThan(details.frame.height, previousHeight)
|
|
461
|
+
previousHeight = details.frame.height
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
44
467
|
func testAutomaticHeightMatchesRenderedStacks() throws {
|
|
45
468
|
let amount: [String: Any] = ["key": "send", "text": "-0.5 ETH", "secondaryText": "$1,000.00"]
|
|
46
469
|
let cases: [(String, [String: Any])] = [
|