@onekeyfe/react-native-native-list 6.7.0-alpha.344 → 6.7.0-alpha.354
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 +105 -8
- package/ios/NativeListDesignAssets.swift +3 -0
- package/ios/NativeListIdentityRenderer.swift +119 -4
- 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 +331 -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 +890 -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,6 +14,7 @@ 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] = []
|
|
@@ -34,10 +35,13 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
34
35
|
columns.alignment = .center
|
|
35
36
|
columns.spacing = 8
|
|
36
37
|
cells.forEach(columns.addArrangedSubview)
|
|
37
|
-
[favorite, visual, accessories, columns].forEach(root.addArrangedSubview)
|
|
38
|
+
[favorite, visual, accessories, columns, trailingAccessories].forEach(root.addArrangedSubview)
|
|
38
39
|
accessories.onAction = { [weak self] key, view, slot, target in
|
|
39
40
|
self?.emitAction(key, from: view, source: "trailingAccessory", slot: slot, target: target)
|
|
40
41
|
}
|
|
42
|
+
trailingAccessories.onAction = { [weak self] key, view, slot, target in
|
|
43
|
+
self?.emitAction(key, from: view, source: "trailingAccessory", slot: slot, target: target)
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
46
|
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
|
43
47
|
override func bindContent(
|
|
@@ -86,6 +90,11 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
86
90
|
item, descriptors: descriptors, theme: theme, style: accessoryStyle,
|
|
87
91
|
checkboxState: checkboxState, fonts: fonts)
|
|
88
92
|
accessories.isHidden = descriptors.isEmpty
|
|
93
|
+
let trailing = data.dictionaries("trailing")
|
|
94
|
+
trailingAccessories.bind(
|
|
95
|
+
item, descriptors: trailing, theme: theme, style: style,
|
|
96
|
+
checkboxState: checkboxState, fonts: fonts)
|
|
97
|
+
trailingAccessories.isHidden = trailing.isEmpty
|
|
89
98
|
NSLayoutConstraint.deactivate(rowConstraints)
|
|
90
99
|
rowConstraints = [
|
|
91
100
|
favorite.widthAnchor.constraint(equalToConstant: 20),
|
|
@@ -93,6 +102,12 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
93
102
|
visual.widthAnchor.constraint(equalToConstant: CGFloat(image.double("width", default: 40))),
|
|
94
103
|
visual.heightAnchor.constraint(equalToConstant: CGFloat(image.double("height", default: 40))),
|
|
95
104
|
]
|
|
105
|
+
if !trailing.isEmpty {
|
|
106
|
+
// UIStackView has no intrinsic width of its own. Reserve the controls' fitted
|
|
107
|
+
// width so extra space goes to the weighted columns instead of this stack.
|
|
108
|
+
rowConstraints.append(trailingAccessories.widthAnchor.constraint(equalToConstant:
|
|
109
|
+
trailingAccessories.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).width))
|
|
110
|
+
}
|
|
96
111
|
let values = Array(data.dictionaries("columns").prefix(4))
|
|
97
112
|
for (index, cell) in cells.enumerated() {
|
|
98
113
|
cell.isHidden = index >= values.count
|
|
@@ -109,6 +124,8 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
109
124
|
cell.applyStyle(style) { label, style in
|
|
110
125
|
NativeListTextStyles.applyStyledText(label, style, fonts: fonts)
|
|
111
126
|
}
|
|
127
|
+
cell.applySegments(values[index])
|
|
128
|
+
cell.bindTitleIcons(values[index], theme: theme)
|
|
112
129
|
if index > 0 {
|
|
113
130
|
rowConstraints.append(
|
|
114
131
|
cell.widthAnchor.constraint(
|
|
@@ -122,10 +139,14 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
122
139
|
override func bindSelectionContent(
|
|
123
140
|
_ item: NativeListItem,
|
|
124
141
|
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
|
|
125
|
-
) {
|
|
142
|
+
) {
|
|
143
|
+
accessories.updateSelection(item, checkboxState: checkboxState)
|
|
144
|
+
trailingAccessories.updateSelection(item, checkboxState: checkboxState)
|
|
145
|
+
}
|
|
126
146
|
override func recycleContent() {
|
|
127
147
|
visual.recycle()
|
|
128
148
|
accessories.reset()
|
|
149
|
+
trailingAccessories.reset()
|
|
129
150
|
cells.forEach { $0.reset() }
|
|
130
151
|
}
|
|
131
152
|
}
|
|
@@ -133,6 +154,8 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
133
154
|
private final class NativeListTableColumnView: UIStackView {
|
|
134
155
|
private let primaryLine = UIStackView()
|
|
135
156
|
private let primaryLabel = NativeListTextLabel()
|
|
157
|
+
private let titleIconView = UIImageView()
|
|
158
|
+
private let secondaryTitleIconView = UIImageView()
|
|
136
159
|
private let badgesStack = UIStackView()
|
|
137
160
|
private let secondaryLine = UIStackView()
|
|
138
161
|
private let secondaryLeadingLabel = NativeListTextLabel()
|
|
@@ -152,11 +175,21 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
152
175
|
primaryLabel.numberOfLines = 1
|
|
153
176
|
primaryLabel.lineBreakMode = .byTruncatingTail
|
|
154
177
|
primaryLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
|
178
|
+
for icon in [titleIconView, secondaryTitleIconView] {
|
|
179
|
+
icon.contentMode = .scaleAspectFit
|
|
180
|
+
icon.translatesAutoresizingMaskIntoConstraints = false
|
|
181
|
+
icon.widthAnchor.constraint(equalToConstant: 20).isActive = true
|
|
182
|
+
icon.heightAnchor.constraint(equalToConstant: 20).isActive = true
|
|
183
|
+
icon.setContentHuggingPriority(.required, for: .horizontal)
|
|
184
|
+
icon.isHidden = true
|
|
185
|
+
}
|
|
155
186
|
badgesStack.axis = .horizontal
|
|
156
187
|
badgesStack.alignment = .center
|
|
157
188
|
badgesStack.spacing = 4
|
|
158
189
|
badgesStack.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
159
190
|
primaryLine.addArrangedSubview(primaryLabel)
|
|
191
|
+
primaryLine.addArrangedSubview(titleIconView)
|
|
192
|
+
primaryLine.addArrangedSubview(secondaryTitleIconView)
|
|
160
193
|
primaryLine.addArrangedSubview(badgesStack)
|
|
161
194
|
|
|
162
195
|
secondaryLine.axis = .horizontal
|
|
@@ -180,6 +213,15 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
180
213
|
|
|
181
214
|
func reset() {
|
|
182
215
|
linear = false
|
|
216
|
+
primaryLine.alignment = .center
|
|
217
|
+
for icon in [titleIconView, secondaryTitleIconView] {
|
|
218
|
+
icon.image = nil
|
|
219
|
+
icon.isHidden = true
|
|
220
|
+
icon.accessibilityLabel = nil
|
|
221
|
+
icon.isAccessibilityElement = false
|
|
222
|
+
}
|
|
223
|
+
primaryLine.setCustomSpacing(UIStackView.spacingUseDefault, after: primaryLabel)
|
|
224
|
+
primaryLine.setCustomSpacing(UIStackView.spacingUseDefault, after: titleIconView)
|
|
183
225
|
for label in [primaryLabel, secondaryLeadingLabel, secondaryLabel] {
|
|
184
226
|
label.rowVerticalAlignment = nil
|
|
185
227
|
label.rowOffsetY = 0
|
|
@@ -202,6 +244,28 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
202
244
|
}
|
|
203
245
|
}
|
|
204
246
|
|
|
247
|
+
func bindTitleIcons(_ column: [String: Any], theme: [String: Any]?) {
|
|
248
|
+
let descriptors = [column.dictionary("titleIcon"), column.dictionary("secondaryTitleIcon")]
|
|
249
|
+
for (index, descriptor) in descriptors.enumerated() {
|
|
250
|
+
guard let descriptor else { continue }
|
|
251
|
+
let icon = index == 0 ? titleIconView : secondaryTitleIconView
|
|
252
|
+
icon.image = nativeListIcon(named: descriptor.string("name"))
|
|
253
|
+
icon.tintColor = UIColor(
|
|
254
|
+
nativeListHex: descriptor.string("tintColor",
|
|
255
|
+
default: theme?["iconSubdued"] as? String ?? "#8D8D8D"),
|
|
256
|
+
fallback: .gray)
|
|
257
|
+
icon.isHidden = false
|
|
258
|
+
let label = descriptor.string("accessibilityLabel")
|
|
259
|
+
icon.accessibilityLabel = label.isEmpty ? nil : label
|
|
260
|
+
icon.isAccessibilityElement = !label.isEmpty
|
|
261
|
+
}
|
|
262
|
+
if descriptors.contains(where: { $0 != nil }) {
|
|
263
|
+
primaryLine.setCustomSpacing(4, after: primaryLabel)
|
|
264
|
+
primaryLine.setCustomSpacing(4, after: titleIconView)
|
|
265
|
+
if linear { primaryLine.alignment = .top }
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
205
269
|
func bind(
|
|
206
270
|
column: [String: Any],
|
|
207
271
|
badges: [[String: Any]],
|
|
@@ -228,7 +292,7 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
228
292
|
secondaryLeadingLabel.font = nativeListFont(ofSize: 12, fonts: fonts)
|
|
229
293
|
secondaryLabel.font = nativeListFont(ofSize: 12, fonts: fonts)
|
|
230
294
|
primaryLabel.attributedText = line(
|
|
231
|
-
column
|
|
295
|
+
nativeListDataColumnText(column, "text"),
|
|
232
296
|
font: nativeListFont(ofSize: 14, weight: .medium, fonts: fonts),
|
|
233
297
|
color: textColor(column.string("tone"), theme: theme),
|
|
234
298
|
height: 20
|
|
@@ -261,7 +325,7 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
261
325
|
secondaryLeadingLabel.isHidden = false
|
|
262
326
|
secondaryLine.isHidden = false
|
|
263
327
|
}
|
|
264
|
-
let secondary = column
|
|
328
|
+
let secondary = nativeListDataColumnText(column, "secondaryText")
|
|
265
329
|
if !secondary.isEmpty {
|
|
266
330
|
secondaryLabel.attributedText = line(
|
|
267
331
|
secondary,
|
|
@@ -331,14 +395,15 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
331
395
|
primaryLabel.textAlignment =
|
|
332
396
|
column.string("alignment") == "end"
|
|
333
397
|
? .right : column.string("alignment") == "center" ? .center : .left
|
|
334
|
-
let secondary = column
|
|
398
|
+
let secondary = nativeListDataColumnText(column, "secondaryText")
|
|
335
399
|
let primaryFont = font(primaryStyle, size: 14, weight: .medium)
|
|
336
400
|
let attributed = NSMutableAttributedString(
|
|
337
|
-
string: column
|
|
401
|
+
string: nativeListDataColumnText(column, "text"),
|
|
338
402
|
attributes: [
|
|
339
403
|
.font: primaryFont,
|
|
340
404
|
.foregroundColor: color(primaryStyle, textColor(column.string("tone"), theme: theme)),
|
|
341
405
|
])
|
|
406
|
+
attributed.setAttributedString(nativeListDataSegments(attributed, column.dictionaries("textSegments")))
|
|
342
407
|
let primaryLength = attributed.length
|
|
343
408
|
// Every badge run is the legacy " text " pill: both lead spaces sit inside the badge
|
|
344
409
|
// background and are its left padding. `titleBadgeGap` adds an exact, unfilled gap between
|
|
@@ -378,7 +443,10 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
378
443
|
textColor(column.string("secondaryTone", default: "secondary"), theme: theme)),
|
|
379
444
|
]
|
|
380
445
|
attributes.merge(paragraph(secondaryStyle, font: secondaryFont, spacing: nil)) { $1 }
|
|
381
|
-
attributed.append(NSAttributedString(string: "\n
|
|
446
|
+
attributed.append(NSAttributedString(string: "\n", attributes: attributes))
|
|
447
|
+
attributed.append(nativeListDataSegments(
|
|
448
|
+
NSAttributedString(string: secondary, attributes: attributes),
|
|
449
|
+
column.dictionaries("secondaryTextSegments")))
|
|
382
450
|
lines = min(3, lines + max(1, secondaryStyle.int("lines", default: 1)))
|
|
383
451
|
}
|
|
384
452
|
primaryLabel.font = nativeListFont(ofSize: 12, fonts: fonts)
|
|
@@ -400,6 +468,16 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
400
468
|
primaryStyle.double("offsetY", default: secondaryStyle.double("offsetY")))
|
|
401
469
|
}
|
|
402
470
|
|
|
471
|
+
func applySegments(_ column: [String: Any]) {
|
|
472
|
+
guard !linear else { return }
|
|
473
|
+
if let text = primaryLabel.attributedText {
|
|
474
|
+
primaryLabel.attributedText = nativeListDataSegments(text, column.dictionaries("textSegments"))
|
|
475
|
+
}
|
|
476
|
+
if let text = secondaryLabel.attributedText {
|
|
477
|
+
secondaryLabel.attributedText = nativeListDataSegments(text, column.dictionaries("secondaryTextSegments"))
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
403
481
|
func applyStyle(_ style: [String: Any], text: (UILabel, [String: Any]) -> Void) {
|
|
404
482
|
// The linear single label already mapped its styles onto attributed ranges.
|
|
405
483
|
guard !linear else { return }
|
|
@@ -446,3 +524,22 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
446
524
|
}
|
|
447
525
|
}
|
|
448
526
|
}
|
|
527
|
+
|
|
528
|
+
private func nativeListDataColumnText(_ column: [String: Any], _ field: String) -> String {
|
|
529
|
+
let segments = column.dictionaries("\(field)Segments")
|
|
530
|
+
return segments.isEmpty ? column.string(field) : segments.map { $0.string("text") }.joined()
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
private func nativeListDataSegments(_ fallback: NSAttributedString, _ segments: [[String: Any]]) -> NSAttributedString {
|
|
534
|
+
guard !segments.isEmpty, fallback.length > 0 else { return fallback }
|
|
535
|
+
let attributes = fallback.attributes(at: 0, effectiveRange: nil)
|
|
536
|
+
let result = NSMutableAttributedString(string: "")
|
|
537
|
+
for segment in segments {
|
|
538
|
+
var runAttributes = attributes
|
|
539
|
+
if segment.string("style") == "subscript", let font = attributes[.font] as? UIFont {
|
|
540
|
+
runAttributes[.font] = font.withSize(ceil(font.pointSize * 0.6))
|
|
541
|
+
}
|
|
542
|
+
result.append(NSAttributedString(string: segment.string("text"), attributes: runAttributes))
|
|
543
|
+
}
|
|
544
|
+
return result
|
|
545
|
+
}
|
|
@@ -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
|
|
@@ -569,6 +672,17 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
569
672
|
trailingStack.axis = .horizontal
|
|
570
673
|
trailingStack.alignment = .center
|
|
571
674
|
trailingStack.spacing = 8
|
|
675
|
+
} else if accessories.count == 2,
|
|
676
|
+
(accessories[0].string("kind") == "valuePair"
|
|
677
|
+
&& accessories[1].string("kind") == "chevron")
|
|
678
|
+
|| (accessories[0].string("kind") == "icon"
|
|
679
|
+
&& accessories[0].string("name") == "RefreshCcwOutline"
|
|
680
|
+
&& accessories[0].string("actionKey").isEmpty
|
|
681
|
+
&& accessories[1].string("kind") == "chevron")
|
|
682
|
+
{
|
|
683
|
+
trailingStack.axis = .horizontal
|
|
684
|
+
trailingStack.alignment = .center
|
|
685
|
+
trailingStack.spacing = 12
|
|
572
686
|
} else if accessories.count == 2,
|
|
573
687
|
accessories[0].string("kind") == "icon",
|
|
574
688
|
accessories[0].string("name") == "PencilOutline",
|
|
@@ -590,12 +704,13 @@ final class NativeListIdentityCell: NativeListRendererCell {
|
|
|
590
704
|
trailingStack.isHidden = false
|
|
591
705
|
if let gap = trailingStack.contentGap { root.setCustomSpacing(gap, after: mainStack) }
|
|
592
706
|
if let inset = trailingStack.endInset { rightInset = -inset }
|
|
593
|
-
if
|
|
594
|
-
|
|
707
|
+
if accessories.count == 1,
|
|
708
|
+
(item.data.string("presentation") == "accountSelector"
|
|
709
|
+
|| accessories[0].string("kind") == "valuePair"),
|
|
595
710
|
let accessory = trailingStack.firstVisibleControl
|
|
596
711
|
{
|
|
597
712
|
// The vertical trailing stack has no stable intrinsic width, so keep its
|
|
598
|
-
// flexible space in the
|
|
713
|
+
// flexible space in the title and subtitle column.
|
|
599
714
|
let width = trailingStack.widthAnchor.constraint(equalTo: accessory.widthAnchor)
|
|
600
715
|
width.isActive = true
|
|
601
716
|
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 =
|
|
@@ -29,7 +29,9 @@ enum NativeListMessageRenderer {
|
|
|
29
29
|
body = NativeListResolvedText(
|
|
30
30
|
item.data.string("body"), style: style.dictionary("body"), size: 14,
|
|
31
31
|
color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 20,
|
|
32
|
-
lines: item.data.int("bodyLines", default: 3),
|
|
32
|
+
lines: item.data.int("bodyLines", default: 3),
|
|
33
|
+
breakMode: item.data.int("bodyLines", default: 3) == 0 ? .byWordWrapping : .byTruncatingTail,
|
|
34
|
+
fonts: fonts)
|
|
33
35
|
time = NativeListResolvedText(
|
|
34
36
|
item.data.string("time"), style: style.dictionary("time"), size: 12,
|
|
35
37
|
color: nativeListColor(theme, "disabledText", "#8D8D8D"), lineHeight: 16, lines: 1,
|
|
@@ -150,6 +152,11 @@ enum NativeListMessageRenderer {
|
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
final class NativeListMessageCell: NativeListRendererCell {
|
|
155
|
+
private let topWarningBorder = CALayer()
|
|
156
|
+
private let bottomWarningBorder = CALayer()
|
|
157
|
+
private var warningBorderWidth: CGFloat = 0
|
|
158
|
+
private var warningBorderColor = UIColor.clear
|
|
159
|
+
private var isInlineWarning = false
|
|
153
160
|
override class func measure(
|
|
154
161
|
_ item: NativeListItem, width: CGFloat, theme: [String: Any]?, layout: String,
|
|
155
162
|
fonts: NativeListFontFamilies
|
|
@@ -167,6 +174,10 @@ final class NativeListMessageCell: NativeListRendererCell {
|
|
|
167
174
|
_ item: NativeListItem, theme: [String: Any]?, layout: String,
|
|
168
175
|
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
|
|
169
176
|
) {
|
|
177
|
+
let container = item.data.dictionary("style")?.dictionary("container") ?? [:]
|
|
178
|
+
isInlineWarning = item.data.string("presentation") == "inlineWarning"
|
|
179
|
+
warningBorderWidth = isInlineWarning ? CGFloat(container.double("borderWidth")) : 0
|
|
180
|
+
warningBorderColor = UIColor(nativeListHex: container.string("borderColor"), fallback: .clear)
|
|
170
181
|
let resolved = NativeListMessageRenderer.Resolved(
|
|
171
182
|
item, theme: theme, layout: layout, fonts: fonts)
|
|
172
183
|
views.bind(resolved, item: item, theme: theme, fonts: fonts)
|
|
@@ -174,5 +185,27 @@ final class NativeListMessageCell: NativeListRendererCell {
|
|
|
174
185
|
top: resolved.verticalPadding, left: resolved.horizontalPadding,
|
|
175
186
|
bottom: resolved.verticalPadding, right: resolved.horizontalPadding)
|
|
176
187
|
}
|
|
188
|
+
override func applyAppearance() {
|
|
189
|
+
super.applyAppearance()
|
|
190
|
+
if isInlineWarning {
|
|
191
|
+
layer.cornerRadius = 0
|
|
192
|
+
contentView.layer.cornerRadius = 0
|
|
193
|
+
contentView.layer.borderWidth = 0
|
|
194
|
+
topWarningBorder.backgroundColor = warningBorderColor.cgColor
|
|
195
|
+
bottomWarningBorder.backgroundColor = warningBorderColor.cgColor
|
|
196
|
+
if topWarningBorder.superlayer == nil { contentView.layer.addSublayer(topWarningBorder) }
|
|
197
|
+
if bottomWarningBorder.superlayer == nil { contentView.layer.addSublayer(bottomWarningBorder) }
|
|
198
|
+
} else {
|
|
199
|
+
topWarningBorder.removeFromSuperlayer()
|
|
200
|
+
bottomWarningBorder.removeFromSuperlayer()
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
override func layoutSubviews() {
|
|
204
|
+
super.layoutSubviews()
|
|
205
|
+
let height = max(0, warningBorderWidth)
|
|
206
|
+
topWarningBorder.frame = CGRect(x: 0, y: 0, width: contentView.bounds.width, height: height)
|
|
207
|
+
bottomWarningBorder.frame = CGRect(
|
|
208
|
+
x: 0, y: contentView.bounds.height - height, width: contentView.bounds.width, height: height)
|
|
209
|
+
}
|
|
177
210
|
override func recycleContent() { views.recycle() }
|
|
178
211
|
}
|