@onekeyfe/react-native-native-list 6.7.0-5 → 6.7.0-51

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 (214) 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 +35 -7
  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 +149 -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 +3 -2
  23. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
  24. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -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/NativeListIdentityTrailingAxisTest.kt +36 -0
  28. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
  29. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
  30. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
  31. package/docs/ROW_TEMPLATES.md +74 -13
  32. package/docs/SPEC.md +1232 -16
  33. package/docs/STYLE_SPEC.md +14 -0
  34. package/ios/HybridNativeList.swift +21 -2
  35. package/ios/NativeListAccessoryStack.swift +237 -51
  36. package/ios/NativeListActivityDetailsView.swift +30 -11
  37. package/ios/NativeListActivityRenderer.swift +8 -2
  38. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  39. package/ios/NativeListDataRowRenderer.swift +167 -30
  40. package/ios/NativeListDesignAssets.swift +13 -75
  41. package/ios/NativeListGeneratedIcons.swift +55 -0
  42. package/ios/NativeListIconBinding.swift +171 -0
  43. package/ios/NativeListIdentityRenderer.swift +256 -39
  44. package/ios/NativeListLeadingVisual.swift +127 -28
  45. package/ios/NativeListMarketRenderer.swift +120 -31
  46. package/ios/NativeListMediaPlaceholderView.swift +189 -0
  47. package/ios/NativeListMediaPreviewSlot.swift +122 -61
  48. package/ios/NativeListMediaTileRenderer.swift +15 -11
  49. package/ios/NativeListMessageRenderer.swift +34 -1
  50. package/ios/NativeListMetricCardRenderer.swift +4 -2
  51. package/ios/NativeListModels.swift +42 -2
  52. package/ios/NativeListRendererRegistry.swift +1 -0
  53. package/ios/NativeListResolvedText.swift +2 -1
  54. package/ios/NativeListRowHost.swift +14 -0
  55. package/ios/NativeListSectionHeaderRenderer.swift +100 -4
  56. package/ios/RNCNativeListView.swift +1093 -59
  57. package/ios/tests/NativeListAccessoryStackTests.swift +101 -0
  58. package/ios/tests/NativeListAccountSelectorLayoutTests.swift +96 -0
  59. package/ios/tests/NativeListActivityPresentationTests.swift +153 -0
  60. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
  61. package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
  62. package/ios/tests/NativeListLifecycleTests.swift +2915 -4
  63. package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
  64. package/ios/tests/NativeListMediaVisibilityTests.swift +26 -1
  65. package/ios/tests/NativeListSharedIconTests.swift +236 -0
  66. package/lib/module/NativeList.js +236 -38
  67. package/lib/module/NativeList.web.js +167 -46
  68. package/lib/module/index.js +1 -1
  69. package/lib/module/models.js +3 -0
  70. package/lib/module/selection.js +1 -1
  71. package/lib/module/validation.js +1246 -48
  72. package/lib/module/web/NativeListGeneratedIcons.js +31 -0
  73. package/lib/module/web/NativeListWebEngine.js +513 -275
  74. package/lib/module/web/templates/ActivityRowRenderer.js +12 -31
  75. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  76. package/lib/module/web/templates/DataRowRenderer.js +40 -5
  77. package/lib/module/web/templates/IdentityRowRenderer.js +158 -6
  78. package/lib/module/web/templates/MarketTableRowRenderer.js +36 -19
  79. package/lib/module/web/templates/MediaTileRowRenderer.js +84 -25
  80. package/lib/module/web/templates/MessageRowRenderer.js +18 -2
  81. package/lib/module/web/templates/RowContainerStyle.js +1 -0
  82. package/lib/module/web/templates/RowRendererRegistry.js +3 -0
  83. package/lib/module/web/templates/SectionHeaderRowRenderer.js +36 -2
  84. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  85. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  86. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  87. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  88. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  89. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  90. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  91. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  92. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  93. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  94. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  95. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  96. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  97. package/lib/typescript/src/NativeList.d.ts +3 -3
  98. package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
  99. package/lib/typescript/src/NativeList.types.d.ts +20 -2
  100. package/lib/typescript/src/index.d.ts +2 -2
  101. package/lib/typescript/src/models.d.ts +126 -17
  102. package/lib/typescript/src/validation.d.ts +20 -0
  103. package/lib/typescript/src/web/NativeListGeneratedIcons.d.ts +2 -0
  104. package/lib/typescript/src/web/NativeListWebEngine.d.ts +32 -1
  105. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  106. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  107. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +9 -3
  108. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  109. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  110. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  111. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  112. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  113. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  114. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  115. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  116. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  117. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  118. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  119. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  120. package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  121. package/package.json +16 -10
  122. package/react-native-native-list.podspec +2 -6
  123. package/scripts/generate-icons.mjs +150 -0
  124. package/scripts/generate-icons.test.mjs +288 -0
  125. package/scripts/native-list-icons.json +260 -0
  126. package/src/NativeList.nitro.ts +2 -0
  127. package/src/NativeList.tsx +439 -91
  128. package/src/NativeList.types.ts +24 -2
  129. package/src/NativeList.web.tsx +295 -89
  130. package/src/index.ts +2 -0
  131. package/src/models.ts +263 -144
  132. package/src/selection.ts +1 -0
  133. package/src/validation.ts +3013 -152
  134. package/src/web/NativeListGeneratedIcons.ts +28 -0
  135. package/src/web/NativeListWebEngine.ts +818 -343
  136. package/src/web/templates/ActivityRowRenderer.ts +29 -59
  137. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  138. package/src/web/templates/DataRowRenderer.ts +93 -20
  139. package/src/web/templates/IdentityRowRenderer.ts +231 -6
  140. package/src/web/templates/MarketTableRowRenderer.ts +53 -33
  141. package/src/web/templates/MediaTileRowRenderer.ts +90 -28
  142. package/src/web/templates/MessageRowRenderer.ts +23 -7
  143. package/src/web/templates/RowContainerStyle.ts +2 -0
  144. package/src/web/templates/RowRendererRegistry.ts +11 -1
  145. package/src/web/templates/SectionHeaderRowRenderer.ts +47 -4
  146. package/ios/Resources/NativeListIcons.xcassets/Contents.json +0 -1
  147. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/Contents.json +0 -1
  148. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/icon.svg +0 -1
  149. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/Contents.json +0 -1
  150. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/icon.svg +0 -1
  151. package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/Contents.json +0 -1
  152. package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/icon.svg +0 -1
  153. package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/Contents.json +0 -1
  154. package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/icon.svg +0 -1
  155. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/Contents.json +0 -1
  156. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/icon.svg +0 -1
  157. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/Contents.json +0 -1
  158. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/icon.svg +0 -1
  159. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/Contents.json +0 -1
  160. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/icon.svg +0 -1
  161. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/Contents.json +0 -1
  162. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/icon.svg +0 -1
  163. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/Contents.json +0 -1
  164. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/icon.svg +0 -1
  165. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/Contents.json +0 -1
  166. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/icon.svg +0 -1
  167. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/Contents.json +0 -1
  168. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/icon.svg +0 -1
  169. package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/Contents.json +0 -1
  170. package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/icon.svg +0 -1
  171. package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/Contents.json +0 -1
  172. package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/icon.svg +0 -1
  173. package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/Contents.json +0 -1
  174. package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/icon.svg +0 -1
  175. package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/Contents.json +0 -1
  176. package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/icon.svg +0 -1
  177. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/Contents.json +0 -1
  178. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/icon.svg +0 -1
  179. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/Contents.json +0 -1
  180. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/icon.svg +0 -1
  181. package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/Contents.json +0 -1
  182. package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/icon.svg +0 -1
  183. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/Contents.json +0 -1
  184. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/icon.svg +0 -1
  185. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/Contents.json +0 -1
  186. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/icon.svg +0 -1
  187. package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/Contents.json +0 -1
  188. package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/icon.svg +0 -1
  189. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/Contents.json +0 -15
  190. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/icon.svg +0 -14
  191. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/Contents.json +0 -15
  192. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/icon.svg +0 -12
  193. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/Contents.json +0 -15
  194. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/icon.svg +0 -6
  195. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/Contents.json +0 -15
  196. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/icon.svg +0 -15
  197. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/Contents.json +0 -15
  198. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/icon.svg +0 -3
  199. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/Contents.json +0 -15
  200. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/icon.svg +0 -7
  201. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/Contents.json +0 -15
  202. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/icon.svg +0 -18
  203. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/Contents.json +0 -15
  204. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/icon.svg +0 -7
  205. package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/Contents.json +0 -1
  206. package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/icon.svg +0 -1
  207. package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/Contents.json +0 -1
  208. package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/icon.svg +0 -1
  209. package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/Contents.json +0 -1
  210. package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/icon.svg +0 -1
  211. package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/Contents.json +0 -1
  212. package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/icon.svg +0 -1
  213. package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/Contents.json +0 -1
  214. 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,118 @@ 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
