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

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
@@ -0,0 +1,244 @@
1
+ package com.margelo.nitro.nativelist
2
+
3
+ import android.content.Context
4
+ import android.graphics.Canvas
5
+ import android.graphics.Color
6
+ import android.graphics.LinearGradient
7
+ import android.graphics.Matrix
8
+ import android.graphics.Paint
9
+ import android.graphics.Path
10
+ import android.graphics.PorterDuff
11
+ import android.graphics.PorterDuffXfermode
12
+ import android.graphics.RadialGradient
13
+ import android.graphics.RectF
14
+ import android.graphics.Shader
15
+ import android.os.SystemClock
16
+ import android.provider.Settings
17
+ import android.view.View
18
+ import android.view.animation.PathInterpolator
19
+ import kotlin.math.sqrt
20
+ import kotlin.math.tan
21
+ import org.json.JSONObject
22
+
23
+ /**
24
+ * Loading sheen and failed hatch drawn over a media tile while it has no picture. Geometry mirrors
25
+ * the Web renderer (`MediaTileRowRenderer.ts`) and iOS (`NativeListMediaPlaceholderView.swift`) so
26
+ * every platform draws the same placeholder.
27
+ */
28
+ internal class NativeListMediaPlaceholderView(context: Context) : View(context) {
29
+ enum class State {
30
+ Hidden,
31
+ Loading,
32
+ Failed,
33
+ }
34
+
35
+ var state = State.Hidden
36
+ private set
37
+
38
+ var cornerRadius = 0f
39
+ set(value) {
40
+ if (field == value) return
41
+ field = value
42
+ invalidate()
43
+ }
44
+
45
+ private val density = resources.displayMetrics.density
46
+ private val clip = Path()
47
+ private val bounds = RectF()
48
+ private val hatchPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE }
49
+ private val hatchMaskPaint =
50
+ Paint(Paint.ANTI_ALIAS_FLAG).apply { xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_IN) }
51
+ private val sheenPaint = Paint(Paint.ANTI_ALIAS_FLAG)
52
+ private val fillPaint = Paint(Paint.ANTI_ALIAS_FLAG)
53
+ private val glyphPaint =
54
+ Paint(Paint.ANTI_ALIAS_FLAG).apply {
55
+ style = Paint.Style.STROKE
56
+ strokeCap = Paint.Cap.ROUND
57
+ strokeJoin = Paint.Join.ROUND
58
+ }
59
+ private val borderPaint =
60
+ Paint(Paint.ANTI_ALIAS_FLAG).apply {
61
+ style = Paint.Style.STROKE
62
+ strokeWidth = 1f
63
+ }
64
+ private val picture = Path()
65
+ private val slash = Path()
66
+ private val pictureClip = Path()
67
+ private var shine = Color.argb(191, 255, 255, 255)
68
+ private var laidOutWidth = -1
69
+ private var laidOutHeight = -1
70
+ private var reduceMotion = false
71
+
72
+ init {
73
+ visibility = GONE
74
+ setWillNotDraw(false)
75
+ importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_NO
76
+ }
77
+
78
+ fun applyTheme(theme: JSONObject?) {
79
+ fun tint(name: String, fallback: String) =
80
+ parseNativeListColor(theme?.optString(name, fallback)?.takeIf(String::isNotEmpty) ?: fallback)
81
+ glyphPaint.color = withAlpha(tint("disabledText", "#8C8C8C"), 0.7f)
82
+ fillPaint.color = tint("strongBackground", "#0000000F")
83
+ borderPaint.color = withAlpha(tint("separator", "#E5E7EB"), 0.6f)
84
+ val primary = tint("primaryText", "#202020")
85
+ hatchPaint.color = Color.argb(11, Color.red(primary), Color.green(primary), Color.blue(primary))
86
+ val row = tint("rowBackground", "#FFFFFF")
87
+ val dark = Color.red(row) * 299 + Color.green(row) * 587 + Color.blue(row) * 114 < 128_000
88
+ val nextShine = Color.argb(if (dark) 18 else 191, 255, 255, 255)
89
+ if (nextShine != shine) {
90
+ shine = nextShine
91
+ laidOutWidth = -1
92
+ }
93
+ invalidate()
94
+ }
95
+
96
+ fun setState(next: State) {
97
+ if (next == state) return
98
+ state = next
99
+ if (next == State.Loading) reduceMotion = animatorScale() == 0f
100
+ visibility = if (next == State.Hidden) GONE else VISIBLE
101
+ invalidate()
102
+ }
103
+
104
+ override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
105
+ super.onSizeChanged(w, h, oldw, oldh)
106
+ laidOutWidth = -1
107
+ }
108
+
109
+ private fun layoutShapes() {
110
+ if (laidOutWidth == width && laidOutHeight == height) return
111
+ laidOutWidth = width
112
+ laidOutHeight = height
113
+ val w = width.toFloat()
114
+ val h = height.toFloat()
115
+ val center = 0.5f * sqrt(w * w + h * h)
116
+ hatchMaskPaint.shader =
117
+ RadialGradient(
118
+ w / 2,
119
+ h / 2,
120
+ center.coerceAtLeast(1f),
121
+ intArrayOf(Color.TRANSPARENT, Color.TRANSPARENT, Color.BLACK, Color.BLACK),
122
+ floatArrayOf(0f, 0.22f, 0.7f, 1f),
123
+ Shader.TileMode.CLAMP,
124
+ )
125
+ val transparentShine = shine and 0x00FFFFFF
126
+ sheenPaint.shader =
127
+ LinearGradient(
128
+ 0f,
129
+ 0f,
130
+ w * 0.6f,
131
+ 0f,
132
+ intArrayOf(transparentShine, shine, transparentShine),
133
+ floatArrayOf(0f, 0.5f, 1f),
134
+ Shader.TileMode.CLAMP,
135
+ )
136
+ hatchPaint.strokeWidth = density
137
+ // Glyph geometry in a 24-unit box, scaled to 28% of the tile and capped at 44pt.
138
+ val size = minOf(w * 0.28f, 44f * density)
139
+ val scale = size / 24f
140
+ val matrix =
141
+ Matrix().apply {
142
+ setScale(scale, scale)
143
+ postTranslate((w - size) / 2, (h - size) / 2)
144
+ }
145
+ glyphPaint.strokeWidth = 1.5f * scale
146
+ picture.reset()
147
+ picture.addRoundRect(RectF(3f, 3f, 21f, 21f), 4f, 4f, Path.Direction.CW)
148
+ picture.addCircle(9f, 9f, 1.6f, Path.Direction.CW)
149
+ picture.moveTo(5f, 20.5f)
150
+ picture.lineTo(14.5f, 11f)
151
+ picture.lineTo(21f, 17.5f)
152
+ picture.transform(matrix)
153
+ slash.reset()
154
+ slash.moveTo(3f, 3f)
155
+ slash.lineTo(21f, 21f)
156
+ slash.transform(matrix)
157
+ val band =
158
+ Path().apply {
159
+ moveTo(2.6f, -0.6f)
160
+ lineTo(24.6f, 21.4f)
161
+ lineTo(21.4f, 24.6f)
162
+ lineTo(-0.6f, 2.6f)
163
+ close()
164
+ transform(matrix)
165
+ }
166
+ pictureClip.reset()
167
+ pictureClip.addRect(0f, 0f, w, h, Path.Direction.CW)
168
+ pictureClip.op(band, Path.Op.DIFFERENCE)
169
+ }
170
+
171
+ override fun onDraw(canvas: Canvas) {
172
+ if (state == State.Hidden || width == 0 || height == 0) return
173
+ layoutShapes()
174
+ val w = width.toFloat()
175
+ val h = height.toFloat()
176
+ bounds.set(0f, 0f, w, h)
177
+ clip.reset()
178
+ clip.addRoundRect(bounds, cornerRadius, cornerRadius, Path.Direction.CW)
179
+ canvas.save()
180
+ canvas.clipPath(clip)
181
+ // The placeholder owns the slot fill: the image view underneath is empty while
182
+ // loading and hidden once every probe failed.
183
+ canvas.drawRect(0f, 0f, w, h, fillPaint)
184
+ if (state == State.Failed) drawHatch(canvas, w, h) else drawSheen(canvas, w, h)
185
+ if (state == State.Failed) {
186
+ canvas.save()
187
+ canvas.clipPath(pictureClip)
188
+ canvas.drawPath(picture, glyphPaint)
189
+ canvas.restore()
190
+ canvas.drawPath(slash, glyphPaint)
191
+ } else canvas.drawPath(picture, glyphPaint)
192
+ canvas.restore()
193
+ val inset = borderPaint.strokeWidth / 2
194
+ bounds.inset(inset, inset)
195
+ canvas.drawRoundRect(bounds, cornerRadius - inset, cornerRadius - inset, borderPaint)
196
+ }
197
+
198
+ private fun drawHatch(canvas: Canvas, w: Float, h: Float) {
199
+ val layer = canvas.saveLayer(0f, 0f, w, h, null)
200
+ // Lines along x + y = c, 7pt apart measured perpendicular to the stripes.
201
+ val step = 7f * density * sqrt(2f)
202
+ var c = 0f
203
+ while (c <= w + h) {
204
+ canvas.drawLine(c, 0f, 0f, c, hatchPaint)
205
+ c += step
206
+ }
207
+ canvas.drawRect(0f, 0f, w, h, hatchMaskPaint)
208
+ canvas.restoreToCount(layer)
209
+ }
210
+
211
+ private fun drawSheen(canvas: Canvas, w: Float, h: Float) {
212
+ // Band left edge travels from -80% to 130% of the tile, then rests for 30% of the period.
213
+ // Every tile derives its phase from the shared uptime clock so the grid sweeps in step.
214
+ val phase = (SystemClock.uptimeMillis() % SWEEP_PERIOD_MS).toFloat() / SWEEP_PERIOD_MS
215
+ val progress = if (phase < 0.7f) SWEEP_EASING.getInterpolation(phase / 0.7f) else 1f
216
+ val left = if (reduceMotion) w * 0.2f else w * (-0.8f + 2.1f * progress)
217
+ sheenPaint.alpha = if (reduceMotion) 153 else 255
218
+ canvas.save()
219
+ canvas.translate(left + w * 0.3f, h / 2)
220
+ canvas.skew(SKEW, 0f)
221
+ canvas.translate(-w * 0.3f, 0f)
222
+ canvas.drawRect(0f, -h, w * 0.6f, h, sheenPaint)
223
+ canvas.restore()
224
+ if (!reduceMotion && isAttachedToWindow) postInvalidateOnAnimation()
225
+ }
226
+
227
+ private fun animatorScale() =
228
+ Settings.Global.getFloat(context.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f)
229
+
230
+ private fun withAlpha(color: Int, factor: Float) =
231
+ Color.argb(
232
+ (Color.alpha(color) * factor).toInt(),
233
+ Color.red(color),
234
+ Color.green(color),
235
+ Color.blue(color),
236
+ )
237
+
238
+ private companion object {
239
+ const val SWEEP_PERIOD_MS = 1600L
240
+ // CSS skewX(-12deg).
241
+ val SKEW = tan(Math.toRadians(-12.0)).toFloat()
242
+ val SWEEP_EASING = PathInterpolator(0.4f, 0f, 0.2f, 1f)
243
+ }
244
+ }
@@ -26,6 +26,8 @@ import com.facebook.react.modules.network.OkHttpClientProvider
26
26
  import com.facebook.react.uimanager.ThemedReactContext
