@onekeyfe/react-native-native-list 6.7.0-alpha.344 → 6.7.0-alpha.359
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 +7 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +240 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +7 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +6 -3
- 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 +87 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +135 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +43 -14
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +17 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +22 -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 +585 -21
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +1 -0
- package/docs/ROW_TEMPLATES.md +60 -9
- package/docs/SPEC.md +361 -8
- package/docs/STYLE_SPEC.md +6 -0
- package/ios/HybridNativeList.swift +10 -0
- package/ios/NativeListAccessoryStack.swift +220 -37
- package/ios/NativeListActivityDetailsView.swift +18 -8
- package/ios/NativeListActivityRenderer.swift +8 -2
- package/ios/NativeListButtonGroupRenderer.swift +89 -0
- package/ios/NativeListDataRowRenderer.swift +128 -16
- package/ios/NativeListDesignAssets.swift +3 -0
- package/ios/NativeListIdentityRenderer.swift +123 -5
- package/ios/NativeListLeadingVisual.swift +49 -14
- package/ios/NativeListMessageRenderer.swift +34 -1
- package/ios/NativeListModels.swift +16 -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 +335 -29
- 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_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_refresh_ccw_outline.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +56 -0
- package/ios/tests/NativeListLifecycleTests.swift +1283 -3
- package/lib/module/NativeList.js +64 -27
- package/lib/module/NativeList.web.js +84 -17
- package/lib/module/models.js +1 -0
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +532 -18
- package/lib/module/web/NativeListWebEngine.js +391 -24
- package/lib/module/web/templates/ActivityRowRenderer.js +8 -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 +90 -4
- 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 +9 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
- package/lib/typescript/src/NativeList.d.ts +2 -2
- package/lib/typescript/src/NativeList.nitro.d.ts +1 -0
- package/lib/typescript/src/NativeList.types.d.ts +8 -0
- package/lib/typescript/src/models.d.ts +101 -9
- package/lib/typescript/src/validation.d.ts +13 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -0
- 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 +9 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
- package/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
- package/package.json +3 -3
- package/react-native-native-list.podspec +1 -0
- package/src/NativeList.nitro.ts +1 -0
- package/src/NativeList.tsx +155 -69
- package/src/NativeList.types.ts +9 -0
- package/src/NativeList.web.tsx +159 -49
- package/src/models.ts +113 -3
- package/src/selection.ts +1 -0
- package/src/validation.ts +1156 -18
- package/src/web/NativeListWebEngine.ts +594 -28
- package/src/web/templates/ActivityRowRenderer.ts +14 -6
- package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
- package/src/web/templates/DataRowRenderer.ts +93 -20
- package/src/web/templates/IdentityRowRenderer.ts +150 -5
- 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
|
@@ -6,7 +6,7 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
6
6
|
fonts: NativeListFontFamilies
|
|
7
7
|
) -> CGFloat? {
|
|
8
8
|
let secondary = item.data.dictionaries("columns").contains {
|
|
9
|
-
|
|
9
|
+
!nativeListDataColumnText($0, "secondaryText").isEmpty
|
|
10
10
|
}
|
|
11
11
|
return secondary ? 60 : layout == "table" ? 48 : 56
|
|
12
12
|
}
|
|
@@ -14,9 +14,12 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
14
14
|
private let visual = NativeListLeadingVisual()
|
|
15
15
|
private let favorite = UIImageView()
|
|
16
16
|
private let accessories = NativeListAccessoryStack()
|
|
17
|
+
private let trailingAccessories = NativeListAccessoryStack()
|
|
17
18
|
private let columns = UIStackView()
|
|
18
19
|
private let cells = (0..<4).map { _ in NativeListTableColumnView() }
|
|
19
20
|
private var rowConstraints: [NSLayoutConstraint] = []
|
|
21
|
+
private var columnWidthConstraints: [NSLayoutConstraint] = []
|
|
22
|
+
private var columnWeights: [Int]?
|
|
20
23
|
override func unselectedBackground(
|
|
21
24
|
_ item: NativeListItem, theme: [String: Any]?, layout: String, itemIndex: Int?
|
|
22
25
|
) -> UIColor {
|
|
@@ -34,10 +37,13 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
34
37
|
columns.alignment = .center
|
|
35
38
|
columns.spacing = 8
|
|
36
39
|
cells.forEach(columns.addArrangedSubview)
|
|
37
|
-
[favorite, visual, accessories, columns].forEach(root.addArrangedSubview)
|
|
40
|
+
[favorite, visual, accessories, columns, trailingAccessories].forEach(root.addArrangedSubview)
|
|
38
41
|
accessories.onAction = { [weak self] key, view, slot, target in
|
|
39
42
|
self?.emitAction(key, from: view, source: "trailingAccessory", slot: slot, target: target)
|
|
40
43
|
}
|
|
44
|
+
trailingAccessories.onAction = { [weak self] key, view, slot, target in
|
|
45
|
+
self?.emitAction(key, from: view, source: "trailingAccessory", slot: slot, target: target)
|
|
46
|
+
}
|
|
41
47
|
}
|
|
42
48
|
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
|
43
49
|
override func bindContent(
|
|
@@ -86,6 +92,11 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
86
92
|
item, descriptors: descriptors, theme: theme, style: accessoryStyle,
|
|
87
93
|
checkboxState: checkboxState, fonts: fonts)
|
|
88
94
|
accessories.isHidden = descriptors.isEmpty
|
|
95
|
+
let trailing = data.dictionaries("trailing")
|
|
96
|
+
trailingAccessories.bind(
|
|
97
|
+
item, descriptors: trailing, theme: theme, style: style,
|
|
98
|
+
checkboxState: checkboxState, fonts: fonts)
|
|
99
|
+
trailingAccessories.isHidden = trailing.isEmpty
|
|
89
100
|
NSLayoutConstraint.deactivate(rowConstraints)
|
|
90
101
|
rowConstraints = [
|
|
91
102
|
favorite.widthAnchor.constraint(equalToConstant: 20),
|
|
@@ -93,9 +104,27 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
93
104
|
visual.widthAnchor.constraint(equalToConstant: CGFloat(image.double("width", default: 40))),
|
|
94
105
|
visual.heightAnchor.constraint(equalToConstant: CGFloat(image.double("height", default: 40))),
|
|
95
106
|
]
|
|
107
|
+
if !trailing.isEmpty {
|
|
108
|
+
// UIStackView has no intrinsic width of its own. Reserve the controls' fitted
|
|
109
|
+
// width so extra space goes to the weighted columns instead of this stack.
|
|
110
|
+
rowConstraints.append(trailingAccessories.widthAnchor.constraint(equalToConstant:
|
|
111
|
+
trailingAccessories.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).width))
|
|
112
|
+
}
|
|
96
113
|
let values = Array(data.dictionaries("columns").prefix(4))
|
|
114
|
+
let weights = values.map { max(1, $0.int("weight", default: 1)) }
|
|
115
|
+
var divisor = weights.first ?? 1
|
|
116
|
+
for weight in weights.dropFirst() {
|
|
117
|
+
var a = divisor
|
|
118
|
+
var b = weight
|
|
119
|
+
while b != 0 { (a, b) = (b, a % b) }
|
|
120
|
+
divisor = a
|
|
121
|
+
}
|
|
122
|
+
let normalizedWeights = weights.map { $0 / divisor }
|
|
123
|
+
let columnsChanged = columnWeights != normalizedWeights
|
|
124
|
+
if columnsChanged { NSLayoutConstraint.deactivate(columnWidthConstraints) }
|
|
97
125
|
for (index, cell) in cells.enumerated() {
|
|
98
|
-
|
|
126
|
+
let hidden = index >= values.count
|
|
127
|
+
if cell.isHidden != hidden { cell.isHidden = hidden }
|
|
99
128
|
guard index < values.count else {
|
|
100
129
|
cell.reset()
|
|
101
130
|
continue
|
|
@@ -109,23 +138,30 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
109
138
|
cell.applyStyle(style) { label, style in
|
|
110
139
|
NativeListTextStyles.applyStyledText(label, style, fonts: fonts)
|
|
111
140
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
cell.widthAnchor.constraint(
|
|
115
|
-
equalTo: cells[0].widthAnchor,
|
|
116
|
-
multiplier: CGFloat(max(1, values[index].int("weight", default: 1)))
|
|
117
|
-
/ CGFloat(max(1, values[0].int("weight", default: 1)))))
|
|
118
|
-
}
|
|
141
|
+
cell.applySegments(values[index])
|
|
142
|
+
cell.bindTitleIcons(values[index], theme: theme)
|
|
119
143
|
}
|
|
120
144
|
NSLayoutConstraint.activate(rowConstraints)
|
|
145
|
+
if columnsChanged {
|
|
146
|
+
columnWidthConstraints = values.count > 1 ? (1..<values.count).map { index in
|
|
147
|
+
cells[index].widthAnchor.constraint(equalTo: cells[0].widthAnchor,
|
|
148
|
+
multiplier: CGFloat(weights[index]) / CGFloat(weights[0]))
|
|
149
|
+
} : []
|
|
150
|
+
NSLayoutConstraint.activate(columnWidthConstraints)
|
|
151
|
+
columnWeights = normalizedWeights
|
|
152
|
+
}
|
|
121
153
|
}
|
|
122
154
|
override func bindSelectionContent(
|
|
123
155
|
_ item: NativeListItem,
|
|
124
156
|
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
|
|
125
|
-
) {
|
|
157
|
+
) {
|
|
158
|
+
accessories.updateSelection(item, checkboxState: checkboxState)
|
|
159
|
+
trailingAccessories.updateSelection(item, checkboxState: checkboxState)
|
|
160
|
+
}
|
|
126
161
|
override func recycleContent() {
|
|
127
162
|
visual.recycle()
|
|
128
163
|
accessories.reset()
|
|
164
|
+
trailingAccessories.reset()
|
|
129
165
|
cells.forEach { $0.reset() }
|
|
130
166
|
}
|
|
131
167
|
}
|
|
@@ -133,6 +169,8 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
133
169
|
private final class NativeListTableColumnView: UIStackView {
|
|
134
170
|
private let primaryLine = UIStackView()
|
|
135
171
|
private let primaryLabel = NativeListTextLabel()
|
|
172
|
+
private let titleIconView = UIImageView()
|
|
173
|
+
private let secondaryTitleIconView = UIImageView()
|
|
136
174
|
private let badgesStack = UIStackView()
|
|
137
175
|
private let secondaryLine = UIStackView()
|
|
138
176
|
private let secondaryLeadingLabel = NativeListTextLabel()
|
|
@@ -152,11 +190,21 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
152
190
|
primaryLabel.numberOfLines = 1
|
|
153
191
|
primaryLabel.lineBreakMode = .byTruncatingTail
|
|
154
192
|
primaryLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
|
193
|
+
for icon in [titleIconView, secondaryTitleIconView] {
|
|
194
|
+
icon.contentMode = .scaleAspectFit
|
|
195
|
+
icon.translatesAutoresizingMaskIntoConstraints = false
|
|
196
|
+
icon.widthAnchor.constraint(equalToConstant: 20).isActive = true
|
|
197
|
+
icon.heightAnchor.constraint(equalToConstant: 20).isActive = true
|
|
198
|
+
icon.setContentHuggingPriority(.required, for: .horizontal)
|
|
199
|
+
icon.isHidden = true
|
|
200
|
+
}
|
|
155
201
|
badgesStack.axis = .horizontal
|
|
156
202
|
badgesStack.alignment = .center
|
|
157
203
|
badgesStack.spacing = 4
|
|
158
204
|
badgesStack.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
159
205
|
primaryLine.addArrangedSubview(primaryLabel)
|
|
206
|
+
primaryLine.addArrangedSubview(titleIconView)
|
|
207
|
+
primaryLine.addArrangedSubview(secondaryTitleIconView)
|
|
160
208
|
primaryLine.addArrangedSubview(badgesStack)
|
|
161
209
|
|
|
162
210
|
secondaryLine.axis = .horizontal
|
|
@@ -180,6 +228,15 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
180
228
|
|
|
181
229
|
func reset() {
|
|
182
230
|
linear = false
|
|
231
|
+
primaryLine.alignment = .center
|
|
232
|
+
for icon in [titleIconView, secondaryTitleIconView] {
|
|
233
|
+
icon.image = nil
|
|
234
|
+
icon.isHidden = true
|
|
235
|
+
icon.accessibilityLabel = nil
|
|
236
|
+
icon.isAccessibilityElement = false
|
|
237
|
+
}
|
|
238
|
+
primaryLine.setCustomSpacing(UIStackView.spacingUseDefault, after: primaryLabel)
|
|
239
|
+
primaryLine.setCustomSpacing(UIStackView.spacingUseDefault, after: titleIconView)
|
|
183
240
|
for label in [primaryLabel, secondaryLeadingLabel, secondaryLabel] {
|
|
184
241
|
label.rowVerticalAlignment = nil
|
|
185
242
|
label.rowOffsetY = 0
|
|
@@ -202,6 +259,28 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
202
259
|
}
|
|
203
260
|
}
|
|
204
261
|
|
|
262
|
+
func bindTitleIcons(_ column: [String: Any], theme: [String: Any]?) {
|
|
263
|
+
let descriptors = [column.dictionary("titleIcon"), column.dictionary("secondaryTitleIcon")]
|
|
264
|
+
for (index, descriptor) in descriptors.enumerated() {
|
|
265
|
+
guard let descriptor else { continue }
|
|
266
|
+
let icon = index == 0 ? titleIconView : secondaryTitleIconView
|
|
267
|
+
icon.image = nativeListIcon(named: descriptor.string("name"))
|
|
268
|
+
icon.tintColor = UIColor(
|
|
269
|
+
nativeListHex: descriptor.string("tintColor",
|
|
270
|
+
default: theme?["iconSubdued"] as? String ?? "#8D8D8D"),
|
|
271
|
+
fallback: .gray)
|
|
272
|
+
icon.isHidden = false
|
|
273
|
+
let label = descriptor.string("accessibilityLabel")
|
|
274
|
+
icon.accessibilityLabel = label.isEmpty ? nil : label
|
|
275
|
+
icon.isAccessibilityElement = !label.isEmpty
|
|
276
|
+
}
|
|
277
|
+
if descriptors.contains(where: { $0 != nil }) {
|
|
278
|
+
primaryLine.setCustomSpacing(4, after: primaryLabel)
|
|
279
|
+
primaryLine.setCustomSpacing(4, after: titleIconView)
|
|
280
|
+
if linear { primaryLine.alignment = .top }
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
205
284
|
func bind(
|
|
206
285
|
column: [String: Any],
|
|
207
286
|
badges: [[String: Any]],
|
|
@@ -228,7 +307,7 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
228
307
|
secondaryLeadingLabel.font = nativeListFont(ofSize: 12, fonts: fonts)
|
|
229
308
|
secondaryLabel.font = nativeListFont(ofSize: 12, fonts: fonts)
|
|
230
309
|
primaryLabel.attributedText = line(
|
|
231
|
-
column
|
|
310
|
+
nativeListDataColumnText(column, "text"),
|
|
232
311
|
font: nativeListFont(ofSize: 14, weight: .medium, fonts: fonts),
|
|
233
312
|
color: textColor(column.string("tone"), theme: theme),
|
|
234
313
|
height: 20
|
|
@@ -261,7 +340,7 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
261
340
|
secondaryLeadingLabel.isHidden = false
|
|
262
341
|
secondaryLine.isHidden = false
|
|
263
342
|
}
|
|
264
|
-
let secondary = column
|
|
343
|
+
let secondary = nativeListDataColumnText(column, "secondaryText")
|
|
265
344
|
if !secondary.isEmpty {
|
|
266
345
|
secondaryLabel.attributedText = line(
|
|
267
346
|
secondary,
|
|
@@ -331,14 +410,15 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
331
410
|
primaryLabel.textAlignment =
|
|
332
411
|
column.string("alignment") == "end"
|
|
333
412
|
? .right : column.string("alignment") == "center" ? .center : .left
|
|
334
|
-
let secondary = column
|
|
413
|
+
let secondary = nativeListDataColumnText(column, "secondaryText")
|
|
335
414
|
let primaryFont = font(primaryStyle, size: 14, weight: .medium)
|
|
336
415
|
let attributed = NSMutableAttributedString(
|
|
337
|
-
string: column
|
|
416
|
+
string: nativeListDataColumnText(column, "text"),
|
|
338
417
|
attributes: [
|
|
339
418
|
.font: primaryFont,
|
|
340
419
|
.foregroundColor: color(primaryStyle, textColor(column.string("tone"), theme: theme)),
|
|
341
420
|
])
|
|
421
|
+
attributed.setAttributedString(nativeListDataSegments(attributed, column.dictionaries("textSegments")))
|
|
342
422
|
let primaryLength = attributed.length
|
|
343
423
|
// Every badge run is the legacy " text " pill: both lead spaces sit inside the badge
|
|
344
424
|
// background and are its left padding. `titleBadgeGap` adds an exact, unfilled gap between
|
|
@@ -378,7 +458,10 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
378
458
|
textColor(column.string("secondaryTone", default: "secondary"), theme: theme)),
|
|
379
459
|
]
|
|
380
460
|
attributes.merge(paragraph(secondaryStyle, font: secondaryFont, spacing: nil)) { $1 }
|
|
381
|
-
attributed.append(NSAttributedString(string: "\n
|
|
461
|
+
attributed.append(NSAttributedString(string: "\n", attributes: attributes))
|
|
462
|
+
attributed.append(nativeListDataSegments(
|
|
463
|
+
NSAttributedString(string: secondary, attributes: attributes),
|
|
464
|
+
column.dictionaries("secondaryTextSegments")))
|
|
382
465
|
lines = min(3, lines + max(1, secondaryStyle.int("lines", default: 1)))
|
|
383
466
|
}
|
|
384
467
|
primaryLabel.font = nativeListFont(ofSize: 12, fonts: fonts)
|
|
@@ -400,6 +483,16 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
400
483
|
primaryStyle.double("offsetY", default: secondaryStyle.double("offsetY")))
|
|
401
484
|
}
|
|
402
485
|
|
|
486
|
+
func applySegments(_ column: [String: Any]) {
|
|
487
|
+
guard !linear else { return }
|
|
488
|
+
if let text = primaryLabel.attributedText {
|
|
489
|
+
primaryLabel.attributedText = nativeListDataSegments(text, column.dictionaries("textSegments"))
|
|
490
|
+
}
|
|
491
|
+
if let text = secondaryLabel.attributedText {
|
|
492
|
+
secondaryLabel.attributedText = nativeListDataSegments(text, column.dictionaries("secondaryTextSegments"))
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
403
496
|
func applyStyle(_ style: [String: Any], text: (UILabel, [String: Any]) -> Void) {
|
|
404
497
|
// The linear single label already mapped its styles onto attributed ranges.
|
|
405
498
|
guard !linear else { return }
|
|
@@ -446,3 +539,22 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
446
539
|
}
|
|
447
540
|
}
|
|
448
541
|
}
|
|
542
|
+
|
|
543
|
+
private func nativeListDataColumnText(_ column: [String: Any], _ field: String) -> String {
|
|
544
|
+
let segments = column.dictionaries("\(field)Segments")
|
|
545
|
+
return segments.isEmpty ? column.string(field) : segments.map { $0.string("text") }.joined()
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
private func nativeListDataSegments(_ fallback: NSAttributedString, _ segments: [[String: Any]]) -> NSAttributedString {
|
|
549
|
+
guard !segments.isEmpty, fallback.length > 0 else { return fallback }
|
|
550
|
+
let attributes = fallback.attributes(at: 0, effectiveRange: nil)
|
|
551
|
+
let result = NSMutableAttributedString(string: "")
|
|
552
|
+
for segment in segments {
|
|
553
|
+
var runAttributes = attributes
|
|
554
|
+
if segment.string("style") == "subscript", let font = attributes[.font] as? UIFont {
|
|
555
|
+
runAttributes[.font] = font.withSize(ceil(font.pointSize * 0.6))
|
|
556
|
+
}
|
|
557
|
+
result.append(NSAttributedString(string: segment.string("text"), attributes: runAttributes))
|
|
558
|
+
}
|
|
559
|
+
return result
|
|
560
|
+
}
|
|
@@ -110,6 +110,9 @@ func nativeListIcon(named name: String) -> UIImage? {
|
|
|
110
110
|
case "LockSolid": assetName = "onekey_selector_lock_solid"
|
|
111
111
|
// OneKey patch: official selector icon geometry.
|
|
112
112
|
case "GlobusOutline": assetName = "onekey_selector_globus_outline"
|
|
113
|
+
case "GasSolid": assetName = "onekey_gas_solid"
|
|
114
|
+
case "RefreshCcwOutline": assetName = "onekey_refresh_ccw_outline"
|
|
115
|
+
case "CryptoCoinOutline": assetName = "onekey_crypto_coin_outline"
|
|
113
116
|
case "ArrowBottomOutline": assetName = "onekey_arrow_bottom"
|
|
114
117
|
case "ArrowTopOutline": assetName = "onekey_arrow_top"
|
|
115
118
|
case "ChartTrendingUpOutline": assetName = "onekey_chart_trending_up"
|
|
@@ -12,6 +12,35 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
12
12
|
return item.data.dictionaries("badges").isEmpty ? 68 : 92
|
|
13
13
|
}
|
|
14
14
|
if item.data.string("presentation") == "networkSelector" { return 47 }
|
|
15
|
+
if item.data.string("contentHeight") == "auto" {
|
|
16
|
+
let style = item.data.dictionary("style") ?? [:]
|
|
17
|
+
let horizontalPadding = CGFloat(style.double("horizontalPadding", default: layout == "table" ? 16 : 12))
|
|
18
|
+
let verticalPadding = CGFloat(style.double("verticalPadding", default: 8))
|
|
19
|
+
let imageWidth = CGFloat(style.dictionary("image")?.double("width", default: 40) ?? 40)
|
|
20
|
+
let imageHeight = CGFloat(style.dictionary("image")?.double("height", default: 40) ?? 40)
|
|
21
|
+
let leadingGap = CGFloat(style.double("leadingGap", default: 12))
|
|
22
|
+
let trailingWidth: CGFloat = item.data.dictionaries("trailing").isEmpty ? 0 : 48
|
|
23
|
+
let textWidth = max(1, width - horizontalPadding * 2 - imageWidth - leadingGap - trailingWidth - 12)
|
|
24
|
+
let title = NativeListResolvedText(
|
|
25
|
+
item.data.string("title"), style: style.dictionary("title"), size: 16,
|
|
26
|
+
weight: .medium, color: .black, lineHeight: 24,
|
|
27
|
+
lines: item.data.int("titleLines", default: 1), fonts: fonts)
|
|
28
|
+
let subtitle = NativeListResolvedText(
|
|
29
|
+
item.data.string("subtitle"), style: style.dictionary("subtitle"), size: 14,
|
|
30
|
+
color: .black, lineHeight: 20,
|
|
31
|
+
lines: item.data.int("subtitleLines", default: 1),
|
|
32
|
+
breakMode: item.data.int("subtitleLines", default: 1) == 0 ? .byWordWrapping : .byTruncatingTail,
|
|
33
|
+
fonts: fonts)
|
|
34
|
+
let tertiary = NativeListResolvedText(
|
|
35
|
+
item.data.string("tertiary"), style: style.dictionary("tertiary"), size: 14,
|
|
36
|
+
color: .black, lineHeight: 20, lines: 1, fonts: fonts)
|
|
37
|
+
let textHeight = title.measure(width: textWidth)
|
|
38
|
+
+ subtitle.measure(width: textWidth)
|
|
39
|
+
+ tertiary.measure(width: textWidth)
|
|
40
|
+
+ (item.data.string("subtitle").isEmpty ? 0 : CGFloat(style.double("lineGap", default: 0)))
|
|
41
|
+
return max(item.data.string("subtitle").isEmpty ? 56 : 60,
|
|
42
|
+
verticalPadding * 2 + max(imageHeight, textHeight))
|
|
43
|
+
}
|
|
15
44
|
return !item.data.string("tertiary").isEmpty
|
|
16
45
|
? 72 : !item.data.string("subtitle").isEmpty ? 60 : 56
|
|
17
46
|
}
|
|
@@ -20,6 +49,7 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
20
49
|
private let mainStack = UIStackView()
|
|
21
50
|
private let titleRowStack = UIStackView()
|
|
22
51
|
private let titleLabel = NativeListTextLabel()
|
|
52
|
+
private let titleIconView = UIImageView()
|
|
23
53
|
private let subtitleLabel = NativeListTextLabel()
|
|
24
54
|
private let tertiaryLabel = NativeListTextLabel()
|
|
25
55
|
private let badgeLabel = NativeListInsetLabel()
|
|
@@ -75,7 +105,17 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
75
105
|
titleRowStack.axis = .horizontal
|
|
76
106
|
titleRowStack.alignment = .center
|
|
77
107
|
titleRowStack.addArrangedSubview(titleLabel)
|
|
108
|
+
titleRowStack.addArrangedSubview(titleIconView)
|
|
78
109
|
titleRowStack.addArrangedSubview(badgeLabel)
|
|
110
|
+
titleIconView.translatesAutoresizingMaskIntoConstraints = false
|
|
111
|
+
let titleIconWidth = titleIconView.widthAnchor.constraint(equalToConstant: 20)
|
|
112
|
+
titleIconWidth.priority = UILayoutPriority(999)
|
|
113
|
+
NSLayoutConstraint.activate([
|
|
114
|
+
titleIconWidth,
|
|
115
|
+
titleIconView.heightAnchor.constraint(equalToConstant: 20),
|
|
116
|
+
])
|
|
117
|
+
titleIconView.contentMode = .scaleAspectFit
|
|
118
|
+
titleIconView.setContentHuggingPriority(.required, for: .horizontal)
|
|
79
119
|
[titleRowStack, subtitleLabel, tertiaryLabel].forEach(mainStack.addArrangedSubview)
|
|
80
120
|
visual.translatesAutoresizingMaskIntoConstraints = false
|
|
81
121
|
leadingWidth = visual.widthAnchor.constraint(equalToConstant: 40)
|
|
@@ -133,6 +173,10 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
133
173
|
titleRowStack.setCustomSpacing(UIStackView.spacingUseDefault, after: $0)
|
|
134
174
|
}
|
|
135
175
|
titleRowStack.spacing = 8
|
|
176
|
+
titleIconView.image = nil
|
|
177
|
+
titleIconView.isHidden = true
|
|
178
|
+
titleIconView.accessibilityLabel = nil
|
|
179
|
+
titleIconView.isAccessibilityElement = false
|
|
136
180
|
titleRowStack.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
|
137
181
|
titleRowStack.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
|
138
182
|
for label in [titleLabel, subtitleLabel, tertiaryLabel, badgeLabel] {
|
|
@@ -165,6 +209,10 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
165
209
|
leadingWidth.constant = 40
|
|
166
210
|
leadingHeight.constant = 40
|
|
167
211
|
visual.glyphSize = 18
|
|
212
|
+
visual.bitmapBorderWidth =
|
|
213
|
+
item.data.dictionary("leading")?.string("borderColor").isEmpty == false
|
|
214
|
+
&& item.data.dictionary("leading")?.string("borderStyle") != "dashed"
|
|
215
|
+
? 1 : 0
|
|
168
216
|
fallbackLabel.attributedText = nil
|
|
169
217
|
fallbackLabel.font = nativeListFont(ofSize: 13, weight: .bold, fonts: fonts)
|
|
170
218
|
trailingStack.reset()
|
|
@@ -175,6 +223,31 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
175
223
|
leadingActionButton.setImage(nil, for: .normal)
|
|
176
224
|
bindIdentity(item, theme: theme, selected: item.data.bool("selected"), checkboxState)
|
|
177
225
|
let style = item.data.dictionary("style") ?? [:]
|
|
226
|
+
if let titleIcon = item.data.dictionary("titleIcon") {
|
|
227
|
+
titleIconView.image = nativeListIcon(named: titleIcon.string("name"))
|
|
228
|
+
titleIconView.tintColor = UIColor(
|
|
229
|
+
nativeListHex: titleIcon.string("tintColor",
|
|
230
|
+
default: theme?["iconSubdued"] as? String ?? "#8D8D8D"),
|
|
231
|
+
fallback: .gray)
|
|
232
|
+
titleIconView.isHidden = false
|
|
233
|
+
let label = titleIcon.string("accessibilityLabel")
|
|
234
|
+
titleIconView.accessibilityLabel = label.isEmpty ? nil : label
|
|
235
|
+
titleIconView.isAccessibilityElement = !label.isEmpty
|
|
236
|
+
titleRowStack.setCustomSpacing(4, after: titleLabel)
|
|
237
|
+
}
|
|
238
|
+
if let ratio = style["leadingContentMaxWidthRatio"] as? NSNumber,
|
|
239
|
+
root.arrangedSubviews.contains(visual)
|
|
240
|
+
{
|
|
241
|
+
titleLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
|
242
|
+
let visualWidth = CGFloat(style.dictionary("image")?.double("width", default: 40) ?? 40)
|
|
243
|
+
let leadingGap = CGFloat(style.double("leadingGap", default: 12))
|
|
244
|
+
let constraint = mainStack.widthAnchor.constraint(
|
|
245
|
+
lessThanOrEqualTo: root.widthAnchor,
|
|
246
|
+
multiplier: CGFloat(ratio.doubleValue),
|
|
247
|
+
constant: -(visualWidth + leadingGap))
|
|
248
|
+
constraint.isActive = true
|
|
249
|
+
selectorConstraints.append(constraint)
|
|
250
|
+
}
|
|
178
251
|
if style["horizontalPadding"] != nil {
|
|
179
252
|
leftInset = CGFloat(style.double("horizontalPadding"))
|
|
180
253
|
rightInset = -leftInset
|
|
@@ -196,7 +269,9 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
196
269
|
if walletBadgeLine != nil {
|
|
197
270
|
mainStack.setCustomSpacing(CGFloat(style.double("titleBadgeGap")), after: titleRowStack)
|
|
198
271
|
} else {
|
|
199
|
-
titleRowStack.setCustomSpacing(
|
|
272
|
+
titleRowStack.setCustomSpacing(
|
|
273
|
+
CGFloat(style.double("titleBadgeGap")),
|
|
274
|
+
after: titleIconView.isHidden ? titleLabel : titleIconView)
|
|
200
275
|
}
|
|
201
276
|
}
|
|
202
277
|
if style["trailingGap"] != nil { trailingStack.spacing = CGFloat(style.double("trailingGap")) }
|
|
@@ -440,9 +515,37 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
440
515
|
}
|
|
441
516
|
root.addArrangedSubview(mainStack)
|
|
442
517
|
show(titleLabel, item.data.string("title"), lines: item.data.int("titleLines", default: 1))
|
|
518
|
+
let titleSuffixes = item.data.dictionaries("titleSuffixes")
|
|
519
|
+
if !titleSuffixes.isEmpty {
|
|
520
|
+
titleLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
|
521
|
+
let minimumTitleWidth = titleLabel.widthAnchor.constraint(greaterThanOrEqualToConstant: 80)
|
|
522
|
+
minimumTitleWidth.priority = UILayoutPriority(751)
|
|
523
|
+
minimumTitleWidth.isActive = true
|
|
524
|
+
selectorConstraints.append(minimumTitleWidth)
|
|
525
|
+
for suffix in titleSuffixes {
|
|
526
|
+
let label = NativeListTextLabel()
|
|
527
|
+
label.font = nativeListFont(ofSize: 12, fonts: fonts)
|
|
528
|
+
label.textColor = dataTextColor(suffix.string("tone", default: "secondary"), theme: theme)
|
|
529
|
+
label.numberOfLines = 1
|
|
530
|
+
label.lineBreakMode = .byTruncatingTail
|
|
531
|
+
label.setContentHuggingPriority(.defaultHigh, for: .horizontal)
|
|
532
|
+
label.setContentCompressionResistancePriority(UILayoutPriority(749), for: .horizontal)
|
|
533
|
+
setLineHeight(label, text: suffix.string("text"), lineHeight: 16)
|
|
534
|
+
if let maxWidth = suffix["maxWidth"] as? NSNumber {
|
|
535
|
+
let limit = label.widthAnchor.constraint(lessThanOrEqualToConstant: CGFloat(truncating: maxWidth))
|
|
536
|
+
limit.isActive = true
|
|
537
|
+
selectorConstraints.append(limit)
|
|
538
|
+
}
|
|
539
|
+
titleRowStack.insertArrangedSubview(label, at: titleRowStack.arrangedSubviews.count - 1)
|
|
540
|
+
selectorViews.append(label)
|
|
541
|
+
}
|
|
542
|
+
}
|
|
443
543
|
show(
|
|
444
544
|
subtitleLabel, item.data.string("subtitle"), lines: item.data.int("subtitleLines", default: 1)
|
|
445
545
|
)
|
|
546
|
+
if item.data.int("subtitleLines", default: 1) == 0 {
|
|
547
|
+
subtitleLabel.lineBreakMode = .byWordWrapping
|
|
548
|
+
}
|
|
446
549
|
show(tertiaryLabel, item.data.string("tertiary"), lines: 1)
|
|
447
550
|
if !item.data.string("subtitle").isEmpty, item.data.string("tertiary").isEmpty {
|
|
448
551
|
mainStack.spacing = 0
|
|
@@ -564,11 +667,25 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
564
667
|
trailingStack.spacing = 12
|
|
565
668
|
} else if accessories.count == 2,
|
|
566
669
|
accessories[0].string("kind") == "valuePair",
|
|
567
|
-
accessories[1].string("kind") == "menu"
|
|
670
|
+
(accessories[1].string("kind") == "menu"
|
|
671
|
+
|| (accessories[1].string("kind") == "icon"
|
|
672
|
+
&& accessories[1].string("name") == "DotVerSolid"
|
|
673
|
+
&& accessories[1].string("actionKey") == "menu"))
|
|
568
674
|
{
|
|
569
675
|
trailingStack.axis = .horizontal
|
|
570
676
|
trailingStack.alignment = .center
|
|
571
677
|
trailingStack.spacing = 8
|
|
678
|
+
} else if accessories.count == 2,
|
|
679
|
+
(accessories[0].string("kind") == "valuePair"
|
|
680
|
+
&& accessories[1].string("kind") == "chevron")
|
|
681
|
+
|| (accessories[0].string("kind") == "icon"
|
|
682
|
+
&& accessories[0].string("name") == "RefreshCcwOutline"
|
|
683
|
+
&& accessories[0].string("actionKey").isEmpty
|
|
684
|
+
&& accessories[1].string("kind") == "chevron")
|
|
685
|
+
{
|
|
686
|
+
trailingStack.axis = .horizontal
|
|
687
|
+
trailingStack.alignment = .center
|
|
688
|
+
trailingStack.spacing = 12
|
|
572
689
|
} else if accessories.count == 2,
|
|
573
690
|
accessories[0].string("kind") == "icon",
|
|
574
691
|
accessories[0].string("name") == "PencilOutline",
|
|
@@ -590,12 +707,13 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
590
707
|
trailingStack.isHidden = false
|
|
591
708
|
if let gap = trailingStack.contentGap { root.setCustomSpacing(gap, after: mainStack) }
|
|
592
709
|
if let inset = trailingStack.endInset { rightInset = -inset }
|
|
593
|
-
if
|
|
594
|
-
|
|
710
|
+
if accessories.count == 1,
|
|
711
|
+
(item.data.string("presentation") == "accountSelector"
|
|
712
|
+
|| accessories[0].string("kind") == "valuePair"),
|
|
595
713
|
let accessory = trailingStack.firstVisibleControl
|
|
596
714
|
{
|
|
597
715
|
// The vertical trailing stack has no stable intrinsic width, so keep its
|
|
598
|
-
// flexible space in the
|
|
716
|
+
// flexible space in the title and subtitle column.
|
|
599
717
|
let width = trailingStack.widthAnchor.constraint(equalTo: accessory.widthAnchor)
|
|
600
718
|
width.isActive = true
|
|
601
719
|
selectorConstraints.append(width)
|
|
@@ -21,6 +21,7 @@ final class NativeListLeadingVisual: UIView {
|
|
|
21
21
|
private let cornerBackdrop = UIView()
|
|
22
22
|
private var slots: [NativeListImageSlot] = []
|
|
23
23
|
private var overlaySlots: [NativeListImageSlot] = []
|
|
24
|
+
private var overlayFallbackIcons: [UIImageView] = []
|
|
24
25
|
private var overlays: [(UIView, [String: Any])] = []
|
|
25
26
|
private let dashedBorder = CAShapeLayer()
|
|
26
27
|
private var visual: [String: Any] = [:]
|
|
@@ -87,6 +88,7 @@ final class NativeListLeadingVisual: UIView {
|
|
|
87
88
|
}
|
|
88
89
|
let placeholder = theme?.string("strongBackground", default: "#0000000F") ?? "#0000000F"
|
|
89
90
|
let fallbackIcon = visual.dictionary("fallbackIcon")
|
|
91
|
+
let fallbackBackground = fallbackIcon?.string("backgroundColor", default: placeholder) ?? placeholder
|
|
90
92
|
let sourceFallback =
|
|
91
93
|
kind != "icon" && !sources.isEmpty
|
|
92
94
|
&& sources[0].0.string("loadingStrategy", default: "none") != "none"
|
|
@@ -95,7 +97,8 @@ final class NativeListLeadingVisual: UIView {
|
|
|
95
97
|
let restored = fallbackKey.map(NativeListSourceFallbackState.has) ?? false
|
|
96
98
|
let fallbackData = kind == "icon" ? visual : fallbackIcon
|
|
97
99
|
fallback.text = String(visual.string("fallbackText").prefix(2))
|
|
98
|
-
fallback.textColor = UIColor(
|
|
100
|
+
fallback.textColor = UIColor(
|
|
101
|
+
nativeListHex: visual.string("fallbackTextColor", default: "#8D8D8D"), fallback: .gray)
|
|
99
102
|
icon.image = fallbackData.map { nativeListIcon(named: $0.string("name")) } ?? nil
|
|
100
103
|
icon.tintColor = UIColor(
|
|
101
104
|
nativeListHex: fallbackData?.string("tintColor", default: "#646464") ?? "#646464",
|
|
@@ -106,7 +109,9 @@ final class NativeListLeadingVisual: UIView {
|
|
|
106
109
|
nativeListHex: visual.string(
|
|
107
110
|
"backgroundColor", default: sources.isEmpty ? placeholder : "#00000000"), fallback: .clear)
|
|
108
111
|
backgroundColor =
|
|
109
|
-
|
|
112
|
+
sources.isEmpty && fallbackIcon?["backgroundColor"] != nil || restored
|
|
113
|
+
? UIColor(nativeListHex: fallbackBackground, fallback: .clear)
|
|
114
|
+
: sourceFallback ? UIColor(nativeListHex: placeholder, fallback: .clear) : visualBackground
|
|
110
115
|
layer.borderWidth = kind == "icon" ? 1 / UIScreen.main.scale : 0
|
|
111
116
|
layer.borderColor = UIColor(nativeListHex: "#0000001F", fallback: .clear).cgColor
|
|
112
117
|
if bitmapBorderWidth > 0 {
|
|
@@ -121,7 +126,7 @@ final class NativeListLeadingVisual: UIView {
|
|
|
121
126
|
continue
|
|
122
127
|
}
|
|
123
128
|
let source = sources[index]
|
|
124
|
-
slot.view.isHidden = index > 0 ||
|
|
129
|
+
slot.view.isHidden = index > 0 || restored
|
|
125
130
|
slot.bind(
|
|
126
131
|
source.0, key: "\(key):leading:\(index)", variant: source.1,
|
|
127
132
|
fit: index == 0 ? style["contentFit"] as? String : nil, placeholder: placeholder
|
|
@@ -136,7 +141,7 @@ final class NativeListLeadingVisual: UIView {
|
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
143
|
self.backgroundColor =
|
|
139
|
-
loaded ? visualBackground : UIColor(nativeListHex:
|
|
144
|
+
loaded ? visualBackground : UIColor(nativeListHex: fallbackBackground, fallback: .clear)
|
|
140
145
|
self.fallback.isHidden = loaded || fallbackIcon != nil
|
|
141
146
|
self.icon.isHidden = loaded || fallbackIcon == nil
|
|
142
147
|
}
|
|
@@ -158,8 +163,17 @@ final class NativeListLeadingVisual: UIView {
|
|
|
158
163
|
overlays.removeAll(keepingCapacity: true)
|
|
159
164
|
let descriptors = Array(visual.dictionaries("overlays").prefix(2))
|
|
160
165
|
while overlaySlots.count < descriptors.count { overlaySlots.append(NativeListImageSlot()) }
|
|
166
|
+
while overlayFallbackIcons.count < descriptors.count { overlayFallbackIcons.append(UIImageView()) }
|
|
161
167
|
for (index, data) in descriptors.enumerated() {
|
|
162
168
|
let frame = index < previousOverlays.count ? previousOverlays[index].0 : UIView()
|
|
169
|
+
let fallbackData = data.dictionary("fallbackIcon")
|
|
170
|
+
let fallbackGlyph = overlayFallbackIcons[index]
|
|
171
|
+
fallbackGlyph.image = fallbackData.flatMap { nativeListIcon(named: $0.string("name")) }
|
|
172
|
+
fallbackGlyph.tintColor = UIColor(
|
|
173
|
+
nativeListHex: fallbackData?.string("tintColor", default: "#646464") ?? "#646464",
|
|
174
|
+
fallback: .darkGray)
|
|
175
|
+
fallbackGlyph.contentMode = .scaleAspectFit
|
|
176
|
+
fallbackGlyph.isHidden = true
|
|
163
177
|
frame.clipsToBounds = true
|
|
164
178
|
frame.backgroundColor = UIColor(
|
|
165
179
|
nativeListHex: data.string(
|
|
@@ -172,7 +186,9 @@ final class NativeListLeadingVisual: UIView {
|
|
|
172
186
|
child = slot.view
|
|
173
187
|
child.isHidden = true
|
|
174
188
|
slot.bind(image, key: "\(key):overlay:\(index)", placeholder: placeholder) {
|
|
175
|
-
[weak child] loaded in
|
|
189
|
+
[weak child, weak fallbackGlyph] loaded in
|
|
190
|
+
child?.isHidden = !loaded
|
|
191
|
+
fallbackGlyph?.isHidden = loaded || fallbackData == nil
|
|
176
192
|
}
|
|
177
193
|
} else if !data.string("text").isEmpty {
|
|
178
194
|
overlaySlots[index].recycle()
|
|
@@ -181,7 +197,10 @@ final class NativeListLeadingVisual: UIView {
|
|
|
181
197
|
label.textAlignment = .center
|
|
182
198
|
// A line-height box is the legacy wallet text badge: regular weight, centered metrics.
|
|
183
199
|
label.font = nativeListFont(
|
|
184
|
-
ofSize: overlayTextFontSize,
|
|
200
|
+
ofSize: overlayTextFontSize,
|
|
201
|
+
weight: NativeListTextStyles.marketFontWeight(
|
|
202
|
+
data.string("fontWeight"),
|
|
203
|
+
fallback: overlayTextLineHeight == nil ? .medium : .regular),
|
|
185
204
|
fonts: fonts)
|
|
186
205
|
if let line = overlayTextLineHeight {
|
|
187
206
|
let paragraph = NSMutableParagraphStyle()
|
|
@@ -207,10 +226,9 @@ final class NativeListLeadingVisual: UIView {
|
|
|
207
226
|
nativeListHex: data.string("tintColor", default: "#646464"), fallback: .darkGray)
|
|
208
227
|
child = glyph
|
|
209
228
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
229
|
+
frame.subviews.forEach { $0.removeFromSuperview() }
|
|
230
|
+
frame.addSubview(child)
|
|
231
|
+
if data.dictionary("image") != nil && fallbackData != nil { frame.addSubview(fallbackGlyph) }
|
|
214
232
|
if frame.superview == nil { addSubview(frame) }
|
|
215
233
|
overlays.append((frame, data))
|
|
216
234
|
}
|
|
@@ -253,10 +271,16 @@ final class NativeListLeadingVisual: UIView {
|
|
|
253
271
|
}
|
|
254
272
|
fallback.frame = bounds
|
|
255
273
|
let fallbackIcon = visual.dictionary("fallbackIcon")
|
|
274
|
+
let explicitFallbackSize: CGFloat? = fallbackIcon.flatMap { data in
|
|
275
|
+
guard data["size"] != nil else { return nil }
|
|
276
|
+
let size = data.double("size")
|
|
277
|
+
return size > 0 ? CGFloat(size) : nil
|
|
278
|
+
}
|
|
256
279
|
let iconSize: CGFloat =
|
|
257
|
-
|
|
280
|
+
explicitFallbackSize
|
|
281
|
+
?? (!sources.isEmpty && fallbackIcon != nil
|
|
258
282
|
? min(bounds.width, bounds.height)
|
|
259
|
-
* (fallbackIcon?.string("name") == "GlobusOutline" ? 1.2 : 1) : glyphSize
|
|
283
|
+
* (fallbackIcon?.string("name") == "GlobusOutline" ? 1.2 : 1) : glyphSize)
|
|
260
284
|
icon.frame = CGRect(
|
|
261
285
|
x: (bounds.width - iconSize) / 2, y: (bounds.height - iconSize) / 2, width: iconSize,
|
|
262
286
|
height: iconSize)
|
|
@@ -306,7 +330,8 @@ final class NativeListLeadingVisual: UIView {
|
|
|
306
330
|
cornerBackdrop.frame = networkBackdrop.frame
|
|
307
331
|
corner.frame = cornerBackdrop.frame.insetBy(dx: 1, dy: 1)
|
|
308
332
|
unread.frame = logical(CGRect(x: bounds.width - 8, y: 0, width: 8, height: 8))
|
|
309
|
-
for (
|
|
333
|
+
for (index, overlay) in overlays.enumerated() {
|
|
334
|
+
let (frame, data) = overlay
|
|
310
335
|
let size = CGFloat(data.double("size", default: 20))
|
|
311
336
|
// Legacy wallet text badges size to their text (tabular 12pt + 4) at the line height.
|
|
312
337
|
let textBadgeLine =
|
|
@@ -331,9 +356,19 @@ final class NativeListLeadingVisual: UIView {
|
|
|
331
356
|
height: height))
|
|
332
357
|
frame.layer.cornerRadius = min(width, height) / 2
|
|
333
358
|
let inset = CGFloat(data.double("padding", default: 0))
|
|
334
|
-
|
|
359
|
+
let contentFrame = frame.bounds.insetBy(
|
|
335
360
|
dx: data["text"] != nil ? overlayTextHorizontalInset ?? inset : inset,
|
|
336
361
|
dy: data["text"] != nil && overlayTextHorizontalInset != nil ? 0 : inset)
|
|
362
|
+
frame.subviews.forEach { $0.frame = contentFrame }
|
|
363
|
+
let slot = overlaySlots[index].view
|
|
364
|
+
if data.dictionary("image") != nil {
|
|
365
|
+
let circularImage = inset > 0 && width == height
|
|
366
|
+
slot.layer.cornerRadius = circularImage ? min(contentFrame.width, contentFrame.height) / 2 : 0
|
|
367
|
+
slot.clipsToBounds = circularImage
|
|
368
|
+
} else {
|
|
369
|
+
slot.layer.cornerRadius = 0
|
|
370
|
+
slot.clipsToBounds = false
|
|
371
|
+
}
|
|
337
372
|
}
|
|
338
373
|
dashedBorder.isHidden = visual.string("borderStyle") != "dashed"
|
|
339
374
|
dashedBorder.strokeColor =
|