@onekeyfe/react-native-native-list 6.7.0-2 → 6.7.0-21

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 (148) hide show
  1. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
  2. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +245 -9
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +35 -7
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +25 -3
  5. package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
  6. package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
  8. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +102 -7
  9. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +225 -11
  10. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +147 -33
  11. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
  12. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +149 -3
  14. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +51 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
  16. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +2 -0
  17. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +3 -2
  18. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
  19. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -1
  20. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1953 -117
  21. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +35 -0
  22. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
  23. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
  24. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
  25. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
  26. package/docs/ROW_TEMPLATES.md +70 -11
  27. package/docs/SPEC.md +1235 -20
  28. package/docs/STYLE_SPEC.md +6 -0
  29. package/ios/HybridNativeList.swift +21 -2
  30. package/ios/NativeListAccessoryStack.swift +235 -39
  31. package/ios/NativeListActivityDetailsView.swift +30 -11
  32. package/ios/NativeListActivityRenderer.swift +8 -2
  33. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  34. package/ios/NativeListDataRowRenderer.swift +155 -27
  35. package/ios/NativeListDesignAssets.swift +9 -0
  36. package/ios/NativeListIdentityRenderer.swift +239 -31
  37. package/ios/NativeListLeadingVisual.swift +119 -22
  38. package/ios/NativeListMarketRenderer.swift +113 -18
  39. package/ios/NativeListMessageRenderer.swift +34 -1
  40. package/ios/NativeListModels.swift +42 -2
  41. package/ios/NativeListRendererRegistry.swift +1 -0
  42. package/ios/NativeListResolvedText.swift +2 -1
  43. package/ios/NativeListRowHost.swift +14 -0
  44. package/ios/NativeListSectionHeaderRenderer.swift +88 -0
  45. package/ios/RNCNativeListView.swift +1052 -58
  46. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
  47. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
  48. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/Contents.json +1 -0
  49. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/icon.svg +1 -0
  50. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/Contents.json +1 -0
  51. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/icon.svg +1 -0
  52. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
  53. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
  54. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/Contents.json +1 -0
  55. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/icon.svg +1 -0
  56. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
  57. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
  58. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +1 -0
  59. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +1 -0
  60. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +1 -0
  61. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +1 -0
  62. package/ios/tests/NativeListAccessoryStackTests.swift +89 -0
  63. package/ios/tests/NativeListActivityPresentationTests.swift +153 -0
  64. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
  65. package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
  66. package/ios/tests/NativeListLifecycleTests.swift +2789 -3
  67. package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
  68. package/lib/module/NativeList.js +223 -36
  69. package/lib/module/NativeList.web.js +260 -33
  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 +1386 -81
  74. package/lib/module/web/NativeListWebEngine.js +914 -80
  75. package/lib/module/web/templates/ActivityRowRenderer.js +487 -7
  76. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  77. package/lib/module/web/templates/DataRowRenderer.js +40 -5
  78. package/lib/module/web/templates/IdentityRowRenderer.js +145 -5
  79. package/lib/module/web/templates/MarketRowRenderer.js +8 -3
  80. package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
  81. package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
  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 +8 -3
  85. package/lib/module/web/templates/SectionHeaderRowRenderer.js +70 -3
  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 +29 -1
  102. package/lib/typescript/src/NativeList.web.d.ts +2 -2
  103. package/lib/typescript/src/index.d.ts +2 -2
  104. package/lib/typescript/src/models.d.ts +196 -17
  105. package/lib/typescript/src/validation.d.ts +20 -0
  106. package/lib/typescript/src/web/NativeListWebEngine.d.ts +58 -1
  107. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
  108. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  109. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  110. package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
  111. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
  112. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +10 -4
  113. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
  114. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  115. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  116. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  117. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  118. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  119. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  120. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  121. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  122. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  123. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  124. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  125. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  126. package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  127. package/package.json +3 -3
  128. package/react-native-native-list.podspec +1 -0
  129. package/src/NativeList.nitro.ts +2 -0
  130. package/src/NativeList.tsx +418 -89
  131. package/src/NativeList.types.ts +34 -1
  132. package/src/NativeList.web.tsx +417 -66
  133. package/src/index.ts +2 -0
  134. package/src/models.ts +355 -143
  135. package/src/selection.ts +1 -0
  136. package/src/validation.ts +3315 -166
  137. package/src/web/NativeListWebEngine.ts +1473 -113
  138. package/src/web/templates/ActivityRowRenderer.ts +732 -8
  139. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  140. package/src/web/templates/DataRowRenderer.ts +93 -20
  141. package/src/web/templates/IdentityRowRenderer.ts +217 -6
  142. package/src/web/templates/MarketRowRenderer.ts +19 -3
  143. package/src/web/templates/MarketTableRowRenderer.ts +755 -0
  144. package/src/web/templates/MediaTileRowRenderer.ts +313 -5
  145. package/src/web/templates/MessageRowRenderer.ts +23 -7
  146. package/src/web/templates/RowContainerStyle.ts +2 -0
  147. package/src/web/templates/RowRendererRegistry.ts +21 -6
  148. package/src/web/templates/SectionHeaderRowRenderer.ts +89 -5
