@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
|
@@ -4,6 +4,7 @@ import org.json.JSONArray
|
|
|
4
4
|
import org.json.JSONObject
|
|
5
5
|
import java.nio.ByteBuffer
|
|
6
6
|
import java.security.MessageDigest
|
|
7
|
+
import kotlin.math.roundToInt
|
|
7
8
|
import java.util.Locale
|
|
8
9
|
|
|
9
10
|
internal data class NativeSelectionTarget(val scope: String, val key: String?)
|
|
@@ -13,7 +14,7 @@ internal fun isNativeListRowPressEnabled(
|
|
|
13
14
|
variant: String,
|
|
14
15
|
disabled: Boolean,
|
|
15
16
|
pressDisabled: Boolean,
|
|
16
|
-
): Boolean = !disabled && !pressDisabled && (type != "system" || variant == "retry")
|
|
17
|
+
): Boolean = !disabled && !pressDisabled && type != "buttonGroup" && (type != "system" || variant == "retry")
|
|
17
18
|
|
|
18
19
|
internal fun isNativeListWholeRowInteractive(
|
|
19
20
|
type: String,
|
|
@@ -27,6 +28,178 @@ internal fun isNativeListWholeRowInteractive(
|
|
|
27
28
|
pressDisabled = pressDisabled,
|
|
28
29
|
)
|
|
29
30
|
|
|
31
|
+
/**
|
|
32
|
+
* A trailing text accessory (value, value pair, progress, radio, switch) owns its
|
|
33
|
+
* tap only when it carries an action key; otherwise the touch belongs to the row
|
|
34
|
+
* press, so a value such as a network balance is part of the row's hit area.
|
|
35
|
+
*/
|
|
36
|
+
internal fun isNativeListTrailingTextClickable(actionKey: String?): Boolean = !actionKey.isNullOrEmpty()
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A leading visual lays these badges past its own frame: the token network image
|
|
40
|
+
* with its backdrop, a `cornerIcon`, and every overlay (their default offset
|
|
41
|
+
* already overhangs; iOS stops clipping for the same descriptors). Android clips
|
|
42
|
+
* a child to its own bounds whenever its parent clips children, so the host row
|
|
43
|
+
* must stop clipping, or the badge is cut flat (OK-65694).
|
|
44
|
+
*/
|
|
45
|
+
internal fun nativeListLeadingVisualOverhangsFrame(
|
|
46
|
+
kind: String,
|
|
47
|
+
sourceCount: Int,
|
|
48
|
+
hasCornerIcon: Boolean,
|
|
49
|
+
overlayCount: Int,
|
|
50
|
+
): Boolean = kind == "token" && sourceCount > 1 || hasCornerIcon || overlayCount > 0
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Whether an Activity row host (and, for a rich `amounts` row, the details view
|
|
54
|
+
* with its nested columns) clips its children and padding for this bind. One
|
|
55
|
+
* row view serves both the legacy row and the rich row and is reused across
|
|
56
|
+
* binds, so clipping is derived from the bound item alone and applied on every
|
|
57
|
+
* bind: a row whose bound leading visual lays a badge past its frame
|
|
58
|
+
* ([nativeListLeadingVisualOverhangsFrame]) opts out, whether that visual sits
|
|
59
|
+
* on the host (legacy row, OK-66071) or on the details view (rich row,
|
|
60
|
+
* OK-66275); a row without such a badge clips again even when the view it
|
|
61
|
+
* reuses last showed one.
|
|
62
|
+
*/
|
|
63
|
+
internal fun nativeListActivityHostClips(leadingOverhangs: Boolean): Boolean = !leadingOverhangs
|
|
64
|
+
|
|
65
|
+
/** A one-line text view shows each line break of its text as one space. */
|
|
66
|
+
internal fun nativeListFoldLineBreaks(text: String): String = text.replace(Regex("\\r\\n|[\\r\\n]"), " ")
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Offset into the displayed text for [sourceOffset], a UTF-16 offset into the
|
|
70
|
+
* caller's [source], kept within the text. Folding line breaks
|
|
71
|
+
* ([nativeListFoldLineBreaks]) moves every offset after a CRLF. The offset is a
|
|
72
|
+
* Long because JSON carries any safe integer; narrowing it first would wrap a
|
|
73
|
+
* value past Int range instead of clamping it to the end.
|
|
74
|
+
*/
|
|
75
|
+
internal fun nativeListDisplayOffset(source: String, sourceOffset: Long, foldsLineBreaks: Boolean): Int {
|
|
76
|
+
val clamped = sourceOffset.coerceIn(0L, source.length.toLong()).toInt()
|
|
77
|
+
return if (foldsLineBreaks) nativeListFoldLineBreaks(source.substring(0, clamped)).length else clamped
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A horizontal run of laid-out text on one line, in view coordinates. */
|
|
81
|
+
internal data class NativeListTextRun(val left: Float, val right: Float)
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* One laid-out line of a text view, in view coordinates: its vertical extent,
|
|
85
|
+
* the runs of [touchable] text and the runs of [plain] text before it. A line
|
|
86
|
+
* holds one run of each, or several where mixed-direction text puts plain text
|
|
87
|
+
* between touchable text.
|
|
88
|
+
*/
|
|
89
|
+
internal data class NativeListTextLine(
|
|
90
|
+
val top: Float,
|
|
91
|
+
val bottom: Float,
|
|
92
|
+
val touchable: List<NativeListTextRun>,
|
|
93
|
+
val plain: List<NativeListTextRun> = emptyList(),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
internal data class NativeListTouchRegion(val left: Float, val top: Float, val right: Float, val bottom: Float) {
|
|
97
|
+
fun contains(x: Float, y: Float): Boolean = x in left..right && y in top..bottom
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Runs are read back from pixel regions, so neighbours can be a pixel apart. */
|
|
101
|
+
private const val TEXT_RUN_EDGE = 1f
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Parts of a stretched text view that take touches: every run of touchable
|
|
105
|
+
* text, widened by [slop] into blank space only. The widening stops at plain
|
|
106
|
+
* text on the same line, so text before the touchable text never takes the
|
|
107
|
+
* touch, however narrow it is. Touches outside the regions fall through to the
|
|
108
|
+
* row behind the view (OK-67219).
|
|
109
|
+
*/
|
|
110
|
+
internal fun nativeListTouchableTextRegions(
|
|
111
|
+
lines: List<NativeListTextLine>,
|
|
112
|
+
slop: Float,
|
|
113
|
+
): List<NativeListTouchRegion> = lines.flatMap { line ->
|
|
114
|
+
line.touchable.map { run ->
|
|
115
|
+
var left = run.left - slop
|
|
116
|
+
var right = run.right + slop
|
|
117
|
+
for (other in line.plain) {
|
|
118
|
+
if (other.right <= run.left + TEXT_RUN_EDGE) left = maxOf(left, other.right)
|
|
119
|
+
if (other.left >= run.right - TEXT_RUN_EDGE) right = minOf(right, other.left)
|
|
120
|
+
}
|
|
121
|
+
NativeListTouchRegion(left, line.top, right, line.bottom)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
internal data class NativeListSlotFrame(val x: Int, val y: Int, val width: Int, val height: Int)
|
|
126
|
+
|
|
127
|
+
/** Side of one member of an Activity token pair inside a [frame]-unit box (24 in 40). */
|
|
128
|
+
internal fun nativeListLeadingPairMemberSize(frame: Int): Int = (frame * 0.6f).roundToInt()
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Frame of image source [index] of a leading visual inside its [width]×[height]
|
|
132
|
+
* box (SPEC "Activity leading pair", OK-66071). [networkIndex] is the token
|
|
133
|
+
* `networkImage` badge and [pairIndex] the Activity `secondaryLeading` token;
|
|
134
|
+
* either is null when absent. A pair draws the primary at the top-left and the
|
|
135
|
+
* secondary at the bottom-right, both [nativeListLeadingPairMemberSize] wide and
|
|
136
|
+
* the secondary inset by its [pairRing]; the badge keeps its corner geometry
|
|
137
|
+
* above them. A lone token, or a token with only a badge, fills the box. Any
|
|
138
|
+
* other multi-source visual (stackedImages) steps 0.72-sized images diagonally.
|
|
139
|
+
*/
|
|
140
|
+
internal fun nativeListLeadingSlotFrame(
|
|
141
|
+
index: Int,
|
|
142
|
+
sourceCount: Int,
|
|
143
|
+
networkIndex: Int?,
|
|
144
|
+
pairIndex: Int?,
|
|
145
|
+
width: Int,
|
|
146
|
+
height: Int,
|
|
147
|
+
badgeSize: Int,
|
|
148
|
+
badgeOverhang: Int,
|
|
149
|
+
pairRing: Int,
|
|
150
|
+
): NativeListSlotFrame {
|
|
151
|
+
if (index == networkIndex)
|
|
152
|
+
return NativeListSlotFrame(
|
|
153
|
+
width - badgeSize + badgeOverhang,
|
|
154
|
+
height - badgeSize + badgeOverhang,
|
|
155
|
+
badgeSize,
|
|
156
|
+
badgeSize,
|
|
157
|
+
)
|
|
158
|
+
if (pairIndex != null) {
|
|
159
|
+
val member = nativeListLeadingPairMemberSize(height)
|
|
160
|
+
return if (index == pairIndex)
|
|
161
|
+
NativeListSlotFrame(width - member - pairRing, height - member - pairRing, member, member)
|
|
162
|
+
else NativeListSlotFrame(0, 0, member, member)
|
|
163
|
+
}
|
|
164
|
+
if (sourceCount == 1 || networkIndex != null) return NativeListSlotFrame(0, 0, width, height)
|
|
165
|
+
val side = (height * 0.72f).roundToInt()
|
|
166
|
+
val x = (index * (width - side).toFloat() / maxOf(1, sourceCount - 1)).roundToInt()
|
|
167
|
+
return NativeListSlotFrame(x, (height - side) / 2, side, side)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
internal data class NativeListTrailingDescriptor(
|
|
171
|
+
val kind: String,
|
|
172
|
+
val name: String = "",
|
|
173
|
+
val actionKey: String = "",
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Identity trailing accessories stack vertically unless they form one of the
|
|
178
|
+
* pairs every platform lays out side by side. The `valuePair` + `DotVerSolid`
|
|
179
|
+
* menu icon pair (the Swap token selector's balance and row menu) matches
|
|
180
|
+
* iOS `configureTrailingStack`; stacking it put the menu under the balance and
|
|
181
|
+
* clipped both inside the fixed row height on Android only.
|
|
182
|
+
*/
|
|
183
|
+
internal fun nativeListIdentityTrailingIsHorizontal(
|
|
184
|
+
accessories: List<NativeListTrailingDescriptor>,
|
|
185
|
+
): Boolean {
|
|
186
|
+
val kinds = accessories.map { it.kind }
|
|
187
|
+
if (kinds.containsAll(listOf("value", "checkbox"))) return true
|
|
188
|
+
if (accessories.size != 2) return false
|
|
189
|
+
val (first, second) = accessories
|
|
190
|
+
return kinds == listOf("valuePair", "menu") ||
|
|
191
|
+
kinds == listOf("valuePair", "chevron") ||
|
|
192
|
+
(kinds == listOf("valuePair", "icon") &&
|
|
193
|
+
second.name == "DotVerSolid" &&
|
|
194
|
+
second.actionKey == "menu") ||
|
|
195
|
+
(kinds == listOf("icon", "chevron") &&
|
|
196
|
+
first.name == "RefreshCcwOutline" &&
|
|
197
|
+
first.actionKey.isEmpty()) ||
|
|
198
|
+
(kinds == listOf("icon", "icon") &&
|
|
199
|
+
first.name == "PencilOutline" &&
|
|
200
|
+
second.name == "DragOutline")
|
|
201
|
+
}
|
|
202
|
+
|
|
30
203
|
internal fun resolveNativeListSelectorBackgroundColor(
|
|
31
204
|
rowType: String,
|
|
32
205
|
styleBackgroundColor: String?,
|
|
@@ -57,7 +230,7 @@ private fun updateLengthPrefixed(digest: MessageDigest, value: String) {
|
|
|
57
230
|
}
|
|
58
231
|
|
|
59
232
|
// Template type alone partitions reuse; data keys and styles never select a renderer.
|
|
60
|
-
internal enum class NativeListRendererKey { MESSAGE, RAIL, MEDIA_TILE, ACTION, SYSTEM, ACTIVITY, DATA_ROW, METRIC_CARD, MARKET, IDENTITY, SECTION_HEADER, WALLET_GROUP }
|
|
233
|
+
internal enum class NativeListRendererKey { MESSAGE, RAIL, MEDIA_TILE, ACTION, SYSTEM, ACTIVITY, DATA_ROW, METRIC_CARD, MARKET, IDENTITY, SECTION_HEADER, WALLET_GROUP, BUTTON_GROUP }
|
|
61
234
|
|
|
62
235
|
internal data class NativeListItem(
|
|
63
236
|
val key: String,
|
|
@@ -142,6 +315,8 @@ internal data class NativeListItem(
|
|
|
142
315
|
|
|
143
316
|
internal data class NativeListConfig(
|
|
144
317
|
val generation: Int,
|
|
318
|
+
val structuralTransition: StructuralTransition?,
|
|
319
|
+
val disclosure: Disclosure?,
|
|
145
320
|
val layout: String,
|
|
146
321
|
val orientation: String,
|
|
147
322
|
val gridColumns: Int,
|
|
@@ -168,9 +343,36 @@ internal data class NativeListConfig(
|
|
|
168
343
|
val fixedFooter: NativeListItem?,
|
|
169
344
|
val items: List<NativeListItem>,
|
|
170
345
|
) {
|
|
346
|
+
internal data class StructuralTransition(
|
|
347
|
+
val id: String,
|
|
348
|
+
val durationMs: Long,
|
|
349
|
+
val anchorKey: String?,
|
|
350
|
+
)
|
|
351
|
+
internal data class Disclosure(
|
|
352
|
+
val expanded: Boolean,
|
|
353
|
+
val expandedTrailingInset: Double,
|
|
354
|
+
)
|
|
171
355
|
companion object {
|
|
172
356
|
fun parse(snapshotJson: String): NativeListConfig {
|
|
173
357
|
val root = JSONObject(snapshotJson)
|
|
358
|
+
val transition = root.optJSONObject("structuralTransition")
|
|
359
|
+
val structuralTransition = transition?.optString("id")?.takeIf(String::isNotEmpty)?.let { id ->
|
|
360
|
+
StructuralTransition(
|
|
361
|
+
id = id,
|
|
362
|
+
durationMs = transition.optDouble("durationMs", 220.0).coerceIn(0.0, 2000.0).toLong(),
|
|
363
|
+
anchorKey = transition.optString("anchorKey").takeIf(String::isNotEmpty),
|
|
364
|
+
)
|
|
365
|
+
}
|
|
366
|
+
val disclosureJson = root.optJSONObject("disclosure")
|
|
367
|
+
require(!root.has("disclosure") || disclosureJson != null) { "Invalid disclosure" }
|
|
368
|
+
val disclosure = disclosureJson?.let { value ->
|
|
369
|
+
require(value.opt("expanded") is Boolean) { "Invalid disclosure.expanded" }
|
|
370
|
+
require(!value.has("expandedTrailingInset") ||
|
|
371
|
+
value.opt("expandedTrailingInset") is Number) { "Invalid disclosure.expandedTrailingInset" }
|
|
372
|
+
val inset = value.optDouble("expandedTrailingInset", 0.0)
|
|
373
|
+
require(inset.isFinite() && inset >= 0.0) { "Invalid disclosure.expandedTrailingInset" }
|
|
374
|
+
Disclosure(value.getBoolean("expanded"), inset)
|
|
375
|
+
}
|
|
174
376
|
require(root.getInt("schemaVersion") == 1) { "Unsupported schemaVersion" }
|
|
175
377
|
val layout = root.getJSONObject("layout")
|
|
176
378
|
val selection = root.optJSONObject("selection")
|
|
@@ -193,6 +395,8 @@ internal data class NativeListConfig(
|
|
|
193
395
|
val fixedFooter = root.optJSONObject("fixedFooter")?.let(NativeListItem::parse)
|
|
194
396
|
return NativeListConfig(
|
|
195
397
|
generation = root.getInt("generation"),
|
|
398
|
+
structuralTransition = structuralTransition,
|
|
399
|
+
disclosure = disclosure,
|
|
196
400
|
layout = layout.getString("kind"),
|
|
197
401
|
orientation = layout.optString("orientation", "vertical"),
|
|
198
402
|
gridColumns = layout.optInt("gridColumns", 1).coerceIn(1, 7),
|
|
@@ -235,7 +439,9 @@ internal fun mergeRow(original: JSONObject, changes: JSONObject): JSONObject {
|
|
|
235
439
|
val keys = changes.keys()
|
|
236
440
|
while (keys.hasNext()) {
|
|
237
441
|
val key = keys.next()
|
|
238
|
-
if (key != "key" && key != "type")
|
|
442
|
+
if (key != "key" && key != "type") {
|
|
443
|
+
if (changes.isNull(key)) result.remove(key) else result.put(key, changes.get(key))
|
|
444
|
+
}
|
|
239
445
|
}
|
|
240
446
|
return result
|
|
241
447
|
}
|