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

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 (144) 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 +7 -4
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +29 -3
  5. package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
  6. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +87 -7
  8. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +193 -10
  9. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +147 -33
  10. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +145 -2
  12. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +51 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
  14. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +2 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +3 -2
  16. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
  17. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -1
  18. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1920 -109
  19. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +29 -0
  20. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
  21. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
  22. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
  23. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
  24. package/docs/ROW_TEMPLATES.md +60 -9
  25. package/docs/SPEC.md +1004 -17
  26. package/docs/STYLE_SPEC.md +6 -0
  27. package/ios/HybridNativeList.swift +21 -2
  28. package/ios/NativeListAccessoryStack.swift +235 -39
  29. package/ios/NativeListActivityDetailsView.swift +18 -8
  30. package/ios/NativeListActivityRenderer.swift +8 -2
  31. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  32. package/ios/NativeListDataRowRenderer.swift +155 -27
  33. package/ios/NativeListDesignAssets.swift +9 -0
  34. package/ios/NativeListIdentityRenderer.swift +191 -30
  35. package/ios/NativeListLeadingVisual.swift +119 -22
  36. package/ios/NativeListMessageRenderer.swift +34 -1
  37. package/ios/NativeListModels.swift +42 -2
  38. package/ios/NativeListRendererRegistry.swift +1 -0
  39. package/ios/NativeListResolvedText.swift +2 -1
  40. package/ios/NativeListRowHost.swift +14 -0
  41. package/ios/NativeListSectionHeaderRenderer.swift +88 -0
  42. package/ios/RNCNativeListView.swift +1031 -55
  43. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
  44. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
  45. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/Contents.json +1 -0
  46. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/icon.svg +1 -0
  47. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/Contents.json +1 -0
  48. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/icon.svg +1 -0
  49. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
  50. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
  51. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/Contents.json +1 -0
  52. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/icon.svg +1 -0
  53. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
  54. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
  55. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +1 -0
  56. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +1 -0
  57. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +1 -0
  58. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +1 -0
  59. package/ios/tests/NativeListAccessoryStackTests.swift +89 -0
  60. package/ios/tests/NativeListActivityPresentationTests.swift +56 -0
  61. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
  62. package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
  63. package/ios/tests/NativeListLifecycleTests.swift +2720 -3
  64. package/lib/module/NativeList.js +200 -32
  65. package/lib/module/NativeList.web.js +262 -32
  66. package/lib/module/index.js +1 -1
  67. package/lib/module/models.js +1 -0
  68. package/lib/module/selection.js +1 -1
  69. package/lib/module/validation.js +776 -52
  70. package/lib/module/web/NativeListWebEngine.js +919 -79
  71. package/lib/module/web/templates/ActivityRowRenderer.js +487 -7
  72. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  73. package/lib/module/web/templates/DataRowRenderer.js +40 -5
  74. package/lib/module/web/templates/IdentityRowRenderer.js +90 -4
  75. package/lib/module/web/templates/MarketRowRenderer.js +8 -3
  76. package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
  77. package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
  78. package/lib/module/web/templates/MessageRowRenderer.js +18 -2
  79. package/lib/module/web/templates/RowContainerStyle.js +1 -0
  80. package/lib/module/web/templates/RowRendererRegistry.js +8 -3
  81. package/lib/module/web/templates/SectionHeaderRowRenderer.js +70 -3
  82. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  83. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  84. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  85. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  86. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  87. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  88. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  89. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  90. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  91. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  92. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  93. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  94. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  95. package/lib/typescript/src/NativeList.d.ts +3 -3
  96. package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
  97. package/lib/typescript/src/NativeList.types.d.ts +29 -1
  98. package/lib/typescript/src/NativeList.web.d.ts +2 -2
  99. package/lib/typescript/src/index.d.ts +2 -2
  100. package/lib/typescript/src/models.d.ts +176 -10
  101. package/lib/typescript/src/validation.d.ts +15 -0
  102. package/lib/typescript/src/web/NativeListWebEngine.d.ts +58 -1
  103. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
  104. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  105. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  106. package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
  107. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
  108. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +10 -4
  109. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
  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 +3 -3
  124. package/react-native-native-list.podspec +1 -0
  125. package/src/NativeList.nitro.ts +2 -0
  126. package/src/NativeList.tsx +391 -82
  127. package/src/NativeList.types.ts +34 -1
  128. package/src/NativeList.web.tsx +420 -65
  129. package/src/index.ts +2 -0
  130. package/src/models.ts +210 -3
  131. package/src/selection.ts +1 -0
  132. package/src/validation.ts +1635 -76
  133. package/src/web/NativeListWebEngine.ts +1476 -112
  134. package/src/web/templates/ActivityRowRenderer.ts +732 -8
  135. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  136. package/src/web/templates/DataRowRenderer.ts +93 -20
  137. package/src/web/templates/IdentityRowRenderer.ts +150 -5
  138. package/src/web/templates/MarketRowRenderer.ts +19 -3
  139. package/src/web/templates/MarketTableRowRenderer.ts +755 -0
  140. package/src/web/templates/MediaTileRowRenderer.ts +313 -5
  141. package/src/web/templates/MessageRowRenderer.ts +23 -7
  142. package/src/web/templates/RowContainerStyle.ts +2 -0
  143. package/src/web/templates/RowRendererRegistry.ts +21 -6
  144. 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() {
@@ -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
  }