@@ -23,14 +23,21 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
23
23
  private val icon = OneKeyIconView(context)
24
24
  private val unread = View(context)
25
25
  private val networkBackdrop = View(context)
26
+ // Ring under the secondary token of an Activity pair (SPEC "Activity leading pair").
27
+ private val pairBackdrop = View(context)
26
28
  private val corner = OneKeyIconView(context)
27
29
  private val cornerBackdrop = View(context)
28
30
  private val slots = mutableListOf<NativeListImageSlot>()
29
31
  private val overlaySlots = mutableListOf<NativeListImageSlot>()
32
+ private val overlayFallbackIcons = mutableListOf<OneKeyIconView>()
30
33
  private val overlays = mutableListOf<Pair<FrameLayout, JSONObject>>()
31
34
  private var visual = JSONObject()
32
35
  private var style = JSONObject()
33
36
  private var sources = emptyList<Pair<JSONObject, String>>()
37
+ // Roles inside [sources]: the token `networkImage` badge and the Activity
38
+ // `secondaryLeading` token; null when absent.
39
+ private var networkIndex: Int? = null
40
+ private var pairIndex: Int? = null
34
41
  val fallbackTextView: TextView
35
42
  get() = fallback
36
43
 
@@ -42,6 +49,15 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
42
49
  */
43
50
  var walletTextOverlays = false
44
51
 
52
+ /**
53
+ * True once the bound visual lays a badge past this frame (see
54
+ * [nativeListLeadingVisualOverhangsFrame]). This view never clips its children,
55
+ * but a host that clips children clips this view to its own bounds, so such a
56
+ * host must stop clipping or the badge is cut flat (OK-65694).
57
+ */
58
+ var requestsUnclippedHost = false
59
+ private set
60
+
45
61
  private fun isWalletText(data: JSONObject) =
46
62
  walletTextOverlays &&
47
63
  data.optString("text").isNotEmpty() &&
@@ -80,7 +96,9 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
80
96
  }
81
97
 
82
98
  init {
83
- listOf(fallback, icon, networkBackdrop, cornerBackdrop, corner, unread).forEach { addView(it) }
99
+ listOf(fallback, icon, pairBackdrop, networkBackdrop, cornerBackdrop, corner, unread).forEach {
100
+ addView(it)
101
+ }
84
102
  clipChildren = false
85
103
  clipToPadding = false
86
104
  }
@@ -109,6 +127,8 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
109
127
  "wallet" -> "avatar"
110
128
  else -> "generic"
111
129
  }
130
+ networkIndex = null
131
+ pairIndex = null
112
132
  sources =
113
133
  if (kind == "stackedImages")
114
134
  visual
@@ -122,7 +142,10 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
122
142
  else if (kind == "icon") emptyList()
123
143
  else visual.optJSONObject("image")?.let { listOf(it to variant) }.orEmpty()
124
144
  if (kind == "token" && sources.isNotEmpty())
125
- visual.optJSONObject("networkImage")?.let { sources = sources + (it to "network") }
145
+ visual.optJSONObject("networkImage")?.let {
146
+ networkIndex = sources.size
147
+ sources = sources + (it to "network")
148
+ }
126
149
  secondaryVisual?.let { second ->
127
150
  val kind = second.optString("kind")
128
151
  val source =
@@ -131,7 +154,10 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
131
154
  "icon" -> null
132
155
  else -> second.optJSONObject("image")
133
156
  }