+ internal data class NativeListSlotFrame(val x: Int, val y: Int, val width: Int, val height: Int)
66
+
67
+ /** Side of one member of an Activity token pair inside a [frame]-unit box (24 in 40). */
68
+ internal fun nativeListLeadingPairMemberSize(frame: Int): Int = (frame * 0.6f).roundToInt()
69
+
70
+ /**
71
+ * Frame of image source [index] of a leading visual inside its [width]×[height]
72
+ * box (SPEC "Activity leading pair", OK-66071). [networkIndex] is the token
73
+ * `networkImage` badge and [pairIndex] the Activity `secondaryLeading` token;
74
+ * either is null when absent. A pair draws the primary at the top-left and the
75
+ * secondary at the bottom-right, both [nativeListLeadingPairMemberSize] wide and
76
+ * the secondary inset by its [pairRing]; the badge keeps its corner geometry
77
+ * above them. A lone token, or a token with only a badge, fills the box. Any
78
+ * other multi-source visual (stackedImages) steps 0.72-sized images diagonally.
79
+ */
80
+ internal fun nativeListLeadingSlotFrame(
81
+ index: Int,
82
+ sourceCount: Int,
83
+ networkIndex: Int?,
84
+ pairIndex: Int?,
85
+ width: Int,
86
+ height: Int,
87
+ badgeSize: Int,
88
+ badgeOverhang: Int,
89
+ pairRing: Int,
90
+ ): NativeListSlotFrame {
91
+ if (index == networkIndex)
92
+ return NativeListSlotFrame(
93
+ width - badgeSize + badgeOverhang,
94
+ height - badgeSize + badgeOverhang,
95
+ badgeSize,
96
+ badgeSize,
97
+ )
98
+ if (pairIndex != null) {
99
+ val member = nativeListLeadingPairMemberSize(height)
100
+ return if (index == pairIndex)
101
+ NativeListSlotFrame(width - member - pairRing, height - member - pairRing, member, member)
102
+ else NativeListSlotFrame(0, 0, member, member)
103
+ }
104
+ if (sourceCount == 1 || networkIndex != null) return NativeListSlotFrame(0, 0, width, height)
105
+ val side = (height * 0.72f).roundToInt()
106
+ val x = (index * (width - side).toFloat() / maxOf(1, sourceCount - 1)).roundToInt()
107
+ return NativeListSlotFrame(x, (height - side) / 2, side, side)
108
+ }
109
+
110
+ internal data class NativeListTrailingDescriptor(
111
+ val kind: String,
112
+ val name: String = "",
113
+ val actionKey: String = "",
114
+ )
115
+
116
+ /**
117
+ * Identity trailing accessories stack vertically unless they form one of the
118
+ * pairs every platform lays out side by side. The `valuePair` + `DotVerSolid`
119
+ * menu icon pair (the Swap token selector's balance and row menu) matches
120
+ * iOS `configureTrailingStack`; stacking it put the menu under the balance and
121
+ * clipped both inside the fixed row height on Android only.
122
+ */
123
+ internal fun nativeListIdentityTrailingIsHorizontal(
124
+ accessories: List<NativeListTrailingDescriptor>,
125
+ ): Boolean {
126
+ val kinds = accessories.map { it.kind }
127
+ if (kinds.containsAll(listOf("value", "checkbox"))) return true
128
+ if (accessories.size != 2) return false
129
+ val (first, second) = accessories
130
+ return kinds == listOf("valuePair", "menu") ||
131
+ kinds == listOf("valuePair", "chevron") ||
132
+ (kinds == listOf("valuePair", "icon") &&
133
+ second.name == "DotVerSolid" &&
134
+ second.actionKey == "menu") ||
135
+ (kinds == listOf("icon", "chevron") &&
136
+ first.name == "RefreshCcwOutline" &&
137
+ first.actionKey.isEmpty()) ||
138
+ (kinds == listOf("icon", "icon") &&
139
+ first.name == "PencilOutline" &&
140
+ second.name == "DragOutline")
141
+ }
142
+
30
143
  internal fun resolveNativeListSelectorBackgroundColor(
31
144
  rowType: String,
32
145
  styleBackgroundColor: String?,
@@ -57,7 +170,7 @@ private fun updateLengthPrefixed(digest: MessageDigest, value: String) {
57
170
  }
58
171
 
59
172
  // 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 }
173
+ internal enum class NativeListRendererKey { MESSAGE, RAIL, MEDIA_TILE, ACTION, SYSTEM, ACTIVITY, DATA_ROW, METRIC_CARD, MARKET, IDENTITY, SECTION_HEADER, WALLET_GROUP, BUTTON_GROUP }
61
174
 
62
175
  internal data class NativeListItem(
63
176
  val key: String,
@@ -142,6 +255,8 @@ internal data class NativeListItem(
142
255
 
143
256
  internal data class NativeListConfig(
144
257
  val generation: Int,
258
+ val structuralTransition: StructuralTransition?,
259
+ val disclosure: Disclosure?,
145
260
  val layout: String,
146
261
  val orientation: String,
147
262
  val gridColumns: Int,
@@ -168,9 +283,36 @@ internal data class NativeListConfig(
168
283
  val fixedFooter: NativeListItem?,
169
284
  val items: List<NativeListItem>,
170
285
  ) {
286
+ internal data class StructuralTransition(
287
+ val id: String,
288
+ val durationMs: Long,
289
+ val anchorKey: String?,
290
+ )
291
+ internal data class Disclosure(
292
+ val expanded: Boolean,
293
+ val expandedTrailingInset: Double,
294
+ )
171
295
  companion object {
172
296
  fun parse(snapshotJson: String): NativeListConfig {
173
297
  val root = JSONObject(snapshotJson)
298
+ val transition = root.optJSONObject("structuralTransition")
299
+ val structuralTransition = transition?.optString("id")?.takeIf(String::isNotEmpty)?.let { id ->
300
+ StructuralTransition(
301
+ id = id,
302
+ durationMs = transition.optDouble("durationMs", 220.0).coerceIn(0.0, 2000.0).toLong(),
303
+ anchorKey = transition.optString("anchorKey").takeIf(String::isNotEmpty),
304
+ )
305
+ }
306
+ val disclosureJson = root.optJSONObject("disclosure")
307
+ require(!root.has("disclosure") || disclosureJson != null) { "Invalid disclosure" }
308
+ val disclosure = disclosureJson?.let { value ->
309
+ require(value.opt("expanded") is Boolean) { "Invalid disclosure.expanded" }
310
+ require(!value.has("expandedTrailingInset") ||
311
+ value.opt("expandedTrailingInset") is Number) { "Invalid disclosure.expandedTrailingInset" }
312
+ val inset = value.optDouble("expandedTrailingInset", 0.0)
313
+ require(inset.isFinite() && inset >= 0.0) { "Invalid disclosure.expandedTrailingInset" }
314
+ Disclosure(value.getBoolean("expanded"), inset)
315
+ }
174
316
  require(root.getInt("schemaVersion") == 1) { "Unsupported schemaVersion" }
175
317
  val layout = root.getJSONObject("layout")
176
318
  val selection = root.optJSONObject("selection")
@@ -193,6 +335,8 @@ internal data class NativeListConfig(
193
335
  val fixedFooter = root.optJSONObject("fixedFooter")?.let(NativeListItem::parse)
194
336
  return NativeListConfig(
195
337
  generation = root.getInt("generation"),
338
+ structuralTransition = structuralTransition,
339
+ disclosure = disclosure,
196
340
  layout = layout.getString("kind"),
197
341
  orientation = layout.optString("orientation", "vertical"),
198
342
  gridColumns = layout.optInt("gridColumns", 1).coerceIn(1, 7),
@@ -235,7 +379,9 @@ internal fun mergeRow(original: JSONObject, changes: JSONObject): JSONObject {
235
379
  val keys = changes.keys()
236
380
  while (keys.hasNext()) {
237
381
  val key = keys.next()
238
- if (key != "key" && key != "type") result.put(key, changes.get(key))
382
+ if (key != "key" && key != "type") {
383
+ if (changes.isNull(key)) result.remove(key) else result.put(key, changes.get(key))
384
+ }
239
385
  }
240
386
  return result
241
387
  }
@@ -3,12 +3,10 @@ package com.margelo.nitro.nativelist
3
3
  import android.graphics.Canvas
4
4
  import android.graphics.Color
5
5
  import android.graphics.Paint
6
- import android.graphics.Path
7
6
  import android.graphics.Typeface
8
7
  import android.view.View
9
8
  import android.widget.LinearLayout
10
9
  import android.widget.TextView
11
- import androidx.core.graphics.PathParser
12
10
  import com.facebook.react.common.assets.ReactFontManager
13
11
  import kotlin.math.roundToInt
14
12
 
@@ -183,306 +181,141 @@ internal class SelectorSubtitleLayout(context: android.content.Context) : Linear
183
181
  }
184
182
  }
185
183
 
186
- internal class OneKeyIconView(context: android.content.Context) : View(context) {
184
+ internal open class OneKeyIconView(context: android.content.Context) : View(context) {
187
185
  var useSourceScale = false
186
+ set(value) { if (field == value) return; field = value; refresh() }
188
187
  var iconName: String = ""
189
- set(value) {
190
- field = value
191
- invalidate()
192
- }
193
-
188
+ set(value) { if (field == value) return; field = value; refresh() }
194
189
  var tintColor: Int = Color.rgb(100, 100, 100)
195
- set(value) {
196
- field = value
197
- invalidate()
198
- }
199
-
190
+ set(value) { if (field == value) return; field = value; refresh() }
200
191
  var glyphSizeDp: Int? = null
201
- set(value) {
202
- field = value
203
- invalidate()
204
- }
192
+ set(value) { if (field == value) return; field = value; refresh() }
193
+ private val owner = Any()
194
+ private var generation = 0L
195
+ private var identity: String? = null
196
+ private var bitmap: android.graphics.Bitmap? = null
197
+ private var displayed: com.margelo.nitro.onekeyimage.OneKeyNamedSVG.RenderResult? = null
198
+ private var displayedGeometry: String? = null
199
+ private val fill = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)
200
+ private var updateDepth = 0
201
+ private var initialized = true
202
+ private var attached = false
205
203
 
206
- private val fill = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
204
+ internal fun beginIconUpdate() { updateDepth++ }
205
+ internal fun endIconUpdate() { updateDepth--; if (updateDepth == 0) refresh() }
207
206
 
208
- override fun onDraw(canvas: Canvas) {
209
- super.onDraw(canvas)
210
- val pathData = iconPaths[iconName] ?: return
211
- val drawSize =
212
- minOf(
213
- minOf(width, height).toFloat(),
214
- glyphSizeDp?.let {
215
- if (useSourceScale) (it * resources.displayMetrics.density).roundToInt().toFloat()
216
- else NativeListScale.dp(resources, it).toFloat()
217
- } ?: Float.MAX_VALUE,
218
- )
219
- // OneKey patch: custom account-error artwork uses an 18-point viewBox.
220
- // val scale = drawSize / 24f
221
- val scale = drawSize / (selectorIconViewBoxes[iconName] ?: 24f)
222
- fill.color = tintColor
223
- canvas.save()
224
- canvas.translate((width - drawSize) / 2f, (height - drawSize) / 2f)
225
- canvas.scale(scale, scale)
226
- val sourceFillTypes = actionIconFillTypes[iconName]
227
- pathData.forEachIndexed { index, data ->
228
- PathParser.createPathFromPathData(data)?.let { path ->
229
- path.fillType = sourceFillTypes?.getOrNull(index) ?: Path.FillType.EVEN_ODD
230
- // OneKey patch: provider illustration colors are part of their source asset.
231
- fill.color = selectorIconColors[iconName]?.getOrNull(index) ?: tintColor
232
- canvas.drawPath(path, fill)
207
+ protected open fun metadata(): NativeListIconMetadata? {
208
+ nativeListGeneratedIcons[iconName]?.let { return it }
209
+ if (iconName.isEmpty()) return null
210
+ val meta = com.margelo.nitro.onekeyimage.OneKeyNamedSVG.iconMetadata(context.applicationContext.assets, iconName) ?: return null
211
+ return NativeListIconMetadata(iconName, meta.width, meta.height)
212
+ }
213
+ protected open fun glyphRect(icon: NativeListIconMetadata): android.graphics.RectF {
214
+ val limit = glyphSizeDp?.let {
215
+ if (useSourceScale) (it * resources.displayMetrics.density).roundToInt().toFloat()
216
+ else NativeListScale.dp(resources,it).toFloat()
217
+ } ?: Float.MAX_VALUE
218
+ val scale = minOf(minOf(width.toFloat(), limit) / icon.width, minOf(height.toFloat(), limit) / icon.height)
219
+ val drawWidth = icon.width * scale
220
+ val drawHeight = icon.height * scale
221
+ val left = (width - drawWidth) / 2f
222
+ val top = (height - drawHeight) / 2f
223
+ return android.graphics.RectF(left, top, left + drawWidth, top + drawHeight)
224
+ }
225
+
226
+ protected fun refresh(force: Boolean = false) {
227
+ if (updateDepth > 0) return
228
+ val icon = metadata()
229
+ val rect = icon?.let { glyphRect(it) }
230
+ val next = "$iconName|$tintColor|$rect|${resources.displayMetrics.density}|$attached|$isShown"
231
+ if (!force && next == identity) return
232
+ identity = next; generation++
233
+ val revision = generation
234
+ com.margelo.nitro.onekeyimage.OneKeyNamedSVG.cancel(owner)
235
+ fun clear() { bitmap = null; displayed = null; displayedGeometry = null; fill.colorFilter = null; invalidate() }
236
+ if (!attached || !isShown || icon == null || rect == null || rect.isEmpty || icon.name == "Circle") { clear(); return }
237
+ val w = kotlin.math.ceil(rect.width()).toInt()
238
+ val h = kotlin.math.ceil(rect.height()).toInt()
239
+ if (w !in 1..4096 || h !in 1..4096 || w.toLong() * h > 4194304) { clear(); return }
240
+ val color = "rgba(${Color.red(tintColor)},${Color.green(tintColor)},${Color.blue(tintColor)},${Color.alpha(tintColor)/255.0})"
241
+ val geometry = "${icon.name}|$rect|${resources.displayMetrics.density}"
242
+ val ready = displayed
243
+ if (displayedGeometry == geometry && ready != null && bitmap != null) {
244
+ if (ready.canTint(color)) {
245
+ fill.colorFilter = ready.tintColor(color)?.let { android.graphics.PorterDuffColorFilter(it, android.graphics.PorterDuff.Mode.SRC_IN) }
246
+ invalidate(); return
247
+ }
248
+ } else clear()
249
+ val weakView = java.lang.ref.WeakReference(this)
250
+ com.margelo.nitro.onekeyimage.OneKeyNamedSVG.requestRender(owner, context.applicationContext.assets,
251
+ icon.name,color,w,h,resources.displayMetrics.density) { result ->
252
+ val view = weakView.get()
253
+ if (view != null && view.generation == revision && view.attached && view.isShown) {
254
+ view.displayed = result
255
+ view.displayedGeometry = if (result != null) geometry else null
256
+ view.bitmap = result?.bitmap
257
+ view.fill.colorFilter = result?.tintColor(color)?.let { android.graphics.PorterDuffColorFilter(it, android.graphics.PorterDuff.Mode.SRC_IN) }
258
+ view.invalidate()
233
259
  }
234
260
  }
235
- canvas.restore()
236
261
  }
237
262
 
238
- companion object {
239
- // OneKey patch: preserve provider colors and non-24 viewBoxes.
240
- private val selectorIconColors: Map<String, List<Int?>> =
241
- mapOf(
242
- "GlobusOutline" to listOf(null),
243
- "LockSolid" to listOf(null),
244
- "GoogleIllus" to
245
- listOf(
246
- parseNativeListColor("#4285F4"),
247
- parseNativeListColor("#34A853"),
248
- parseNativeListColor("#FBBC05"),
249
- parseNativeListColor("#EA4335"),
250
- ),
251
- "AppleBrand" to listOf(null),
252
- "BotIllus" to
253
- listOf(
254
- parseNativeListColor("#8897A5"),
255
- parseNativeListColor("#3FA9F5"),
256
- parseNativeListColor("#8897A5"),
257
- parseNativeListColor("#8897A5"),
258
- parseNativeListColor("#10243E"),
259
- parseNativeListColor("#10243E"),
260
- parseNativeListColor("#10243E"),
261
- ),
262
- "AllNetworksSolid" to listOf(null, null),
263
- "CrossedSmallSolid" to listOf(null),
264
- "AccountErrorCustom" to listOf(Color.argb(0x72, 0, 0, 0), Color.argb(0x72, 0, 0, 0)),
265
- "Circle" to listOf(null),
266
- )
267
- private val selectorIconViewBoxes =
268
- mapOf(
269
- "GlobusOutline" to 24f,
270
- "LockSolid" to 24f,
271
- "GoogleIllus" to 24f,
272
- "AppleBrand" to 16f,
273
- "BotIllus" to 24f,
274
- "AllNetworksSolid" to 24f,
275
- "CrossedSmallSolid" to 24f,
276
- "AccountErrorCustom" to 18f,
277
- "Circle" to 24f,
278
- )
279
- // Keep the SVG fill-rule used by each Action-row source path. React Native
280
- // SVG defaults to nonzero (WINDING); only paths declaring fillRule="evenodd"
281
- // use EVEN_ODD. Other existing icons retain their prior rendering behavior.
282
- private val actionIconFillTypes =
283
- mapOf(
284
- "GlobusOutline" to listOf(Path.FillType.EVEN_ODD),
285
- "LockSolid" to listOf(Path.FillType.EVEN_ODD),
286
- "GoogleIllus" to
287
- listOf(
288
- Path.FillType.WINDING,
289
- Path.FillType.WINDING,
290
- Path.FillType.WINDING,
291
- Path.FillType.WINDING,
292
- ),
293
- "AppleBrand" to listOf(Path.FillType.WINDING),
294
- "BotIllus" to
295
- listOf(
296
- Path.FillType.WINDING,
297
- Path.FillType.WINDING,
298
- Path.FillType.WINDING,
299
- Path.FillType.WINDING,
300
- Path.FillType.WINDING,
301
- Path.FillType.WINDING,
302
- Path.FillType.WINDING,
303
- ),
304
- "AllNetworksSolid" to listOf(Path.FillType.WINDING, Path.FillType.EVEN_ODD),
305
- "CrossedSmallSolid" to listOf(Path.FillType.WINDING),
306
- "AccountErrorCustom" to listOf(Path.FillType.WINDING, Path.FillType.EVEN_ODD),
307
- "Circle" to listOf(Path.FillType.WINDING),
308
- "BadgeVerifiedSolid" to listOf(Path.FillType.EVEN_ODD),
309
- "ChevronRightSmallOutline" to listOf(Path.FillType.WINDING),
310
- "MinusCircleOutline" to listOf(Path.FillType.WINDING, Path.FillType.EVEN_ODD),
311
- "PlusCircleOutline" to listOf(Path.FillType.WINDING, Path.FillType.EVEN_ODD),
312
- "PlusSmallOutline" to listOf(Path.FillType.WINDING),
313
- "DotHorOutline" to listOf(Path.FillType.WINDING),
314
- "MinusCircleSolid" to listOf(Path.FillType.EVEN_ODD),
315
- "PencilOutline" to listOf(Path.FillType.EVEN_ODD),
316
- "DragOutline" to listOf(Path.FillType.WINDING),
317
- "StarSolid" to listOf(Path.FillType.WINDING),
318
- "ChevronGrabberVerOutline" to listOf(Path.FillType.WINDING),
319
- "ChevronBottomOutline" to listOf(Path.FillType.WINDING),
320
- "ChevronTopOutline" to listOf(Path.FillType.WINDING),
321
- "ImageSquareWavesOutline" to listOf(Path.FillType.WINDING, Path.FillType.EVEN_ODD),
322
- )
323
-
324
- // Exact 24x24 paths from app-monorepo packages/components Icon sources.
325
- private val iconPaths =
326
- mapOf(
327
- // OneKey patch: official selector SVG path geometry.
328
- "GlobusOutline" to
329
- listOf(
330
- "M12 2c5.185 0 9.448 3.947 9.95 9H22v2h-.05c-.502 5.053-4.765 9-9.95 9s-9.448-3.947-9.95-9H2v-2h.05C2.552 5.947 6.815 2 12 2M9.523 13c.09 1.982.438 3.726.934 5.002.29.746.612 1.282.917 1.614.304.331.517.384.626.384s.322-.053.626-.384c.305-.332.627-.868.917-1.614.496-1.276.845-3.02.934-5.002zm-5.459 0a8 8 0 0 0 4.8 6.36 10 10 0 0 1-.271-.633C7.994 17.187 7.61 15.189 7.52 13zm12.416 0c-.09 2.189-.474 4.187-1.073 5.727a10 10 0 0 1-.271.633 8 8 0 0 0 4.8-6.36zM8.863 4.639A8 8 0 0 0 4.064 11h3.457c.09-2.189.473-4.187 1.072-5.727q.127-.327.27-.634M12 4c-.109 0-.322.053-.626.384-.305.332-.627.868-.917 1.614-.496 1.276-.844 3.02-.934 5.002h4.954c-.09-1.982-.438-3.726-.934-5.002-.29-.746-.612-1.282-.917-1.614C12.322 4.053 12.109 4 12 4m3.136.639q.144.307.271.634c.599 1.54.982 3.538 1.073 5.727h3.456a8 8 0 0 0-4.8-6.361"
331
- ),
332
- "LockSolid" to
333
- listOf(
334
- "M12 2a5 5 0 0 1 5 5v2h3v13H4V9h3V7a5 5 0 0 1 5-5m-1 11v5h2v-5zm1-9a3 3 0 0 0-3 3v2h6V7a3 3 0 0 0-3-3"
335
- ),
336
- "GoogleIllus" to
337
- listOf(
338
- "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09",
339
- "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23",
340
- "M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22z",
341
- "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53",
342
- ),
343
- "AppleBrand" to
344
- listOf(
345
- "M11.67.834c.117 1.074-.315 2.153-.955 2.928-.64.773-1.692 1.378-2.718 1.298-.14-1.054.38-2.151.971-2.836C9.63 1.45 10.746.872 11.67.834M14.994 7.093c-.176.108-1.992 1.224-1.972 3.482.025 2.769 2.428 3.693 2.46 3.705l-.004.015a10.1 10.1 0 0 1-1.264 2.593c-.764 1.116-1.556 2.229-2.806 2.254-.598.011-1-.162-1.416-.343-.437-.19-.891-.386-1.609-.386-.751 0-1.226.203-1.683.398-.397.169-.78.333-1.32.354-1.208.047-2.124-1.207-2.895-2.32C.909 14.57-.294 10.414 1.322 7.612c.803-1.395 2.237-2.275 3.794-2.298.671-.014 1.32.244 1.89.47.434.172.821.326 1.135.326.282 0 .659-.149 1.099-.323.692-.273 1.539-.607 2.41-.518.599.026 2.276.24 3.354 1.818z"
346
- ),
347
- "BotIllus" to
348
- listOf(
349
- "M11 2a1 1 0 1 1 2 0v1.8l1.6 1.6a1 1 0 1 1-1.4 1.4L12 5.6l-1.2 1.2a1 1 0 0 1-1.4-1.4L11 3.8z",
350
- "M8.0 6.0h8.0a5.0 5.0 0 0 1 5.0 5.0v4.0a5.0 5.0 0 0 1 -5.0 5.0h-8.0a5.0 5.0 0 0 1 -5.0 -5.0v-4.0a5.0 5.0 0 0 1 5.0 -5.0z",
351
- "M3.0 10.0h0.0a1.5 1.5 0 0 1 1.5 1.5v3.0a1.5 1.5 0 0 1 -1.5 1.5h0.0a1.5 1.5 0 0 1 -1.5 -1.5v-3.0a1.5 1.5 0 0 1 1.5 -1.5z",
352
- "M21.0 10.0h0.0a1.5 1.5 0 0 1 1.5 1.5v3.0a1.5 1.5 0 0 1 -1.5 1.5h0.0a1.5 1.5 0 0 1 -1.5 -1.5v-3.0a1.5 1.5 0 0 1 1.5 -1.5z",
353
- "M7.5 12.0a1.5 1.5 0 1 0 3.0 0a1.5 1.5 0 1 0 -3.0 0",
354
- "M13.5 12.0a1.5 1.5 0 1 0 3.0 0a1.5 1.5 0 1 0 -3.0 0",
355
- "M8.5 15.4c.9.8 2.08 1.2 3.5 1.2s2.6-.4 3.5-1.2c.24-.2.6-.18.8.06.2.23.17.6-.06.8-1.14.98-2.58 1.46-4.24 1.46s-3.1-.48-4.24-1.46a.58.58 0 0 1-.06-.8c.2-.24.56-.26.8-.06",
356
- ),
357
- "AllNetworksSolid" to
358
- listOf(
359
- "M15.333 13.998a1.335 1.335 0 1 1 0 2.67 1.335 1.335 0 0 1 0-2.67",
360
- "M12 0c6.627 0 12 5.373 12 12s-5.373 12-12 12S0 18.627 0 12 5.373 0 12 0M8 12.668A2 2 0 0 0 6 14.666V16c0 1.103.895 1.997 1.998 1.998h1.334A2 2 0 0 0 11.33 16v-1.334a2 2 0 0 0-1.998-1.998zm7.333 0a2.665 2.665 0 1 0 0 5.33 2.665 2.665 0 0 0 0-5.33M7.999 6.001A2 2 0 0 0 6.001 8v1.334c0 1.103.895 1.998 1.998 1.998h1.334a2 2 0 0 0 1.998-1.998V7.999a2 2 0 0 0-1.998-1.998zm6.667 0A2 2 0 0 0 12.668 8v1.334c0 1.103.895 1.998 1.998 1.998H16a2 2 0 0 0 1.998-1.998V7.999A2 2 0 0 0 16 6.001z",
361
- ),
362
- "CrossedSmallSolid" to
363
- listOf(
364
- "M17.87 8.25 14.12 12l3.75 3.75-2.12 2.121-3.75-3.75-3.75 3.75-2.121-2.121L9.879 12l-3.75-3.75 2.12-2.121L12 9.879l3.75-3.75 2.122 2.121Z"
365
- ),
366
- "AccountErrorCustom" to
367
- listOf(
368
- "M12.5 12.75a1.25 1.25 0 1 0 0-2.5 1.25 1.25 0 0 0 0 2.5",
369
- "M0 3.5A3.5 3.5 0 0 1 3.5 0h8.088A2.41 2.41 0 0 1 14 2.412V5h1a3 3 0 0 1 3 3v7a3 3 0 0 1-3 3H4a4 4 0 0 1-4-4zm2 3.163V14a2 2 0 0 0 2 2h11a1 1 0 0 0 1-1V8a1 1 0 0 0-1-1H3.5c-.537 0-1.045-.12-1.5-.337M2 3.5A1.5 1.5 0 0 0 3.5 5H12V2.412A.41.41 0 0 0 11.588 2H3.5A1.5 1.5 0 0 0 2 3.5",
370
- ),
371
- "Circle" to listOf("M0 12a12 12 0 1 0 24 0a12 12 0 1 0 -24 0"),
372
- "BadgeVerifiedSolid" to
373
- listOf(
374
- "M9.483 11.458v3.5h-1v-3.5z M10.467 2.698a2.03 2.03 0 0 1 3.065 0l1.358 1.564a.03.03 0 0 0 .028.01l2.046-.325a2.03 2.03 0 0 1 2.347 1.971l.037 2.07q0 .016.014.026l1.776 1.066a2.03 2.03 0 0 1 .532 3.019l-1.304 1.609a.03.03 0 0 0-.005.03l.675 1.956a2.03 2.03 0 0 1-1.533 2.656l-2.033.394a.03.03 0 0 0-.023.019l-.741 1.933a2.03 2.03 0 0 1-2.88 1.05l-1.811-1.006a.03.03 0 0 0-.03 0l-1.811 1.005a2.03 2.03 0 0 1-2.88-1.049l-.742-1.933a.03.03 0 0 0-.023-.019l-2.033-.394a2.03 2.03 0 0 1-1.532-2.656l.675-1.957a.03.03 0 0 0-.005-.029l-1.304-1.61a2.03 2.03 0 0 1 .532-3.018l1.776-1.066a.03.03 0 0 0 .014-.026l.035-2.07a2.03 2.03 0 0 1 2.349-1.97l2.045.324a.03.03 0 0 0 .028-.01zm1.516 3.76a.5.5 0 0 0-.447.276l-1.861 3.724H8.483a1 1 0 0 0-1 1v3.5a1 1 0 0 0 1 1h6.692a2 2 0 0 0 1.981-1.73l.341-2.5a2 2 0 0 0-1.982-2.27h-1.939l.197-1.269a1.5 1.5 0 0 0-1.481-1.731z"
375
- ),
376
- "ArrowBottomOutline" to
377
- listOf("m13 17.586 5-5L19.414 14 12 21.414 4.586 14 6 12.586l5 5V3h2z"),
378
- "ArrowTopOutline" to
379
- listOf("M19.414 10 18 11.414l-5-5V21h-2V6.414l-5 5L4.586 10 12 2.586z"),
380
- "ChartTrendingUpOutline" to
381
- listOf("M22 13h-2V9.414l-7 7-4-4-6 6L1.586 17 9 9.586l4 4L18.586 8H15V6h7z"),
382
- "SwapHorOutline" to
383
- listOf(
384
- "M21 16H6.914l2.293 2.293-1.414 1.414L2.086 14H21zm.914-6H3V8h14.086l-2.293-2.293 1.414-1.414z"
385
- ),
386
- "ShieldExclamationOutline" to
387
- listOf(
388
- "M12 12.25a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5m0-4.75a1 1 0 0 1 1 1v2a1 1 0 0 1-2 0v-2a1 1 0 0 1 1-1",
389
- "M11.352 2.223c.42-.145.876-.145 1.296 0l6.98 2.4a1.995 1.995 0 0 1 1.347 1.886v5.432c0 2.799-1.146 4.817-2.805 6.387-1.61 1.525-3.735 2.652-5.696 3.71a1 1 0 0 1-.947 0c-1.961-1.058-4.086-2.185-5.697-3.71-1.659-1.57-2.805-3.588-2.805-6.386V6.508c0-.852.542-1.61 1.347-1.887l6.98-2.4ZM5.02 6.509v5.432c0 2.16.848 3.676 2.18 4.938 1.272 1.204 2.957 2.149 4.799 3.145 1.842-.996 3.527-1.94 4.799-3.145 1.332-1.262 2.181-2.778 2.181-4.938V6.51L12 4.109z",
390
- ),
391
- "InfoCircleOutline" to
392
- listOf(
393
- "M13 17h-2v-5h-1v-2h3zm0-8h-2V7h2z",
394
- "M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2m0 2a8 8 0 1 0 0 16 8 8 0 0 0 0-16",
395
- ),
396
- "SpeakerPromoteOutline" to
397
- listOf(
398
- "M21.996 11a4 4 0 0 1-3 3.874v5.495l-5.361-1.711A3.998 3.998 0 0 1 5.996 17v-.779l-4-1.276v-7.89l17-5.424v5.495c1.725.444 3 2.01 3 3.874m-2 0c0-.74-.402-1.385-1-1.731v3.46c.597-.345 1-.989 1-1.729M7.998 7.24v7.521l8.998 2.871V4.368l-8.998 2.87ZM3.996 8.516v4.967l2.002.638V7.877zm4 8.484a2 2 0 0 0 3.706 1.041L7.996 16.86z"
399
- ),
400
- "PlusCircleOutline" to
401
- listOf(
402
- "M13 11h4v2h-4v4h-2v-4l-4 .001v-2L11 11V7h2z",
403
- "M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2m0 2a8 8 0 1 0 0 16 8 8 0 0 0 0-16",
404
- ),
405
- "PlusSmallOutline" to listOf("M13 11h5v2h-5v5h-2v-5H6v-2h5V6h2z"),
406
- "DotHorOutline" to listOf("M6 14H2v-4h4zm8 0h-4v-4h4zm8 0h-4v-4h4z"),
407
- "MinusCircleOutline" to
408
- listOf(
409
- "M17 13H7v-2h10z",
410
- "M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2m0 2a8 8 0 1 0 0 16 8 8 0 0 0 0-16",
411
- ),
412
- "MinusCircleSolid" to
413
- listOf(
414
- "M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2M7 13h10v-2H7z"
415
- ),
416
- "ErrorSolid" to listOf("M23.256 20H.742L12 1.041zM11 15v2h2v-2zm0-6v5h2V9z"),
417
- "QuestionmarkSolid" to
418
- listOf(
419
- "M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2m-1 15h2v-2h-2zM9 7v3h2V9h2v1l-2 1.5V14h2v-1.5l2-1.5V7z"
420
- ),
421
- "PencilOutline" to
422
- listOf(
423
- "M22.414 7.5 7.914 22H2v-5.914l14.5-14.5zM4 16.914V20h3.086l9.5-9.5L13.5 7.414zM14.914 6 18 9.086 19.586 7.5 16.5 4.414z"
424
- ),
425
- "ChevronRightSmallOutline" to listOf("M15.414 12 10 17.414 8.586 16l4-4-4-4L10 6.586z"),
426
- "DragOutline" to
427
- listOf("M11 21H7v-4h4zm6 0h-4v-4h4zm-6-7H7v-4h4zm6 0h-4v-4h4zm-6-7H7V3h4zm6 0h-4V3h4z"),
428
- "StarOutline" to
429
- listOf(
430
- "m15.455 7.243 7.729 1.123-5.592 5.45 1.32 7.698L12 17.879l-6.911 3.635 1.32-7.698-5.592-5.45 7.728-1.123L12 .24zM9.872 9.071l-4.759.69 3.444 3.358-.814 4.738L12 15.62l.465.245 3.791 1.993-.813-4.739 3.443-3.357-4.758-.69L12 4.758z"
431
- ),
432
- "StarSolid" to
433
- listOf(
434
- "m15.405 7.313 7.84 1.034-5.735 5.443 1.44 7.774L12 17.793l-6.948 3.771 1.44-7.774L.756 8.347l7.839-1.034L12 .178z"
435
- ),
436
- "ChevronGrabberVerOutline" to
437
- listOf(
438
- "M17.414 15 12 20.414 6.586 15 8 13.586l4 4 4-4zm0-6L16 10.414l-4-4-4 4L6.586 9 12 3.586z"
439
- ),
440
- "ChevronBottomOutline" to
441
- listOf("M20.707 9.707 12 18.414 3.293 9.707l1.414-1.414L12 15.586l7.293-7.293z"),
442
- "ChevronTopOutline" to
443
- listOf("m20.707 14.293-1.414 1.414L12 8.414l-7.293 7.293-1.414-1.414L12 5.586z"),
444
- "ImageSquareWavesOutline" to
445
- listOf(
446
- "M14.25 7a2 2 0 1 1 0 4 2 2 0 0 1 0-4",
447
- "M21 21H3V3h18zM5 16.414V19h12.586L14 15.414l-2 2-4-4zm0-2.828 3-3 4 4 2-2 5 5V5H5z",
448
- ),
449
- )
263
+ override fun onDraw(canvas: Canvas) {
264
+ super.onDraw(canvas)
265
+ val icon = metadata() ?: return
266
+ val rect = glyphRect(icon)
267
+ if (icon.name == "Circle") { fill.colorFilter = null; fill.color = tintColor; canvas.drawOval(rect,fill); return }
268
+ fill.alpha = 255
269
+ bitmap?.let { canvas.drawBitmap(it,null,rect,fill) }
450
270
  }
271
+ override fun onAttachedToWindow() { super.onAttachedToWindow(); attached = true; refresh() }
272
+ override fun onDetachedFromWindow() {
273
+ attached = false
274
+ super.onDetachedFromWindow()
275
+ refresh()
276
+ }
277
+ override fun onVisibilityChanged(changedView: View, visibility: Int) {
278
+ super.onVisibilityChanged(changedView, visibility)
279
+ if (initialized) refresh()
280
+ }
281
+ override fun onSizeChanged(w: Int,h: Int,oldw: Int,oldh: Int) { super.onSizeChanged(w,h,oldw,oldh); refresh() }
282
+ override fun onConfigurationChanged(config: android.content.res.Configuration) { super.onConfigurationChanged(config); refresh(true) }
451
283
  }
452
284
 
453
- internal class OneKeyCheckboxView(context: android.content.Context) : View(context) {
285
+ internal class OneKeyCheckboxView(context: android.content.Context) : OneKeyIconView(context) {
454
286
  var usesSelectorGeometry = false
455
- private val glyphPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
456
- private var state = "unchecked"
457
-
458
- fun setState(value: String, color: Int) {
459
- state = value
460
- glyphPaint.color = color
461
- invalidate()
287
+ set(value) { if (field == value) return; field = value; refresh() }
288
+ fun setState(value: String,color: Int) {
289
+ tintColor = color
290
+ iconName = when(value) {
291
+ "checked" -> "CheckboxCheckedCustom"
292
+ "indeterminate" -> "CheckboxIndeterminateCustom"
293
+ else -> ""
294
+ }
462
295
  }
296
+ override fun metadata(): NativeListIconMetadata? = when(iconName) {
297
+ "CheckboxCheckedCustom", "CheckboxIndeterminateCustom" -> NativeListIconMetadata(iconName,16f,16f)
298
+ else -> null
299
+ }
300
+ override fun glyphRect(icon: NativeListIconMetadata): android.graphics.RectF {
301
+ val size = if (usesSelectorGeometry) (16 * resources.displayMetrics.density).roundToInt().toFloat() else minOf(width,height)*0.8f
302
+ val border = (2 * resources.displayMetrics.density).roundToInt().toFloat()
303
+ val left = if(usesSelectorGeometry) border else (width-size)/2f
304
+ val top = if(usesSelectorGeometry) border else (height-size)/2f
305
+ return android.graphics.RectF(left,top,left+size,top+size)
306
+ }
307
+ }
463
308
 
464
- override fun onDraw(canvas: Canvas) {
465
- super.onDraw(canvas)
466
- val pathData =
467
- when (state) {
468
- "checked" ->
469
- "M12.204 5.043a1 1 0 0 1 0 1.414l-4.5 4.5a1 1 0 0 1-1.414 0l-2-2a1 1 0 1 1 1.414-1.414l1.293 1.293 3.793-3.793a1 1 0 0 1 1.414 0"
470
- "indeterminate" -> "M4 8a1 1 0 0 1 1-1h6a1 1 0 0 1 0 2H5a1 1 0 0 1-1-1"
471
- else -> return
472
- }
473
- // OneKey patch: the source icon is a 16dp child after the 2dp border, not 80% of a rounded
474
- // frame.
475
- val drawSize =
476
- if (usesSelectorGeometry) (16 * resources.displayMetrics.density).roundToInt().toFloat()
477
- else minOf(width, height) * 0.8f
478
- val borderOffset = (2 * resources.displayMetrics.density).roundToInt().toFloat()
479
- canvas.save()
480
- canvas.translate(
481
- if (usesSelectorGeometry) borderOffset else (width - drawSize) / 2f,
482
- if (usesSelectorGeometry) borderOffset else (height - drawSize) / 2f,
483
- )
484
- canvas.scale(drawSize / 16f, drawSize / 16f)
485
- PathParser.createPathFromPathData(pathData)?.let { canvas.drawPath(it, glyphPaint) }
486
- canvas.restore()
309
+ /** Captures existing glyph slots only; nested synchronous binds share their final identity. */
310
+ internal class NativeListIconUpdate(root: View) {
311
+ private val icons = mutableListOf<OneKeyIconView>()
312
+ init {
313
+ fun collect(view: View) {
314
+ if (view is OneKeyIconView) icons.add(view)
315
+ if (view is android.view.ViewGroup) for (index in 0 until view.childCount) collect(view.getChildAt(index))
316
+ }
317
+ collect(root)
318
+ icons.forEach { it.beginIconUpdate() }
487
319
  }
320
+ fun finish() { icons.forEach { it.endIconUpdate() } }
488
321
  }