@onekeyfe/react-native-native-list 6.7.0-2 → 6.7.0-21
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/HybridNativeList.kt +14 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +245 -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/NativeListIdentityRenderer.kt +225 -11
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +147 -33
- package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
- 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 +51 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +2 -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 +70 -11
- package/docs/SPEC.md +1235 -20
- package/docs/STYLE_SPEC.md +6 -0
- package/ios/HybridNativeList.swift +21 -2
- package/ios/NativeListAccessoryStack.swift +235 -39
- package/ios/NativeListActivityDetailsView.swift +30 -11
- package/ios/NativeListActivityRenderer.swift +8 -2
- package/ios/NativeListButtonGroupRenderer.swift +89 -0
- package/ios/NativeListDataRowRenderer.swift +155 -27
- package/ios/NativeListDesignAssets.swift +9 -0
- package/ios/NativeListIdentityRenderer.swift +239 -31
- package/ios/NativeListLeadingVisual.swift +119 -22
- package/ios/NativeListMarketRenderer.swift +113 -18
- package/ios/NativeListMessageRenderer.swift +34 -1
- 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 +88 -0
- package/ios/RNCNativeListView.swift +1052 -58
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +1 -0
- package/ios/tests/NativeListAccessoryStackTests.swift +89 -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 +2789 -3
- package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
- package/lib/module/NativeList.js +223 -36
- package/lib/module/NativeList.web.js +260 -33
- 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 +1386 -81
- package/lib/module/web/NativeListWebEngine.js +914 -80
- package/lib/module/web/templates/ActivityRowRenderer.js +487 -7
- 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 +145 -5
- package/lib/module/web/templates/MarketRowRenderer.js +8 -3
- package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
- package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
- 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 +8 -3
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +70 -3
- 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 +29 -1
- package/lib/typescript/src/NativeList.web.d.ts +2 -2
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/models.d.ts +196 -17
- package/lib/typescript/src/validation.d.ts +20 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +58 -1
- package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
- 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/MarketTableRowRenderer.d.ts +17 -0
- package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +10 -4
- package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
- 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 +3 -3
- package/react-native-native-list.podspec +1 -0
- package/src/NativeList.nitro.ts +2 -0
- package/src/NativeList.tsx +418 -89
- package/src/NativeList.types.ts +34 -1
- package/src/NativeList.web.tsx +417 -66
- package/src/index.ts +2 -0
- package/src/models.ts +355 -143
- package/src/selection.ts +1 -0
- package/src/validation.ts +3315 -166
- package/src/web/NativeListWebEngine.ts +1473 -113
- package/src/web/templates/ActivityRowRenderer.ts +732 -8
- package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
- package/src/web/templates/DataRowRenderer.ts +93 -20
- package/src/web/templates/IdentityRowRenderer.ts +217 -6
- package/src/web/templates/MarketRowRenderer.ts +19 -3
- package/src/web/templates/MarketTableRowRenderer.ts +755 -0
- package/src/web/templates/MediaTileRowRenderer.ts +313 -5
- package/src/web/templates/MessageRowRenderer.ts +23 -7
- package/src/web/templates/RowContainerStyle.ts +2 -0
- package/src/web/templates/RowRendererRegistry.ts +21 -6
- package/src/web/templates/SectionHeaderRowRenderer.ts +89 -5
|
@@ -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,6 +109,13 @@ 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 = UIImageView()
|
|
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()
|
|
@@ -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)
|
|
@@ -133,6 +242,15 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
133
242
|
titleRowStack.setCustomSpacing(UIStackView.spacingUseDefault, after: $0)
|
|
134
243
|
}
|
|
135
244
|
titleRowStack.spacing = 8
|
|
245
|
+
titleIconView.image = nil
|
|
246
|
+
titleIconView.isHidden = true
|
|
247
|
+
titleIconView.accessibilityLabel = nil
|
|
248
|
+
titleIconView.isAccessibilityElement = false
|
|
249
|
+
titleImageSlot?.view.isHidden = true
|
|
250
|
+
titleImageSlot?.view.accessibilityLabel = nil
|
|
251
|
+
titleImageSlot?.view.isAccessibilityElement = false
|
|
252
|
+
NSLayoutConstraint.deactivate(titleImageConstraints)
|
|
253
|
+
titleImageConstraints = []
|
|
136
254
|
titleRowStack.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
|
137
255
|
titleRowStack.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
|
138
256
|
for label in [titleLabel, subtitleLabel, tertiaryLabel, badgeLabel] {
|
|
@@ -165,6 +283,10 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
165
283
|
leadingWidth.constant = 40
|
|
166
284
|
leadingHeight.constant = 40
|
|
167
285
|
visual.glyphSize = 18
|
|
286
|
+
visual.bitmapBorderWidth =
|
|
287
|
+
item.data.dictionary("leading")?.string("borderColor").isEmpty == false
|
|
288
|
+
&& item.data.dictionary("leading")?.string("borderStyle") != "dashed"
|
|
289
|
+
? 1 : 0
|
|
168
290
|
fallbackLabel.attributedText = nil
|
|
169
291
|
fallbackLabel.font = nativeListFont(ofSize: 13, weight: .bold, fonts: fonts)
|
|
170
292
|
trailingStack.reset()
|
|
@@ -175,6 +297,67 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
175
297
|
leadingActionButton.setImage(nil, for: .normal)
|
|
176
298
|
bindIdentity(item, theme: theme, selected: item.data.bool("selected"), checkboxState)
|
|
177
299
|
let style = item.data.dictionary("style") ?? [:]
|
|
300
|
+
if let titleIcon = item.data.dictionary("titleIcon") {
|
|
301
|
+
titleIconView.image = nativeListIcon(named: titleIcon.string("name"))
|
|
302
|
+
titleIconView.tintColor = UIColor(
|
|
303
|
+
nativeListHex: titleIcon.string("tintColor",
|
|
304
|
+
default: theme?["iconSubdued"] as? String ?? "#8D8D8D"),
|
|
305
|
+
fallback: .gray)
|
|
306
|
+
titleIconView.isHidden = false
|
|
307
|
+
let label = titleIcon.string("accessibilityLabel")
|
|
308
|
+
titleIconView.accessibilityLabel = label.isEmpty ? nil : label
|
|
309
|
+
titleIconView.isAccessibilityElement = !label.isEmpty
|
|
310
|
+
titleRowStack.setCustomSpacing(4, after: titleLabel)
|
|
311
|
+
// A long title truncates ahead of the 20pt glyph (Android caps the title
|
|
312
|
+
// at row width minus accessories, Web shrinks the title first); with the
|
|
313
|
+
// title at `.required` the icon's 999 width constraint collapsed to 0.
|
|
314
|
+
titleLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
|
315
|
+
}
|
|
316
|
+
if let descriptor = item.data.dictionary("titleImage"),
|
|
317
|
+
let image = descriptor.dictionary("image"), !image.string("uri").isEmpty
|
|
318
|
+
{
|
|
319
|
+
let size = CGFloat(image.double("width"))
|
|
320
|
+
let slot = titleImageSlot ?? NativeListImageSlot()
|
|
321
|
+
titleImageSlot = slot
|
|
322
|
+
let view = slot.view
|
|
323
|
+
if view.superview == nil {
|
|
324
|
+
let index = titleRowStack.arrangedSubviews.firstIndex(of: titleIconView)! + 1
|
|
325
|
+
titleRowStack.insertArrangedSubview(view, at: index)
|
|
326
|
+
}
|
|
327
|
+
view.clipsToBounds = true
|
|
328
|
+
view.setContentHuggingPriority(.required, for: .horizontal)
|
|
329
|
+
view.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
330
|
+
view.translatesAutoresizingMaskIntoConstraints = false
|
|
331
|
+
view.layer.cornerRadius = size / 2
|
|
332
|
+
view.isHidden = false
|
|
333
|
+
let label = descriptor.string("accessibilityLabel")
|
|
334
|
+
view.accessibilityLabel = label.isEmpty ? nil : label
|
|
335
|
+
view.isAccessibilityElement = !label.isEmpty
|
|
336
|
+
titleImageConstraints = [
|
|
337
|
+
view.widthAnchor.constraint(equalToConstant: size),
|
|
338
|
+
view.heightAnchor.constraint(equalToConstant: size),
|
|
339
|
+
]
|
|
340
|
+
titleImageConstraints.forEach { $0.priority = UILayoutPriority(999) }
|
|
341
|
+
NSLayoutConstraint.activate(titleImageConstraints)
|
|
342
|
+
titleRowStack.setCustomSpacing(4, after: titleIconView.isHidden ? titleLabel : titleIconView)
|
|
343
|
+
titleLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
|
344
|
+
slot.bind(image, key: "\(item.key):titleImage", placeholder: "#00000000")
|
|
345
|
+
} else {
|
|
346
|
+
titleImageSlot?.recycle()
|
|
347
|
+
}
|
|
348
|
+
if let ratio = style["leadingContentMaxWidthRatio"] as? NSNumber,
|
|
349
|
+
root.arrangedSubviews.contains(visual)
|
|
350
|
+
{
|
|
351
|
+
titleLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
|
352
|
+
let visualWidth = CGFloat(style.dictionary("image")?.double("width", default: 40) ?? 40)
|
|
353
|
+
let leadingGap = CGFloat(style.double("leadingGap", default: 12))
|
|
354
|
+
let constraint = mainStack.widthAnchor.constraint(
|
|
355
|
+
lessThanOrEqualTo: root.widthAnchor,
|
|
356
|
+
multiplier: CGFloat(ratio.doubleValue),
|
|
357
|
+
constant: -(visualWidth + leadingGap))
|
|
358
|
+
constraint.isActive = true
|
|
359
|
+
selectorConstraints.append(constraint)
|
|
360
|
+
}
|
|
178
361
|
if style["horizontalPadding"] != nil {
|
|
179
362
|
leftInset = CGFloat(style.double("horizontalPadding"))
|
|
180
363
|
rightInset = -leftInset
|
|
@@ -196,7 +379,10 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
196
379
|
if walletBadgeLine != nil {
|
|
197
380
|
mainStack.setCustomSpacing(CGFloat(style.double("titleBadgeGap")), after: titleRowStack)
|
|
198
381
|
} else {
|
|
199
|
-
titleRowStack.setCustomSpacing(
|
|
382
|
+
titleRowStack.setCustomSpacing(
|
|
383
|
+
CGFloat(style.double("titleBadgeGap")),
|
|
384
|
+
after: titleImageSlot?.view.isHidden == false ? titleImageSlot!.view
|
|
385
|
+
: titleIconView.isHidden ? titleLabel : titleIconView)
|
|
200
386
|
}
|
|
201
387
|
}
|
|
202
388
|
if style["trailingGap"] != nil { trailingStack.spacing = CGFloat(style.double("trailingGap")) }
|
|
@@ -219,8 +405,19 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
219
405
|
: style.dictionary("container")?.string("contentVerticalAlignment") == "bottom"
|
|
220
406
|
? .bottom : .center
|
|
221
407
|
}
|
|
408
|
+
settleTitleRowFillerSpacing()
|
|
222
409
|
applySelectorTypography(item)
|
|
223
410
|
}
|
|
411
|
+
|
|
412
|
+
/// The filler is the title row's last arranged view; the stack's default
|
|
413
|
+
/// spacing before it would shave 8pt off the title's available width (visible
|
|
414
|
+
/// under `leadingContentMaxWidthRatio`), so the gap before the filler is zero.
|
|
415
|
+
private func settleTitleRowFillerSpacing() {
|
|
416
|
+
let visible = titleRowStack.arrangedSubviews.filter { $0 !== titleRowFiller && !$0.isHidden }
|
|
417
|
+
if let last = visible.last {
|
|
418
|
+
titleRowStack.setCustomSpacing(0, after: last)
|
|
419
|
+
}
|
|
420
|
+
}
|
|
224
421
|
override func bindSelectionContent(
|
|
225
422
|
_ item: NativeListItem,
|
|
226
423
|
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
|
|
@@ -259,6 +456,10 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
259
456
|
}
|
|
260
457
|
override func recycleContent() {
|
|
261
458
|
visual.recycle()
|
|
459
|
+
titleImageSlot?.recycle()
|
|
460
|
+
titleImageSlot?.view.isHidden = true
|
|
461
|
+
titleImageSlot?.view.accessibilityLabel = nil
|
|
462
|
+
titleImageSlot?.view.isAccessibilityElement = false
|
|
262
463
|
trailingStack.reset()
|
|
263
464
|
currentItem = nil
|
|
264
465
|
}
|
|
@@ -440,9 +641,40 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
440
641
|
}
|
|
441
642
|
root.addArrangedSubview(mainStack)
|
|
442
643
|
show(titleLabel, item.data.string("title"), lines: item.data.int("titleLines", default: 1))
|
|
644
|
+
let titleSuffixes = item.data.dictionaries("titleSuffixes")
|
|
645
|
+
if !titleSuffixes.isEmpty {
|
|
646
|
+
titleLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
|
647
|
+
let minimumTitleWidth = titleLabel.widthAnchor.constraint(greaterThanOrEqualToConstant: 80)
|
|
648
|
+
minimumTitleWidth.priority = UILayoutPriority(751)
|
|
649
|
+
minimumTitleWidth.isActive = true
|
|
650
|
+
selectorConstraints.append(minimumTitleWidth)
|
|
651
|
+
for suffix in titleSuffixes {
|
|
652
|
+
let label = NativeListTextLabel()
|
|
653
|
+
label.font = nativeListFont(ofSize: 12, fonts: fonts)
|
|
654
|
+
label.textColor = dataTextColor(suffix.string("tone", default: "secondary"), theme: theme)
|
|
655
|
+
label.numberOfLines = 1
|
|
656
|
+
label.lineBreakMode = .byTruncatingTail
|
|
657
|
+
label.setContentHuggingPriority(.defaultHigh, for: .horizontal)
|
|
658
|
+
label.setContentCompressionResistancePriority(UILayoutPriority(749), for: .horizontal)
|
|
659
|
+
setLineHeight(label, text: suffix.string("text"), lineHeight: 16)
|
|
660
|
+
if let maxWidth = suffix["maxWidth"] as? NSNumber {
|
|
661
|
+
let limit = label.widthAnchor.constraint(lessThanOrEqualToConstant: CGFloat(truncating: maxWidth))
|
|
662
|
+
limit.isActive = true
|
|
663
|
+
selectorConstraints.append(limit)
|
|
664
|
+
}
|
|
665
|
+
titleRowStack.insertArrangedSubview(
|
|
666
|
+
label,
|
|
667
|
+
at: titleRowStack.arrangedSubviews.firstIndex(of: badgeLabel)
|
|
668
|
+
?? titleRowStack.arrangedSubviews.count)
|
|
669
|
+
selectorViews.append(label)
|
|
670
|
+
}
|
|
671
|
+
}
|
|
443
672
|
show(
|
|
444
673
|
subtitleLabel, item.data.string("subtitle"), lines: item.data.int("subtitleLines", default: 1)
|
|
445
674
|
)
|
|
675
|
+
if item.data.int("subtitleLines", default: 1) == 0 {
|
|
676
|
+
subtitleLabel.lineBreakMode = .byWordWrapping
|
|
677
|
+
}
|
|
446
678
|
show(tertiaryLabel, item.data.string("tertiary"), lines: 1)
|
|
447
679
|
if !item.data.string("subtitle").isEmpty, item.data.string("tertiary").isEmpty {
|
|
448
680
|
mainStack.spacing = 0
|
|
@@ -556,32 +788,7 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
556
788
|
}
|
|
557
789
|
root.addArrangedSubview(trailingStack)
|
|
558
790
|
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
|
-
}
|
|
791
|
+
Self.configureTrailingStack(trailingStack, descriptors: accessories)
|
|
585
792
|
trailingStack.bind(
|
|
586
793
|
item, descriptors: accessories, theme: theme, style: item.data.dictionary("style") ?? [:],
|
|
587
794
|
defaultSpacing: trailingStack.spacing, checkboxState: checkboxState, fonts: fonts)
|
|
@@ -590,12 +797,13 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
590
797
|
trailingStack.isHidden = false
|
|
591
798
|
if let gap = trailingStack.contentGap { root.setCustomSpacing(gap, after: mainStack) }
|
|
592
799
|
if let inset = trailingStack.endInset { rightInset = -inset }
|
|
593
|
-
if
|
|
594
|
-
|
|
800
|
+
if accessories.count == 1,
|
|
801
|
+
(item.data.string("presentation") == "accountSelector"
|
|
802
|
+
|| accessories[0].string("kind") == "valuePair"),
|
|
595
803
|
let accessory = trailingStack.firstVisibleControl
|
|
596
804
|
{
|
|
597
805
|
// The vertical trailing stack has no stable intrinsic width, so keep its
|
|
598
|
-
// flexible space in the
|
|
806
|
+
// flexible space in the title and subtitle column.
|
|
599
807
|
let width = trailingStack.widthAnchor.constraint(equalTo: accessory.widthAnchor)
|
|
600
808
|
width.isActive = true
|
|
601
809
|
selectorConstraints.append(width)
|