134
- if (source != null)
157
+ if (source != null) {
158
+ // A second token forms a pair only next to a primary image; without one
159
+ // it simply takes the primary's place (OK-66071).
160
+ if (this.visual.optString("kind") == "token" && sources.isNotEmpty()) pairIndex = sources.size
135
161
  sources =
136
162
  sources +
137
163
  (source to
@@ -142,6 +168,7 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
142
168
  "wallet" -> "avatar"
143
169
  else -> "generic"
144
170
  })
171
+ }
145
172
  }
146
173
  while (slots.size < sources.size) {
147
174
  val slot = NativeListImageSlot(reactContext)
@@ -150,6 +177,8 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
150
177
  }
151
178
  val placeholder = theme?.optString("strongBackground", "#0000000F") ?: "#0000000F"
152
179
  val fallbackIcon = visual.optJSONObject("fallbackIcon")
180
+ val fallbackBackground = fallbackIcon?.optString("backgroundColor")
181
+ ?.takeIf(String::isNotEmpty) ?: placeholder
153
182
  val sourceFallback =
154
183
  sources.firstOrNull()?.first?.optString("loadingStrategy", "none")?.let { it != "none" } ==
155
184
  true && (visual.has("fallbackText") || fallbackIcon != null)
@@ -170,7 +199,7 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
170
199
  val restored = fallbackKey?.let(NativeListSourceFallbackState::has) == true
171
200
  fallback.textSize = if (sourceScale) 13f else NativeListScale.font(resources, 13f)
172
201
  fallback.text = visual.optString("fallbackText").take(2)
173
- fallback.setTextColor(color("#00000072"))
202
+ fallback.setTextColor(color(visual.optString("fallbackTextColor", "#00000072")))
174
203
  fallback.visibility =
175
204
  if (kind != "icon" && fallbackIcon == null && (sources.isEmpty() || restored)) VISIBLE
176
205
  else GONE
@@ -184,7 +213,9 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
184
213
  color(
185
214
  visual.optString("backgroundColor", if (sources.isEmpty()) placeholder else "#00000000")
186
215
  )
187
- val backgroundColor = if (sourceFallback) color(placeholder) else visualBackground
216
+ val backgroundColor =
217
+ if (sources.isEmpty() && fallbackIcon?.has("backgroundColor") == true || restored) color(fallbackBackground)
218
+ else if (sourceFallback) color(placeholder) else visualBackground
188
219
  background =
189
220
  fill(backgroundColor, 0f).apply {
190
221
  if (kind == "icon" && iconBorder) setStroke(1, color("#0000001F"))
@@ -201,7 +232,7 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
201
232
  slot.recycle()
202
233
  slot.view.visibility = GONE
203
234
  } else {
204
- slot.view.visibility = if (index > 0 || sourceFallback) INVISIBLE else VISIBLE
235
+ slot.view.visibility = if (index > 0 || restored) INVISIBLE else VISIBLE
205
236
  slot.bind(
206
237
  sources[index].first,
207
238
  "$key:leading:$index",
@@ -214,13 +245,14 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
214
245
  ) { loaded ->
215
246
  slot.view.visibility =
216
247
  if (!loaded && (index > 0 || sourceFallback)) INVISIBLE else VISIBLE
248
+ if (index == pairIndex) syncPairBackdrop()
217
249
  if (index == 0 && sourceFallback) {
218
250
  fallbackKey?.let {
219
251
  if (loaded) NativeListSourceFallbackState.forget(it)
220
252
  else NativeListSourceFallbackState.remember(it)
221
253
  }
222
254
  (background as? GradientDrawable)?.setColor(
223
- if (loaded) visualBackground else color(placeholder)
255
+ if (loaded) visualBackground else color(fallbackBackground)
224
256
  )
225
257
  fallback.visibility = if (!loaded && fallbackIcon == null) VISIBLE else GONE
226
258
  icon.visibility = if (!loaded && fallbackIcon != null) VISIBLE else GONE
@@ -228,9 +260,21 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
228
260
  }
229
261
  }
230
262
  }