@@ -4,6 +4,7 @@ import org.json.JSONArray
4
4
  import org.json.JSONObject
5
5
  import java.nio.ByteBuffer
6
6
  import java.security.MessageDigest
7
+ import kotlin.math.roundToInt
7
8
  import java.util.Locale
8
9
 
9
10
  internal data class NativeSelectionTarget(val scope: String, val key: String?)
@@ -13,7 +14,7 @@ internal fun isNativeListRowPressEnabled(
13
14
  variant: String,
14
15
  disabled: Boolean,
15
16
  pressDisabled: Boolean,
16
- ): Boolean = !disabled && !pressDisabled && (type != "system" || variant == "retry")
17
+ ): Boolean = !disabled && !pressDisabled && type != "buttonGroup" && (type != "system" || variant == "retry")
17
18
 
18
19
  internal fun isNativeListWholeRowInteractive(
19
20
  type: String,
@@ -27,6 +28,117 @@ internal fun isNativeListWholeRowInteractive(
27
28
  pressDisabled = pressDisabled,
28
29
  )
29
30
 
31
+ /**
32
+ * A trailing text accessory (value, value pair, progress, radio, switch) owns its
33
+ * tap only when it carries an action key; otherwise the touch belongs to the row
34
+ * press, so a value such as a network balance is part of the row's hit area.
35
+ */
36
+ internal fun isNativeListTrailingTextClickable(actionKey: String?): Boolean = !actionKey.isNullOrEmpty()
37
+
38
+ /**
39
+ * A leading visual lays these badges past its own frame: the token network image
40
+ * with its backdrop, a `cornerIcon`, and every overlay (their default offset
41
+ * already overhangs; iOS stops clipping for the same descriptors). Android clips
42
+ * a child to its own bounds whenever its parent clips children, so the host row
43
+ * must stop clipping, or the badge is cut flat (OK-65694).
44
+ */
45
+ internal fun nativeListLeadingVisualOverhangsFrame(
46
+ kind: String,
47
+ sourceCount: Int,
48
+ hasCornerIcon: Boolean,
49
+ overlayCount: Int,
50
+ ): Boolean = kind == "token" && sourceCount > 1 || hasCornerIcon || overlayCount > 0
51
+
52
+ /**
53
+ * Whether an Activity row host clips its children and padding for this bind.
54
+ * One row view serves both the legacy row and the rich (`amounts`) row and is
55
+ * reused across binds, so clipping is derived from the bound item alone and
56
+ * applied on every bind: only a legacy row whose leading visual lays a badge
57
+ * past its frame ([nativeListLeadingVisualOverhangsFrame], OK-66071) opts out;
58
+ * a rich row keeps Android's default clipping even when the view it reuses
59
+ * last showed such a badge.
60
+ */
61
+ internal fun nativeListActivityHostClips(rich: Boolean, leadingOverhangs: Boolean): Boolean =
62
+ rich || !leadingOverhangs
63
+
64
+ internal data class NativeListSlotFrame(val x: Int, val y: Int, val width: Int, val height: Int)
65
+
66
+ /** Side of one member of an Activity token pair inside a [frame]-unit box (24 in 40). */
67
+ internal fun nativeListLeadingPairMemberSize(frame: Int): Int = (frame * 0.6f).roundToInt()
68
+
69
+ /**
70
+ * Frame of image source [index] of a leading visual inside its [width]×[height]
71
+ * box (SPEC "Activity leading pair", OK-66071). [networkIndex] is the token
72
+ * `networkImage` badge and [pairIndex] the Activity `secondaryLeading` token;
73
+ * either is null when absent. A pair draws the primary at the top-left and the
74
+ * secondary at the bottom-right, both [nativeListLeadingPairMemberSize] wide and
75
+ * the secondary inset by its [pairRing]; the badge keeps its corner geometry
76
+ * above them. A lone token, or a token with only a badge, fills the box. Any
77
+ * other multi-source visual (stackedImages) steps 0.72-sized images diagonally.
78
+ */
79
+ internal fun nativeListLeadingSlotFrame(
80
+ index: Int,
81
+ sourceCount: Int,
82
+ networkIndex: Int?,
83
+ pairIndex: Int?,
84
+ width: Int,
85
+ height: Int,
86
+ badgeSize: Int,
87
+ badgeOverhang: Int,
88
+ pairRing: Int,
89
+ ): NativeListSlotFrame {
90
+ if (index == networkIndex)
91
+ return NativeListSlotFrame(
92
+ width - badgeSize + badgeOverhang,
93
+ height - badgeSize + badgeOverhang,
94
+ badgeSize,
95
+ badgeSize,
96
+ )
97
+ if (pairIndex != null) {
98
+ val member = nativeListLeadingPairMemberSize(height)
99
+ return if (index == pairIndex)
100
+ NativeListSlotFrame(width - member - pairRing, height - member - pairRing, member, member)
101
+ else NativeListSlotFrame(0, 0, member, member)
102
+ }
103
+ if (sourceCount == 1 || networkIndex != null) return NativeListSlotFrame(0, 0, width, height)
104
+ val side = (height * 0.72f).roundToInt()
105
+ val x = (index * (width - side).toFloat() / maxOf(1, sourceCount - 1)).roundToInt()
106
+ return NativeListSlotFrame(x, (height - side) / 2, side, side)
107
+ }
108
+
109
+ internal data class NativeListTrailingDescriptor(
110
+ val kind: String,
111
+ val name: String = "",
112
+ val actionKey: String = "",
113
+ )
114
+
115
+ /**
116
+ * Identity trailing accessories stack vertically unless they form one of the
117
+ * pairs every platform lays out side by side. The `valuePair` + `DotVerSolid`
118
+ * menu icon pair (the Swap token selector's balance and row menu) matches
119
+ * iOS `configureTrailingStack`; stacking it put the menu under the balance and
120
+ * clipped both inside the fixed row height on Android only.
121
+ */
122
+ internal fun nativeListIdentityTrailingIsHorizontal(
123
+ accessories: List<NativeListTrailingDescriptor>,
124
+ ): Boolean {
125
+ val kinds = accessories.map { it.kind }
126
+ if (kinds.containsAll(listOf("value", "checkbox"))) return true
127
+ if (accessories.size != 2) return false
128
+ val (first, second) = accessories
129
+ return kinds == listOf("valuePair", "menu") ||
130
+ kinds == listOf("valuePair", "chevron") ||
131
+ (kinds == listOf("valuePair", "icon") &&
132
+ second.name == "DotVerSolid" &&
133
+ second.actionKey == "menu") ||
134
+ (kinds == listOf("icon", "chevron") &&
135
+ first.name == "RefreshCcwOutline" &&
136
+ first.actionKey.isEmpty()) ||
137
+ (kinds == listOf("icon", "icon") &&
138
+ first.name == "PencilOutline" &&
139
+ second.name == "DragOutline")
140
+ }
141
+
30
142
  internal fun resolveNativeListSelectorBackgroundColor(
31
143
  rowType: String,
32
144
  styleBackgroundColor: String?,
@@ -57,7 +169,7 @@ private fun updateLengthPrefixed(digest: MessageDigest, value: String) {
57
169
  }
58
170
 
59
171
  // Template type alone partitions reuse; data keys and styles never select a renderer.
60
- internal enum class NativeListRendererKey { MESSAGE, RAIL, MEDIA_TILE, ACTION, SYSTEM, ACTIVITY, DATA_ROW, METRIC_CARD, MARKET, IDENTITY, SECTION_HEADER, WALLET_GROUP }
172
+ internal enum class NativeListRendererKey { MESSAGE, RAIL, MEDIA_TILE, ACTION, SYSTEM, ACTIVITY, DATA_ROW, METRIC_CARD, MARKET, IDENTITY, SECTION_HEADER, WALLET_GROUP, BUTTON_GROUP }
61
173
 
62
174
  internal data class NativeListItem(
63
175
  val key: String,
@@ -142,6 +254,8 @@ internal data class NativeListItem(
142
254
 
143
255
  internal data class NativeListConfig(
144
256
  val generation: Int,
257
+ val structuralTransition: StructuralTransition?,
258
+ val disclosure: Disclosure?,
145
259
  val layout: String,
146
260
  val orientation: String,
147
261
  val gridColumns: Int,
@@ -168,9 +282,36 @@ internal data class NativeListConfig(
168
282
  val fixedFooter: NativeListItem?,
169
283
  val items: List<NativeListItem>,
170
284
  ) {
285
+ internal data class StructuralTransition(
286
+ val id: String,
287
+ val durationMs: Long,
288
+ val anchorKey: String?,
289
+ )
290
+ internal data class Disclosure(
291
+ val expanded: Boolean,
292
+ val expandedTrailingInset: Double,
293
+ )
171
294
  companion object {
172
295
  fun parse(snapshotJson: String): NativeListConfig {
173
296
  val root = JSONObject(snapshotJson)
297
+ val transition = root.optJSONObject("structuralTransition")
298
+ val structuralTransition = transition?.optString("id")?.takeIf(String::isNotEmpty)?.let { id ->
299
+ StructuralTransition(
300
+ id = id,
301
+ durationMs = transition.optDouble("durationMs", 220.0).coerceIn(0.0, 2000.0).toLong(),
302
+ anchorKey = transition.optString("anchorKey").takeIf(String::isNotEmpty),
303
+ )
304
+ }
305
+ val disclosureJson = root.optJSONObject("disclosure")
306
+ require(!root.has("disclosure") || disclosureJson != null) { "Invalid disclosure" }
307
+ val disclosure = disclosureJson?.let { value ->
308
+ require(value.opt("expanded") is Boolean) { "Invalid disclosure.expanded" }
309
+ require(!value.has("expandedTrailingInset") ||
310
+ value.opt("expandedTrailingInset") is Number) { "Invalid disclosure.expandedTrailingInset" }
311
+ val inset = value.optDouble("expandedTrailingInset", 0.0)
312
+ require(inset.isFinite() && inset >= 0.0) { "Invalid disclosure.expandedTrailingInset" }
313
+ Disclosure(value.getBoolean("expanded"), inset)
314
+ }
174
315
  require(root.getInt("schemaVersion") == 1) { "Unsupported schemaVersion" }
175
316
  val layout = root.getJSONObject("layout")
176
317
  val selection = root.optJSONObject("selection")
@@ -193,6 +334,8 @@ internal data class NativeListConfig(
193
334
  val fixedFooter = root.optJSONObject("fixedFooter")?.let(NativeListItem::parse)
194
335
  return NativeListConfig(
195
336
  generation = root.getInt("generation"),
337
+ structuralTransition = structuralTransition,
338
+ disclosure = disclosure,
196
339
  layout = layout.getString("kind"),
197
340
  orientation = layout.optString("orientation", "vertical"),
198
341
  gridColumns = layout.optInt("gridColumns", 1).coerceIn(1, 7),