@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.
Files changed (216) hide show
  1. package/README.md +312 -375
  2. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
  3. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +250 -9
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +50 -13
  5. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +25 -3
  6. package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
  7. package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
  8. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
  9. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +102 -7
  10. package/android/src/main/java/com/onekey/nativelist/NativeListGeneratedIcons.kt +47 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +225 -11
  12. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +152 -33
  13. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
  14. package/android/src/main/java/com/onekey/nativelist/NativeListMediaPlaceholderView.kt +244 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +66 -31
  16. package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +32 -11
  17. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
  18. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +209 -3
  19. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +120 -287
  20. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
  21. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +7 -0
  22. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +8 -3
  23. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
  24. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +130 -1
  25. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1978 -136
  26. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +35 -0
  27. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListDescriptionTouchPolicyTest.kt +153 -0
  28. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
  29. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
  30. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
  31. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
  32. package/docs/ROW_TEMPLATES.md +78 -14
  33. package/docs/SPEC.md +1318 -16
  34. package/docs/STYLE_SPEC.md +18 -0
  35. package/ios/HybridNativeList.swift +21 -2
  36. package/ios/NativeListAccessoryStack.swift +237 -51
  37. package/ios/NativeListActivityDetailsView.swift +43 -16
  38. package/ios/NativeListActivityRenderer.swift +8 -2
  39. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  40. package/ios/NativeListDataRowRenderer.swift +167 -30
  41. package/ios/NativeListDesignAssets.swift +13 -75
  42. package/ios/NativeListGeneratedIcons.swift +55 -0
  43. package/ios/NativeListIconBinding.swift +171 -0
  44. package/ios/NativeListIdentityRenderer.swift +256 -39
  45. package/ios/NativeListLeadingVisual.swift +127 -28
  46. package/ios/NativeListMarketRenderer.swift +120 -31
  47. package/ios/NativeListMediaPlaceholderView.swift +189 -0
  48. package/ios/NativeListMediaPreviewSlot.swift +122 -61
  49. package/ios/NativeListMediaTileRenderer.swift +15 -11
  50. package/ios/NativeListMessageRenderer.swift +34 -1
  51. package/ios/NativeListMetricCardRenderer.swift +4 -2
  52. package/ios/NativeListModels.swift +42 -2
  53. package/ios/NativeListRendererRegistry.swift +1 -0
  54. package/ios/NativeListResolvedText.swift +17 -5
  55. package/ios/NativeListRowHost.swift +14 -0
  56. package/ios/NativeListSectionHeaderRenderer.swift +100 -4
  57. package/ios/NativeListTextLabel.swift +106 -0
  58. package/ios/RNCNativeListView.swift +1097 -60
  59. package/ios/tests/NativeListAccessoryStackTests.swift +101 -0
  60. package/ios/tests/NativeListAccountSelectorLayoutTests.swift +96 -0
  61. package/ios/tests/NativeListActivityPresentationTests.swift +423 -0
  62. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
  63. package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
  64. package/ios/tests/NativeListLifecycleTests.swift +2959 -4
  65. package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
  66. package/ios/tests/NativeListMediaVisibilityTests.swift +41 -7
  67. package/ios/tests/NativeListSharedIconTests.swift +236 -0
  68. package/lib/module/NativeList.js +236 -38
  69. package/lib/module/NativeList.web.js +163 -45
  70. package/lib/module/index.js +1 -1
  71. package/lib/module/models.js +3 -0
  72. package/lib/module/selection.js +1 -1
  73. package/lib/module/validation.js +1263 -48
  74. package/lib/module/web/NativeListGeneratedIcons.js +31 -0
  75. package/lib/module/web/NativeListWebEngine.js +513 -275
  76. package/lib/module/web/templates/ActivityRowRenderer.js +41 -54
  77. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  78. package/lib/module/web/templates/DataRowRenderer.js +56 -5
  79. package/lib/module/web/templates/IdentityRowRenderer.js +161 -7
  80. package/lib/module/web/templates/MarketTableRowRenderer.js +36 -19
  81. package/lib/module/web/templates/MediaTileRowRenderer.js +84 -25
  82. package/lib/module/web/templates/MessageRowRenderer.js +18 -2
  83. package/lib/module/web/templates/RowContainerStyle.js +1 -0
  84. package/lib/module/web/templates/RowRendererRegistry.js +3 -0
  85. package/lib/module/web/templates/SectionHeaderRowRenderer.js +36 -2
  86. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  87. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  88. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  89. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  90. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  91. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  92. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  93. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  94. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  95. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  96. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  97. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  98. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  99. package/lib/typescript/src/NativeList.d.ts +3 -3
  100. package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
  101. package/lib/typescript/src/NativeList.types.d.ts +20 -2
  102. package/lib/typescript/src/index.d.ts +2 -2
  103. package/lib/typescript/src/models.d.ts +134 -17
  104. package/lib/typescript/src/validation.d.ts +20 -0
  105. package/lib/typescript/src/web/NativeListGeneratedIcons.d.ts +2 -0
  106. package/lib/typescript/src/web/NativeListWebEngine.d.ts +32 -1
  107. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  108. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  109. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +9 -3
  110. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  111. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  112. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  113. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  114. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  115. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  116. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  117. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  118. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  119. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  120. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  121. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  122. package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  123. package/package.json +16 -10
  124. package/react-native-native-list.podspec +2 -6
  125. package/scripts/generate-icons.mjs +150 -0
  126. package/scripts/generate-icons.test.mjs +288 -0
  127. package/scripts/native-list-icons.json +260 -0
  128. package/src/NativeList.nitro.ts +2 -0
  129. package/src/NativeList.tsx +439 -91
  130. package/src/NativeList.types.ts +24 -2
  131. package/src/NativeList.web.tsx +286 -88
  132. package/src/index.ts +2 -0
  133. package/src/models.ts +272 -144
  134. package/src/selection.ts +1 -0
  135. package/src/validation.ts +3041 -146
  136. package/src/web/NativeListGeneratedIcons.ts +28 -0
  137. package/src/web/NativeListWebEngine.ts +818 -343
  138. package/src/web/templates/ActivityRowRenderer.ts +71 -91
  139. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  140. package/src/web/templates/DataRowRenderer.ts +121 -20
  141. package/src/web/templates/IdentityRowRenderer.ts +234 -9
  142. package/src/web/templates/MarketTableRowRenderer.ts +53 -33
  143. package/src/web/templates/MediaTileRowRenderer.ts +90 -28
  144. package/src/web/templates/MessageRowRenderer.ts +23 -7
  145. package/src/web/templates/RowContainerStyle.ts +2 -0
  146. package/src/web/templates/RowRendererRegistry.ts +11 -1
  147. package/src/web/templates/SectionHeaderRowRenderer.ts +47 -4
  148. package/ios/Resources/NativeListIcons.xcassets/Contents.json +0 -1
  149. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/Contents.json +0 -1
  150. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/icon.svg +0 -1
  151. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/Contents.json +0 -1
  152. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/icon.svg +0 -1
  153. package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/Contents.json +0 -1
  154. package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/icon.svg +0 -1
  155. package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/Contents.json +0 -1
  156. package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/icon.svg +0 -1
  157. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/Contents.json +0 -1
  158. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/icon.svg +0 -1
  159. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/Contents.json +0 -1
  160. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/icon.svg +0 -1
  161. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/Contents.json +0 -1
  162. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/icon.svg +0 -1
  163. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/Contents.json +0 -1
  164. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/icon.svg +0 -1
  165. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/Contents.json +0 -1
  166. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/icon.svg +0 -1
  167. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/Contents.json +0 -1
  168. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/icon.svg +0 -1
  169. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/Contents.json +0 -1
  170. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/icon.svg +0 -1
  171. package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/Contents.json +0 -1
  172. package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/icon.svg +0 -1
  173. package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/Contents.json +0 -1
  174. package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/icon.svg +0 -1
  175. package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/Contents.json +0 -1
  176. package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/icon.svg +0 -1
  177. package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/Contents.json +0 -1
  178. package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/icon.svg +0 -1
  179. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/Contents.json +0 -1
  180. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/icon.svg +0 -1
  181. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/Contents.json +0 -1
  182. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/icon.svg +0 -1
  183. package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/Contents.json +0 -1
  184. package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/icon.svg +0 -1
  185. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/Contents.json +0 -1
  186. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/icon.svg +0 -1
  187. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/Contents.json +0 -1
  188. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/icon.svg +0 -1
  189. package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/Contents.json +0 -1
  190. package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/icon.svg +0 -1
  191. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/Contents.json +0 -15
  192. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/icon.svg +0 -14
  193. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/Contents.json +0 -15
  194. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/icon.svg +0 -12
  195. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/Contents.json +0 -15
  196. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/icon.svg +0 -6
  197. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/Contents.json +0 -15
  198. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/icon.svg +0 -15
  199. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/Contents.json +0 -15
  200. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/icon.svg +0 -3
  201. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/Contents.json +0 -15
  202. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/icon.svg +0 -7
  203. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/Contents.json +0 -15
  204. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/icon.svg +0 -18
  205. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/Contents.json +0 -15
  206. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/icon.svg +0 -7
  207. package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/Contents.json +0 -1
  208. package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/icon.svg +0 -1
  209. package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/Contents.json +0 -1
  210. package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/icon.svg +0 -1
  211. package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/Contents.json +0 -1
  212. package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/icon.svg +0 -1
  213. package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/Contents.json +0 -1
  214. package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/icon.svg +0 -1
  215. package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/Contents.json +0 -1
  216. 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") result.put(key, changes.get(key))
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
  }