231
- networkBackdrop.visibility = if (kind == "token" && sources.size > 1) VISIBLE else GONE
263
+ networkBackdrop.visibility = if (networkIndex != null) VISIBLE else GONE
232
264
  networkBackdrop.background =
233
265
  fill(color(theme?.optString("rowBackground", "#FFFFFF") ?: "#FFFFFF"), dp(10).toFloat())
266
+ pairBackdrop.background =
267
+ fill(color(theme?.optString("rowBackground", "#FFFFFF") ?: "#FFFFFF"), 0f)
268
+ syncPairBackdrop()
269
+ // Stacking order by role: primary, pair ring, secondary token, badge
270
+ // backdrop, badge, corner icon. Slots are reused across binds with
271
+ // different roles, so the order is restored on every bind.
272
+ pairBackdrop.bringToFront()
273
+ pairIndex?.let { slots[it].view.bringToFront() }
274
+ networkBackdrop.bringToFront()
275
+ networkIndex?.let { slots[it].view.bringToFront() }
276
+ cornerBackdrop.bringToFront()
277
+ corner.bringToFront()
234
278
  val badge = visual.optJSONObject("cornerIcon")
235
279
  corner.visibility = if (badge == null) GONE else VISIBLE
236
280
  cornerBackdrop.visibility = corner.visibility
@@ -255,9 +299,26 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
255
299
  .optJSONArray("overlays")
256
300
  ?.let { values -> (0 until minOf(2, values.length())).map { values.getJSONObject(it) } }
257
301
  .orEmpty()
302
+ requestsUnclippedHost =
303
+ nativeListLeadingVisualOverhangsFrame(
304
+ kind = kind,
305
+ sourceCount = sources.size,
306
+ hasCornerIcon = badge != null,
307
+ overlayCount = descriptors.size,
308
+ )
258
309
  while (overlaySlots.size < descriptors.size) overlaySlots.add(NativeListImageSlot(reactContext))
