@onekeyfe/react-native-native-list 6.7.0-2 → 6.7.0-20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +245 -9
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +7 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +29 -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 +193 -10
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +147 -33
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +145 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +51 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +2 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +3 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1920 -109
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +29 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
- package/docs/ROW_TEMPLATES.md +60 -9
- package/docs/SPEC.md +1004 -17
- package/docs/STYLE_SPEC.md +6 -0
- package/ios/HybridNativeList.swift +21 -2
- package/ios/NativeListAccessoryStack.swift +235 -39
- package/ios/NativeListActivityDetailsView.swift +18 -8
- package/ios/NativeListActivityRenderer.swift +8 -2
- package/ios/NativeListButtonGroupRenderer.swift +89 -0
- package/ios/NativeListDataRowRenderer.swift +155 -27
- package/ios/NativeListDesignAssets.swift +9 -0
- package/ios/NativeListIdentityRenderer.swift +191 -30
- package/ios/NativeListLeadingVisual.swift +119 -22
- package/ios/NativeListMessageRenderer.swift +34 -1
- package/ios/NativeListModels.swift +42 -2
- package/ios/NativeListRendererRegistry.swift +1 -0
- package/ios/NativeListResolvedText.swift +2 -1
- package/ios/NativeListRowHost.swift +14 -0
- package/ios/NativeListSectionHeaderRenderer.swift +88 -0
- package/ios/RNCNativeListView.swift +1031 -55
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +1 -0
- package/ios/tests/NativeListAccessoryStackTests.swift +89 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +56 -0
- package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
- package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
- package/ios/tests/NativeListLifecycleTests.swift +2720 -3
- package/lib/module/NativeList.js +200 -32
- package/lib/module/NativeList.web.js +262 -32
- package/lib/module/index.js +1 -1
- package/lib/module/models.js +1 -0
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +776 -52
- package/lib/module/web/NativeListWebEngine.js +919 -79
- package/lib/module/web/templates/ActivityRowRenderer.js +487 -7
- package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
- package/lib/module/web/templates/DataRowRenderer.js +40 -5
- package/lib/module/web/templates/IdentityRowRenderer.js +90 -4
- package/lib/module/web/templates/MarketRowRenderer.js +8 -3
- package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
- package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
- package/lib/module/web/templates/MessageRowRenderer.js +18 -2
- package/lib/module/web/templates/RowContainerStyle.js +1 -0
- package/lib/module/web/templates/RowRendererRegistry.js +8 -3
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +70 -3
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
- package/lib/typescript/src/NativeList.d.ts +3 -3
- package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
- package/lib/typescript/src/NativeList.types.d.ts +29 -1
- package/lib/typescript/src/NativeList.web.d.ts +2 -2
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/models.d.ts +176 -10
- package/lib/typescript/src/validation.d.ts +15 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +58 -1
- package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
- package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
- package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +10 -4
- package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
- package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
- package/package.json +3 -3
- package/react-native-native-list.podspec +1 -0
- package/src/NativeList.nitro.ts +2 -0
- package/src/NativeList.tsx +391 -82
- package/src/NativeList.types.ts +34 -1
- package/src/NativeList.web.tsx +420 -65
- package/src/index.ts +2 -0
- package/src/models.ts +210 -3
- package/src/selection.ts +1 -0
- package/src/validation.ts +1635 -76
- package/src/web/NativeListWebEngine.ts +1476 -112
- package/src/web/templates/ActivityRowRenderer.ts +732 -8
- package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
- package/src/web/templates/DataRowRenderer.ts +93 -20
- package/src/web/templates/IdentityRowRenderer.ts +150 -5
- package/src/web/templates/MarketRowRenderer.ts +19 -3
- package/src/web/templates/MarketTableRowRenderer.ts +755 -0
- package/src/web/templates/MediaTileRowRenderer.ts +313 -5
- package/src/web/templates/MessageRowRenderer.ts +23 -7
- package/src/web/templates/RowContainerStyle.ts +2 -0
- package/src/web/templates/RowRendererRegistry.ts +21 -6
- package/src/web/templates/SectionHeaderRowRenderer.ts +89 -5
|
@@ -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
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import CoreFoundation
|
|
2
3
|
import UIKit
|
|
3
4
|
|
|
4
5
|
// Template type alone partitions reuse; data keys and styles never select a renderer.
|
|
5
6
|
enum NativeListRendererKey: String, CaseIterable {
|
|
6
|
-
case message, rail, mediaTile, action, system, activity, dataRow, metricCard, market, identity, sectionHeader, walletGroup
|
|
7
|
+
case message, rail, mediaTile, action, buttonGroup, system, activity, dataRow, metricCard, market, identity, sectionHeader, walletGroup
|
|
7
8
|
/// Not a template: legacy accepted any non-empty type and drew an empty row with the
|
|
8
9
|
/// shared chrome. Unknown types keep that placeholder instead of failing the snapshot.
|
|
9
10
|
case unsupported = "__nativeListUnsupported"
|
|
@@ -35,7 +36,7 @@ struct NativeListItem {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
var isRowPressEnabled: Bool {
|
|
38
|
-
!data.bool("disabled") &&
|
|
39
|
+
type != "buttonGroup" && !data.bool("disabled") &&
|
|
39
40
|
!data.bool("pressDisabled") &&
|
|
40
41
|
(type != "system" || data.string("variant") == "retry")
|
|
41
42
|
}
|
|
@@ -78,7 +79,18 @@ struct NativeListItem {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
struct NativeListConfig {
|
|
82
|
+
struct StructuralTransition {
|
|
83
|
+
let id: String
|
|
84
|
+
let duration: TimeInterval
|
|
85
|
+
let anchorKey: String?
|
|
86
|
+
}
|
|
87
|
+
struct Disclosure {
|
|
88
|
+
let expanded: Bool
|
|
89
|
+
let expandedTrailingInset: CGFloat
|
|
90
|
+
}
|
|
81
91
|
let generation: Int
|
|
92
|
+
let structuralTransition: StructuralTransition?
|
|
93
|
+
let disclosure: Disclosure?
|
|
82
94
|
let layout: String
|
|
83
95
|
let orientation: String
|
|
84
96
|
let gridColumns: Int
|
|
@@ -129,6 +141,32 @@ struct NativeListConfig {
|
|
|
129
141
|
let capabilities = root["capabilities"] as? [String: Any]
|
|
130
142
|
let sectionIndex = capabilities?["sectionIndex"] as? [String: Any]
|
|
131
143
|
let footer = try (root["fixedFooter"] as? [String: Any]).map(NativeListItem.init)
|
|
144
|
+
let transition = root["structuralTransition"] as? [String: Any]
|
|
145
|
+
let structuralTransition = (transition?["id"] as? String).map { id in
|
|
146
|
+
StructuralTransition(
|
|
147
|
+
id: id,
|
|
148
|
+
duration: min(2, max(0, (transition?["durationMs"] as? Double ?? 220) / 1000)),
|
|
149
|
+
anchorKey: transition?["anchorKey"] as? String)
|
|
150
|
+
}
|
|
151
|
+
let disclosure: Disclosure?
|
|
152
|
+
if let value = root["disclosure"] {
|
|
153
|
+
guard let data = value as? [String: Any],
|
|
154
|
+
let expandedNumber = data["expanded"] as? NSNumber,
|
|
155
|
+
CFGetTypeID(expandedNumber) == CFBooleanGetTypeID() else {
|
|
156
|
+
throw NativeListModelError.invalidSnapshot
|
|
157
|
+
}
|
|
158
|
+
let insetNumber = data["expandedTrailingInset"] as? NSNumber
|
|
159
|
+
guard data["expandedTrailingInset"] == nil || insetNumber != nil,
|
|
160
|
+
insetNumber.map({ CFGetTypeID($0) != CFBooleanGetTypeID() }) ?? true else {
|
|
161
|
+
throw NativeListModelError.invalidSnapshot
|
|
162
|
+
}
|
|
163
|
+
let inset = insetNumber?.doubleValue ?? 0
|
|
164
|
+
guard inset.isFinite, inset >= 0 else { throw NativeListModelError.invalidSnapshot }
|
|
165
|
+
disclosure = Disclosure(expanded: expandedNumber.boolValue,
|
|
166
|
+
expandedTrailingInset: CGFloat(inset))
|
|
167
|
+
} else {
|
|
168
|
+
disclosure = nil
|
|
169
|
+
}
|
|
132
170
|
|
|
133
171
|
let contentPadding = max(0, CGFloat(layoutData.double("contentPadding")))
|
|
134
172
|
let contentPaddingHorizontal = layoutData["contentPaddingHorizontal"] == nil
|
|
@@ -143,6 +181,8 @@ struct NativeListConfig {
|
|
|
143
181
|
|
|
144
182
|
return NativeListConfig(
|
|
145
183
|
generation: generation,
|
|
184
|
+
structuralTransition: structuralTransition,
|
|
185
|
+
disclosure: disclosure,
|
|
146
186
|
layout: layout,
|
|
147
187
|
orientation: layoutData["orientation"] as? String ?? "vertical",
|
|
148
188
|
gridColumns: min(7, max(1, layoutData["gridColumns"] as? Int ?? 1)),
|
|
@@ -18,6 +18,7 @@ enum NativeListRendererRegistry {
|
|
|
18
18
|
.activity: (NativeListActivityCell.self, { NativeListActivityCell(frame: .zero) }),
|
|
19
19
|
.system: (NativeListSystemCell.self, { NativeListSystemCell(frame: .zero) }),
|
|
20
20
|
.action: (NativeListActionCell.self, { NativeListActionCell(frame: .zero) }),
|
|
21
|
+
.buttonGroup: (NativeListButtonGroupCell.self, { NativeListButtonGroupCell(frame: .zero) }),
|
|
21
22
|
.unsupported: (
|
|
22
23
|
NativeListUnsupportedCell.self, { NativeListUnsupportedCell(frame: .zero) }
|
|
23
24
|
),
|
|
@@ -26,7 +26,8 @@ struct NativeListResolvedText {
|
|
|
26
26
|
let style = style ?? [:]
|
|
27
27
|
self.tabular = tabular
|
|
28
28
|
self.preservesBreakMode = preservesBreakMode
|
|
29
|
-
|
|
29
|
+
let requestedLines = style.int("lines", default: lines)
|
|
30
|
+
self.lines = requestedLines == 0 ? 0 : min(3, max(1, requestedLines))
|
|
30
31
|
explicitTruncation = style["lines"] != nil || style["truncate"] != nil
|
|
31
32
|
text =
|
|
32
33
|
self.lines == 1 && explicitTruncation
|
|
@@ -42,6 +42,20 @@ class NativeListRowHost: UICollectionViewCell {
|
|
|
42
42
|
var listStyle: [String: Any]?
|
|
43
43
|
var onAction: ((NativeListItem, String, NativeSelectionTarget?, NativeListActionOrigin?) -> Void)?
|
|
44
44
|
var onBindingInvalidated: ((NativeListRowHost, Int) -> Void)?
|
|
45
|
+
var structuralContentHeight: CGFloat?
|
|
46
|
+
|
|
47
|
+
override func layoutSubviews() {
|
|
48
|
+
super.layoutSubviews()
|
|
49
|
+
// UIKit relays out cells again when the collection's offset changes.
|
|
50
|
+
if let structuralContentHeight {
|
|
51
|
+
contentView.frame = CGRect(x: 0, y: 0, width: bounds.width, height: structuralContentHeight)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override func prepareForReuse() {
|
|
56
|
+
super.prepareForReuse()
|
|
57
|
+
structuralContentHeight = nil
|
|
58
|
+
}
|
|
45
59
|
|
|
46
60
|
func bind(
|
|
47
61
|
item: NativeListItem, theme: [String: Any]?, layout: String, itemIndex: Int? = nil,
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import UIKit
|
|
2
2
|
|
|
3
3
|
final class NativeListDottedUnderlineLabel: NativeListTextLabel {
|
|
4
|
+
var usesDashedUnderline = false {
|
|
5
|
+
didSet {
|
|
6
|
+
dottedUnderlineLayer.lineDashPattern = usesDashedUnderline ? [3, 2] : [0, 4]
|
|
7
|
+
dottedUnderlineLayer.lineCap = usesDashedUnderline ? .butt : .round
|
|
8
|
+
setNeedsLayout()
|
|
9
|
+
}
|
|
10
|
+
}
|
|
4
11
|
var showsDottedUnderline = false {
|
|
5
12
|
didSet { setNeedsLayout() }
|
|
6
13
|
}
|
|
@@ -111,6 +118,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
111
118
|
private let mainStack = UIStackView()
|
|
112
119
|
private let titleRowStack = UIStackView()
|
|
113
120
|
private let titleLabel = NativeListDottedUnderlineLabel()
|
|
121
|
+
private let leadingBadge = NativeListInsetLabel()
|
|
114
122
|
private let titleSpinner = UIActivityIndicatorView(style: .medium)
|
|
115
123
|
private let subtitleLabel = NativeListTextLabel()
|
|
116
124
|
private let trailingStack = UIStackView()
|
|
@@ -148,6 +156,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
148
156
|
titleRowStack.axis = .horizontal
|
|
149
157
|
titleRowStack.alignment = .center
|
|
150
158
|
titleRowStack.spacing = 8
|
|
159
|
+
leadingBadge.heightAnchor.constraint(equalToConstant: 20).isActive = true
|
|
151
160
|
titleRowStack.addArrangedSubview(titleLabel)
|
|
152
161
|
mainStack.addArrangedSubview(titleRowStack)
|
|
153
162
|
mainStack.addArrangedSubview(subtitleLabel)
|
|
@@ -182,6 +191,15 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
182
191
|
selectorTypographyRestorers = []
|
|
183
192
|
currentItem = item
|
|
184
193
|
currentTheme = theme
|
|
194
|
+
if accessoryButtons[0].superview === titleRowStack {
|
|
195
|
+
titleRowStack.removeArrangedSubview(accessoryButtons[0])
|
|
196
|
+
accessoryButtons[0].removeFromSuperview()
|
|
197
|
+
trailingStack.insertArrangedSubview(accessoryButtons[0], at: 0)
|
|
198
|
+
}
|
|
199
|
+
titleRowStack.removeArrangedSubview(leadingBadge)
|
|
200
|
+
leadingBadge.removeFromSuperview()
|
|
201
|
+
leadingBadge.text = nil
|
|
202
|
+
leadingBadge.accessibilityLabel = nil
|
|
185
203
|
titleSpinner.stopAnimating()
|
|
186
204
|
NSLayoutConstraint.deactivate(selectorConstraints)
|
|
187
205
|
selectorConstraints = []
|
|
@@ -198,6 +216,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
198
216
|
titleLabel.removeGestureRecognizer(selectorTitleTap)
|
|
199
217
|
titleLabel.isUserInteractionEnabled = false
|
|
200
218
|
titleLabel.showsDottedUnderline = false
|
|
219
|
+
titleLabel.usesDashedUnderline = false
|
|
201
220
|
titleLabel.reservesDottedUnderlineSpace = false
|
|
202
221
|
titleLabel.dottedUnderlineVerticalOffset = 0
|
|
203
222
|
for label in [titleLabel, subtitleLabel] {
|
|
@@ -211,6 +230,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
211
230
|
label.rowVerticalAlignment = nil
|
|
212
231
|
}
|
|
213
232
|
titleLabel.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
|
233
|
+
titleLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
214
234
|
subtitleLabel.font = nativeListFont(ofSize: 14, fonts: fonts)
|
|
215
235
|
subtitleLabel.textColor = nativeListColor(theme, "secondaryText", "#646464")
|
|
216
236
|
mainStack.alignment = .fill
|
|
@@ -228,6 +248,10 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
228
248
|
value.contentHorizontalAlignment = .center
|
|
229
249
|
value.contentVerticalAlignment = .center
|
|
230
250
|
value.rowTextOffsetY = 0
|
|
251
|
+
value.helpBindingGeneration += 1
|
|
252
|
+
value.helpPrimaryLineOnly = false
|
|
253
|
+
value.showsHelpUnderline = false
|
|
254
|
+
value.isUserInteractionEnabled = true
|
|
231
255
|
value.marketLineHeight = nil
|
|
232
256
|
value.selectorSummaryLineHeight = nil
|
|
233
257
|
value.isHidden = true
|
|
@@ -253,6 +277,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
253
277
|
if style["lineGap"] != nil { mainStack.spacing = CGFloat(style.double("lineGap")) }
|
|
254
278
|
if style["trailingGap"] != nil { trailingStack.spacing = CGFloat(style.double("trailingGap")) }
|
|
255
279
|
applyTextStyle(item)
|
|
280
|
+
bindPositionHeaderFields(item, theme: theme)
|
|
256
281
|
titleSpinner.color = titleLabel.textColor
|
|
257
282
|
updateTitleSpinner()
|
|
258
283
|
contentInsets = UIEdgeInsets(
|
|
@@ -273,6 +298,63 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
273
298
|
selectorConstraints.append(width)
|
|
274
299
|
}
|
|
275
300
|
}
|
|
301
|
+
private func bindPositionHeaderFields(_ item: NativeListItem, theme: [String: Any]?) {
|
|
302
|
+
let style = item.data.dictionary("style") ?? [:]
|
|
303
|
+
if let badge = item.data.dictionary("leadingBadge") {
|
|
304
|
+
leadingBadge.text = badge.string("text")
|
|
305
|
+
leadingBadge.font = nativeListFont(ofSize: 12, weight: .medium, fonts: fonts)
|
|
306
|
+
let tones = ["info": ("info", "#0F69F6"), "success": ("positive", "#008F5A"), "warning": ("caution", "#A35E00"), "danger": ("negative", "#CE2C31")]
|
|
307
|
+
if let tone = tones[badge.string("tone")] {
|
|
308
|
+
let color = nativeListColor(theme, tone.0, tone.1)
|
|
309
|
+
leadingBadge.textColor = color
|
|
310
|
+
leadingBadge.backgroundColor = color.withAlphaComponent(0.12)
|
|
311
|
+
if badge.string("tone") == "success", let background = theme?["successBackground"] as? String {
|
|
312
|
+
leadingBadge.backgroundColor = UIColor(nativeListHex: background, fallback: color.withAlphaComponent(0.12))
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
leadingBadge.textColor = nativeListColor(theme, "secondaryText", "#646464")
|
|
316
|
+
leadingBadge.backgroundColor = nativeListColor(theme, "strongBackground", "#F0F0F0")
|
|
317
|
+
}
|
|
318
|
+
let paragraph = NSMutableParagraphStyle()
|
|
319
|
+
paragraph.minimumLineHeight = 16
|
|
320
|
+
paragraph.maximumLineHeight = 16
|
|
321
|
+
leadingBadge.attributedText = NSAttributedString(
|
|
322
|
+
string: badge.string("text"), attributes: [
|
|
323
|
+
.font: leadingBadge.font as Any,
|
|
324
|
+
.foregroundColor: leadingBadge.textColor as Any,
|
|
325
|
+
.paragraphStyle: paragraph,
|
|
326
|
+
])
|
|
327
|
+
leadingBadge.horizontalInset = 8
|
|
328
|
+
leadingBadge.topInset = 2
|
|
329
|
+
leadingBadge.bottomInset = 2
|
|
330
|
+
leadingBadge.layer.cornerRadius = 4
|
|
331
|
+
leadingBadge.clipsToBounds = true
|
|
332
|
+
leadingBadge.accessibilityLabel = badge["accessibilityLabel"] as? String
|
|
333
|
+
leadingBadge.setContentHuggingPriority(.required, for: .horizontal)
|
|
334
|
+
leadingBadge.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
335
|
+
titleLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
|
336
|
+
titleRowStack.insertArrangedSubview(leadingBadge, at: 0)
|
|
337
|
+
}
|
|
338
|
+
if style["titleDecoration"] != nil {
|
|
339
|
+
titleLabel.showsDottedUnderline = style.string("titleDecoration") == "dashed"
|
|
340
|
+
titleLabel.usesDashedUnderline = true
|
|
341
|
+
titleLabel.dottedUnderlineColor = titleLabel.textColor
|
|
342
|
+
}
|
|
343
|
+
let value = accessoryButtons[0]
|
|
344
|
+
if style.string("valuePlacement") == "afterTitle" {
|
|
345
|
+
trailingStack.removeArrangedSubview(value)
|
|
346
|
+
value.removeFromSuperview()
|
|
347
|
+
titleLabel.setContentHuggingPriority(.required, for: .horizontal)
|
|
348
|
+
mainStack.alignment = .leading
|
|
349
|
+
titleRowStack.addArrangedSubview(value)
|
|
350
|
+
}
|
|
351
|
+
if let help = item.data.dictionary("valueHelp") {
|
|
352
|
+
value.showsHelpUnderline = help.string("underline") == "dashed"
|
|
353
|
+
value.isUserInteractionEnabled = help.string("presentation") == "popover"
|
|
354
|
+
accessoryActions = [(help.string("presentation") == "popover" ? help.string("actionKey") : "", nil)]
|
|
355
|
+
value.setNeedsLayout()
|
|
356
|
+
}
|
|
357
|
+
}
|
|
276
358
|
private func applyTextStyle(_ item: NativeListItem) {
|
|
277
359
|
let style = item.data.dictionary("style") ?? [:]
|
|
278
360
|
if let title = style.dictionary("title") {
|
|
@@ -312,6 +394,12 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
312
394
|
override func recycleContent() {
|
|
313
395
|
checkboxControl.reset()
|
|
314
396
|
currentItem = nil
|
|
397
|
+
accessoryActions = []
|
|
398
|
+
titleLabel.removeGestureRecognizer(selectorTitleTap)
|
|
399
|
+
titleLabel.isUserInteractionEnabled = false
|
|
400
|
+
accessoryButtons[0].helpBindingGeneration += 1
|
|
401
|
+
accessoryButtons[0].isUserInteractionEnabled = false
|
|
402
|
+
accessoryButtons[0].showsHelpUnderline = false
|
|
315
403
|
titleSpinner.stopAnimating()
|
|
316
404
|
}
|
|
317
405
|
override func didMoveToWindow() {
|