@onekeyfe/react-native-native-list 6.7.0-6 → 6.7.0-60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +27 -1
  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
@@ -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
  }
@@ -17,6 +17,7 @@ internal object NativeListRendererRegistry {
17
17
  NativeListRendererKey.ACTIVITY to ::NativeListActivityRowView,
18
18
  NativeListRendererKey.SYSTEM to ::NativeListSystemRowView,
19
19
  NativeListRendererKey.ACTION to ::NativeListActionRowView,
20
+ NativeListRendererKey.BUTTON_GROUP to ::NativeListButtonGroupRowView,
20
21
  )
21
22
 
22
23
  private val keys =
@@ -33,6 +34,7 @@ internal object NativeListRendererRegistry {
33
34
  "activity" to NativeListRendererKey.ACTIVITY,
34
35
  "system" to NativeListRendererKey.SYSTEM,
35
36
  "action" to NativeListRendererKey.ACTION,
37
+ "buttonGroup" to NativeListRendererKey.BUTTON_GROUP,
36
38
  )
37
39
 
38
40
  fun key(type: String) = keys.getValue(type)
@@ -106,6 +106,8 @@ internal abstract class NativeListRendererRowView(protected val reactContext: Th
106
106
  protected open val pressedColorName = "rowPressedBackground"
107
107
  protected open val pressedColorFallback = "#00000017"
108
108
  private var current: NativeListItem? = null
109
+ protected val boundItem: NativeListItem?
110
+ get() = current
109
111
  private var theme: JSONObject? = null
110
112
  private var listLayout = "linear"
111
113
  private var itemIndex: Int? = null
@@ -184,6 +186,9 @@ internal abstract class NativeListRendererRowView(protected val reactContext: Th
184
186
  checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String,
185
187
  useSourceScale: Boolean,
186
188
  ) {
189
+ val iconUpdate = NativeListIconUpdate(this)
190
+ try {
191
+
187
192
  val update = update(current, item)
188
193
  val signature =
189
194
  nativeListCanonical(
@@ -244,6 +249,8 @@ internal abstract class NativeListRendererRowView(protected val reactContext: Th
244
249
  bindSelectionContent(item, checkboxState)
245
250
  appearance()
246
251
  requestLayout()
252
+
253
+ } finally { iconUpdate.finish() }
247
254
  }
248
255
 
249
256
  override fun bindSelection(
@@ -43,6 +43,10 @@ internal data class NativeListResolvedText(
43
43
  val gravity: Int,
44
44
  val offset: Float,
45
45
  ) {
46
+ /** Offset into [text] for a UTF-16 offset into the [source] it was resolved from. */
47
+ fun displayOffset(sourceOffset: Long, source: String): Int =
48
+ nativeListDisplayOffset(source, sourceOffset, foldsLineBreaks = lines == 1 && explicitTruncation)
49
+
46
50
  fun bind(view: NativeListTextView) {
47
51
  view.includeFontPadding = false
48
52
  view.fontFeatureSettings = "tnum"
@@ -52,7 +56,7 @@ internal data class NativeListResolvedText(
52
56
  view.letterSpacing = 0f
53
57
  view.gravity = gravity
54
58
  view.opticalOffsetY = offset
55
- view.maxLines = lines
59
+ view.maxLines = if (lines == 0) Int.MAX_VALUE else lines
56
60
  view.setHorizontallyScrolling(lines == 1 && explicitTruncation)
57
61
  view.ellipsize = if (explicitTruncation && !clip) TextUtils.TruncateAt.END else null
58
62
  view.setLineSpacing(0f, 1f)
@@ -87,7 +91,8 @@ internal data class NativeListResolvedText(
87
91
  sourceScale: Boolean,
88
92
  ): NativeListResolvedText {
89
93
  val density = context.resources.displayMetrics.density
90
- val maxLines = (style?.optInt("lines", lines) ?: lines).coerceIn(1, 3)
94
+ val requestedLines = style?.optInt("lines", lines) ?: lines
95
+ val maxLines = if (requestedLines == 0) 0 else requestedLines.coerceIn(1, 3)
91
96
  val truncation = style?.let { it.has("lines") || it.has("truncate") } == true
92
97
  val fontSize =
93
98
  if (style?.has("fontSize") == true) (style.optDouble("fontSize") * density).toFloat()
@@ -118,7 +123,7 @@ internal data class NativeListResolvedText(
118
123
  else -> Gravity.TOP
119
124
  }
120
125
  return NativeListResolvedText(
121
- if (maxLines == 1 && truncation) text.replace(Regex("\\r\\n|[\\r\\n]"), " ") else text,
126
+ if (maxLines == 1 && truncation) nativeListFoldLineBreaks(text) else text,
122
127
  fontSize,
123
128
  face,
124
129
  style
@@ -26,6 +26,7 @@ internal class NativeListSectionHeaderRowView(context: ThemedReactContext, fonts
26
26
  private val mainColumn = LinearLayout(context)
27
27
  private val titleLine = PackedTitleLineLayout(context)
28
28
  private val title = DottedUnderlineTextView(context)
29
+ private val leadingBadge = NativeListTextView(context)
29
30
  private val titleSpinner = ProgressBar(context, null, android.R.attr.progressBarStyleSmall).apply {
30
31
  isIndeterminate = true
31
32
  importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
@@ -165,6 +166,12 @@ internal class NativeListSectionHeaderRowView(context: ThemedReactContext, fonts
165
166
  currentTheme = theme
166
167
  currentLayout = layout
167
168
  removeAllViews()
169
+ if (trailingViews[0].parent === titleLine) {
170
+ titleLine.removeView(trailingViews[0])
171
+ trailingColumn.addView(trailingViews[0], 0)
172
+ }
173
+ titleLine.removeView(leadingBadge)
174
+ leadingBadge.text = ""
168
175
  titleLine.removeView(headerTitleIcon)
169
176
  trailingColumn.removeView(headerValueIcon)
170
177
  paintDefaults.forEach { (view, flags) -> view.paintFlags = flags }
@@ -188,6 +195,10 @@ internal class NativeListSectionHeaderRowView(context: ThemedReactContext, fonts
188
195
  view.ellipsize = null
189
196
  view.setHorizontallyScrolling(false)
190
197
  view.opticalOffsetY = 0f
198
+ view.helpBindingGeneration += 1
199
+ view.guardsHelpTouches = false
200
+ view.primaryHelpOnly = false
201
+ view.showsHelpUnderline = false
191
202
  view.gravity = Gravity.START
192
203
  view.letterSpacing = 0f
193
204
  view.fontFeatureSettings = "tnum"
@@ -291,6 +302,7 @@ internal class NativeListSectionHeaderRowView(context: ThemedReactContext, fonts
291
302
  }
292
303
  }
293
304
  applyTextStyle(item)
305
+ bindPositionHeaderFields(item, theme)
294
306
  titleSpinner.indeterminateTintList = ColorStateList.valueOf(title.currentTextColor)
295
307
  style
296
308
  .optJSONObject("container")
@@ -307,6 +319,57 @@ internal class NativeListSectionHeaderRowView(context: ThemedReactContext, fonts
307
319
  applySelectorTypography(item)
308
320
  }
309
321
 
322
+ private fun bindPositionHeaderFields(item: NativeListItem, theme: JSONObject?) {
323
+ val style = item.json.optJSONObject("style") ?: JSONObject()
324
+ item.json.optJSONObject("leadingBadge")?.let { badge ->
325
+ leadingBadge.text = badge.optString("text")
326
+ leadingBadge.textSize = sp(12f)
327
+ leadingBadge.typeface = fonts.medium(context)
328
+ leadingBadge.includeFontPadding = false
329
+ val tones = mapOf("info" to ("info" to "#0F69F6"), "success" to ("positive" to "#008F5A"), "warning" to ("caution" to "#A35E00"), "danger" to ("negative" to "#CE2C31"))
330
+ val tone = tones[badge.optString("tone")]
331
+ if (tone != null) {
332
+ val tint = color(theme, tone.first, tone.second)
333
+ leadingBadge.setTextColor(tint)
334
+ val fallback = (tint and 0x00FFFFFF) or (31 shl 24)
335
+ val fill = if (badge.optString("tone") == "success" && theme?.has("successBackground") == true)
336
+ safeColor(theme.optString("successBackground"), fallback) else fallback
337
+ leadingBadge.background = roundedFill(fill, 4f)
338
+ } else {
339
+ leadingBadge.setTextColor(color(theme, "secondaryText", "#0000009B"))
340
+ leadingBadge.background = roundedFill(color(theme, "strongBackground", "#0000000F"), 4f)
341
+ }
342
+ leadingBadge.setPadding(dp(8), dp(2), dp(8), dp(2))
343
+ TextViewCompat.setLineHeight(leadingBadge, dp(16))
344
+ titleLine.addView(leadingBadge, 0, LayoutParams(LayoutParams.WRAP_CONTENT, dp(20)).apply { marginEnd = dp(8) })
345
+ }
346
+ if (style.has("titleDecoration")) {
347
+ title.showsDottedUnderline = false
348
+ title.showsHelpUnderline = style.optString("titleDecoration") == "dashed"
349
+ title.setPadding(0, 0, 0, if (title.showsHelpUnderline) dp(3) else 0)
350
+ }
351
+ val value = trailingViews[0]
352
+ if (style.optString("valuePlacement") == "afterTitle") {
353
+ trailingColumn.removeView(value)
354
+ title.layoutParams = wrap()
355
+ titleLine.packsChildrenAtStart = false
356
+ titleLine.addView(value, wrap().apply { marginStart = dp(8) })
357
+ }
358
+ item.json.optJSONObject("valueHelp")?.let { help ->
359
+ value.guardsHelpTouches = true
360
+ value.setOnClickListener(null)
361
+ value.isClickable = false
362
+ value.showsHelpUnderline = help.optString("underline") == "dashed"
363
+ if (help.optString("presentation") == "popover") {
364
+ value.setOnClickListener {
365
+ currentItem?.takeUnless { it.json.optBoolean("disabled") }?.let {
366
+ emitAction(it, help.optString("actionKey"), null, value, "trailingAccessory", 0)
367
+ }
368
+ }
369
+ }
370
+ }
371
+ }
372
+
310
373
  private fun applyTextStyle(item: NativeListItem) {
311
374
  val style = item.json.optJSONObject("style") ?: return
312
375
  for ((slot, view) in
@@ -411,6 +474,12 @@ internal class NativeListSectionHeaderRowView(context: ThemedReactContext, fonts
411
474
  override fun recycleContent() {
412
475
  checkboxControl.reset()
413
476
  currentItem = null
477
+ title.setOnClickListener(null)
478
+ title.isClickable = false
479
+ trailingViews[0].helpBindingGeneration += 1
480
+ trailingViews[0].setOnClickListener(null)
481
+ trailingViews[0].isClickable = false
482
+ trailingViews[0].showsHelpUnderline = false
414
483
  titleSpinner.visibility = GONE
415
484
  }
416
485