@onekeyfe/react-native-native-list 6.7.0-6 → 6.7.0-60
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/README.md +312 -375
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +250 -9
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +50 -13
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +25 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +102 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListGeneratedIcons.kt +47 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +225 -11
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +152 -33
- package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaPlaceholderView.kt +244 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +66 -31
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +32 -11
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +209 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +120 -287
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +7 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +8 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +130 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1978 -136
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +35 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListDescriptionTouchPolicyTest.kt +153 -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 +78 -14
- package/docs/SPEC.md +1318 -16
- package/docs/STYLE_SPEC.md +18 -0
- package/ios/HybridNativeList.swift +21 -2
- package/ios/NativeListAccessoryStack.swift +237 -51
- package/ios/NativeListActivityDetailsView.swift +43 -16
- package/ios/NativeListActivityRenderer.swift +8 -2
- package/ios/NativeListButtonGroupRenderer.swift +89 -0
- package/ios/NativeListDataRowRenderer.swift +167 -30
- package/ios/NativeListDesignAssets.swift +13 -75
- package/ios/NativeListGeneratedIcons.swift +55 -0
- package/ios/NativeListIconBinding.swift +171 -0
- package/ios/NativeListIdentityRenderer.swift +256 -39
- package/ios/NativeListLeadingVisual.swift +127 -28
- package/ios/NativeListMarketRenderer.swift +120 -31
- package/ios/NativeListMediaPlaceholderView.swift +189 -0
- package/ios/NativeListMediaPreviewSlot.swift +122 -61
- package/ios/NativeListMediaTileRenderer.swift +15 -11
- package/ios/NativeListMessageRenderer.swift +34 -1
- package/ios/NativeListMetricCardRenderer.swift +4 -2
- package/ios/NativeListModels.swift +42 -2
- package/ios/NativeListRendererRegistry.swift +1 -0
- package/ios/NativeListResolvedText.swift +17 -5
- package/ios/NativeListRowHost.swift +14 -0
- package/ios/NativeListSectionHeaderRenderer.swift +100 -4
- package/ios/NativeListTextLabel.swift +106 -0
- package/ios/RNCNativeListView.swift +1097 -60
- package/ios/tests/NativeListAccessoryStackTests.swift +101 -0
- package/ios/tests/NativeListAccountSelectorLayoutTests.swift +96 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +423 -0
- package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
- package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
- package/ios/tests/NativeListLifecycleTests.swift +2959 -4
- package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
- package/ios/tests/NativeListMediaVisibilityTests.swift +27 -1
- package/ios/tests/NativeListSharedIconTests.swift +236 -0
- package/lib/module/NativeList.js +236 -38
- package/lib/module/NativeList.web.js +163 -45
- package/lib/module/index.js +1 -1
- package/lib/module/models.js +3 -0
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +1263 -48
- package/lib/module/web/NativeListGeneratedIcons.js +31 -0
- package/lib/module/web/NativeListWebEngine.js +513 -275
- package/lib/module/web/templates/ActivityRowRenderer.js +41 -54
- package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
- package/lib/module/web/templates/DataRowRenderer.js +56 -5
- package/lib/module/web/templates/IdentityRowRenderer.js +161 -7
- package/lib/module/web/templates/MarketTableRowRenderer.js +36 -19
- package/lib/module/web/templates/MediaTileRowRenderer.js +84 -25
- 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 +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 +20 -2
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/models.d.ts +134 -17
- package/lib/typescript/src/validation.d.ts +20 -0
- package/lib/typescript/src/web/NativeListGeneratedIcons.d.ts +2 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +32 -1
- 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 +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 +16 -10
- package/react-native-native-list.podspec +2 -6
- package/scripts/generate-icons.mjs +150 -0
- package/scripts/generate-icons.test.mjs +288 -0
- package/scripts/native-list-icons.json +260 -0
- package/src/NativeList.nitro.ts +2 -0
- package/src/NativeList.tsx +439 -91
- package/src/NativeList.types.ts +24 -2
- package/src/NativeList.web.tsx +286 -88
- package/src/index.ts +2 -0
- package/src/models.ts +272 -144
- package/src/selection.ts +1 -0
- package/src/validation.ts +3041 -146
- package/src/web/NativeListGeneratedIcons.ts +28 -0
- package/src/web/NativeListWebEngine.ts +818 -343
- package/src/web/templates/ActivityRowRenderer.ts +71 -91
- package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
- package/src/web/templates/DataRowRenderer.ts +121 -20
- package/src/web/templates/IdentityRowRenderer.ts +234 -9
- package/src/web/templates/MarketTableRowRenderer.ts +53 -33
- package/src/web/templates/MediaTileRowRenderer.ts +90 -28
- 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
- package/ios/Resources/NativeListIcons.xcassets/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/icon.svg +0 -14
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/icon.svg +0 -12
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/icon.svg +0 -6
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/icon.svg +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/icon.svg +0 -3
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/icon.svg +0 -7
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/icon.svg +0 -18
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/icon.svg +0 -7
- package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/icon.svg +0 -1
|
@@ -70,8 +70,10 @@ final class NativeListActivityDetailsView: UIStackView {
|
|
|
70
70
|
let verticalPadding = CGFloat(style.double("verticalPadding", default: 8))
|
|
71
71
|
let lineGap = CGFloat(style.double("lineGap"))
|
|
72
72
|
let gap = CGFloat(style.double("leadingGap", default: 12))
|
|
73
|
+
let hideLeading = data.bool("hideLeading")
|
|
73
74
|
let imageWidth = CGFloat(image.double("width", default: 40))
|
|
74
75
|
let imageHeight = CGFloat(image.double("height", default: 40))
|
|
76
|
+
let leadingWidth = hideLeading ? 0 : imageWidth + gap
|
|
75
77
|
let mainWidth = max(0, width - horizontalPadding * 2)
|
|
76
78
|
|
|
77
79
|
let amounts = data.dictionaries("amounts").map { amount -> (width: CGFloat, height: CGFloat) in
|
|
@@ -112,10 +114,11 @@ final class NativeListActivityDetailsView: UIStackView {
|
|
|
112
114
|
let feeColumn = data.dictionary("fee") == nil ? 0 : gap + feeWidth
|
|
113
115
|
let identityWidth: CGFloat
|
|
114
116
|
if table {
|
|
115
|
-
let
|
|
116
|
-
|
|
117
|
+
let hasFee = data.dictionary("fee") != nil
|
|
118
|
+
let columnWidth = max(0, mainWidth - gap * (hasFee ? 2 : 1)) / (hasFee ? 2.6 : 2)
|
|
119
|
+
identityWidth = columnWidth - leadingWidth
|
|
117
120
|
} else {
|
|
118
|
-
identityWidth = mainWidth -
|
|
121
|
+
identityWidth = mainWidth - leadingWidth - gap - feeColumn - min(amountsWidth, mainWidth * 0.5)
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
let title = NativeListResolvedText(data.string("title"), style: style.dictionary("title"), size: 16,
|
|
@@ -140,7 +143,7 @@ final class NativeListActivityDetailsView: UIStackView {
|
|
|
140
143
|
return max(height, ceil(sizingButton.intrinsicContentSize.height))
|
|
141
144
|
} + 8
|
|
142
145
|
}
|
|
143
|
-
return max(imageHeight, identityHeight, amountsHeight, feeHeight) + actionsHeight + verticalPadding * 2
|
|
146
|
+
return max(hideLeading ? 0 : imageHeight, identityHeight, amountsHeight, feeHeight) + actionsHeight + verticalPadding * 2
|
|
144
147
|
}
|
|
145
148
|
|
|
146
149
|
func bind(_ item: NativeListItem, theme: [String: Any]?, fonts: NativeListFontFamilies) {
|
|
@@ -150,35 +153,58 @@ final class NativeListActivityDetailsView: UIStackView {
|
|
|
150
153
|
let image = style.dictionary("image") ?? [:]
|
|
151
154
|
let table = data.string("presentation") == "table"
|
|
152
155
|
let gap = CGFloat(style.double("leadingGap", default: 12))
|
|
156
|
+
let hideLeading = data.bool("hideLeading")
|
|
153
157
|
main.spacing = gap
|
|
154
158
|
identity.spacing = CGFloat(style.double("lineGap"))
|
|
155
159
|
amounts.spacing = CGFloat(style.double("trailingGap", default: 2))
|
|
156
160
|
titleLine.spacing = CGFloat(style.double("titleBadgeGap", default: 4))
|
|
157
161
|
NSLayoutConstraint.deactivate(dimensions)
|
|
162
|
+
let visualWidth = visual.widthAnchor.constraint(equalToConstant: CGFloat(image.double("width", default: 40)))
|
|
163
|
+
if hideLeading { visualWidth.priority = UILayoutPriority(999) }
|
|
158
164
|
dimensions = [
|
|
159
|
-
|
|
165
|
+
visualWidth,
|
|
160
166
|
visual.heightAnchor.constraint(equalToConstant: CGFloat(image.double("height", default: 40))),
|
|
161
|
-
amounts.widthAnchor.constraint(lessThanOrEqualTo: main.widthAnchor, multiplier: table ? 0.42 : 0.5),
|
|
162
167
|
]
|
|
163
|
-
if table {
|
|
168
|
+
if table {
|
|
169
|
+
// The leading visual belongs to identity, so its visibility cannot shift amounts.
|
|
170
|
+
let leadingWidth = hideLeading ? 0 : CGFloat(image.double("width", default: 40)) + gap
|
|
171
|
+
dimensions.append(amounts.widthAnchor.constraint(equalTo: identity.widthAnchor, constant: leadingWidth))
|
|
172
|
+
if data.dictionary("fee") != nil {
|
|
173
|
+
dimensions.append(fee.widthAnchor.constraint(equalTo: amounts.widthAnchor, multiplier: 0.6))
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
dimensions.append(amounts.widthAnchor.constraint(lessThanOrEqualTo: main.widthAnchor, multiplier: 0.5))
|
|
177
|
+
}
|
|
164
178
|
NSLayoutConstraint.activate(dimensions)
|
|
165
|
-
visual.
|
|
166
|
-
|
|
179
|
+
visual.isHidden = hideLeading
|
|
180
|
+
if hideLeading {
|
|
181
|
+
visual.recycle()
|
|
182
|
+
} else {
|
|
183
|
+
visual.bind(data.dictionary("leading") ?? [:], style: image, key: item.key, theme: theme,
|
|
184
|
+
isUnread: false, secondaryVisual: data.dictionary("secondaryLeading"), fonts: fonts)
|
|
185
|
+
}
|
|
167
186
|
NativeListResolvedText(data.string("title"), style: style.dictionary("title"), size: 16,
|
|
168
187
|
weight: .medium, color: nativeListColor(theme, "primaryText", "#202020"), lineHeight: 24,
|
|
169
188
|
lines: 1, fonts: fonts
|
|
170
189
|
).bind(title)
|
|
171
|
-
NativeListResolvedText(data.string("description"), style: style.dictionary("description"), size: 14,
|
|
190
|
+
let descriptionText = NativeListResolvedText(data.string("description"), style: style.dictionary("description"), size: 14,
|
|
172
191
|
color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 20, lines: 2,
|
|
173
|
-
fonts: fonts
|
|
174
|
-
|
|
192
|
+
fonts: fonts)
|
|
193
|
+
descriptionText.bind(descriptionLabel)
|
|
175
194
|
NativeListResolvedText(data.string("status"), style: style.dictionary("status"), size: 12,
|
|
176
195
|
color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 16, lines: 1,
|
|
177
196
|
fonts: fonts
|
|
178
197
|
).bind(status)
|
|
179
198
|
descriptionKey = data.string("descriptionActionKey")
|
|
180
|
-
|
|
181
|
-
|
|
199
|
+
// The label spans the identity column, so with an action only its text
|
|
200
|
+
// from the caller's `descriptionActionStart` on takes touches. The start is
|
|
201
|
+
// never read out of the string, and one at the end leaves no action.
|
|
202
|
+
let actionStart = descriptionKey.isEmpty
|
|
203
|
+
? nil : descriptionText.displayOffset(data.int("descriptionActionStart"), in: data.string("description"))
|
|
204
|
+
let hasActionText = actionStart.map { $0 < (descriptionText.text as NSString).length } ?? false
|
|
205
|
+
descriptionLabel.touchableTextStart = actionStart
|
|
206
|
+
descriptionLabel.isUserInteractionEnabled = hasActionText
|
|
207
|
+
descriptionLabel.accessibilityTraits = hasActionText ? .button : .staticText
|
|
182
208
|
for badge in badgeViews { titleLine.removeArrangedSubview(badge); badge.removeFromSuperview() }
|
|
183
209
|
badgeViews = data.dictionaries("badges").map { descriptor in
|
|
184
210
|
let label = NativeListTextLabel()
|
|
@@ -225,7 +251,7 @@ final class NativeListActivityDetailsView: UIStackView {
|
|
|
225
251
|
let actionData = data.dictionaries("footerActions")
|
|
226
252
|
actionKeys = actionData.map { $0.string("key") }
|
|
227
253
|
actions.isHidden = actionData.isEmpty
|
|
228
|
-
actions.directionalLayoutMargins = NSDirectionalEdgeInsets(top: 0, leading: CGFloat(image.double("width", default: 40)) + gap, bottom: 0, trailing: 0)
|
|
254
|
+
actions.directionalLayoutMargins = NSDirectionalEdgeInsets(top: 0, leading: hideLeading ? 0 : CGFloat(image.double("width", default: 40)) + gap, bottom: 0, trailing: 0)
|
|
229
255
|
for (index, descriptor) in actionData.enumerated() {
|
|
230
256
|
let button = UIButton(type: .system); button.tag = index
|
|
231
257
|
button.setTitle(descriptor.string("label"), for: .normal)
|
|
@@ -249,7 +275,8 @@ final class NativeListActivityDetailsView: UIStackView {
|
|
|
249
275
|
onAction?(actionKeys[button.tag], button, "footerAction", button.tag)
|
|
250
276
|
}
|
|
251
277
|
func recycle() {
|
|
252
|
-
visual.recycle(); amountViews.forEach { $0.recycle() }; actionKeys = []; descriptionKey = ""
|
|
278
|
+
visual.recycle(); visual.isHidden = false; amountViews.forEach { $0.recycle() }; actionKeys = []; descriptionKey = ""
|
|
279
|
+
descriptionLabel.touchableTextStart = nil
|
|
253
280
|
}
|
|
254
281
|
}
|
|
255
282
|
|
|
@@ -97,6 +97,7 @@ final class NativeListActivityCell: NativeListRendererCell {
|
|
|
97
97
|
details.recycle()
|
|
98
98
|
let style = data.dictionary("style") ?? [:]
|
|
99
99
|
let image = style.dictionary("image") ?? [:]
|
|
100
|
+
let hideLeading = data.bool("hideLeading")
|
|
100
101
|
root.spacing = 12
|
|
101
102
|
root.setCustomSpacing(CGFloat(style.double("leadingGap", default: 12)), after: visual)
|
|
102
103
|
switch style.dictionary("container")?.string("contentVerticalAlignment") {
|
|
@@ -113,12 +114,17 @@ final class NativeListActivityCell: NativeListRendererCell {
|
|
|
113
114
|
bottom: CGFloat(style.double("verticalPadding", default: 8)),
|
|
114
115
|
right: CGFloat(style.double("horizontalPadding", default: layout == "table" ? 16 : 12)))
|
|
115
116
|
NSLayoutConstraint.deactivate(dimensions)
|
|
117
|
+
let visualWidth = visual.widthAnchor.constraint(equalToConstant: CGFloat(image.double("width", default: 40)))
|
|
118
|
+
if hideLeading { visualWidth.priority = UILayoutPriority(999) }
|
|
116
119
|
dimensions = [
|
|
117
|
-
|
|
120
|
+
visualWidth,
|
|
118
121
|
visual.heightAnchor.constraint(equalToConstant: CGFloat(image.double("height", default: 40))),
|
|
119
122
|
]
|
|
120
123
|
NSLayoutConstraint.activate(dimensions)
|
|
121
|
-
|
|
124
|
+
visual.isHidden = hideLeading
|
|
125
|
+
if hideLeading {
|
|
126
|
+
visual.recycle()
|
|
127
|
+
} else if let leading = data.dictionary("leading") {
|
|
122
128
|
visual.bind(
|
|
123
129
|
leading, style: image, key: item.key, theme: theme, isUnread: false,
|
|
124
130
|
secondaryVisual: data.dictionary("secondaryLeading"), fonts: fonts)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
final class NativeListButtonGroupCell: NativeListRendererCell {
|
|
4
|
+
override class func measure(
|
|
5
|
+
_ item: NativeListItem, width: CGFloat, theme: [String: Any]?, layout: String,
|
|
6
|
+
fonts: NativeListFontFamilies
|
|
7
|
+
) -> CGFloat? { 64 }
|
|
8
|
+
|
|
9
|
+
private var buttons: [UIButton] = []
|
|
10
|
+
private var actionKeys: [String] = []
|
|
11
|
+
private var rowOpacity: CGFloat = 1
|
|
12
|
+
|
|
13
|
+
override func applyAppearance() {
|
|
14
|
+
super.applyAppearance()
|
|
15
|
+
contentView.alpha = rowOpacity
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override init(frame: CGRect) {
|
|
19
|
+
super.init(frame: frame)
|
|
20
|
+
root.axis = .horizontal
|
|
21
|
+
root.alignment = .fill
|
|
22
|
+
root.distribution = .fillEqually
|
|
23
|
+
root.spacing = 10
|
|
24
|
+
}
|
|
25
|
+
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
|
26
|
+
|
|
27
|
+
override func bindContent(
|
|
28
|
+
_ item: NativeListItem, theme: [String: Any]?, layout: String,
|
|
29
|
+
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
|
|
30
|
+
) {
|
|
31
|
+
recycleContent()
|
|
32
|
+
rowOpacity = CGFloat(item.data.dictionary("style")?.dictionary("container")?.double("opacity", default: item.data.double("opacity", default: 1)) ?? item.data.double("opacity", default: 1))
|
|
33
|
+
contentInsets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
|
|
34
|
+
let info = nativeListColor(theme, "info", "#0F69F6")
|
|
35
|
+
for (index, descriptor) in item.data.dictionaries("buttons").enumerated() {
|
|
36
|
+
let button = NativeListAccessoryButton(type: .custom)
|
|
37
|
+
button.tag = index
|
|
38
|
+
button.setTitle(descriptor.string("label"), for: .normal)
|
|
39
|
+
button.titleLabel?.font = nativeListFont(ofSize: 14, weight: .medium, fonts: fonts)
|
|
40
|
+
button.titleLabel?.lineBreakMode = .byTruncatingTail
|
|
41
|
+
button.setTitleColor(info, for: .normal)
|
|
42
|
+
button.contentEdgeInsets = UIEdgeInsets(top: 12, left: 8, bottom: 12, right: 8)
|
|
43
|
+
button.layer.cornerRadius = 12
|
|
44
|
+
button.layer.borderWidth = 1
|
|
45
|
+
button.layer.borderColor = info.withAlphaComponent(0.35).cgColor
|
|
46
|
+
button.normalBackgroundColor = .clear
|
|
47
|
+
button.pressedBackgroundColor = info.withAlphaComponent(0.17)
|
|
48
|
+
button.isEnabled = !item.data.bool("disabled") && !descriptor.bool("disabled") && !descriptor.bool("loading")
|
|
49
|
+
button.alpha = button.isEnabled ? 1 : 0.4
|
|
50
|
+
button.accessibilityIdentifier = descriptor["testID"] as? String
|
|
51
|
+
button.accessibilityLabel = descriptor.string("accessibilityLabel", default: descriptor.string("label"))
|
|
52
|
+
button.addTarget(self, action: #selector(pressed(_:)), for: .touchUpInside)
|
|
53
|
+
if descriptor.bool("loading"), let titleLabel = button.titleLabel {
|
|
54
|
+
let spinner = UIActivityIndicatorView(style: .medium)
|
|
55
|
+
spinner.color = info
|
|
56
|
+
spinner.isUserInteractionEnabled = false
|
|
57
|
+
spinner.translatesAutoresizingMaskIntoConstraints = false
|
|
58
|
+
button.addSubview(spinner)
|
|
59
|
+
button.contentEdgeInsets = UIEdgeInsets(top: 12, left: 36, bottom: 12, right: 8)
|
|
60
|
+
NSLayoutConstraint.activate([
|
|
61
|
+
spinner.trailingAnchor.constraint(equalTo: titleLabel.leadingAnchor, constant: -8),
|
|
62
|
+
spinner.centerYAnchor.constraint(equalTo: button.centerYAnchor),
|
|
63
|
+
spinner.widthAnchor.constraint(equalToConstant: 20),
|
|
64
|
+
spinner.heightAnchor.constraint(equalToConstant: 20),
|
|
65
|
+
])
|
|
66
|
+
spinner.startAnimating()
|
|
67
|
+
}
|
|
68
|
+
buttons.append(button)
|
|
69
|
+
actionKeys.append(descriptor.string("actionKey"))
|
|
70
|
+
root.addArrangedSubview(button)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@objc private func pressed(_ button: UIButton) {
|
|
75
|
+
guard button.isEnabled, buttons.indices.contains(button.tag), buttons[button.tag] === button else { return }
|
|
76
|
+
emitAction(actionKeys[button.tag], from: button, source: "buttonGroup", slot: button.tag)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
override func recycleContent() {
|
|
80
|
+
for button in buttons {
|
|
81
|
+
button.removeTarget(self, action: nil, for: .allEvents)
|
|
82
|
+
button.subviews.compactMap { $0 as? UIActivityIndicatorView }.forEach { $0.stopAnimating() }
|
|
83
|
+
root.removeArrangedSubview(button)
|
|
84
|
+
button.removeFromSuperview()
|
|
85
|
+
}
|
|
86
|
+
buttons.removeAll()
|
|
87
|
+
actionKeys.removeAll()
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -6,17 +6,21 @@ 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
|
}
|
|
13
13
|
|
|
14
14
|
private let visual = NativeListLeadingVisual()
|
|
15
|
-
private let favorite =
|
|
15
|
+
private let favorite = NativeListIconImageView()
|
|
16
16
|
private let accessories = NativeListAccessoryStack()
|
|
17
|
+
private let trailingAccessories = NativeListAccessoryStack()
|
|
17
18
|
private let columns = UIStackView()
|
|
18
19
|
private let cells = (0..<4).map { _ in NativeListTableColumnView() }
|
|
19
20
|
private var rowConstraints: [NSLayoutConstraint] = []
|
|
21
|
+
private var trailingWidthConstraint: NSLayoutConstraint?
|
|
22
|
+
private var columnWidthConstraints: [NSLayoutConstraint] = []
|
|
23
|
+
private var columnWeights: [Int]?
|
|
20
24
|
override func unselectedBackground(
|
|
21
25
|
_ item: NativeListItem, theme: [String: Any]?, layout: String, itemIndex: Int?
|
|
22
26
|
) -> UIColor {
|
|
@@ -34,16 +38,22 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
34
38
|
columns.alignment = .center
|
|
35
39
|
columns.spacing = 8
|
|
36
40
|
cells.forEach(columns.addArrangedSubview)
|
|
37
|
-
[favorite, visual, accessories, columns].forEach(root.addArrangedSubview)
|
|
41
|
+
[favorite, visual, accessories, columns, trailingAccessories].forEach(root.addArrangedSubview)
|
|
38
42
|
accessories.onAction = { [weak self] key, view, slot, target in
|
|
39
43
|
self?.emitAction(key, from: view, source: "trailingAccessory", slot: slot, target: target)
|
|
40
44
|
}
|
|
45
|
+
trailingAccessories.onAction = { [weak self] key, view, slot, target in
|
|
46
|
+
self?.emitAction(key, from: view, source: "trailingAccessory", slot: slot, target: target)
|
|
47
|
+
}
|
|
41
48
|
}
|
|
42
49
|
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
|
43
50
|
override func bindContent(
|
|
44
51
|
_ item: NativeListItem, theme: [String: Any]?, layout: String,
|
|
45
52
|
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
|
|
46
53
|
) {
|
|
54
|
+
let iconUpdate = NativeListIconUpdate(self)
|
|
55
|
+
defer { iconUpdate.finish() }
|
|
56
|
+
|
|
47
57
|
let data = item.data
|
|
48
58
|
let style = data.dictionary("style") ?? [:]
|
|
49
59
|
let image = style.dictionary("image") ?? [:]
|
|
@@ -57,8 +67,7 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
57
67
|
let vp = CGFloat(style.double("verticalPadding", default: layout == "table" ? 10 : 8))
|
|
58
68
|
contentInsets = UIEdgeInsets(top: vp, left: hp, bottom: vp, right: hp)
|
|
59
69
|
favorite.isHidden = !data.bool("favorite") && !data.bool("favoriteActive")
|
|
60
|
-
favorite.
|
|
61
|
-
named: data.bool("favoriteActive") ? "StarSolid" : "StarOutline")
|
|
70
|
+
favorite.bindIcon(data.bool("favoriteActive") ? "StarSolid" : "StarOutline")
|
|
62
71
|
favorite.tintColor = nativeListColor(
|
|
63
72
|
theme, data.bool("favoriteActive") ? "icon" : "iconSubdued",
|
|
64
73
|
data.bool("favoriteActive") ? "#646464" : "#8D8D8D")
|
|
@@ -86,16 +95,55 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
86
95
|
item, descriptors: descriptors, theme: theme, style: accessoryStyle,
|
|
87
96
|
checkboxState: checkboxState, fonts: fonts)
|
|
88
97
|
accessories.isHidden = descriptors.isEmpty
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
let trailing = data.dictionaries("trailing")
|
|
99
|
+
trailingAccessories.bind(
|
|
100
|
+
item, descriptors: trailing, theme: theme, style: style,
|
|
101
|
+
checkboxState: checkboxState, fonts: fonts)
|
|
102
|
+
trailingAccessories.isHidden = trailing.isEmpty
|
|
103
|
+
if rowConstraints.isEmpty {
|
|
104
|
+
rowConstraints = [
|
|
105
|
+
favorite.widthAnchor.constraint(equalToConstant: 20),
|
|
106
|
+
favorite.heightAnchor.constraint(equalToConstant: 20),
|
|
107
|
+
visual.widthAnchor.constraint(equalToConstant: 40),
|
|
108
|
+
visual.heightAnchor.constraint(equalToConstant: 40),
|
|
109
|
+
]
|
|
110
|
+
NSLayoutConstraint.activate(rowConstraints)
|
|
111
|
+
}
|
|
112
|
+
let visualWidth = CGFloat(image.double("width", default: 40))
|
|
113
|
+
let visualHeight = CGFloat(image.double("height", default: 40))
|
|
114
|
+
if rowConstraints[2].constant != visualWidth { rowConstraints[2].constant = visualWidth }
|
|
115
|
+
if rowConstraints[3].constant != visualHeight { rowConstraints[3].constant = visualHeight }
|
|
116
|
+
if !trailing.isEmpty {
|
|
117
|
+
// UIStackView has no intrinsic width of its own. Reserve the controls' fitted
|
|
118
|
+
// width so extra space goes to the weighted columns instead of this stack.
|
|
119
|
+
if trailingWidthConstraint == nil {
|
|
120
|
+
trailingWidthConstraint = trailingAccessories.widthAnchor.constraint(equalToConstant: 0)
|
|
121
|
+
}
|
|
122
|
+
if trailingWidthConstraint?.isActive == true { trailingWidthConstraint?.isActive = false }
|
|
123
|
+
let trailingWidth =
|
|
124
|
+
trailingAccessories.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).width
|
|
125
|
+
if trailingWidthConstraint?.constant != trailingWidth {
|
|
126
|
+
trailingWidthConstraint?.constant = trailingWidth
|
|
127
|
+
}
|
|
128
|
+
trailingWidthConstraint?.isActive = true
|
|
129
|
+
} else {
|
|
130
|
+
if trailingWidthConstraint?.isActive == true { trailingWidthConstraint?.isActive = false }
|
|
131
|
+
}
|
|
96
132
|
let values = Array(data.dictionaries("columns").prefix(4))
|
|
133
|
+
let weights = values.map { max(1, $0.int("weight", default: 1)) }
|
|
134
|
+
var divisor = weights.first ?? 1
|
|
135
|
+
for weight in weights.dropFirst() {
|
|
136
|
+
var a = divisor
|
|
137
|
+
var b = weight
|
|
138
|
+
while b != 0 { (a, b) = (b, a % b) }
|
|
139
|
+
divisor = a
|
|
140
|
+
}
|
|
141
|
+
let normalizedWeights = weights.map { $0 / divisor }
|
|
142
|
+
let columnsChanged = columnWeights != normalizedWeights
|
|
143
|
+
if columnsChanged { NSLayoutConstraint.deactivate(columnWidthConstraints) }
|
|
97
144
|
for (index, cell) in cells.enumerated() {
|
|
98
|
-
|
|
145
|
+
let hidden = index >= values.count
|
|
146
|
+
if cell.isHidden != hidden { cell.isHidden = hidden }
|
|
99
147
|
guard index < values.count else {
|
|
100
148
|
cell.reset()
|
|
101
149
|
continue
|
|
@@ -109,23 +157,34 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
109
157
|
cell.applyStyle(style) { label, style in
|
|
110
158
|
NativeListTextStyles.applyStyledText(label, style, fonts: fonts)
|
|
111
159
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
160
|
+
cell.applySegments(values[index])
|
|
161
|
+
cell.bindTitleIcons(values[index], theme: theme)
|
|
162
|
+
}
|
|
163
|
+
if columnsChanged {
|
|
164
|
+
columnWidthConstraints = values.count > 1 ? (1..<values.count).map { index in
|
|
165
|
+
cells[index].widthAnchor.constraint(equalTo: cells[0].widthAnchor,
|
|
166
|
+
multiplier: CGFloat(weights[index]) / CGFloat(weights[0]))
|
|
167
|
+
} : []
|
|
168
|
+
NSLayoutConstraint.activate(columnWidthConstraints)
|
|
169
|
+
columnWeights = normalizedWeights
|
|
119
170
|
}
|
|
120
|
-
|
|
171
|
+
|
|
121
172
|
}
|
|
122
173
|
override func bindSelectionContent(
|
|
123
174
|
_ item: NativeListItem,
|
|
124
175
|
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
|
|
125
|
-
) {
|
|
176
|
+
) {
|
|
177
|
+
let iconUpdate = NativeListIconUpdate(self)
|
|
178
|
+
defer { iconUpdate.finish() }
|
|
179
|
+
|
|
180
|
+
accessories.updateSelection(item, checkboxState: checkboxState)
|
|
181
|
+
trailingAccessories.updateSelection(item, checkboxState: checkboxState)
|
|
182
|
+
|
|
183
|
+
}
|
|
126
184
|
override func recycleContent() {
|
|
127
185
|
visual.recycle()
|
|
128
186
|
accessories.reset()
|
|
187
|
+
trailingAccessories.reset()
|
|
129
188
|
cells.forEach { $0.reset() }
|
|
130
189
|
}
|
|
131
190
|
}
|
|
@@ -133,6 +192,8 @@ final class NativeListDataRowCell: NativeListRendererCell {
|
|
|
133
192
|
private final class NativeListTableColumnView: UIStackView {
|
|
134
193
|
private let primaryLine = UIStackView()
|
|
135
194
|
private let primaryLabel = NativeListTextLabel()
|
|
195
|
+
private let titleIconView = NativeListIconImageView()
|
|
196
|
+
private let secondaryTitleIconView = NativeListIconImageView()
|
|
136
197
|
private let badgesStack = UIStackView()
|
|
137
198
|
private let secondaryLine = UIStackView()
|
|
138
199
|
private let secondaryLeadingLabel = NativeListTextLabel()
|
|
@@ -152,11 +213,21 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
152
213
|
primaryLabel.numberOfLines = 1
|
|
153
214
|
primaryLabel.lineBreakMode = .byTruncatingTail
|
|
154
215
|
primaryLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
|
216
|
+
for icon in [titleIconView, secondaryTitleIconView] {
|
|
217
|
+
icon.contentMode = .scaleAspectFit
|
|
218
|
+
icon.translatesAutoresizingMaskIntoConstraints = false
|
|
219
|
+
icon.widthAnchor.constraint(equalToConstant: 20).isActive = true
|
|
220
|
+
icon.heightAnchor.constraint(equalToConstant: 20).isActive = true
|
|
221
|
+
icon.setContentHuggingPriority(.required, for: .horizontal)
|
|
222
|
+
icon.isHidden = true
|
|
223
|
+
}
|
|
155
224
|
badgesStack.axis = .horizontal
|
|
156
225
|
badgesStack.alignment = .center
|
|
157
226
|
badgesStack.spacing = 4
|
|
158
227
|
badgesStack.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
159
228
|
primaryLine.addArrangedSubview(primaryLabel)
|
|
229
|
+
primaryLine.addArrangedSubview(titleIconView)
|
|
230
|
+
primaryLine.addArrangedSubview(secondaryTitleIconView)
|
|
160
231
|
primaryLine.addArrangedSubview(badgesStack)
|
|
161
232
|
|
|
162
233
|
secondaryLine.axis = .horizontal
|
|
@@ -178,8 +249,17 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
178
249
|
fatalError("init(coder:) has not been implemented")
|
|
179
250
|
}
|
|
180
251
|
|
|
181
|
-
func reset() {
|
|
252
|
+
func reset(clearPrimaryText: Bool = true) {
|
|
182
253
|
linear = false
|
|
254
|
+
primaryLine.alignment = .center
|
|
255
|
+
for icon in [titleIconView, secondaryTitleIconView] {
|
|
256
|
+
icon.image = nil
|
|
257
|
+
icon.isHidden = true
|
|
258
|
+
icon.accessibilityLabel = nil
|
|
259
|
+
icon.isAccessibilityElement = false
|
|
260
|
+
}
|
|
261
|
+
primaryLine.setCustomSpacing(UIStackView.spacingUseDefault, after: primaryLabel)
|
|
262
|
+
primaryLine.setCustomSpacing(UIStackView.spacingUseDefault, after: titleIconView)
|
|
183
263
|
for label in [primaryLabel, secondaryLeadingLabel, secondaryLabel] {
|
|
184
264
|
label.rowVerticalAlignment = nil
|
|
185
265
|
label.rowOffsetY = 0
|
|
@@ -190,7 +270,7 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
190
270
|
primaryLabel.numberOfLines = 1
|
|
191
271
|
secondaryLeadingLabel.numberOfLines = 1
|
|
192
272
|
secondaryLabel.numberOfLines = 1
|
|
193
|
-
primaryLabel.attributedText = nil
|
|
273
|
+
if clearPrimaryText { primaryLabel.attributedText = nil }
|
|
194
274
|
secondaryLeadingLabel.attributedText = nil
|
|
195
275
|
secondaryLabel.attributedText = nil
|
|
196
276
|
secondaryLeadingLabel.isHidden = true
|
|
@@ -202,12 +282,36 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
202
282
|
}
|
|
203
283
|
}
|
|
204
284
|
|
|
285
|
+
func bindTitleIcons(_ column: [String: Any], theme: [String: Any]?) {
|
|
286
|
+
let descriptors = [column.dictionary("titleIcon"), column.dictionary("secondaryTitleIcon")]
|
|
287
|
+
for (index, descriptor) in descriptors.enumerated() {
|
|
288
|
+
guard let descriptor else { continue }
|
|
289
|
+
let icon = index == 0 ? titleIconView : secondaryTitleIconView
|
|
290
|
+
icon.bindIcon(descriptor.string("name"))
|
|
291
|
+
icon.tintColor = UIColor(
|
|
292
|
+
nativeListHex: descriptor.string("tintColor",
|
|
293
|
+
default: theme?["iconSubdued"] as? String ?? "#8D8D8D"),
|
|
294
|
+
fallback: .gray)
|
|
295
|
+
icon.isHidden = false
|
|
296
|
+
let label = descriptor.string("accessibilityLabel")
|
|
297
|
+
icon.accessibilityLabel = label.isEmpty ? nil : label
|
|
298
|
+
icon.isAccessibilityElement = !label.isEmpty
|
|
299
|
+
}
|
|
300
|
+
if descriptors.contains(where: { $0 != nil }) {
|
|
301
|
+
primaryLine.setCustomSpacing(4, after: primaryLabel)
|
|
302
|
+
primaryLine.setCustomSpacing(4, after: titleIconView)
|
|
303
|
+
if linear { primaryLine.alignment = .top }
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
205
307
|
func bind(
|
|
206
308
|
column: [String: Any],
|
|
207
309
|
badges: [[String: Any]],
|
|
208
310
|
theme: [String: Any]?,
|
|
209
311
|
fonts: NativeListFontFamilies
|
|
210
312
|
) {
|
|
313
|
+
let iconUpdate = NativeListIconUpdate(self)
|
|
314
|
+
defer { iconUpdate.finish() }
|
|
211
315
|
reset()
|
|
212
316
|
let textAlignment: NSTextAlignment
|
|
213
317
|
switch column.string("alignment") {
|
|
@@ -228,7 +332,7 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
228
332
|
secondaryLeadingLabel.font = nativeListFont(ofSize: 12, fonts: fonts)
|
|
229
333
|
secondaryLabel.font = nativeListFont(ofSize: 12, fonts: fonts)
|
|
230
334
|
primaryLabel.attributedText = line(
|
|
231
|
-
column
|
|
335
|
+
nativeListDataColumnText(column, "text"),
|
|
232
336
|
font: nativeListFont(ofSize: 14, weight: .medium, fonts: fonts),
|
|
233
337
|
color: textColor(column.string("tone"), theme: theme),
|
|
234
338
|
height: 20
|
|
@@ -261,7 +365,7 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
261
365
|
secondaryLeadingLabel.isHidden = false
|
|
262
366
|
secondaryLine.isHidden = false
|
|
263
367
|
}
|
|
264
|
-
let secondary = column
|
|
368
|
+
let secondary = nativeListDataColumnText(column, "secondaryText")
|
|
265
369
|
if !secondary.isEmpty {
|
|
266
370
|
secondaryLabel.attributedText = line(
|
|
267
371
|
secondary,
|
|
@@ -286,7 +390,7 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
286
390
|
column: [String: Any], badges: [[String: Any]], theme: [String: Any]?,
|
|
287
391
|
style: [String: Any] = [:], fonts: NativeListFontFamilies
|
|
288
392
|
) {
|
|
289
|
-
reset()
|
|
393
|
+
reset(clearPrimaryText: !linear)
|
|
290
394
|
linear = true
|
|
291
395
|
alignment = .fill
|
|
292
396
|
badgesStack.isHidden = true
|
|
@@ -331,14 +435,15 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
331
435
|
primaryLabel.textAlignment =
|
|
332
436
|
column.string("alignment") == "end"
|
|
333
437
|
? .right : column.string("alignment") == "center" ? .center : .left
|
|
334
|
-
let secondary = column
|
|
438
|
+
let secondary = nativeListDataColumnText(column, "secondaryText")
|
|
335
439
|
let primaryFont = font(primaryStyle, size: 14, weight: .medium)
|
|
336
440
|
let attributed = NSMutableAttributedString(
|
|
337
|
-
string: column
|
|
441
|
+
string: nativeListDataColumnText(column, "text"),
|
|
338
442
|
attributes: [
|
|
339
443
|
.font: primaryFont,
|
|
340
444
|
.foregroundColor: color(primaryStyle, textColor(column.string("tone"), theme: theme)),
|
|
341
445
|
])
|
|
446
|
+
attributed.setAttributedString(nativeListDataSegments(attributed, column.dictionaries("textSegments")))
|
|
342
447
|
let primaryLength = attributed.length
|
|
343
448
|
// Every badge run is the legacy " text " pill: both lead spaces sit inside the badge
|
|
344
449
|
// background and are its left padding. `titleBadgeGap` adds an exact, unfilled gap between
|
|
@@ -378,7 +483,10 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
378
483
|
textColor(column.string("secondaryTone", default: "secondary"), theme: theme)),
|
|
379
484
|
]
|
|
380
485
|
attributes.merge(paragraph(secondaryStyle, font: secondaryFont, spacing: nil)) { $1 }
|
|
381
|
-
attributed.append(NSAttributedString(string: "\n
|
|
486
|
+
attributed.append(NSAttributedString(string: "\n", attributes: attributes))
|
|
487
|
+
attributed.append(nativeListDataSegments(
|
|
488
|
+
NSAttributedString(string: secondary, attributes: attributes),
|
|
489
|
+
column.dictionaries("secondaryTextSegments")))
|
|
382
490
|
lines = min(3, lines + max(1, secondaryStyle.int("lines", default: 1)))
|
|
383
491
|
}
|
|
384
492
|
primaryLabel.font = nativeListFont(ofSize: 12, fonts: fonts)
|
|
@@ -400,6 +508,16 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
400
508
|
primaryStyle.double("offsetY", default: secondaryStyle.double("offsetY")))
|
|
401
509
|
}
|
|
402
510
|
|
|
511
|
+
func applySegments(_ column: [String: Any]) {
|
|
512
|
+
guard !linear else { return }
|
|
513
|
+
if let text = primaryLabel.attributedText {
|
|
514
|
+
primaryLabel.attributedText = nativeListDataSegments(text, column.dictionaries("textSegments"))
|
|
515
|
+
}
|
|
516
|
+
if let text = secondaryLabel.attributedText {
|
|
517
|
+
secondaryLabel.attributedText = nativeListDataSegments(text, column.dictionaries("secondaryTextSegments"))
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
403
521
|
func applyStyle(_ style: [String: Any], text: (UILabel, [String: Any]) -> Void) {
|
|
404
522
|
// The linear single label already mapped its styles onto attributed ranges.
|
|
405
523
|
guard !linear else { return }
|
|
@@ -446,3 +564,22 @@ private final class NativeListTableColumnView: UIStackView {
|
|
|
446
564
|
}
|
|
447
565
|
}
|
|
448
566
|
}
|
|
567
|
+
|
|
568
|
+
private func nativeListDataColumnText(_ column: [String: Any], _ field: String) -> String {
|
|
569
|
+
let segments = column.dictionaries("\(field)Segments")
|
|
570
|
+
return segments.isEmpty ? column.string(field) : segments.map { $0.string("text") }.joined()
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
private func nativeListDataSegments(_ fallback: NSAttributedString, _ segments: [[String: Any]]) -> NSAttributedString {
|
|
574
|
+
guard !segments.isEmpty, fallback.length > 0 else { return fallback }
|
|
575
|
+
let attributes = fallback.attributes(at: 0, effectiveRange: nil)
|
|
576
|
+
let result = NSMutableAttributedString(string: "")
|
|
577
|
+
for segment in segments {
|
|
578
|
+
var runAttributes = attributes
|
|
579
|
+
if segment.string("style") == "subscript", let font = attributes[.font] as? UIFont {
|
|
580
|
+
runAttributes[.font] = font.withSize(ceil(font.pointSize * 0.6))
|
|
581
|
+
}
|
|
582
|
+
result.append(NSAttributedString(string: segment.string("text"), attributes: runAttributes))
|
|
583
|
+
}
|
|
584
|
+
return result
|
|
585
|
+
}
|