27
27
  import okhttp3.JavaNetCookieJar
28
28
  import org.json.JSONObject
29
+ import com.margelo.nitro.onekeyimage.OneKeyMediaPreviewCache
30
+ import java.util.UUID
29
31
 
30
32
  /**
31
33
  * Uses Media3 like native Video, but never starts playback or requests audio focus. A player
@@ -35,9 +37,10 @@ import org.json.JSONObject
35
37
  internal class NativeListMediaPreviewSlot(private val context: ThemedReactContext) {
36
38
  val view: FrameLayout = object : FrameLayout(context) {
37
39
  override fun onAttachedToWindow() { super.onAttachedToWindow(); observeViewport(); updateVisibility() }
38
- override fun onDetachedFromWindow() { stopObservingViewport(); releasePlayer(); super.onDetachedFromWindow() }
40
+ override fun onDetachedFromWindow() { stopObservingViewport(); cancelPreview(); super.onDetachedFromWindow() }
41
+ override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { super.onSizeChanged(w, h, oldw, oldh); updateVisibility() }
39
42
  override fun onWindowVisibilityChanged(visibility: Int) { super.onWindowVisibilityChanged(visibility); updateVisibility() }
40
- override fun onVisibilityAggregated(isVisible: Boolean) { super.onVisibilityAggregated(isVisible); if (isVisible) updateVisibility() else releasePlayer() }
43
+ override fun onVisibilityAggregated(isVisible: Boolean) { super.onVisibilityAggregated(isVisible); if (isVisible) updateVisibility() else cancelPreview() }
41
44
  }
42
45
  private val image = NativeListImageSlot(context)
43
46
  private val video = AspectRatioFrameLayout(context)
@@ -51,6 +54,10 @@ internal class NativeListMediaPreviewSlot(private val context: ThemedReactContex
51
54
  private var completion: ((Boolean) -> Unit)? = null
52
55
  private var pendingCompletion: Runnable? = null
53
56
  private var player: ExoPlayer? = null
57
+ private var subscription: OneKeyMediaPreviewCache.Subscription? = null
58
+ private var extractionLease: UUID? = null
59
+ private var requestedEdge: Int? = null
60
+ private val previewCache by lazy { OneKeyMediaPreviewCache.get(context) }
54
61
  private var resumeVideo: (() -> Unit)? = null
55
62
  private var viewportObserver: ViewTreeObserver? = null
56
63
  private val visibleRect = Rect()
@@ -99,7 +106,7 @@ internal class NativeListMediaPreviewSlot(private val context: ThemedReactContex
99
106
  val candidate = candidateGeneration
100
107
  resumeVideo = null
101
108
  stopObservingViewport()
102
- releasePlayer()
109
+ cancelPreview()
103
110
  if (attempt >= order.size) {
104
111
  result = false
105
112
  completion?.invoke(false)
@@ -133,8 +140,36 @@ internal class NativeListMediaPreviewSlot(private val context: ThemedReactContex
133
140
  val uri = source.optString("uri")
134
141
  if (uri.isBlank()) { finished(false); return }
135
142
  val headers = source.optJSONObject("headers")?.let { values -> values.keys().asSequence().associateWith { values.optString(it) } } ?: emptyMap()
143
+ val fitKey = if ((fit ?: source.optString("contentFit")) == "cover") "cover" else "contain"
136
144
  resumeVideo = start@{
137
- if (epoch != token || candidateGeneration != candidate || player != null) return@start
145
+ if (epoch != token || candidateGeneration != candidate || subscription != null || frame.drawable != null ||
146
+ video.width <= 0 || video.height <= 0) return@start
147
+ val edge = OneKeyMediaPreviewCache.targetEdge(maxOf(view.width, view.height))
148
+ requestedEdge = edge
149
+ subscription = previewCache.request(uri, headers, edge, fitKey, source.optString("cachePolicy", "memory-disk"),
150
+ onImage = { still ->
151
+ if (epoch == token && candidateGeneration == candidate) {
152
+ subscription = null
153
+ video.setAspectRatio(still.width.toFloat() / still.height)
154
+ frame.setImageBitmap(still); frame.visibility = View.VISIBLE
155
+ stopObservingViewport(); finished(true)
156
+ }
157
+ }, onExtract = { lease ->
158
+ if (epoch == token && candidateGeneration == candidate) {
159
+ extractionLease = lease
160
+ updateVisibility()
161
+ if (extractionLease == lease && requestedEdge == edge) startPlayer(uri, headers, token, candidate, edge, lease)
162
+ }
163
+ }, onRevoked = { extractionLease = null; releasePlayer() },
164
+ onFailure = {
165
+ if (epoch == token && candidateGeneration == candidate) { subscription = null; finished(false) }
166
+ })
167
+ }
168
+ observeViewport()
169
+ updateVisibility()
170
+ }
171
+
172
+ private fun startPlayer(uri: String, headers: Map<String, String>, token: Int, candidate: Int, edge: Int, lease: UUID) {
138
173
  playerGeneration++
139
174
  val generation = playerGeneration
140
175
  try {
@@ -158,10 +193,11 @@ internal class NativeListMediaPreviewSlot(private val context: ThemedReactContex
158
193
  next.addListener(object : Player.Listener {
159
194
  override fun onRenderedFirstFrame() {
160
195
  if (playerGeneration != generation) return
161
- finished(true, generation)
162
- captureFirstFrame(token, candidate, generation, FIRST_FRAME_CAPTURE_ATTEMPTS)
196
+ captureFirstFrame(token, candidate, generation, FIRST_FRAME_CAPTURE_ATTEMPTS, edge, lease)
197
+ }
198
+ override fun onPlayerError(error: PlaybackException) {
199
+ view.post { if (playerGeneration == generation) previewCache.fail(lease) }
163
200
  }
164
- override fun onPlayerError(error: PlaybackException) { if (playerGeneration == generation) finished(false, generation) }
165
201
  override fun onVideoSizeChanged(size: VideoSize) {
166
202
  if (playerGeneration == generation && size.height > 0) video.setAspectRatio(size.width * size.pixelWidthHeightRatio / size.height)
167
203
  }
@@ -170,39 +206,26 @@ internal class NativeListMediaPreviewSlot(private val context: ThemedReactContex
170
206
  next.prepare()
171
207
  next.pause()
172
208
  } catch (_: Exception) {
173
- releasePlayer()
174
- finished(false)
209
+ previewCache.fail(lease)
175
210
  }
176
- }
177
- observeViewport()
178
- updateVisibility()
179
211
  }
180
212
 
181
- /**
182
- * The rendered frame reaches the TextureView asynchronously, so a transparent copy is
183
- * retried on later frames. If no frame can be copied the paused player stays attached.
184
- */
185
- private fun captureFirstFrame(token: Int, candidate: Int, generation: Int, attemptsLeft: Int) {
213
+ /** TextureView requires UI access; request bounded pixels before background encoding. */
214
+ private fun captureFirstFrame(token: Int, candidate: Int, generation: Int, attemptsLeft: Int, edge: Int, lease: UUID) {
186
215
  view.postOnAnimation {
187
216
  if (epoch != token || candidateGeneration != candidate || playerGeneration != generation) return@postOnAnimation
188
- // Releasing first would make the queued success completion drop itself as stale.
189
- if (result != true) {
190
- captureFirstFrame(token, candidate, generation, attemptsLeft)
191
- return@postOnAnimation
192
- }
193
217
  val still = if (texture.isAvailable && texture.width > 0 && texture.height > 0) {
194
- runCatching { texture.getBitmap(texture.width, texture.height) }.getOrNull()
218
+ val scale = minOf(1.0, edge.toDouble() / maxOf(texture.width, texture.height))
219
+ runCatching { texture.getBitmap(maxOf(1, (texture.width * scale).toInt()), maxOf(1, (texture.height * scale).toInt())) }.getOrNull()
195
220
  } else null
196
221
  if (still == null || !hasVisiblePixels(still)) {
197
222
  still?.recycle()
198
- if (attemptsLeft > 1) captureFirstFrame(token, candidate, generation, attemptsLeft - 1)
223
+ if (attemptsLeft > 1) captureFirstFrame(token, candidate, generation, attemptsLeft - 1, edge, lease)
224
+ else previewCache.fail(lease)
199
225
  return@postOnAnimation
200
226
  }
201
- frame.setImageBitmap(still)
202
- frame.visibility = View.VISIBLE
203
- resumeVideo = null
204
- stopObservingViewport()
205
227
  releasePlayer()
228
+ previewCache.complete(lease, still)
206
229
  }
207
230
  }
208
231
 
@@ -213,7 +236,7 @@ internal class NativeListMediaPreviewSlot(private val context: ThemedReactContex
213
236
  }
214
237
 
215
238
  private fun observeViewport() {
216
- if (viewportObserver != null || resumeVideo == null || !view.isAttachedToWindow) return
239
+ if (viewportObserver != null || resumeVideo == null || frame.drawable != null || !view.isAttachedToWindow) return
217
240
  view.viewTreeObserver.takeIf { it.isAlive }?.let {
218
241
  it.addOnScrollChangedListener(scrollListener)
219
242
  it.addOnGlobalLayoutListener(layoutListener)
@@ -230,6 +253,13 @@ internal class NativeListMediaPreviewSlot(private val context: ThemedReactContex
230
253
  viewportObserver = null
231
254
  }
232
255
  private fun updateVisibility() {
256
+ requestedEdge?.let { previous ->
257
+ if (video.width > 0 && video.height > 0 && OneKeyMediaPreviewCache.targetEdge(maxOf(view.width, view.height)) != previous) {
258
+ cancelPreview(); requestedEdge = null
259
+ frame.setImageDrawable(null); frame.visibility = View.GONE; result = null
260
+ observeViewport()
261
+ }
262
+ }
233
263
  var ancestor: View? = view
234
264
  var opaque = true
235
265
  while (ancestor != null) {
@@ -238,7 +268,11 @@ internal class NativeListMediaPreviewSlot(private val context: ThemedReactContex
238
268
  }
239
269
  if (opaque && view.isAttachedToWindow && view.windowVisibility == View.VISIBLE && view.isShown &&
240
270
  view.getGlobalVisibleRect(visibleRect) && !visibleRect.isEmpty) resumeVideo?.invoke()
241
- else releasePlayer()
271
+ else cancelPreview()
272
+ }
273
+ private fun cancelPreview() {
274
+ val previous = subscription; subscription = null
275
+ previewCache.cancel(previous); extractionLease = null; releasePlayer()
242
276
  }
243
277
  private fun releasePlayer() {
244
278
  playerGeneration++
@@ -251,11 +285,12 @@ internal class NativeListMediaPreviewSlot(private val context: ThemedReactContex
251
285
  pendingCompletion = null
252
286
  resumeVideo = null
253
287
  stopObservingViewport()
254
- releasePlayer()
288
+ cancelPreview()
255
289
  image.recycle()
256
290
  image.view.visibility = View.VISIBLE
257
291
  video.visibility = View.GONE
258
292
  video.setAspectRatio(0f)
293
+ requestedEdge = null
259
294
  frame.setImageDrawable(null)
260
295
  frame.visibility = View.GONE
261
296
  identity = null; result = null; completion = null
@@ -16,7 +16,7 @@ internal class NativeListMediaTileRowView(context: ThemedReactContext, fonts: Na
16
16
  private val picture = FrameLayout(context)
17
17
  private val image = NativeListMediaPreviewSlot(context)
18
18
  private val network = NativeListImageSlot(context)
19
- private val errorIcon = OneKeyIconView(context)
19
+ private val placeholderView = NativeListMediaPlaceholderView(context)
20
20
  private val title = NativeListTextView(context)
21
21
  private val subtitle = NativeListTextView(context)
22
22
  private val badge = NativeListTextView(context)
@@ -43,7 +43,7 @@ internal class NativeListMediaTileRowView(context: ThemedReactContext, fonts: Na
43
43
  init {
44
44
  orientation = VERTICAL
45
45
  picture.addView(image.view, FrameLayout.LayoutParams(-1, -1))
46
- picture.addView(errorIcon)
46
+ picture.addView(placeholderView, FrameLayout.LayoutParams(-1, -1))
47
47
  picture.addView(badge)
48
48
  subtitleLine.addView(subtitle, LayoutParams(0, -2, 1f))
49
49
  subtitleLine.addView(network.view)
@@ -136,17 +136,20 @@ internal class NativeListMediaTileRowView(context: ThemedReactContext, fonts: Na
136
136
  metadata.layoutParams = LayoutParams(-1, -2).apply { topMargin = size("leadingGap", 8) }
137
137
  (subtitle.layoutParams as LayoutParams).marginEnd = dp(8)
138
138
  val state = item.json.optString("imageState")
139
- errorIcon.visibility = if (state == "error") VISIBLE else GONE
140
- errorIcon.iconName = "ImageSquareWavesOutline"
141
- errorIcon.tintColor = parseNativeListColor("#00000044")
142
- errorIcon.useSourceScale = sourceScale
143
- errorIcon.layoutParams = FrameLayout.LayoutParams(dp(24), dp(24), Gravity.CENTER)
139
+ placeholderView.applyTheme(theme)
140
+ placeholderView.cornerRadius =
141
+ if (imageStyle.optString("shape") == "circle" && !imageStyle.has("cornerRadius")) 10_000f
142
+ else if (imageStyle.has("cornerRadius")) stylePx(imageStyle.optDouble("cornerRadius")).toFloat()
143
+ else if (imageStyle.optString("shape") == "square") 0f
144
+ else dp(10).toFloat()
144
145
  val media = item.json.optJSONObject("media")
145
146
  val source = media?.optJSONObject("source") ?: item.json.optJSONObject("image")
146
147
  val order = media?.optJSONArray("probeOrder")?.let { values ->
147
148
  (0 until values.length()).map { values.optString(it) }
148
149
  } ?: listOf("image")
149
- if (state != "empty" && state != "error" && source != null)
150
+ if (state != "empty" && state != "error" && source != null) {
151
+ // Set before binding: a cached result completes synchronously inside bind.
152
+ showPlaceholder(NativeListMediaPlaceholderView.State.Loading)
150
153
  image.bind(
151
154
  source,
152
155
  "${item.key}:media",
@@ -156,17 +159,26 @@ internal class NativeListMediaTileRowView(context: ThemedReactContext, fonts: Na
156
159
  ?: "#0000000F",
157
160
  probeOrder = order,
158
161
  ) { loaded ->
159
- errorIcon.visibility = if (loaded) GONE else VISIBLE
162
+ showPlaceholder(
163
+ if (loaded) NativeListMediaPlaceholderView.State.Hidden
164
+ else NativeListMediaPlaceholderView.State.Failed
165
+ )
160
166
  if (!loaded) image.view.setBackgroundColor(tint("strongBackground", "#0000000F"))
161
167
  }
162
- else image.recycle()
168
+ } else {
169
+ image.recycle()
170
+ showPlaceholder(
171
+ if (state == "error") NativeListMediaPlaceholderView.State.Failed
172
+ else NativeListMediaPlaceholderView.State.Hidden
173
+ )
174
+ }
163
175
  // Legacy: only the empty/error states paint a slot fill; loaded images show
164
176
  // their own placeholder without a white backing.
165
177
  image.view.background =
166
178
  when (state) {
167
179
  "error" -> GradientDrawable().apply { setColor(tint("strongBackground", "#0000000F")) }
168
180
  "empty" -> GradientDrawable().apply { setColor(Color.WHITE) }
169
- else -> if (errorIcon.visibility == VISIBLE) GradientDrawable().apply { setColor(tint("strongBackground", "#0000000F")) } else null
181
+ else -> if (placeholderView.state == NativeListMediaPlaceholderView.State.Failed) GradientDrawable().apply { setColor(tint("strongBackground", "#0000000F")) } else null
170
182
  }
171
183
  image.view.outlineProvider =
172
184
  object : ViewOutlineProvider() {
@@ -229,8 +241,17 @@ internal class NativeListMediaTileRowView(context: ThemedReactContext, fonts: Na
229
241
  super.onMeasure(widthMeasureSpec, heightMeasureSpec)
230
242
  }
231
243
 
244
+ private fun showPlaceholder(state: NativeListMediaPlaceholderView.State) {
245
+ placeholderView.setState(state)
246
+ // OneKeyImage may paint its own terminal symbol once a probe fails; the failed
247
+ // placeholder replaces the slot entirely instead of drawing over it.
248
+ image.view.visibility =
249
+ if (state == NativeListMediaPlaceholderView.State.Failed) INVISIBLE else VISIBLE
250
+ }
251
+
232
252
  override fun recycleContent() {
233
253
  image.recycle()
254
+ showPlaceholder(NativeListMediaPlaceholderView.State.Hidden)
234
255
  network.recycle()
235
256
  closeKey = ""
236
257
  picture.alpha = 1f
@@ -1,7 +1,9 @@
1
1
  package com.margelo.nitro.nativelist
2
2
 
3
3
  import android.graphics.Color
4
+ import android.graphics.Canvas
4
5
  import android.graphics.Outline
6
+ import android.graphics.Paint
5
7
  import android.graphics.drawable.GradientDrawable
6
8
  import android.view.Gravity
7
9
  import android.view.View
@@ -211,6 +213,7 @@ internal class NativeListMessageRowView(context: ThemedReactContext, fonts: Nati
211
213
  NativeListRendererRowView(context, fonts) {
212
214
  override val assetFields = listOf("leading", "thumbnail")
213
215
  private val views = NativeListMessageRenderer.Views(context, fonts)
216
+ private val warningBorderPaint = Paint(Paint.ANTI_ALIAS_FLAG)
214
217
 
215
218
  override fun bindContent(
216
219
  item: NativeListItem,
@@ -229,5 +232,27 @@ internal class NativeListMessageRowView(context: ThemedReactContext, fonts: Nati
229
232
 
230
233
  override fun recycleContent() = views.recycle()
231
234
 
235
+ override fun appearance() {
236
+ super.appearance()
237
+ if (boundItem?.json?.optString("presentation") == "inlineWarning") {
238
+ foreground = null
239
+ clipToOutline = false
240
+ (background as? GradientDrawable)?.cornerRadius = 0f
241
+ }
242
+ }
243
+
244
+ override fun dispatchDraw(canvas: Canvas) {
245
+ super.dispatchDraw(canvas)
246
+ val item = boundItem ?: return
247
+ if (item.json.optString("presentation") != "inlineWarning") return
248
+ val container = item.json.optJSONObject("style")?.optJSONObject("container") ?: return
249
+ val borderWidth = container.optDouble("borderWidth", 0.0).toFloat()
250
+ if (borderWidth <= 0) return
251
+ val pixels = (borderWidth * resources.displayMetrics.density).coerceAtLeast(1f)
252
+ warningBorderPaint.color = parseNativeListColor(container.optString("borderColor", "#00000000"))
253
+ canvas.drawRect(0f, 0f, width.toFloat(), pixels, warningBorderPaint)
254
+ canvas.drawRect(0f, height - pixels, width.toFloat(), height.toFloat(), warningBorderPaint)
255
+ }
256
+
232
257
  override fun disposeContent() = views.dispose()
233
258
  }