@onekeyfe/react-native-native-list 6.7.0-20 → 6.7.0-22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +5 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +29 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +6 -10
- package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +15 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListGeneratedIcons.kt +47 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +33 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +5 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +13 -10
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +120 -338
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +5 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +33 -8
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +11 -5
- package/docs/ROW_TEMPLATES.md +10 -2
- package/docs/SPEC.md +432 -50
- package/ios/NativeListAccessoryStack.swift +6 -16
- package/ios/NativeListActivityDetailsView.swift +13 -4
- package/ios/NativeListDataRowRenderer.swift +15 -6
- package/ios/NativeListDesignAssets.swift +13 -84
- package/ios/NativeListGeneratedIcons.swift +55 -0
- package/ios/NativeListIconBinding.swift +171 -0
- package/ios/NativeListIdentityRenderer.swift +69 -13
- package/ios/NativeListLeadingVisual.swift +11 -9
- package/ios/NativeListMarketRenderer.swift +120 -31
- package/ios/NativeListMediaTileRenderer.swift +6 -2
- package/ios/NativeListMetricCardRenderer.swift +4 -2
- package/ios/NativeListSectionHeaderRenderer.swift +12 -4
- package/ios/RNCNativeListView.swift +21 -3
- package/ios/tests/NativeListAccessoryStackTests.swift +12 -0
- package/ios/tests/NativeListAccountSelectorLayoutTests.swift +96 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +97 -0
- package/ios/tests/NativeListLifecycleTests.swift +73 -4
- package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
- package/ios/tests/NativeListSharedIconTests.swift +236 -0
- package/lib/module/NativeList.js +25 -6
- package/lib/module/NativeList.web.js +9 -12
- package/lib/module/models.js +2 -0
- package/lib/module/validation.js +695 -114
- package/lib/module/web/NativeListGeneratedIcons.js +31 -0
- package/lib/module/web/NativeListWebEngine.js +24 -332
- package/lib/module/web/templates/ActivityRowRenderer.js +4 -24
- package/lib/module/web/templates/IdentityRowRenderer.js +66 -4
- package/lib/module/web/templates/MarketTableRowRenderer.js +36 -19
- package/lib/module/web/templates/MediaTileRowRenderer.js +2 -12
- package/lib/typescript/src/NativeList.types.d.ts +2 -2
- package/lib/typescript/src/models.d.ts +27 -14
- package/lib/typescript/src/validation.d.ts +7 -2
- package/lib/typescript/src/web/NativeListGeneratedIcons.d.ts +2 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +0 -1
- package/package.json +16 -10
- package/react-native-native-list.podspec +0 -5
- 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.tsx +30 -10
- package/src/NativeList.types.ts +2 -2
- package/src/NativeList.web.tsx +10 -14
- package/src/models.ts +158 -153
- package/src/validation.ts +1757 -167
- package/src/web/NativeListGeneratedIcons.ts +28 -0
- package/src/web/NativeListWebEngine.ts +31 -415
- package/src/web/templates/ActivityRowRenderer.ts +15 -53
- package/src/web/templates/IdentityRowRenderer.ts +78 -4
- package/src/web/templates/MarketTableRowRenderer.ts +53 -33
- package/src/web/templates/MediaTileRowRenderer.ts +2 -15
- 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_crypto_coin_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +0 -4
- package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_document2.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_dot_ver_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.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_gas_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +0 -3
- 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_large.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.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_refresh_ccw_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +0 -3
- 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
- package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +0 -1
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
import XCTest
|
|
3
|
+
import OneKeyImage
|
|
4
|
+
@testable import NativeListModule
|
|
5
|
+
|
|
6
|
+
@MainActor
|
|
7
|
+
final class NativeListSharedIconTests: XCTestCase {
|
|
8
|
+
private func field<T>(_ object: Any, _ name: String, as type: T.Type = T.self) throws -> T {
|
|
9
|
+
var mirror: Mirror? = Mirror(reflecting: object)
|
|
10
|
+
while let current = mirror {
|
|
11
|
+
if let child = current.children.first(where: { $0.label == name }) { return try XCTUnwrap(child.value as? T) }
|
|
12
|
+
mirror = current.superclassMirror
|
|
13
|
+
}
|
|
14
|
+
throw NSError(domain: "Missing field " + name, code: 1)
|
|
15
|
+
}
|
|
16
|
+
private func binding(_ button: UIButton) throws -> Any {
|
|
17
|
+
let mirror = try XCTUnwrap(Mirror(reflecting: button).superclassMirror)
|
|
18
|
+
let storage = try XCTUnwrap(mirror.children.first { $0.label?.contains("iconBinding") == true }?.value)
|
|
19
|
+
return try XCTUnwrap(Mirror(reflecting: storage).children.first?.value)
|
|
20
|
+
}
|
|
21
|
+
private func eventually(_ message: String, _ condition: () -> Bool) {
|
|
22
|
+
let end = Date().addingTimeInterval(5)
|
|
23
|
+
while !condition(), Date() < end { RunLoop.main.run(until: Date().addingTimeInterval(0.01)) }
|
|
24
|
+
XCTAssertTrue(condition(), message)
|
|
25
|
+
}
|
|
26
|
+
private func window() throws -> UIWindow {
|
|
27
|
+
guard UIApplication.perform(NSSelectorFromString("sharedApplication"))?.takeUnretainedValue() is UIApplication else {
|
|
28
|
+
throw XCTSkip("A UIApplication host is required for attached glyph acceptance")
|
|
29
|
+
}
|
|
30
|
+
let window = UIWindow(frame: UIScreen.main.bounds)
|
|
31
|
+
window.rootViewController = UIViewController()
|
|
32
|
+
window.makeKeyAndVisible()
|
|
33
|
+
return window
|
|
34
|
+
}
|
|
35
|
+
private func save(_ image: UIImage, _ name: String) throws {
|
|
36
|
+
guard let directory = ProcessInfo.processInfo.environment["ICON_EVIDENCE_DIR"] else { return }
|
|
37
|
+
try XCTUnwrap(image.pngData()).write(to: URL(fileURLWithPath: directory).appendingPathComponent(name + ".png"))
|
|
38
|
+
}
|
|
39
|
+
private func bind(_ stack: NativeListAccessoryStack, amount: String = "1", name: String = "DotVerSolid", kind: String = "icon", disabled: Bool = false) throws {
|
|
40
|
+
let descriptors: [[String: Any]] = [
|
|
41
|
+
["kind": "valuePair", "primary": amount, "secondary": "$1"],
|
|
42
|
+
["kind": kind, "name": name, "text": "Text", "buttonStyle": "tertiary", "actionKey": "menu", "disabled": disabled],
|
|
43
|
+
]
|
|
44
|
+
let item = try NativeListItem(data: ["key": "swap", "type": "identity", "title": "USDC", "height": 60, "trailing": descriptors])
|
|
45
|
+
stack.axis = .horizontal
|
|
46
|
+
stack.bind(item, descriptors: descriptors, theme: nil,
|
|
47
|
+
style: ["horizontalPadding": 20, "verticalPadding": 8, "leadingGap": 12, "trailingGap": 8],
|
|
48
|
+
checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
|
|
49
|
+
stack.setNeedsLayout(); stack.layoutIfNeeded()
|
|
50
|
+
}
|
|
51
|
+
func testDetachedMeasurementAndRealSwapRebindPreservePendingAndReadyImage() throws {
|
|
52
|
+
let service = OneKeyNamedSVG.shared
|
|
53
|
+
let metadataLock: NSLock = try field(service, "metadataLock")
|
|
54
|
+
let stateLock: NSLock = try field(service, "lock")
|
|
55
|
+
func state(_ owner: NSObject? = nil) throws -> (Int, Int) {
|
|
56
|
+
stateLock.lock(); defer { stateLock.unlock() }
|
|
57
|
+
let pending: Any = try field(service, "pending")
|
|
58
|
+
let keys = Mirror(reflecting: pending).children.compactMap { Mirror(reflecting: $0.value).children.first?.value as? ObjectIdentifier }
|
|
59
|
+
return (try field(service, "workers"), owner.map { owner in keys.filter { $0 == ObjectIdentifier(owner) }.count } ?? keys.count)
|
|
60
|
+
}
|
|
61
|
+
metadataLock.lock()
|
|
62
|
+
var locked = true
|
|
63
|
+
defer { if locked { metadataLock.unlock() } }
|
|
64
|
+
let baseline = try state()
|
|
65
|
+
let stack = NativeListAccessoryStack(frame: CGRect(x: 10, y: 80, width: 180, height: 44))
|
|
66
|
+
try bind(stack)
|
|
67
|
+
let button = try XCTUnwrap(stack.subviews.compactMap { $0 as? NativeListAccessoryButton }.first { !$0.isHidden && $0.image(for: .normal) != nil })
|
|
68
|
+
let slot = try binding(button)
|
|
69
|
+
let owner: NSObject = try field(slot, "owner")
|
|
70
|
+
XCTAssertEqual(try state(owner).0, baseline.0)
|
|
71
|
+
XCTAssertEqual(try state(owner).1, 0)
|
|
72
|
+
let beforeSize = try XCTUnwrap(button.image(for: .normal)).size
|
|
73
|
+
let detachedSize = stack.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
|
|
74
|
+
XCTAssertEqual(try state(owner).0, baseline.0)
|
|
75
|
+
XCTAssertEqual(try state(owner).1, 0)
|
|
76
|
+
let window = try window(); defer { window.isHidden = true }
|
|
77
|
+
do {
|
|
78
|
+
defer { metadataLock.unlock(); locked = false }
|
|
79
|
+
window.rootViewController!.view.addSubview(stack)
|
|
80
|
+
stack.layoutIfNeeded()
|
|
81
|
+
XCTAssertGreaterThan(try state(owner).0 + state(owner).1, baseline.0)
|
|
82
|
+
let bounds = button.bounds.size
|
|
83
|
+
let revision: UInt64 = try field(slot, "revision")
|
|
84
|
+
for index in 0..<100 { try bind(stack, amount: String(index)) }
|
|
85
|
+
XCTAssertEqual(try field(slot, "revision", as: UInt64.self), revision)
|
|
86
|
+
XCTAssertEqual(button.image(for: .normal)?.size, beforeSize)
|
|
87
|
+
XCTAssertEqual(button.bounds.size, bounds)
|
|
88
|
+
XCTAssertEqual(stack.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height, detachedSize.height)
|
|
89
|
+
}
|
|
90
|
+
eventually("Attached Swap glyph has an actual raster") { button.image(for: .normal)?.cgImage != nil && button.image(for: .normal)?.size == beforeSize && (try? self.field(slot, "currentImage", as: UIImage?.self)) != nil }
|
|
91
|
+
// A transparent measurement placeholder also has a CGImage: require painted pixels.
|
|
92
|
+
eventually("Decoded glyph is visible") { self.alphaCount(button.image(for: .normal)) > 0 }
|
|
93
|
+
let ready = try XCTUnwrap(button.image(for: .normal))
|
|
94
|
+
XCTAssertEqual(maximumAlpha(ready), 255)
|
|
95
|
+
try bind(stack, amount: "101")
|
|
96
|
+
XCTAssertTrue(button.image(for: .normal) === ready)
|
|
97
|
+
button.tintColor = .blue
|
|
98
|
+
XCTAssertTrue(button.image(for: .normal) === ready)
|
|
99
|
+
XCTAssertNotNil(button.image(for: .disabled))
|
|
100
|
+
try bind(stack, amount: "101")
|
|
101
|
+
func captureButton() -> UIImage {
|
|
102
|
+
let rect = button.convert(button.bounds, to: stack)
|
|
103
|
+
return UIGraphicsImageRenderer(size: button.bounds.size).image { context in
|
|
104
|
+
context.cgContext.translateBy(x: -rect.minX, y: -rect.minY)
|
|
105
|
+
stack.drawHierarchy(in: stack.bounds, afterScreenUpdates: true)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
try save(captureButton(), "ios-swap-menu-normal")
|
|
109
|
+
var actions = 0
|
|
110
|
+
stack.onAction = { _, _, _, _ in actions += 1 }
|
|
111
|
+
try bind(stack, amount: "101", disabled: true)
|
|
112
|
+
XCTAssertFalse(button.isEnabled); XCTAssertEqual(button.alpha, 0.4, accuracy: 0.000001)
|
|
113
|
+
XCTAssertTrue(button.image(for: .normal) === ready)
|
|
114
|
+
button.sendActions(for: .touchUpInside); XCTAssertEqual(actions, 0)
|
|
115
|
+
button.layoutIfNeeded()
|
|
116
|
+
try save(captureButton(), "ios-swap-menu-disabled")
|
|
117
|
+
try bind(stack, amount: "101")
|
|
118
|
+
try bind(stack, name: "UnknownIcon")
|
|
119
|
+
XCTAssertNil(button.image(for: .normal))
|
|
120
|
+
try bind(stack, kind: "value")
|
|
121
|
+
XCTAssertNil(button.image(for: .normal))
|
|
122
|
+
stack.removeFromSuperview()
|
|
123
|
+
RunLoop.main.run(until: Date().addingTimeInterval(0.05))
|
|
124
|
+
XCTAssertNil(button.image(for: .normal))
|
|
125
|
+
}
|
|
126
|
+
private func alphaCount(_ image: UIImage?) -> Int {
|
|
127
|
+
guard let cg = image?.cgImage else { return 0 }
|
|
128
|
+
var bytes = [UInt8](repeating: 0, count: cg.width * cg.height * 4)
|
|
129
|
+
guard let context = CGContext(data: &bytes, width: cg.width, height: cg.height, bitsPerComponent: 8,
|
|
130
|
+
bytesPerRow: cg.width * 4, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { return 0 }
|
|
131
|
+
context.draw(cg, in: CGRect(x: 0, y: 0, width: cg.width, height: cg.height))
|
|
132
|
+
return stride(from: 3, to: bytes.count, by: 4).filter { bytes[$0] > 0 }.count
|
|
133
|
+
}
|
|
134
|
+
func testMainLineGlyphsPaintInTheSharedNativeSlot() throws {
|
|
135
|
+
let window = try window(); defer { window.isHidden = true }
|
|
136
|
+
let view = NativeListIconImageView(frame: CGRect(x: 10, y: 80, width: 64, height: 64))
|
|
137
|
+
window.rootViewController!.view.addSubview(view)
|
|
138
|
+
for name in ["Document2Outline", "WalletOutline", "PlusLargeOutline", "TicketOutline"] {
|
|
139
|
+
let metadata = try XCTUnwrap(nativeListIconMetadata(named: name))
|
|
140
|
+
XCTAssertEqual(metadata.name, name)
|
|
141
|
+
XCTAssertEqual(metadata.size, CGSize(width: 24, height: 24))
|
|
142
|
+
view.bindIcon(name)
|
|
143
|
+
eventually("Shared main-line glyph paints: " + name) { self.alphaCount(view.image) > 0 }
|
|
144
|
+
let image = try XCTUnwrap(view.image)
|
|
145
|
+
XCTAssertEqual(image.renderingMode, .alwaysTemplate)
|
|
146
|
+
try save(image.withTintColor(.red, renderingMode: .alwaysOriginal), "ios-main-integration-" + name)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
private func maximumAlpha(_ image: UIImage) -> UInt8 {
|
|
150
|
+
guard let cg = image.cgImage else { return 0 }
|
|
151
|
+
var bytes = [UInt8](repeating: 0, count: cg.width * cg.height * 4)
|
|
152
|
+
guard let context = CGContext(data: &bytes, width: cg.width, height: cg.height, bitsPerComponent: 8,
|
|
153
|
+
bytesPerRow: cg.width * 4, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { return 0 }
|
|
154
|
+
context.draw(cg, in: CGRect(x: 0, y: 0, width: cg.width, height: cg.height))
|
|
155
|
+
return stride(from: 3, to: bytes.count, by: 4).map { bytes[$0] }.max() ?? 0
|
|
156
|
+
}
|
|
157
|
+
func testLifecycleLegacyModesAndSizeOverride() throws {
|
|
158
|
+
let window = try window(); defer { window.isHidden = true }
|
|
159
|
+
let view = NativeListIconImageView(frame: CGRect(x: 10, y: 80, width: 64, height: 64))
|
|
160
|
+
window.rootViewController!.view.addSubview(view)
|
|
161
|
+
for name in ["AppleBrand", "BotIllus", "GoogleIllus", "AccountErrorCustom", "StarOutline", "StarSolid", "BadgeVerifiedSolid", "CheckboxCheckedCustom", "CheckboxIndeterminateCustom"] {
|
|
162
|
+
view.bindIcon(name)
|
|
163
|
+
eventually(name) { self.alphaCount(view.image) > 0 }
|
|
164
|
+
let metadata = try XCTUnwrap(nativeListIconMetadata(named: name))
|
|
165
|
+
XCTAssertEqual(view.image?.size, metadata.size)
|
|
166
|
+
if !metadata.original { XCTAssertEqual(maximumAlpha(try XCTUnwrap(view.image)), 255) }
|
|
167
|
+
XCTAssertEqual(view.image?.renderingMode, metadata.original ? .alwaysOriginal : .alwaysTemplate)
|
|
168
|
+
let image = try XCTUnwrap(view.image)
|
|
169
|
+
try save(metadata.original ? image : image.withTintColor(.red, renderingMode: .alwaysOriginal), "ios-new-" + name)
|
|
170
|
+
}
|
|
171
|
+
view.bindIcon("AppleBrand", size: CGSize(width: 28, height: 20))
|
|
172
|
+
eventually("Non-square source stretches to legacy explicit size") { self.alphaCount(view.image) > 0 }
|
|
173
|
+
XCTAssertEqual(view.image?.size, CGSize(width: 28, height: 20))
|
|
174
|
+
XCTAssertEqual(view.image?.renderingMode, .alwaysTemplate)
|
|
175
|
+
try save(try XCTUnwrap(view.image).withTintColor(.red, renderingMode: .alwaysOriginal), "ios-new-AppleBrand-override")
|
|
176
|
+
view.bindIcon("DotVerSolid")
|
|
177
|
+
view.removeFromSuperview()
|
|
178
|
+
RunLoop.main.run(until: Date().addingTimeInterval(0.1))
|
|
179
|
+
XCTAssertEqual(alphaCount(view.image), 0)
|
|
180
|
+
window.rootViewController!.view.addSubview(view)
|
|
181
|
+
eventually("Same glyph redraws after detached completion") { self.alphaCount(view.image) > 0 }
|
|
182
|
+
view.bindIcon("UnknownIcon"); XCTAssertNil(view.image)
|
|
183
|
+
let ordinary = UIGraphicsImageRenderer(size: CGSize(width: 8, height: 8)).image { c in UIColor.green.setFill(); c.fill(CGRect(x: 0, y: 0, width: 8, height: 8)) }
|
|
184
|
+
view.image = ordinary
|
|
185
|
+
XCTAssertTrue(view.image === ordinary)
|
|
186
|
+
}
|
|
187
|
+
func testLegacyCompiledAssetRasterComparison() throws {
|
|
188
|
+
guard let directory = ProcessInfo.processInfo.environment["NATIVE_LIST_LEGACY_BUNDLE"], let bundle = Bundle(path: directory) else {
|
|
189
|
+
throw XCTSkip("An archived pre-migration resource bundle is required for raster comparison")
|
|
190
|
+
}
|
|
191
|
+
let window = try window(); defer { window.isHidden = true }
|
|
192
|
+
let view = NativeListIconImageView(frame: CGRect(x: 0, y: 80, width: 96, height: 96))
|
|
193
|
+
window.rootViewController!.view.addSubview(view)
|
|
194
|
+
let names = [
|
|
195
|
+
"AppleBrand": "onekey_selector_apple_brand", "BotIllus": "onekey_selector_bot_illus",
|
|
196
|
+
"GoogleIllus": "onekey_selector_google_illus", "AccountErrorCustom": "onekey_selector_account_error_custom",
|
|
197
|
+
"BadgeVerifiedSolid": "onekey_badge_verified_solid", "StarOutline": "onekey_star", "StarSolid": "onekey_star_solid",
|
|
198
|
+
"CheckboxCheckedCustom": "onekey_checkbox_checked", "CheckboxIndeterminateCustom": "onekey_checkbox_indeterminate",
|
|
199
|
+
]
|
|
200
|
+
func raster(_ image: UIImage) -> UIImage {
|
|
201
|
+
let format = UIGraphicsImageRendererFormat(); format.scale = 1
|
|
202
|
+
return UIGraphicsImageRenderer(size: CGSize(width: 96, height: 96), format: format).image { _ in
|
|
203
|
+
image.draw(in: CGRect(x: 0, y: 0, width: 96, height: 96))
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
for name in names.keys.sorted() {
|
|
207
|
+
let metadata = try XCTUnwrap(nativeListIconMetadata(named: name))
|
|
208
|
+
let old = try XCTUnwrap(UIImage(named: names[name]!, in: bundle, compatibleWith: nil))
|
|
209
|
+
view.bindIcon(name)
|
|
210
|
+
eventually("Shared raster for legacy comparison " + name) { self.alphaCount(view.image) > 0 }
|
|
211
|
+
let next = try XCTUnwrap(view.image)
|
|
212
|
+
XCTAssertEqual(next.size, old.size)
|
|
213
|
+
let before = raster(metadata.original ? old : old.withTintColor(.red, renderingMode: .alwaysOriginal))
|
|
214
|
+
let after = raster(metadata.original ? next : next.withTintColor(.red, renderingMode: .alwaysOriginal))
|
|
215
|
+
XCTAssertGreaterThan(alphaCount(before), 0); XCTAssertGreaterThan(alphaCount(after), 0)
|
|
216
|
+
if name == "AccountErrorCustom" {
|
|
217
|
+
// The source eye center is inside its 0.447-opacity fill, away from raster edges.
|
|
218
|
+
for image in [before, after] {
|
|
219
|
+
let cg = try XCTUnwrap(image.cgImage)
|
|
220
|
+
var bytes = [UInt8](repeating: 0, count: 96 * 96 * 4)
|
|
221
|
+
let context = try XCTUnwrap(CGContext(data: &bytes, width: 96, height: 96, bitsPerComponent: 8,
|
|
222
|
+
bytesPerRow: 96 * 4, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue))
|
|
223
|
+
context.draw(cg, in: CGRect(x: 0, y: 0, width: 96, height: 96))
|
|
224
|
+
for (x,y) in [(6,48),(48,6),(48,91),(91,64),(67,61)] {
|
|
225
|
+
let index = (y * 96 + x) * 4
|
|
226
|
+
XCTAssertEqual(Array(bytes[index..<(index+3)]), [0,0,0])
|
|
227
|
+
XCTAssertEqual(bytes[index+3], 114)
|
|
228
|
+
}
|
|
229
|
+
for (x,y) in [(48,48),(15,48)] { XCTAssertEqual(bytes[(y * 96 + x) * 4 + 3], 0) }
|
|
230
|
+
}
|
|
231
|
+
} else { XCTAssertEqual(maximumAlpha(after), maximumAlpha(before)) }
|
|
232
|
+
try save(before, "ios-before-" + name); try save(after, "ios-after-" + name)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
}
|
package/lib/module/NativeList.js
CHANGED
|
@@ -67,6 +67,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
67
67
|
...viewProps
|
|
68
68
|
}, forwardedRef) {
|
|
69
69
|
const snapshotRef = useRef(emptyNativeListSnapshot());
|
|
70
|
+
const needsNativeSnapshotRef = useRef(false);
|
|
70
71
|
const renderedSnapshotRef = useRef(undefined);
|
|
71
72
|
const initializedSnapshot = useRef(false);
|
|
72
73
|
const pendingDisclosureSnapshotRef = useRef(undefined);
|
|
@@ -315,10 +316,11 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
315
316
|
return;
|
|
316
317
|
}
|
|
317
318
|
pendingDisclosureSnapshotRef.current = undefined;
|
|
318
|
-
const
|
|
319
|
-
|
|
319
|
+
const native = nativeRef.current;
|
|
320
|
+
if (native) native.applySnapshot(JSON.stringify(accepted));
|
|
320
321
|
snapshotRef.current = accepted;
|
|
321
|
-
|
|
322
|
+
needsNativeSnapshotRef.current = !native;
|
|
323
|
+
if (native && avatarLifecycle.current !== 'unmounted') {
|
|
322
324
|
avatarModelRef.current?.replaceSnapshot(accepted.rows);
|
|
323
325
|
updateAvatarPrefetchRef.current();
|
|
324
326
|
}
|
|
@@ -336,10 +338,15 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
336
338
|
return;
|
|
337
339
|
}
|
|
338
340
|
const native = nativeRef.current;
|
|
339
|
-
|
|
341
|
+
if (!native) {
|
|
342
|
+
snapshotRef.current = nextSnapshot;
|
|
343
|
+
needsNativeSnapshotRef.current = true;
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const dispatch = () => {
|
|
340
347
|
native.applyPatches(accepted.json);
|
|
341
348
|
snapshotRef.current = nextSnapshot;
|
|
342
|
-
}
|
|
349
|
+
};
|
|
343
350
|
if (avatarLifecycle.current === 'unmounted') {
|
|
344
351
|
dispatch?.();
|
|
345
352
|
return;
|
|
@@ -362,7 +369,10 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
362
369
|
if (pending) pendingDisclosureSnapshotRef.current = {
|
|
363
370
|
...pending,
|
|
364
371
|
owned: next
|
|
365
|
-
};else
|
|
372
|
+
};else {
|
|
373
|
+
snapshotRef.current = next;
|
|
374
|
+
if (!nativeRef.current) needsNativeSnapshotRef.current = true;
|
|
375
|
+
}
|
|
366
376
|
}
|
|
367
377
|
},
|
|
368
378
|
scrollToKey(paramsOrKey, animated, alignment) {
|
|
@@ -417,7 +427,16 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
417
427
|
}));
|
|
418
428
|
const nativeCallbacks = useMemo(() => ({
|
|
419
429
|
hybridRef: callback(ref => {
|
|
430
|
+
const previous = nativeRef.current;
|
|
420
431
|
nativeRef.current = ref;
|
|
432
|
+
if (needsNativeSnapshotRef.current || previous && previous !== ref) {
|
|
433
|
+
// The parent can publish values before Fabric delivers the host.
|
|
434
|
+
const latest = snapshotRef.current;
|
|
435
|
+
ref.applySnapshot(JSON.stringify(latest));
|
|
436
|
+
needsNativeSnapshotRef.current = false;
|
|
437
|
+
avatarModelRef.current?.replaceSnapshot(latest.rows);
|
|
438
|
+
updateAvatarPrefetchRef.current();
|
|
439
|
+
}
|
|
421
440
|
applyInitialScrollCallbackRef.current();
|
|
422
441
|
}),
|
|
423
442
|
onRowAction: callback(payloadJson => {
|
|
@@ -4,7 +4,7 @@ import { useNativeListFontFamiliesJson } from "./fonts.js";
|
|
|
4
4
|
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import { View } from 'react-native';
|
|
6
6
|
import { normalizeIndexScroll, normalizeKeyScroll, normalizePositionScroll, resolveLocationIndex, scrollFailure, validateOffset } from "./scrolling.js";
|
|
7
|
-
import { applyRowPatches, containNativeListInput, emptyNativeListSnapshot,
|
|
7
|
+
import { applyRowPatches, containNativeListInput, emptyNativeListSnapshot, validateSnapshot } from "./validation.js";
|
|
8
8
|
import { NativeListWebEngine } from "./web/NativeListWebEngine.js";
|
|
9
9
|
import { acquireNativeListAvatar, canonicalNativeListAvatarUri } from "./web/NativeListWebAvatarCache.js";
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -255,18 +255,15 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
255
255
|
synchronizeSlots(next);
|
|
256
256
|
},
|
|
257
257
|
applyPatches(patches) {
|
|
258
|
-
const
|
|
259
|
-
if (
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
const next = containNativeListInput(() => applyRowPatches(snapshotRef.current, accepted));
|
|
266
|
-
if (next) snapshotRef.current = next;
|
|
267
|
-
}
|
|
268
|
-
acceptedSnapshotRef.current = snapshotRef.current;
|
|
258
|
+
const engine = engineRef.current;
|
|
259
|
+
if (engine) {
|
|
260
|
+
engine.applyPatches(patches);
|
|
261
|
+
snapshotRef.current = engine.currentSnapshot();
|
|
262
|
+
} else {
|
|
263
|
+
const next = containNativeListInput(() => applyRowPatches(snapshotRef.current, patches));
|
|
264
|
+
if (next) snapshotRef.current = next;
|
|
269
265
|
}
|
|
266
|
+
acceptedSnapshotRef.current = snapshotRef.current;
|
|
270
267
|
},
|
|
271
268
|
reconcileSelection(selectedKeys) {
|
|
272
269
|
engineRef.current?.reconcileSelection(selectedKeys);
|
package/lib/module/models.js
CHANGED
|
@@ -54,4 +54,6 @@ export const ROW_BOX_STYLE_KEYS_BY_TYPE = {
|
|
|
54
54
|
// type CommonPatchFields = 'revision' | 'disabled' | 'selected' | 'separator';
|
|
55
55
|
// OneKey patch: balance patches also refresh the existing row's spoken content.
|
|
56
56
|
// type CommonPatchFields = 'revision' | 'disabled' | 'selected' | 'separator' | 'height' | 'heightRounding' | 'opacity' | 'pressDisabled';
|
|
57
|
+
|
|
58
|
+
/** Null removes optional fields; undefined leaves the existing value unchanged. */
|
|
57
59
|
//# sourceMappingURL=models.js.map
|