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