@onekeyfe/react-native-native-list 6.7.0-6 → 6.7.0-61
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 +41 -7
- 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
|
@@ -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,12 +26,10 @@ 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
|
-
text =
|
|
32
|
-
self.lines == 1 && explicitTruncation
|
|
33
|
-
? value.replacingOccurrences(of: "\r\n|[\r\n]", with: " ", options: .regularExpression)
|
|
34
|
-
: value
|
|
32
|
+
text = self.lines == 1 && explicitTruncation ? Self.foldingLineBreaks(value) : value
|
|
35
33
|
let resolvedWeight: NativeListFontWeight
|
|
36
34
|
switch style.string("fontWeight") {
|
|
37
35
|
case "regular": resolvedWeight = .regular
|
|
@@ -58,6 +56,20 @@ struct NativeListResolvedText {
|
|
|
58
56
|
offsetY = CGFloat(style.double("offsetY"))
|
|
59
57
|
}
|
|
60
58
|
|
|
59
|
+
private static func foldingLineBreaks(_ value: String) -> String {
|
|
60
|
+
value.replacingOccurrences(of: "\r\n|[\r\n]", with: " ", options: .regularExpression)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/// UTF-16 offset in `text` for an offset into the caller's `source`, kept
|
|
64
|
+
/// within the text. A one-line label folds each line break into one space,
|
|
65
|
+
/// which moves every offset after a CRLF.
|
|
66
|
+
func displayOffset(_ offset: Int, in source: String) -> Int {
|
|
67
|
+
let units = source as NSString
|
|
68
|
+
let clamped = min(max(offset, 0), units.length)
|
|
69
|
+
guard lines == 1, explicitTruncation else { return clamped }
|
|
70
|
+
return (Self.foldingLineBreaks(units.substring(to: clamped)) as NSString).length
|
|
71
|
+
}
|
|
72
|
+
|
|
61
73
|
/// Start/end follow the host view's layout direction, as legacy `marketTextAlignment` did.
|
|
62
74
|
func alignment(for direction: UIUserInterfaceLayoutDirection) -> NSTextAlignment {
|
|
63
75
|
guard let alignmentName else { return .natural }
|
|
@@ -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,13 +118,14 @@ 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()
|
|
117
125
|
private let accessoryButtons = [NativeListAccessoryButton(type: .system)]
|
|
118
126
|
private let checkboxControl = NativeListAccessoryStack(frame: .zero)
|
|
119
|
-
private let headerTitleIconImageView =
|
|
120
|
-
private let headerValueIconImageView =
|
|
127
|
+
private let headerTitleIconImageView = NativeListIconImageView()
|
|
128
|
+
private let headerValueIconImageView = NativeListIconImageView()
|
|
121
129
|
private var accessoryActions: [(String, NativeSelectionTarget?)] = []
|
|
122
130
|
private var currentItem: NativeListItem?
|
|
123
131
|
private var currentTheme: [String: Any]?
|
|
@@ -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)
|
|
@@ -178,10 +187,22 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
178
187
|
_ item: NativeListItem, theme: [String: Any]?, layout: String,
|
|
179
188
|
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
|
|
180
189
|
) {
|
|
190
|
+
let iconUpdate = NativeListIconUpdate(self)
|
|
191
|
+
defer { iconUpdate.finish() }
|
|
192
|
+
|
|
181
193
|
selectorTypographyRestorers.reversed().forEach { $0() }
|
|
182
194
|
selectorTypographyRestorers = []
|
|
183
195
|
currentItem = item
|
|
184
196
|
currentTheme = theme
|
|
197
|
+
if accessoryButtons[0].superview === titleRowStack {
|
|
198
|
+
titleRowStack.removeArrangedSubview(accessoryButtons[0])
|
|
199
|
+
accessoryButtons[0].removeFromSuperview()
|
|
200
|
+
trailingStack.insertArrangedSubview(accessoryButtons[0], at: 0)
|
|
201
|
+
}
|
|
202
|
+
titleRowStack.removeArrangedSubview(leadingBadge)
|
|
203
|
+
leadingBadge.removeFromSuperview()
|
|
204
|
+
leadingBadge.text = nil
|
|
205
|
+
leadingBadge.accessibilityLabel = nil
|
|
185
206
|
titleSpinner.stopAnimating()
|
|
186
207
|
NSLayoutConstraint.deactivate(selectorConstraints)
|
|
187
208
|
selectorConstraints = []
|
|
@@ -198,6 +219,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
198
219
|
titleLabel.removeGestureRecognizer(selectorTitleTap)
|
|
199
220
|
titleLabel.isUserInteractionEnabled = false
|
|
200
221
|
titleLabel.showsDottedUnderline = false
|
|
222
|
+
titleLabel.usesDashedUnderline = false
|
|
201
223
|
titleLabel.reservesDottedUnderlineSpace = false
|
|
202
224
|
titleLabel.dottedUnderlineVerticalOffset = 0
|
|
203
225
|
for label in [titleLabel, subtitleLabel] {
|
|
@@ -211,6 +233,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
211
233
|
label.rowVerticalAlignment = nil
|
|
212
234
|
}
|
|
213
235
|
titleLabel.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
|
236
|
+
titleLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
214
237
|
subtitleLabel.font = nativeListFont(ofSize: 14, fonts: fonts)
|
|
215
238
|
subtitleLabel.textColor = nativeListColor(theme, "secondaryText", "#646464")
|
|
216
239
|
mainStack.alignment = .fill
|
|
@@ -228,6 +251,10 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
228
251
|
value.contentHorizontalAlignment = .center
|
|
229
252
|
value.contentVerticalAlignment = .center
|
|
230
253
|
value.rowTextOffsetY = 0
|
|
254
|
+
value.helpBindingGeneration += 1
|
|
255
|
+
value.helpPrimaryLineOnly = false
|
|
256
|
+
value.showsHelpUnderline = false
|
|
257
|
+
value.isUserInteractionEnabled = true
|
|
231
258
|
value.marketLineHeight = nil
|
|
232
259
|
value.selectorSummaryLineHeight = nil
|
|
233
260
|
value.isHidden = true
|
|
@@ -253,6 +280,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
253
280
|
if style["lineGap"] != nil { mainStack.spacing = CGFloat(style.double("lineGap")) }
|
|
254
281
|
if style["trailingGap"] != nil { trailingStack.spacing = CGFloat(style.double("trailingGap")) }
|
|
255
282
|
applyTextStyle(item)
|
|
283
|
+
bindPositionHeaderFields(item, theme: theme)
|
|
256
284
|
titleSpinner.color = titleLabel.textColor
|
|
257
285
|
updateTitleSpinner()
|
|
258
286
|
contentInsets = UIEdgeInsets(
|
|
@@ -272,6 +300,64 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
272
300
|
width.isActive = true
|
|
273
301
|
selectorConstraints.append(width)
|
|
274
302
|
}
|
|
303
|
+
|
|
304
|
+
}
|
|
305
|
+
private func bindPositionHeaderFields(_ item: NativeListItem, theme: [String: Any]?) {
|
|
306
|
+
let style = item.data.dictionary("style") ?? [:]
|
|
307
|
+
if let badge = item.data.dictionary("leadingBadge") {
|
|
308
|
+
leadingBadge.text = badge.string("text")
|
|
309
|
+
leadingBadge.font = nativeListFont(ofSize: 12, weight: .medium, fonts: fonts)
|
|
310
|
+
let tones = ["info": ("info", "#0F69F6"), "success": ("positive", "#008F5A"), "warning": ("caution", "#A35E00"), "danger": ("negative", "#CE2C31")]
|
|
311
|
+
if let tone = tones[badge.string("tone")] {
|
|
312
|
+
let color = nativeListColor(theme, tone.0, tone.1)
|
|
313
|
+
leadingBadge.textColor = color
|
|
314
|
+
leadingBadge.backgroundColor = color.withAlphaComponent(0.12)
|
|
315
|
+
if badge.string("tone") == "success", let background = theme?["successBackground"] as? String {
|
|
316
|
+
leadingBadge.backgroundColor = UIColor(nativeListHex: background, fallback: color.withAlphaComponent(0.12))
|
|
317
|
+
}
|
|
318
|
+
} else {
|
|
319
|
+
leadingBadge.textColor = nativeListColor(theme, "secondaryText", "#646464")
|
|
320
|
+
leadingBadge.backgroundColor = nativeListColor(theme, "strongBackground", "#F0F0F0")
|
|
321
|
+
}
|
|
322
|
+
let paragraph = NSMutableParagraphStyle()
|
|
323
|
+
paragraph.minimumLineHeight = 16
|
|
324
|
+
paragraph.maximumLineHeight = 16
|
|
325
|
+
leadingBadge.attributedText = NSAttributedString(
|
|
326
|
+
string: badge.string("text"), attributes: [
|
|
327
|
+
.font: leadingBadge.font as Any,
|
|
328
|
+
.foregroundColor: leadingBadge.textColor as Any,
|
|
329
|
+
.paragraphStyle: paragraph,
|
|
330
|
+
])
|
|
331
|
+
leadingBadge.horizontalInset = 8
|
|
332
|
+
leadingBadge.topInset = 2
|
|
333
|
+
leadingBadge.bottomInset = 2
|
|
334
|
+
leadingBadge.layer.cornerRadius = 4
|
|
335
|
+
leadingBadge.clipsToBounds = true
|
|
336
|
+
leadingBadge.accessibilityLabel = badge["accessibilityLabel"] as? String
|
|
337
|
+
leadingBadge.setContentHuggingPriority(.required, for: .horizontal)
|
|
338
|
+
leadingBadge.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
339
|
+
titleLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
|
340
|
+
titleRowStack.insertArrangedSubview(leadingBadge, at: 0)
|
|
341
|
+
}
|
|
342
|
+
if style["titleDecoration"] != nil {
|
|
343
|
+
titleLabel.showsDottedUnderline = style.string("titleDecoration") == "dashed"
|
|
344
|
+
titleLabel.usesDashedUnderline = true
|
|
345
|
+
titleLabel.dottedUnderlineColor = titleLabel.textColor
|
|
346
|
+
}
|
|
347
|
+
let value = accessoryButtons[0]
|
|
348
|
+
if style.string("valuePlacement") == "afterTitle" {
|
|
349
|
+
trailingStack.removeArrangedSubview(value)
|
|
350
|
+
value.removeFromSuperview()
|
|
351
|
+
titleLabel.setContentHuggingPriority(.required, for: .horizontal)
|
|
352
|
+
mainStack.alignment = .leading
|
|
353
|
+
titleRowStack.addArrangedSubview(value)
|
|
354
|
+
}
|
|
355
|
+
if let help = item.data.dictionary("valueHelp") {
|
|
356
|
+
value.showsHelpUnderline = help.string("underline") == "dashed"
|
|
357
|
+
value.isUserInteractionEnabled = help.string("presentation") == "popover"
|
|
358
|
+
accessoryActions = [(help.string("presentation") == "popover" ? help.string("actionKey") : "", nil)]
|
|
359
|
+
value.setNeedsLayout()
|
|
360
|
+
}
|
|
275
361
|
}
|
|
276
362
|
private func applyTextStyle(_ item: NativeListItem) {
|
|
277
363
|
let style = item.data.dictionary("style") ?? [:]
|
|
@@ -289,6 +375,9 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
289
375
|
_ item: NativeListItem,
|
|
290
376
|
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
|
|
291
377
|
) {
|
|
378
|
+
let iconUpdate = NativeListIconUpdate(self)
|
|
379
|
+
defer { iconUpdate.finish() }
|
|
380
|
+
|
|
292
381
|
currentItem = item
|
|
293
382
|
checkboxControl.updateSelection(item, checkboxState: checkboxState)
|
|
294
383
|
if item.data.string("variant") == "summary" {
|
|
@@ -300,6 +389,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
300
389
|
applyTextStyle(item)
|
|
301
390
|
applySelectorTypography(item)
|
|
302
391
|
}
|
|
392
|
+
|
|
303
393
|
}
|
|
304
394
|
private func bindCheckbox(
|
|
305
395
|
_ item: NativeListItem, _ descriptor: [String: Any],
|
|
@@ -312,6 +402,12 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
312
402
|
override func recycleContent() {
|
|
313
403
|
checkboxControl.reset()
|
|
314
404
|
currentItem = nil
|
|
405
|
+
accessoryActions = []
|
|
406
|
+
titleLabel.removeGestureRecognizer(selectorTitleTap)
|
|
407
|
+
titleLabel.isUserInteractionEnabled = false
|
|
408
|
+
accessoryButtons[0].helpBindingGeneration += 1
|
|
409
|
+
accessoryButtons[0].isUserInteractionEnabled = false
|
|
410
|
+
accessoryButtons[0].showsHelpUnderline = false
|
|
315
411
|
titleSpinner.stopAnimating()
|
|
316
412
|
}
|
|
317
413
|
override func didMoveToWindow() {
|
|
@@ -435,7 +531,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
435
531
|
topInset = 12
|
|
436
532
|
bottomInset = -2
|
|
437
533
|
if let icon = item.data.dictionary("titleIcon") {
|
|
438
|
-
headerTitleIconImageView.
|
|
534
|
+
headerTitleIconImageView.bindIcon(icon.string("name"))
|
|
439
535
|
headerTitleIconImageView.tintColor = UIColor(
|
|
440
536
|
nativeListHex: icon.string("tintColor", default: "#646464"),
|
|
441
537
|
fallback: .darkGray
|
|
@@ -505,7 +601,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
505
601
|
for: .normal
|
|
506
602
|
)
|
|
507
603
|
if let icon = item.data.dictionary("valueIcon") {
|
|
508
|
-
headerValueIconImageView.
|
|
604
|
+
headerValueIconImageView.bindIcon(icon.string("name"))
|
|
509
605
|
headerValueIconImageView.tintColor = UIColor(
|
|
510
606
|
nativeListHex: icon.string("tintColor", default: "#646464"),
|
|
511
607
|
fallback: .darkGray
|
|
@@ -3,6 +3,112 @@ import UIKit
|
|
|
3
3
|
class NativeListTextLabel: UILabel {
|
|
4
4
|
var rowVerticalAlignment: String? { didSet { setNeedsDisplay() } }
|
|
5
5
|
var rowOffsetY: CGFloat = 0 { didSet { setNeedsDisplay() } }
|
|
6
|
+
/// UTF-16 offset the touchable text starts at. `nil` keeps the label's own
|
|
7
|
+
/// hit testing, its whole bounds. With an offset only the drawn text from
|
|
8
|
+
/// there on takes touches, plus a small slop, so text before the offset and
|
|
9
|
+
/// the unused width of a stretched label fall through to the row behind it:
|
|
10
|
+
/// `0` covers all of the text, the text length leaves nothing to touch.
|
|
11
|
+
var touchableTextStart: Int?
|
|
12
|
+
private static let touchSlop = CGSize(width: 8, height: 6)
|
|
13
|
+
|
|
14
|
+
/// One rect per laid-out run of touchable text, in label coordinates. The
|
|
15
|
+
/// label's own layout is not public, so the runs come from a text container
|
|
16
|
+
/// with the label's width, line cap and truncation. A line holds one run, or
|
|
17
|
+
/// several where mixed-direction text puts plain text between touchable text.
|
|
18
|
+
var touchableTextRegions: [CGRect] {
|
|
19
|
+
guard let start = touchableTextStart, let attributed = attributedText, attributed.length > start,
|
|
20
|
+
bounds.width > 0
|
|
21
|
+
else { return [] }
|
|
22
|
+
let storage = NSTextStorage(attributedString: attributed)
|
|
23
|
+
let manager = NSLayoutManager()
|
|
24
|
+
let container = NSTextContainer(
|
|
25
|
+
size: CGSize(width: bounds.width, height: .greatestFiniteMagnitude))
|
|
26
|
+
container.lineFragmentPadding = 0
|
|
27
|
+
container.maximumNumberOfLines = numberOfLines
|
|
28
|
+
container.lineBreakMode = lineBreakMode
|
|
29
|
+
manager.addTextContainer(container)
|
|
30
|
+
storage.addLayoutManager(manager)
|
|
31
|
+
let glyphs = manager.glyphRange(for: container)
|
|
32
|
+
// Mirrors drawText: the text is centered unless the row aligns it.
|
|
33
|
+
let textHeight = manager.usedRect(for: container).height
|
|
34
|
+
var originY = (bounds.height - textHeight) / 2
|
|
35
|
+
if let alignment = rowVerticalAlignment {
|
|
36
|
+
originY = alignment == "top" ? 0 : alignment == "bottom" ? bounds.height - textHeight : originY
|
|
37
|
+
}
|
|
38
|
+
originY += rowOffsetY
|
|
39
|
+
var lines: [CGRect] = []
|
|
40
|
+
var visibleEnd = attributed.length
|
|
41
|
+
manager.enumerateLineFragments(forGlyphRange: glyphs) { _, usedRect, _, lineGlyphs, _ in
|
|
42
|
+
lines.append(usedRect)
|
|
43
|
+
let truncated = manager.truncatedGlyphRange(inLineFragmentForGlyphAt: lineGlyphs.location)
|
|
44
|
+
if truncated.location != NSNotFound {
|
|
45
|
+
visibleEnd = min(visibleEnd, manager.characterIndexForGlyph(at: truncated.location))
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Truncation can hide the touchable text altogether. The ellipsis then
|
|
49
|
+
// stands for plain text as well, so nothing is left to touch.
|
|
50
|
+
guard start < visibleEnd else { return [] }
|
|
51
|
+
// The layout engine's own rects for a character range: one per line and
|
|
52
|
+
// per visual run, which is what makes mixed-direction text come out right.
|
|
53
|
+
func runs(_ characters: NSRange) -> [CGRect] {
|
|
54
|
+
let range = NSIntersectionRange(
|
|
55
|
+
manager.glyphRange(forCharacterRange: characters, actualCharacterRange: nil), glyphs)
|
|
56
|
+
guard range.length > 0 else { return [] }
|
|
57
|
+
var rects: [CGRect] = []
|
|
58
|
+
manager.enumerateEnclosingRects(
|
|
59
|
+
forGlyphRange: range, withinSelectedGlyphRange: NSRange(location: NSNotFound, length: 0),
|
|
60
|
+
in: container
|
|
61
|
+
) { rect, _ in
|
|
62
|
+
// A run that continues on the next line is reported up to the
|
|
63
|
+
// container edge; its text ends where the line's used rect does.
|
|
64
|
+
guard let used = lines.first(where: { $0.minY <= rect.midY && rect.midY < $0.maxY })
|
|
65
|
+
else { return }
|
|
66
|
+
let minX = max(rect.minX, used.minX)
|
|
67
|
+
let maxX = min(rect.maxX, used.maxX)
|
|
68
|
+
if maxX > minX {
|
|
69
|
+
rects.append(CGRect(x: minX, y: rect.minY, width: maxX - minX, height: rect.height))
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return rects
|
|
73
|
+
}
|
|
74
|
+
let plain = runs(NSRange(location: 0, length: start))
|
|
75
|
+
return runs(NSRange(location: start, length: attributed.length - start)).map { run in
|
|
76
|
+
// The slop reaches into blank space only. Sideways it stops at plain
|
|
77
|
+
// text on the same line, so text before the start never takes the
|
|
78
|
+
// touch, however narrow it is.
|
|
79
|
+
var minX = run.minX - Self.touchSlop.width
|
|
80
|
+
var maxX = run.maxX + Self.touchSlop.width
|
|
81
|
+
for other in plain where other.minY < run.midY && run.midY < other.maxY {
|
|
82
|
+
if other.maxX <= run.minX + 0.5 { minX = max(minX, other.maxX) }
|
|
83
|
+
if other.minX >= run.maxX - 0.5 { maxX = min(maxX, other.minX) }
|
|
84
|
+
}
|
|
85
|
+
// Vertically it grows only past the first and last line of the whole
|
|
86
|
+
// layout, so it never reaches into another line.
|
|
87
|
+
let line = lines.firstIndex { $0.minY <= run.midY && run.midY < $0.maxY }
|
|
88
|
+
let top = line == 0 ? Self.touchSlop.height : 0
|
|
89
|
+
let bottom = line == lines.count - 1 ? Self.touchSlop.height : 0
|
|
90
|
+
return CGRect(
|
|
91
|
+
x: minX, y: run.minY + originY - top, width: maxX - minX,
|
|
92
|
+
height: run.height + top + bottom)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
|
97
|
+
guard touchableTextStart != nil else { return super.point(inside: point, with: event) }
|
|
98
|
+
return touchableTextRegions.contains { $0.contains(point) }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Assistive activation taps this point; the label's center can be blank.
|
|
102
|
+
override var accessibilityActivationPoint: CGPoint {
|
|
103
|
+
get {
|
|
104
|
+
guard let region = touchableTextRegions.first else {
|
|
105
|
+
return super.accessibilityActivationPoint
|
|
106
|
+
}
|
|
107
|
+
let target = UIAccessibility.convertToScreenCoordinates(region.intersection(bounds), in: self)
|
|
108
|
+
return CGPoint(x: target.midX, y: target.midY)
|
|
109
|
+
}
|
|
110
|
+
set { super.accessibilityActivationPoint = newValue }
|
|
111
|
+
}
|
|
6
112
|
|
|
7
113
|
override func drawText(in rect: CGRect) {
|
|
8
114
|
var target = rect
|