310
+ while (overlayFallbackIcons.size < descriptors.size)
311
+ overlayFallbackIcons.add(OneKeyIconView(context))
259
312
  descriptors.forEachIndexed { index, data ->
260
313
  val frame = previousOverlays.getOrNull(index)?.first ?: FrameLayout(context)
314
+ val image = data.optJSONObject("image")
315
+ val fallbackData = data.optJSONObject("fallbackIcon")
316
+ val fallbackGlyph = overlayFallbackIcons[index].apply {
317
+ visibility = GONE
318
+ iconName = fallbackData?.optString("name") ?: ""
319
+ tintColor = color(fallbackData?.optString("tintColor", "#0000009B") ?: "#0000009B")
320
+ useSourceScale = sourceScale
321
+ }
261
322
  frame.background =
262
323
  fill(
263
324
  color(data.optString("backgroundColor", "#00000000")),
@@ -269,11 +330,15 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
269
330
  frame.outlineProvider = ViewOutlineProvider.BACKGROUND
270
331
  frame.clipToOutline = true
271
332
  val child: View =
272
- data.optJSONObject("image")?.let { image ->
333
+ image?.let { source ->
273
334
  val slot = overlaySlots[index]
274
335
  slot.view.visibility = INVISIBLE
275
- slot.bind(image, "$key:overlay:$index", placeholder = placeholder) {
336
+ val circularImage = data.optInt("padding", 0) > 0 &&
337
+ data.optInt("width", data.optInt("size", 20)) == overlayHeight(data)
338
+ slot.bind(source, "$key:overlay:$index", placeholder = placeholder,
339
+ round = circularImage) {
276
340
  slot.view.visibility = if (it) VISIBLE else INVISIBLE
341
+ fallbackGlyph.visibility = if (!it && fallbackData != null) VISIBLE else GONE
277
342
  }
278
343
  slot.view
279
344
  }
@@ -290,8 +355,13 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
290
355
  if (walletText) androidx.core.widget.TextViewCompat.setLineHeight(this, dp(16))
291
356
  else setLineSpacing(0f, 1f)
292
357
  typeface =
293
- if (isWalletText(data)) fonts.regular(context)
294
- else fonts.medium(context)
358
+ when (data.optString("fontWeight")) {
359
+ "regular" -> fonts.regular(context)
360
+ "medium" -> fonts.medium(context)
361
+ "semibold" -> fonts.semibold(context)
362
+ "bold" -> fonts.bold(context)
363
+ else -> if (isWalletText(data)) fonts.regular(context) else fonts.medium(context)
364
+ }
295
365
  setTextColor(color(data.optString("tintColor", "#0000009B")))
296
366
  }
297
367
  } else {
@@ -305,13 +375,15 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
305
375
  val inset = data.optInt("padding", 0)
306
376
  if (isWalletText(data)) frame.setPadding(dp(2), 0, dp(2), 0)
307
377
  else frame.setPadding(dp(inset), dp(inset), dp(inset), dp(inset))
308
- if (child.parent !== frame) {
309
- frame.removeAllViews()
310
- // A reused slot view may still belong to a frame dropped by an earlier bind.
311
- (child.parent as? android.view.ViewGroup)?.removeView(child)
312
- frame.addView(child, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
378
+ frame.removeAllViews()
379
+ // A reused slot view may still belong to a frame dropped by an earlier bind.
380
+ (child.parent as? android.view.ViewGroup)?.removeView(child)
381
+ frame.addView(child, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
382
+ if (image != null && fallbackData != null) {
383
+ (fallbackGlyph.parent as? android.view.ViewGroup)?.removeView(fallbackGlyph)
384
+ frame.addView(fallbackGlyph, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
313
385
  }
314
- if (frame.parent == null) addView(frame)
386
+ if (frame.parent == null) addView(frame) else frame.bringToFront()
315
387
  overlays.add(frame to data)
316
388
  }
317
389
  previousOverlays.drop(descriptors.size).forEach { (frame, _) ->
@@ -367,8 +439,11 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
367
439
  )
368
440
  }
369
441
  place(fallback, 0, 0, w, h)
442
+ val explicitFallbackSize = visual.optJSONObject("fallbackIcon")
443
+ ?.optDouble("size", Double.NaN)?.takeIf { it.isFinite() && it > 0.0 }
370
444
  val iconSize =
371
- if (sources.isNotEmpty() && visual.optJSONObject("fallbackIcon") != null)
445
+ if (explicitFallbackSize != null) dp(explicitFallbackSize.roundToInt())
446
+ else if (sources.isNotEmpty() && visual.optJSONObject("fallbackIcon") != null)
372
447
  (minOf(w, h) *
373
448
  if (visual.optJSONObject("fallbackIcon")?.optString("name") == "GlobusOutline") 1.2f
374
449
  else 1f)
@@ -381,28 +456,46 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
381
456
  iconSize,
382
457
  iconSize,
383
458
  )
384
- val tokenPair = kind == "token" && sources.size > 1
459
+ val ring = dp(2)
385
460
  slots.take(sources.size).forEachIndexed { index, slot ->
386
- val size =
387
- if (tokenPair && index == 1) dp(16)
388
- else if (sources.size == 1 || tokenPair) h else (h * 0.72f).roundToInt()
389
- val x =
390
- if (tokenPair && index == 1) w - size + dp(2)
391
- else if (sources.size == 1 || tokenPair) 0
392
- else (index * (w - size).toFloat() / maxOf(1, sources.size - 1)).roundToInt()
393
- val y = if (tokenPair && index == 1) h - size + dp(2) else (h - size) / 2
394
- val imageWidth = if (sources.size == 1 || tokenPair && index == 0) w else size
461
+ val frame =
462
+ nativeListLeadingSlotFrame(
463
+ index = index,
464
+ sourceCount = sources.size,
465
+ networkIndex = networkIndex,
466
+ pairIndex = pairIndex,
467
+ width = w,
468
+ height = h,
469
+ badgeSize = dp(16),
470
+ badgeOverhang = dp(2),
471
+ pairRing = ring,
472
+ )
395
473
  slot.view.measure(
396
- MeasureSpec.makeMeasureSpec(imageWidth, MeasureSpec.EXACTLY),
397
- MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY),
474
+ MeasureSpec.makeMeasureSpec(frame.width, MeasureSpec.EXACTLY),
475
+ MeasureSpec.makeMeasureSpec(frame.height, MeasureSpec.EXACTLY),
398
476
  )
399
477
  val inset = if (index == 0) bitmapBorderWidth else 0
400
- place(slot.view, x + inset, y + inset, imageWidth - 2 * inset, size - 2 * inset)
478
+ place(
479
+ slot.view,
480
+ frame.x + inset,
481
+ frame.y + inset,
482
+ frame.width - 2 * inset,
483
+ frame.height - 2 * inset,
484
+ )
401
485
  val imageRadius =
402
486
  if (shape == "rounded" && !style.has("shape") && !style.has("cornerRadius"))
403
487
  dp(roundedImageRadius).toFloat()
404
488
  else radius
405
- val r = if (index == 0 && (sources.size == 1 || tokenPair)) imageRadius else size / 2f
489
+ val fillsFrame = index == 0 && pairIndex == null && (sources.size == 1 || networkIndex != null)
490
+ val r =
491
+ when {
492
+ fillsFrame -> imageRadius
493
+ // Pair members keep the token shape at their own size (rounded NFTs
494
+ // use the box's 10dp rule scaled to the member).
495
+ pairIndex != null && index != networkIndex && shape == "rounded" ->
496
+ minOf(dp(roundedImageRadius).toFloat(), frame.height / 4f)
497
+ else -> frame.height / 2f
498
+ }
406
499
  slot.view.outlineProvider =
407
500
  object : ViewOutlineProvider() {
408
501
  override fun getOutline(view: View, outline: Outline) {
@@ -413,6 +506,14 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
413
506
  }
414
507
  slot.view.clipToOutline = true
415
508
  }
509
+ if (pairIndex != null) {
510
+ val member = nativeListLeadingPairMemberSize(h)
511
+ val box = member + 2 * ring
512
+ (pairBackdrop.background as? GradientDrawable)?.cornerRadius =
513
+ if (shape == "rounded") minOf(dp(roundedImageRadius).toFloat(), member / 4f) + ring
514
+ else box / 2f
515
+ place(pairBackdrop, w - box, h - box, box, box)
516
+ }
416
517
  place(networkBackdrop, w - dp(16), h - dp(16), dp(20), dp(20))
417
518
  place(cornerBackdrop, w - dp(16), h - dp(16), dp(20), dp(20))
418
519
  place(corner, w - dp(15), h - dp(15), dp(18), dp(18))
@@ -442,9 +543,22 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
442
543
  }
443
544
  }
444
545
 
546
+ /**
547
+ * The pair ring sits above the primary token, so it is shown only while the
548
+ * secondary token image is actually displayed: hidden while that image loads,
549
+ * after a failed load and once the slot is recycled, or it would cover the
550
+ * primary's lower-right corner with a blank row-background disc.
551
+ */
552
+ private fun syncPairBackdrop() {
553
+ val secondary = pairIndex?.let { slots.getOrNull(it) }
554
+ pairBackdrop.visibility =
555
+ if (secondary != null && secondary.view.visibility == VISIBLE) VISIBLE else GONE
556
+ }
557
+
445
558
  fun recycle() {
446
559
  slots.forEach { it.recycle() }
447
560
  overlaySlots.forEach { it.recycle() }
561
+ pairBackdrop.visibility = GONE
448
562
  }
449
563
 
450
564
  fun dispose() {
@@ -38,6 +38,9 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
38
38
  private val marketSubtitleLine = PackedTitleLineLayout(context)
39
39
  private val trailingColumn = LinearLayout(context)
40
40
  private val trailingViews = List(2) { NativeListTextView(context) }
41
+ private val metricColumns = List(3) { LinearLayout(context) }
42
+ private val metricPrimaryViews = List(3) { NativeListTextView(context) }
43
+ private val metricSecondaryViews = List(3) { NativeListTextView(context) }
41
44
  private val marketBadgeViews = List(3) { LinearLayout(context) }
42
45
  private val marketBadgeLabels = List(3) { TextView(context) }
43
46
  private val badgeSlots = List(3) { NativeListImageSlot(context) }
@@ -88,6 +91,12 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
88
91
  mainColumn.addView(subtitle)
89
92
  mainColumn.addView(tertiary)
90
93
  trailingViews.forEach(trailingColumn::addView)
94
+ metricColumns.forEachIndexed { index, column ->
95
+ column.orientation = VERTICAL
96
+ column.gravity = Gravity.CENTER_VERTICAL
97
+ column.addView(metricPrimaryViews[index])
98
+ column.addView(metricSecondaryViews[index])
99
+ }
91
100
  leadingActionIcon.useSourceScale = true
92
101
  marketBadgeViews.forEachIndexed { index, badge ->
93
102
  badge.orientation = HORIZONTAL
@@ -129,6 +138,50 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
129
138
 
130
139
  private fun weighted() = LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f)
131
140
 
141
+ private fun metricColor(theme: JSONObject?, tone: String): Int =
142
+ when (tone) {
143
+ "positive" -> color(theme, "positive", "#218358")
144
+ "negative" -> color(theme, "negative", "#CE2C31")
145
+ "secondary" -> color(theme, "secondaryText", "#646464")
146
+ else -> color(theme, "primaryText", "#202020")
147
+ }
148
+
149
+ private fun bindMetrics(metrics: JSONArray, theme: JSONObject?, gap: Int) {
150
+ updateMetricLabels(metrics, theme)
151
+ for (index in 0 until metrics.length()) {
152
+ val metric = metrics.getJSONObject(index)
153
+ addView(
154
+ metricColumns[index],
155
+ LayoutParams(0, LayoutParams.WRAP_CONTENT, metric.optInt("weight", 1).toFloat()).apply {
156
+ marginStart = dp(gap)
157
+ },
158
+ )
159
+ }
160
+ }
161
+
162
+ private fun updateMetricLabels(metrics: JSONArray, theme: JSONObject?) {
163
+ for (index in 0 until metrics.length()) {
164
+ val metric = metrics.getJSONObject(index)
165
+ val alignment = metric.optString("alignment", "end")
166
+ val primary = metricPrimaryViews[index]
167
+ val secondary = metricSecondaryViews[index]
168
+ applyMarketTextStyle(
169
+ primary, null, 14f, 20, "medium",
170
+ metricColor(theme, metric.optString("tone")), alignment,
171
+ )
172
+ primary.text = marketText(metric.optString("text"), metric.optJSONArray("textSegments"), 14f)
173
+ primary.visibility = VISIBLE
174
+ applyMarketTextStyle(
175
+ secondary, null, 12f, 16, "regular",
176
+ metricColor(theme, metric.optString("secondaryTone", "secondary")), alignment,
177
+ )
178
+ secondary.text = marketText(
179
+ metric.optString("secondaryText"), metric.optJSONArray("secondaryTextSegments"), 12f,
180
+ )
181
+ secondary.visibility = if (secondary.text.isEmpty()) GONE else VISIBLE
182
+ }
183
+ }
184
+
132
185
  private fun showText(view: TextView, text: String, lines: Int) {
133
186
  view.text = text
134
187
  view.maxLines = lines
@@ -146,18 +199,27 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
146
199
  emitAction(key, view, source, slot, target)
147
200
  }
148
201
 
149
- override fun accessibilityText(item: NativeListItem) =
150
- item.json.optString(
151
- "accessibilityLabel",
202
+ override fun accessibilityText(item: NativeListItem): String {
203
+ if (item.json.has("accessibilityLabel") && !item.json.isNull("accessibilityLabel")) {
204
+ return item.json.optString("accessibilityLabel")
205
+ }
206
+ val metrics = item.json.optJSONArray("metrics")?.takeIf { it.length() in 2..3 }
207
+ val values = if (metrics != null) {
208
+ (0 until metrics.length()).flatMap { index ->
209
+ listOf(metricPrimaryViews[index], metricSecondaryViews[index])
210
+ .filter { it.visibility == VISIBLE }
211
+ .map { it.text.toString() }
212
+ }
213
+ } else {
152
214
  listOf(
153
- item.json.optString("title"),
154
- item.json.optString("subtitle"),
155
- item.json.optString("price"),
156
- item.json.optJSONObject("change")?.optString("text") ?: "",
157
- )
158
- .filter(String::isNotEmpty)
159
- .joinToString(", "),
160
- )
215
+ item.json.optString("price"),
216
+ item.json.optJSONObject("change")?.optString("text") ?: "",
217
+ )
218
+ }
219
+ return (listOf(item.json.optString("title"), item.json.optString("subtitle")) + values)
220
+ .filter(String::isNotEmpty)
221
+ .joinToString(", ")
222
+ }
161
223
 
162
224
  override fun bindContent(
163
225
  item: NativeListItem,
@@ -183,7 +245,8 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
183
245
  if (item.json.optJSONArray("badges")?.optJSONObject(index)?.optJSONObject("icon") == null)
184
246
  badgeSlots[index].recycle()
185
247
  }
186
- for (view in listOf(title, subtitle, tertiary) + trailingViews) {
248
+ for (view in listOf(title, subtitle, tertiary) + trailingViews +
249
+ metricPrimaryViews + metricSecondaryViews) {
187
250
  view.text = ""
188
251
  view.visibility = GONE
189
252
  view.maxLines = 1
@@ -217,7 +280,13 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
217
280
  }
218
281
 
219
282
  override fun bindMarketQuote(item: NativeListItem, theme: JSONObject?) {
220
- if (retainBoundItem(item)) bindQuote(item, theme)
283
+ if (retainBoundItem(item)) {
284
+ item.json.optJSONArray("metrics")?.takeIf { it.length() in 2..3 }?.let {
285
+ updateMetricLabels(it, theme)
286
+ }
287
+ bindQuote(item, theme)
288
+ contentDescription = accessibilityText(item)
289
+ }
221
290
  }
222
291
 
223
292
  private fun cancelMarketHold() {
@@ -304,6 +373,7 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
304
373
  longPressFired = false
305
374
  leadingFrame.recycle()
306
375
  badgeSlots.forEach { it.recycle() }
376
+ (metricPrimaryViews + metricSecondaryViews).forEach { it.text = "" }
307
377
  imageSignature = ""
308
378
  }
309
379
 
@@ -561,10 +631,12 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
561
631
  )
562
632
  // OneKey patch: retain the source gap without changing other templates.
563
633
  // addView(mainColumn, weighted())
634
+ val metrics = item.json.optJSONArray("metrics")?.takeIf { it.length() in 2..3 }
564
635
  addView(
565
636
  mainColumn,
566
637
  weighted().apply {
567
- marginEnd = dp(style?.optDouble("contentTrailingGap", 0.0)?.roundToInt() ?: 0)
638
+ if (metrics != null) weight = 2f
639
+ else marginEnd = dp(style?.optDouble("contentTrailingGap", 0.0)?.roundToInt() ?: 0)
568
640
  },
569
641
  )
570
642
  titleLine.packsChildrenAtStart = true
@@ -748,7 +820,11 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
748
820
  }
749
821
  trailingColumn.orientation = HORIZONTAL
750
822
  trailingColumn.gravity = Gravity.END or Gravity.CENTER_VERTICAL
751
- addView(trailingColumn, wrap())
823
+ if (metrics != null) {
824
+ bindMetrics(metrics, theme, style?.optDouble("trailingGap", 8.0)?.roundToInt() ?: 8)
825
+ } else {
826
+ addView(trailingColumn, wrap())
827
+ }
752
828
  bindQuote(item, theme)
753
829
  val nextImageSignature =
754
830
  nativeListCanonical(
@@ -861,18 +937,6 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
861
937
  )
862
938
  }
863
939
  }
864
- contentDescription =
865
- item.json.optString(
866
- "accessibilityLabel",
867
- listOf(
868
- item.json.optString("title"),
869
- item.json.optString("subtitle"),
870
- item.json.optString("price"),
871
- changeData.optString("text"),
872
- )
873
- .filter(String::isNotEmpty)
874
- .joinToString(", "),
875
- )
876
940
  }
877
941
 
878
942
  override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
@@ -912,7 +976,7 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
912
976
  ?.has("contentVerticalAlignment") == true
913
977
  if (item.type == "market" && item.json.optJSONObject("style") != null) {
914
978
  // OneKey patch: preserve Yoga's half-pixel centering for Market columns and badges.
915
- for (column in listOf(leadingFrame, mainColumn, trailingColumn)) {
979
+ for (column in listOf(leadingFrame, mainColumn, trailingColumn) + metricColumns) {
916
980
  if (!hasContainerAlignment && column.parent === this && column.visibility != GONE) {
917
981
  column.offsetTopAndBottom((height - column.height + 1) / 2 - column.top)
918
982
  }
@@ -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
  }