@onekeyfe/react-native-native-list 6.7.0-4 → 6.7.0-40
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,171 @@
|
|
|
1
|
+
import OneKeyImage
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
/// One request owner per glyph slot; metadata also supplies detached measurement.
|
|
5
|
+
private final class NativeListIconBinding {
|
|
6
|
+
private weak var view: UIView?
|
|
7
|
+
private let owner = NSObject()
|
|
8
|
+
private let apply: (UIImage?) -> Void
|
|
9
|
+
private var descriptor: NativeListIconMetadata?
|
|
10
|
+
private var pointSize = CGSize.zero
|
|
11
|
+
private var template = true
|
|
12
|
+
private var sizeOverride: CGSize?
|
|
13
|
+
private var currentImage: UIImage?
|
|
14
|
+
private var placeholder: UIImage?
|
|
15
|
+
private var updateDepth = 0
|
|
16
|
+
private var pendingClear = false
|
|
17
|
+
private var revision: UInt64 = 0
|
|
18
|
+
private var identity: String?
|
|
19
|
+
|
|
20
|
+
init(view: UIView, apply: @escaping (UIImage?) -> Void) { self.view = view; self.apply = apply }
|
|
21
|
+
|
|
22
|
+
func bind(_ name: String?, size: CGSize? = nil) {
|
|
23
|
+
guard let name, let metadata = nativeListIconMetadata(named: name) else {
|
|
24
|
+
clearNow(); return
|
|
25
|
+
}
|
|
26
|
+
if descriptor?.name == metadata.name, descriptor?.original == metadata.original,
|
|
27
|
+
descriptor?.size == metadata.size, sizeOverride == size {
|
|
28
|
+
pendingClear = false
|
|
29
|
+
apply(currentImage)
|
|
30
|
+
refresh(); return
|
|
31
|
+
}
|
|
32
|
+
clearNow()
|
|
33
|
+
descriptor = metadata
|
|
34
|
+
pointSize = size ?? metadata.size
|
|
35
|
+
sizeOverride = size
|
|
36
|
+
template = size != nil || !metadata.original
|
|
37
|
+
let format = UIGraphicsImageRendererFormat(); format.scale = 1
|
|
38
|
+
placeholder = UIGraphicsImageRenderer(size: pointSize, format: format).image { _ in }
|
|
39
|
+
.withRenderingMode(template ? .alwaysTemplate : .alwaysOriginal)
|
|
40
|
+
currentImage = placeholder
|
|
41
|
+
apply(currentImage)
|
|
42
|
+
refresh()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
func clear(display: Bool = true) {
|
|
46
|
+
if display, updateDepth > 0 {
|
|
47
|
+
pendingClear = true; apply(nil); return
|
|
48
|
+
}
|
|
49
|
+
clearNow(display: display)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private func clearNow(display: Bool = true) {
|
|
53
|
+
revision &+= 1; identity = nil; descriptor = nil; currentImage = nil; placeholder = nil
|
|
54
|
+
pendingClear = false
|
|
55
|
+
OneKeyNamedSVG.shared.cancel(owner: owner)
|
|
56
|
+
if display { apply(nil) }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
func beginUpdate() { updateDepth += 1 }
|
|
60
|
+
func endUpdate() {
|
|
61
|
+
updateDepth -= 1
|
|
62
|
+
guard updateDepth == 0 else { return }
|
|
63
|
+
if pendingClear { clearNow() } else { refresh() }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
func retint() { if descriptor != nil && !pendingClear { apply(currentImage) } }
|
|
67
|
+
|
|
68
|
+
func refresh(force: Bool = false) {
|
|
69
|
+
guard updateDepth == 0, let view, let descriptor else { return }
|
|
70
|
+
let attached = view.window != nil && !view.isHidden && !view.bounds.isEmpty
|
|
71
|
+
let screenScale = max(1, view.window?.screen.scale ?? view.traitCollection.displayScale)
|
|
72
|
+
let fit = min(view.bounds.width / pointSize.width, view.bounds.height / pointSize.height)
|
|
73
|
+
let rasterScale = ceil(screenScale * max(1, fit))
|
|
74
|
+
let next = "\(descriptor.name)|\(pointSize)|\(rasterScale)|\(screenScale)|\(attached)|\(template)"
|
|
75
|
+
guard force || next != identity else { return }
|
|
76
|
+
identity = next; revision &+= 1
|
|
77
|
+
let generation = revision
|
|
78
|
+
OneKeyNamedSVG.shared.cancel(owner: owner)
|
|
79
|
+
currentImage = placeholder
|
|
80
|
+
apply(currentImage)
|
|
81
|
+
guard attached else { return }
|
|
82
|
+
if descriptor.name == "Circle" {
|
|
83
|
+
let image = UIGraphicsImageRenderer(size: pointSize).image { _ in
|
|
84
|
+
UIColor.black.setFill(); UIBezierPath(ovalIn: CGRect(origin: .zero, size: pointSize)).fill()
|
|
85
|
+
}
|
|
86
|
+
currentImage = image.withRenderingMode(.alwaysTemplate); apply(currentImage); return
|
|
87
|
+
}
|
|
88
|
+
let sourceSize = descriptor.size
|
|
89
|
+
let sourceScale = sizeOverride == nil ? rasterScale : ceil(rasterScale * max(pointSize.width / sourceSize.width, pointSize.height / sourceSize.height))
|
|
90
|
+
let pixelWidth = ceil(sourceSize.width * sourceScale), pixelHeight = ceil(sourceSize.height * sourceScale)
|
|
91
|
+
guard pixelWidth.isFinite, pixelHeight.isFinite, pixelWidth > 0, pixelHeight > 0,
|
|
92
|
+
pixelWidth <= 4096, pixelHeight <= 4096, pixelWidth * pixelHeight <= 4_194_304 else { return }
|
|
93
|
+
OneKeyNamedSVG.shared.request(owner: owner, name: descriptor.name, color: "rgba(0,0,0,1)",
|
|
94
|
+
width: Int(pixelWidth), height: Int(pixelHeight),
|
|
95
|
+
scale: screenScale) { [weak self] image in
|
|
96
|
+
guard let self, self.revision == generation, let view = self.view,
|
|
97
|
+
view.window != nil, !view.isHidden else { return }
|
|
98
|
+
guard let cgImage = image?.cgImage else { return }
|
|
99
|
+
var result = UIImage(cgImage: cgImage, scale: sourceScale, orientation: .up)
|
|
100
|
+
if let size = self.sizeOverride {
|
|
101
|
+
let format = UIGraphicsImageRendererFormat(); format.scale = rasterScale
|
|
102
|
+
result = UIGraphicsImageRenderer(size: size, format: format).image { _ in
|
|
103
|
+
result.draw(in: CGRect(origin: .zero, size: size))
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
self.currentImage = result.withRenderingMode(self.template ? .alwaysTemplate : .alwaysOriginal)
|
|
107
|
+
self.apply(self.currentImage)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
deinit { OneKeyNamedSVG.shared.cancel(owner: owner) }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
final class NativeListIconImageView: UIImageView {
|
|
115
|
+
private var applying = false
|
|
116
|
+
private lazy var iconBinding = NativeListIconBinding(view: self) { [weak self] image in
|
|
117
|
+
guard let self else { return }
|
|
118
|
+
self.applying = true; self.image = image; self.applying = false
|
|
119
|
+
}
|
|
120
|
+
func bindIcon(_ name: String?, size: CGSize? = nil) { iconBinding.bind(name, size: size) }
|
|
121
|
+
func beginIconUpdate() { iconBinding.beginUpdate() }
|
|
122
|
+
func endIconUpdate() { iconBinding.endUpdate() }
|
|
123
|
+
override var image: UIImage? { didSet { if !applying { iconBinding.clear(display: image == nil) } } }
|
|
124
|
+
override var isHidden: Bool { didSet { iconBinding.refresh() } }
|
|
125
|
+
override func layoutSubviews() { super.layoutSubviews(); iconBinding.refresh() }
|
|
126
|
+
override func didMoveToWindow() { super.didMoveToWindow(); iconBinding.refresh() }
|
|
127
|
+
override func tintColorDidChange() { super.tintColorDidChange(); iconBinding.retint() }
|
|
128
|
+
override func traitCollectionDidChange(_ previous: UITraitCollection?) {
|
|
129
|
+
super.traitCollectionDidChange(previous); iconBinding.refresh()
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
class NativeListIconButton: UIButton {
|
|
134
|
+
private var applying = false
|
|
135
|
+
private lazy var iconBinding = NativeListIconBinding(view: self) { [weak self] image in
|
|
136
|
+
guard let self else { return }
|
|
137
|
+
self.applying = true
|
|
138
|
+
self.setImage(image, for: .normal)
|
|
139
|
+
self.setImage(image?.withTintColor(self.tintColor, renderingMode: .alwaysOriginal), for: .disabled)
|
|
140
|
+
self.applying = false
|
|
141
|
+
}
|
|
142
|
+
func bindIcon(_ name: String?, size: CGSize? = nil) { iconBinding.bind(name, size: size) }
|
|
143
|
+
func beginIconUpdate() { iconBinding.beginUpdate() }
|
|
144
|
+
func endIconUpdate() { iconBinding.endUpdate() }
|
|
145
|
+
override func setImage(_ image: UIImage?, for state: UIControl.State) {
|
|
146
|
+
if !applying && state == .normal { iconBinding.clear(display: image == nil) }
|
|
147
|
+
super.setImage(image, for: state)
|
|
148
|
+
}
|
|
149
|
+
override var isHidden: Bool { didSet { iconBinding.refresh() } }
|
|
150
|
+
override func layoutSubviews() { super.layoutSubviews(); iconBinding.refresh() }
|
|
151
|
+
override func didMoveToWindow() { super.didMoveToWindow(); iconBinding.refresh() }
|
|
152
|
+
override func tintColorDidChange() { super.tintColorDidChange(); iconBinding.retint() }
|
|
153
|
+
override func traitCollectionDidChange(_ previous: UITraitCollection?) {
|
|
154
|
+
super.traitCollectionDidChange(previous); iconBinding.refresh()
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/// A synchronous renderer bind may clear then restore the same glyph descriptor.
|
|
159
|
+
final class NativeListIconUpdate {
|
|
160
|
+
private var images: [NativeListIconImageView] = []
|
|
161
|
+
private var buttons: [NativeListIconButton] = []
|
|
162
|
+
init(_ root: UIView) {
|
|
163
|
+
func collect(_ view: UIView) {
|
|
164
|
+
if let image = view as? NativeListIconImageView { images.append(image); image.beginIconUpdate() }
|
|
165
|
+
if let button = view as? NativeListIconButton { buttons.append(button); button.beginIconUpdate() }
|
|
166
|
+
view.subviews.forEach(collect)
|
|
167
|
+
}
|
|
168
|
+
collect(root)
|
|
169
|
+
}
|
|
170
|
+
func finish() { images.forEach { $0.endIconUpdate() }; buttons.forEach { $0.endIconUpdate() } }
|
|
171
|
+
}
|
|
@@ -4,6 +4,51 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
4
4
|
override class func appliesSizePreset(_ item: NativeListItem) -> Bool {
|
|
5
5
|
!["walletSidebar", "networkSelector"].contains(item.data.string("presentation"))
|
|
6
6
|
}
|
|
7
|
+
private class func configureTrailingStack(
|
|
8
|
+
_ stack: NativeListAccessoryStack, descriptors: [[String: Any]]
|
|
9
|
+
) {
|
|
10
|
+
stack.axis = .vertical
|
|
11
|
+
stack.alignment = .trailing
|
|
12
|
+
stack.spacing = 2
|
|
13
|
+
if descriptors.contains(where: { $0.string("kind") == "checkbox" })
|
|
14
|
+
&& descriptors.contains(where: { $0.string("kind") == "value" })
|
|
15
|
+
{
|
|
16
|
+
stack.axis = .horizontal
|
|
17
|
+
stack.alignment = .center
|
|
18
|
+
stack.spacing = 12
|
|
19
|
+
} else if descriptors.count == 2,
|
|
20
|
+
descriptors[0].string("kind") == "valuePair",
|
|
21
|
+
(descriptors[1].string("kind") == "menu"
|
|
22
|
+
|| (descriptors[1].string("kind") == "icon"
|
|
23
|
+
&& descriptors[1].string("name") == "DotVerSolid"
|
|
24
|
+
&& descriptors[1].string("actionKey") == "menu"))
|
|
25
|
+
{
|
|
26
|
+
stack.axis = .horizontal
|
|
27
|
+
stack.alignment = .center
|
|
28
|
+
stack.spacing = 8
|
|
29
|
+
} else if descriptors.count == 2,
|
|
30
|
+
(descriptors[0].string("kind") == "valuePair"
|
|
31
|
+
&& descriptors[1].string("kind") == "chevron")
|
|
32
|
+
|| (descriptors[0].string("kind") == "icon"
|
|
33
|
+
&& descriptors[0].string("name") == "RefreshCcwOutline"
|
|
34
|
+
&& descriptors[0].string("actionKey").isEmpty
|
|
35
|
+
&& descriptors[1].string("kind") == "chevron")
|
|
36
|
+
{
|
|
37
|
+
stack.axis = .horizontal
|
|
38
|
+
stack.alignment = .center
|
|
39
|
+
stack.spacing = 12
|
|
40
|
+
} else if descriptors.count == 2,
|
|
41
|
+
descriptors[0].string("kind") == "icon",
|
|
42
|
+
descriptors[0].string("name") == "PencilOutline",
|
|
43
|
+
descriptors[1].string("kind") == "icon",
|
|
44
|
+
descriptors[1].string("name") == "DragOutline"
|
|
45
|
+
{
|
|
46
|
+
stack.axis = .horizontal
|
|
47
|
+
stack.alignment = .center
|
|
48
|
+
// Source 36-point icon frames with -7 margins need a 10-point gap.
|
|
49
|
+
stack.spacing = 10
|
|
50
|
+
}
|
|
51
|
+
}
|
|
7
52
|
override class func measure(
|
|
8
53
|
_ item: NativeListItem, width: CGFloat, theme: [String: Any]?, layout: String,
|
|
9
54
|
fonts: NativeListFontFamilies
|
|
@@ -12,6 +57,50 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
12
57
|
return item.data.dictionaries("badges").isEmpty ? 68 : 92
|
|
13
58
|
}
|
|
14
59
|
if item.data.string("presentation") == "networkSelector" { return 47 }
|
|
60
|
+
if item.data.string("contentHeight") == "auto" {
|
|
61
|
+
let style = item.data.dictionary("style") ?? [:]
|
|
62
|
+
let horizontalPadding = CGFloat(style.double("horizontalPadding", default: layout == "table" ? 16 : 12))
|
|
63
|
+
let verticalPadding = CGFloat(style.double("verticalPadding", default: 8))
|
|
64
|
+
let imageWidth = CGFloat(style.dictionary("image")?.double("width", default: 40) ?? 40)
|
|
65
|
+
let imageHeight = CGFloat(style.dictionary("image")?.double("height", default: 40) ?? 40)
|
|
66
|
+
let leadingGap = CGFloat(style.double("leadingGap", default: 12))
|
|
67
|
+
let accessories = item.data.dictionaries("trailing")
|
|
68
|
+
let trailing = NativeListAccessoryStack(frame: .zero)
|
|
69
|
+
configureTrailingStack(trailing, descriptors: accessories)
|
|
70
|
+
trailing.bind(
|
|
71
|
+
item, descriptors: accessories, theme: theme, style: style,
|
|
72
|
+
defaultSpacing: trailing.spacing, checkboxState: { _, _, fallback in fallback }, fonts: fonts)
|
|
73
|
+
trailing.isHidden = false
|
|
74
|
+
let trailingSize = trailing.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
|
|
75
|
+
let rightInset = style["horizontalPadding"] != nil
|
|
76
|
+
? horizontalPadding : trailing.endInset ?? horizontalPadding
|
|
77
|
+
let contentGap = trailing.contentGap ?? 12
|
|
78
|
+
let textWidth = max(1,
|
|
79
|
+
width - horizontalPadding - rightInset - imageWidth - leadingGap
|
|
80
|
+
- trailingSize.width - contentGap)
|
|
81
|
+
let title = NativeListResolvedText(
|
|
82
|
+
item.data.string("title"), style: style.dictionary("title"), size: 16,
|
|
83
|
+
weight: .medium, color: .black, lineHeight: 24,
|
|
84
|
+
lines: item.data.int("titleLines", default: 1), fonts: fonts)
|
|
85
|
+
let subtitle = NativeListResolvedText(
|
|
86
|
+
item.data.string("subtitle"), style: style.dictionary("subtitle"), size: 14,
|
|
87
|
+
color: .black, lineHeight: 20,
|
|
88
|
+
lines: item.data.int("subtitleLines", default: 1),
|
|
89
|
+
breakMode: item.data.int("subtitleLines", default: 1) == 0 ? .byWordWrapping : .byTruncatingTail,
|
|
90
|
+
fonts: fonts)
|
|
91
|
+
let tertiary = NativeListResolvedText(
|
|
92
|
+
item.data.string("tertiary"), style: style.dictionary("tertiary"), size: 14,
|
|
93
|
+
color: .black, lineHeight: 20, lines: 1, fonts: fonts)
|
|
94
|
+
let titleImageSize = CGFloat(item.data.dictionary("titleImage")?.dictionary("image")?.double("width") ?? 0)
|
|
95
|
+
let titleImageWidth = titleImageSize > 0
|
|
96
|
+
? titleImageSize + 4 + (item.data.dictionary("titleIcon") == nil ? 0 : 24) : 0
|
|
97
|
+
let textHeight = max(titleImageSize, title.measure(width: max(1, textWidth - titleImageWidth)))
|
|
98
|
+
+ subtitle.measure(width: textWidth)
|
|
99
|
+
+ tertiary.measure(width: textWidth)
|
|
100
|
+
+ (item.data.string("subtitle").isEmpty ? 0 : CGFloat(style.double("lineGap", default: 0)))
|
|
101
|
+
return max(item.data.string("subtitle").isEmpty ? 56 : 60,
|
|
102
|
+
verticalPadding * 2 + max(imageHeight, textHeight, trailingSize.height))
|
|
103
|
+
}
|
|
15
104
|
return !item.data.string("tertiary").isEmpty
|
|
16
105
|
? 72 : !item.data.string("subtitle").isEmpty ? 60 : 56
|
|
17
106
|
}
|
|
@@ -20,11 +109,18 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
20
109
|
private let mainStack = UIStackView()
|
|
21
110
|
private let titleRowStack = UIStackView()
|
|
22
111
|
private let titleLabel = NativeListTextLabel()
|
|
112
|
+
private let titleIconView = NativeListIconImageView()
|
|
113
|
+
private var titleImageSlot: NativeListImageSlot?
|
|
114
|
+
private var titleImageConstraints: [NSLayoutConstraint] = []
|
|
115
|
+
// Absorbs the title row's slack so the title keeps its intrinsic width and the
|
|
116
|
+
// title icon / badge follow the text (OK-66041); Android's PackedTitleLineLayout
|
|
117
|
+
// and the Web flex row already pack the title row at its start.
|
|
118
|
+
private let titleRowFiller = UIView()
|
|
23
119
|
private let subtitleLabel = NativeListTextLabel()
|
|
24
120
|
private let tertiaryLabel = NativeListTextLabel()
|
|
25
121
|
private let badgeLabel = NativeListInsetLabel()
|
|
26
122
|
private let trailingStack = NativeListAccessoryStack(frame: .zero)
|
|
27
|
-
private let leadingActionButton =
|
|
123
|
+
private let leadingActionButton = NativeListIconButton(type: .system)
|
|
28
124
|
private var leadingWidth: NSLayoutConstraint!
|
|
29
125
|
private var leadingHeight: NSLayoutConstraint!
|
|
30
126
|
private var leftInset: CGFloat = 12
|
|
@@ -40,7 +136,7 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
40
136
|
private var currentItem: NativeListItem?
|
|
41
137
|
private var currentTheme: [String: Any]?
|
|
42
138
|
private var leadingActionKey: String?
|
|
43
|
-
override var assetFields: [String] { ["leading"] }
|
|
139
|
+
override var assetFields: [String] { ["leading", "titleImage"] }
|
|
44
140
|
override var defaultSeparatorInset: CGFloat { 60 }
|
|
45
141
|
override var defaultCornerRadius: CGFloat {
|
|
46
142
|
guard let item = currentItem else { return 0 }
|
|
@@ -75,7 +171,20 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
75
171
|
titleRowStack.axis = .horizontal
|
|
76
172
|
titleRowStack.alignment = .center
|
|
77
173
|
titleRowStack.addArrangedSubview(titleLabel)
|
|
174
|
+
titleRowStack.addArrangedSubview(titleIconView)
|
|
78
175
|
titleRowStack.addArrangedSubview(badgeLabel)
|
|
176
|
+
titleRowStack.addArrangedSubview(titleRowFiller)
|
|
177
|
+
titleRowFiller.setContentHuggingPriority(UILayoutPriority(1), for: .horizontal)
|
|
178
|
+
titleRowFiller.setContentCompressionResistancePriority(UILayoutPriority(1), for: .horizontal)
|
|
179
|
+
titleIconView.translatesAutoresizingMaskIntoConstraints = false
|
|
180
|
+
let titleIconWidth = titleIconView.widthAnchor.constraint(equalToConstant: 20)
|
|
181
|
+
titleIconWidth.priority = UILayoutPriority(999)
|
|
182
|
+
NSLayoutConstraint.activate([
|
|
183
|
+
titleIconWidth,
|
|
184
|
+
titleIconView.heightAnchor.constraint(equalToConstant: 20),
|
|
185
|
+
])
|
|
186
|
+
titleIconView.contentMode = .scaleAspectFit
|
|
187
|
+
titleIconView.setContentHuggingPriority(.required, for: .horizontal)
|
|
79
188
|
[titleRowStack, subtitleLabel, tertiaryLabel].forEach(mainStack.addArrangedSubview)
|
|
80
189
|
visual.translatesAutoresizingMaskIntoConstraints = false
|
|
81
190
|
leadingWidth = visual.widthAnchor.constraint(equalToConstant: 40)
|
|
@@ -99,6 +208,9 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
99
208
|
_ item: NativeListItem, theme: [String: Any]?, layout: String,
|
|
100
209
|
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
|
|
101
210
|
) {
|
|
211
|
+
let iconUpdate = NativeListIconUpdate(self)
|
|
212
|
+
defer { iconUpdate.finish() }
|
|
213
|
+
|
|
102
214
|
selectorTypographyRestorers.reversed().forEach { $0() }
|
|
103
215
|
selectorTypographyRestorers = []
|
|
104
216
|
currentItem = item
|
|
@@ -133,6 +245,15 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
133
245
|
titleRowStack.setCustomSpacing(UIStackView.spacingUseDefault, after: $0)
|
|
134
246
|
}
|
|
135
247
|
titleRowStack.spacing = 8
|
|
248
|
+
titleIconView.image = nil
|
|
249
|
+
titleIconView.isHidden = true
|
|
250
|
+
titleIconView.accessibilityLabel = nil
|
|
251
|
+
titleIconView.isAccessibilityElement = false
|
|
252
|
+
titleImageSlot?.view.isHidden = true
|
|
253
|
+
titleImageSlot?.view.accessibilityLabel = nil
|
|
254
|
+
titleImageSlot?.view.isAccessibilityElement = false
|
|
255
|
+
NSLayoutConstraint.deactivate(titleImageConstraints)
|
|
256
|
+
titleImageConstraints = []
|
|
136
257
|
titleRowStack.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
|
137
258
|
titleRowStack.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
|
138
259
|
for label in [titleLabel, subtitleLabel, tertiaryLabel, badgeLabel] {
|
|
@@ -165,6 +286,10 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
165
286
|
leadingWidth.constant = 40
|
|
166
287
|
leadingHeight.constant = 40
|
|
167
288
|
visual.glyphSize = 18
|
|
289
|
+
visual.bitmapBorderWidth =
|
|
290
|
+
item.data.dictionary("leading")?.string("borderColor").isEmpty == false
|
|
291
|
+
&& item.data.dictionary("leading")?.string("borderStyle") != "dashed"
|
|
292
|
+
? 1 : 0
|
|
168
293
|
fallbackLabel.attributedText = nil
|
|
169
294
|
fallbackLabel.font = nativeListFont(ofSize: 13, weight: .bold, fonts: fonts)
|
|
170
295
|
trailingStack.reset()
|
|
@@ -175,6 +300,67 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
175
300
|
leadingActionButton.setImage(nil, for: .normal)
|
|
176
301
|
bindIdentity(item, theme: theme, selected: item.data.bool("selected"), checkboxState)
|
|
177
302
|
let style = item.data.dictionary("style") ?? [:]
|
|
303
|
+
if let titleIcon = item.data.dictionary("titleIcon") {
|
|
304
|
+
titleIconView.bindIcon(titleIcon.string("name"))
|
|
305
|
+
titleIconView.tintColor = UIColor(
|
|
306
|
+
nativeListHex: titleIcon.string("tintColor",
|
|
307
|
+
default: theme?["iconSubdued"] as? String ?? "#8D8D8D"),
|
|
308
|
+
fallback: .gray)
|
|
309
|
+
titleIconView.isHidden = false
|
|
310
|
+
let label = titleIcon.string("accessibilityLabel")
|
|
311
|
+
titleIconView.accessibilityLabel = label.isEmpty ? nil : label
|
|
312
|
+
titleIconView.isAccessibilityElement = !label.isEmpty
|
|
313
|
+
titleRowStack.setCustomSpacing(4, after: titleLabel)
|
|
314
|
+
// A long title truncates ahead of the 20pt glyph (Android caps the title
|
|
315
|
+
// at row width minus accessories, Web shrinks the title first); with the
|
|
316
|
+
// title at `.required` the icon's 999 width constraint collapsed to 0.
|
|
317
|
+
titleLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
|
318
|
+
}
|
|
319
|
+
if let descriptor = item.data.dictionary("titleImage"),
|
|
320
|
+
let image = descriptor.dictionary("image"), !image.string("uri").isEmpty
|
|
321
|
+
{
|
|
322
|
+
let size = CGFloat(image.double("width"))
|
|
323
|
+
let slot = titleImageSlot ?? NativeListImageSlot()
|
|
324
|
+
titleImageSlot = slot
|
|
325
|
+
let view = slot.view
|
|
326
|
+
if view.superview == nil {
|
|
327
|
+
let index = titleRowStack.arrangedSubviews.firstIndex(of: titleIconView)! + 1
|
|
328
|
+
titleRowStack.insertArrangedSubview(view, at: index)
|
|
329
|
+
}
|
|
330
|
+
view.clipsToBounds = true
|
|
331
|
+
view.setContentHuggingPriority(.required, for: .horizontal)
|
|
332
|
+
view.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
333
|
+
view.translatesAutoresizingMaskIntoConstraints = false
|
|
334
|
+
view.layer.cornerRadius = size / 2
|
|
335
|
+
view.isHidden = false
|
|
336
|
+
let label = descriptor.string("accessibilityLabel")
|
|
337
|
+
view.accessibilityLabel = label.isEmpty ? nil : label
|
|
338
|
+
view.isAccessibilityElement = !label.isEmpty
|
|
339
|
+
titleImageConstraints = [
|
|
340
|
+
view.widthAnchor.constraint(equalToConstant: size),
|
|
341
|
+
view.heightAnchor.constraint(equalToConstant: size),
|
|
342
|
+
]
|
|
343
|
+
titleImageConstraints.forEach { $0.priority = UILayoutPriority(999) }
|
|
344
|
+
NSLayoutConstraint.activate(titleImageConstraints)
|
|
345
|
+
titleRowStack.setCustomSpacing(4, after: titleIconView.isHidden ? titleLabel : titleIconView)
|
|
346
|
+
titleLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
|
347
|
+
slot.bind(image, key: "\(item.key):titleImage", placeholder: "#00000000")
|
|
348
|
+
} else {
|
|
349
|
+
titleImageSlot?.recycle()
|
|
350
|
+
}
|
|
351
|
+
if let ratio = style["leadingContentMaxWidthRatio"] as? NSNumber,
|
|
352
|
+
root.arrangedSubviews.contains(visual)
|
|
353
|
+
{
|
|
354
|
+
titleLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
|
355
|
+
let visualWidth = CGFloat(style.dictionary("image")?.double("width", default: 40) ?? 40)
|
|
356
|
+
let leadingGap = CGFloat(style.double("leadingGap", default: 12))
|
|
357
|
+
let constraint = mainStack.widthAnchor.constraint(
|
|
358
|
+
lessThanOrEqualTo: root.widthAnchor,
|
|
359
|
+
multiplier: CGFloat(ratio.doubleValue),
|
|
360
|
+
constant: -(visualWidth + leadingGap))
|
|
361
|
+
constraint.isActive = true
|
|
362
|
+
selectorConstraints.append(constraint)
|
|
363
|
+
}
|
|
178
364
|
if style["horizontalPadding"] != nil {
|
|
179
365
|
leftInset = CGFloat(style.double("horizontalPadding"))
|
|
180
366
|
rightInset = -leftInset
|
|
@@ -196,7 +382,10 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
196
382
|
if walletBadgeLine != nil {
|
|
197
383
|
mainStack.setCustomSpacing(CGFloat(style.double("titleBadgeGap")), after: titleRowStack)
|
|
198
384
|
} else {
|
|
199
|
-
titleRowStack.setCustomSpacing(
|
|
385
|
+
titleRowStack.setCustomSpacing(
|
|
386
|
+
CGFloat(style.double("titleBadgeGap")),
|
|
387
|
+
after: titleImageSlot?.view.isHidden == false ? titleImageSlot!.view
|
|
388
|
+
: titleIconView.isHidden ? titleLabel : titleIconView)
|
|
200
389
|
}
|
|
201
390
|
}
|
|
202
391
|
if style["trailingGap"] != nil { trailingStack.spacing = CGFloat(style.double("trailingGap")) }
|
|
@@ -219,12 +408,27 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
219
408
|
: style.dictionary("container")?.string("contentVerticalAlignment") == "bottom"
|
|
220
409
|
? .bottom : .center
|
|
221
410
|
}
|
|
411
|
+
settleTitleRowFillerSpacing()
|
|
222
412
|
applySelectorTypography(item)
|
|
413
|
+
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/// The filler is the title row's last arranged view; the stack's default
|
|
417
|
+
/// spacing before it would shave 8pt off the title's available width (visible
|
|
418
|
+
/// under `leadingContentMaxWidthRatio`), so the gap before the filler is zero.
|
|
419
|
+
private func settleTitleRowFillerSpacing() {
|
|
420
|
+
let visible = titleRowStack.arrangedSubviews.filter { $0 !== titleRowFiller && !$0.isHidden }
|
|
421
|
+
if let last = visible.last {
|
|
422
|
+
titleRowStack.setCustomSpacing(0, after: last)
|
|
423
|
+
}
|
|
223
424
|
}
|
|
224
425
|
override func bindSelectionContent(
|
|
225
426
|
_ item: NativeListItem,
|
|
226
427
|
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
|
|
227
428
|
) {
|
|
429
|
+
let iconUpdate = NativeListIconUpdate(self)
|
|
430
|
+
defer { iconUpdate.finish() }
|
|
431
|
+
|
|
228
432
|
currentItem = item
|
|
229
433
|
trailingStack.updateSelection(item, checkboxState: checkboxState)
|
|
230
434
|
if item.data.string("presentation") == "walletSidebar" {
|
|
@@ -242,6 +446,7 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
242
446
|
NativeListTextStyles.applyStyledText(titleLabel, style, fonts: fonts)
|
|
243
447
|
}
|
|
244
448
|
}
|
|
449
|
+
|
|
245
450
|
}
|
|
246
451
|
override func layoutSubviews() {
|
|
247
452
|
super.layoutSubviews()
|
|
@@ -259,6 +464,10 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
259
464
|
}
|
|
260
465
|
override func recycleContent() {
|
|
261
466
|
visual.recycle()
|
|
467
|
+
titleImageSlot?.recycle()
|
|
468
|
+
titleImageSlot?.view.isHidden = true
|
|
469
|
+
titleImageSlot?.view.accessibilityLabel = nil
|
|
470
|
+
titleImageSlot?.view.isAccessibilityElement = false
|
|
262
471
|
trailingStack.reset()
|
|
263
472
|
currentItem = nil
|
|
264
473
|
}
|
|
@@ -409,13 +618,7 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
409
618
|
fallback: .darkGray
|
|
410
619
|
)
|
|
411
620
|
leadingActionButton.tintColor = tintColor
|
|
412
|
-
|
|
413
|
-
leadingActionButton.setImage(image, for: .normal)
|
|
414
|
-
leadingActionButton.setImage(
|
|
415
|
-
image.withTintColor(tintColor, renderingMode: .alwaysOriginal),
|
|
416
|
-
for: .disabled
|
|
417
|
-
)
|
|
418
|
-
}
|
|
621
|
+
leadingActionButton.bindIcon(leadingAction.string("name"))
|
|
419
622
|
leadingActionButton.isEnabled = !leadingAction.bool("disabled")
|
|
420
623
|
leadingActionButton.alpha = leadingActionButton.isEnabled ? 1 : 0.4
|
|
421
624
|
leadingActionKey = leadingAction.string("actionKey")
|
|
@@ -440,9 +643,40 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
440
643
|
}
|
|
441
644
|
root.addArrangedSubview(mainStack)
|
|
442
645
|
show(titleLabel, item.data.string("title"), lines: item.data.int("titleLines", default: 1))
|
|
646
|
+
let titleSuffixes = item.data.dictionaries("titleSuffixes")
|
|
647
|
+
if !titleSuffixes.isEmpty {
|
|
648
|
+
titleLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
|
649
|
+
let minimumTitleWidth = titleLabel.widthAnchor.constraint(greaterThanOrEqualToConstant: 80)
|
|
650
|
+
minimumTitleWidth.priority = UILayoutPriority(751)
|
|
651
|
+
minimumTitleWidth.isActive = true
|
|
652
|
+
selectorConstraints.append(minimumTitleWidth)
|
|
653
|
+
for suffix in titleSuffixes {
|
|
654
|
+
let label = NativeListTextLabel()
|
|
655
|
+
label.font = nativeListFont(ofSize: 12, fonts: fonts)
|
|
656
|
+
label.textColor = dataTextColor(suffix.string("tone", default: "secondary"), theme: theme)
|
|
657
|
+
label.numberOfLines = 1
|
|
658
|
+
label.lineBreakMode = .byTruncatingTail
|
|
659
|
+
label.setContentHuggingPriority(.defaultHigh, for: .horizontal)
|
|
660
|
+
label.setContentCompressionResistancePriority(UILayoutPriority(749), for: .horizontal)
|
|
661
|
+
setLineHeight(label, text: suffix.string("text"), lineHeight: 16)
|
|
662
|
+
if let maxWidth = suffix["maxWidth"] as? NSNumber {
|
|
663
|
+
let limit = label.widthAnchor.constraint(lessThanOrEqualToConstant: CGFloat(truncating: maxWidth))
|
|
664
|
+
limit.isActive = true
|
|
665
|
+
selectorConstraints.append(limit)
|
|
666
|
+
}
|
|
667
|
+
titleRowStack.insertArrangedSubview(
|
|
668
|
+
label,
|
|
669
|
+
at: titleRowStack.arrangedSubviews.firstIndex(of: badgeLabel)
|
|
670
|
+
?? titleRowStack.arrangedSubviews.count)
|
|
671
|
+
selectorViews.append(label)
|
|
672
|
+
}
|
|
673
|
+
}
|
|
443
674
|
show(
|
|
444
675
|
subtitleLabel, item.data.string("subtitle"), lines: item.data.int("subtitleLines", default: 1)
|
|
445
676
|
)
|
|
677
|
+
if item.data.int("subtitleLines", default: 1) == 0 {
|
|
678
|
+
subtitleLabel.lineBreakMode = .byWordWrapping
|
|
679
|
+
}
|
|
446
680
|
show(tertiaryLabel, item.data.string("tertiary"), lines: 1)
|
|
447
681
|
if !item.data.string("subtitle").isEmpty, item.data.string("tertiary").isEmpty {
|
|
448
682
|
mainStack.spacing = 0
|
|
@@ -556,32 +790,7 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
556
790
|
}
|
|
557
791
|
root.addArrangedSubview(trailingStack)
|
|
558
792
|
let accessories = item.data.dictionaries("trailing")
|
|
559
|
-
|
|
560
|
-
&& accessories.contains(where: { $0.string("kind") == "value" })
|
|
561
|
-
{
|
|
562
|
-
trailingStack.axis = .horizontal
|
|
563
|
-
trailingStack.alignment = .center
|
|
564
|
-
trailingStack.spacing = 12
|
|
565
|
-
} else if accessories.count == 2,
|
|
566
|
-
accessories[0].string("kind") == "valuePair",
|
|
567
|
-
accessories[1].string("kind") == "menu"
|
|
568
|
-
{
|
|
569
|
-
trailingStack.axis = .horizontal
|
|
570
|
-
trailingStack.alignment = .center
|
|
571
|
-
trailingStack.spacing = 8
|
|
572
|
-
} else if accessories.count == 2,
|
|
573
|
-
accessories[0].string("kind") == "icon",
|
|
574
|
-
accessories[0].string("name") == "PencilOutline",
|
|
575
|
-
accessories[1].string("kind") == "icon",
|
|
576
|
-
accessories[1].string("name") == "DragOutline"
|
|
577
|
-
{
|
|
578
|
-
trailingStack.axis = .horizontal
|
|
579
|
-
trailingStack.alignment = .center
|
|
580
|
-
// Each source IconButton has a 36-point frame and m=-7. XStack gap=$6
|
|
581
|
-
// therefore places the physical frames 10 points apart (46-point
|
|
582
|
-
// center distance), not 24 points apart.
|
|
583
|
-
trailingStack.spacing = 10
|
|
584
|
-
}
|
|
793
|
+
Self.configureTrailingStack(trailingStack, descriptors: accessories)
|
|
585
794
|
trailingStack.bind(
|
|
586
795
|
item, descriptors: accessories, theme: theme, style: item.data.dictionary("style") ?? [:],
|
|
587
796
|
defaultSpacing: trailingStack.spacing, checkboxState: checkboxState, fonts: fonts)
|
|
@@ -590,15 +799,23 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
590
799
|
trailingStack.isHidden = false
|
|
591
800
|
if let gap = trailingStack.contentGap { root.setCustomSpacing(gap, after: mainStack) }
|
|
592
801
|
if let inset = trailingStack.endInset { rightInset = -inset }
|
|
593
|
-
if
|
|
594
|
-
|
|
802
|
+
if accessories.count == 1,
|
|
803
|
+
(item.data.string("presentation") == "accountSelector"
|
|
804
|
+
|| accessories[0].string("kind") == "valuePair"),
|
|
595
805
|
let accessory = trailingStack.firstVisibleControl
|
|
596
806
|
{
|
|
597
807
|
// The vertical trailing stack has no stable intrinsic width, so keep its
|
|
598
|
-
// flexible space in the
|
|
808
|
+
// flexible space in the title and subtitle column.
|
|
599
809
|
let width = trailingStack.widthAnchor.constraint(equalTo: accessory.widthAnchor)
|
|
600
810
|
width.isActive = true
|
|
601
811
|
selectorConstraints.append(width)
|
|
812
|
+
} else if item.data.string("presentation") == "accountSelector" {
|
|
813
|
+
// Keep flexible space in the text column when there is no accessory button.
|
|
814
|
+
// Stay below visible controls' compression resistance and the hidden checkbox's width.
|
|
815
|
+
let width = trailingStack.widthAnchor.constraint(equalToConstant: 0)
|
|
816
|
+
width.priority = UILayoutPriority(749)
|
|
817
|
+
width.isActive = true
|
|
818
|
+
selectorConstraints.append(width)
|
|
602
819
|
}
|
|
603
820
|
}
|
|
604
821
|
private func dataTextColor(_ tone: String, theme: [String: Any]?) -> UIColor {
|