@onekeyfe/react-native-native-list 6.7.0-alpha.343 → 6.7.0-alpha.354

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 (113) hide show
  1. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +7 -0
  2. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +240 -7
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +7 -4
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +6 -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 +135 -1
  9. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +43 -14
  10. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +17 -2
  12. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +22 -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 +585 -21
  19. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +1 -0
  20. package/docs/ROW_TEMPLATES.md +60 -9
  21. package/docs/SPEC.md +361 -8
  22. package/docs/STYLE_SPEC.md +6 -0
  23. package/ios/HybridNativeList.swift +10 -0
  24. package/ios/NativeListAccessoryStack.swift +220 -37
  25. package/ios/NativeListActivityDetailsView.swift +18 -8
  26. package/ios/NativeListActivityRenderer.swift +8 -2
  27. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  28. package/ios/NativeListDataRowRenderer.swift +105 -8
  29. package/ios/NativeListDesignAssets.swift +3 -0
  30. package/ios/NativeListIdentityRenderer.swift +119 -4
  31. package/ios/NativeListLeadingVisual.swift +49 -14
  32. package/ios/NativeListMessageRenderer.swift +34 -1
  33. package/ios/NativeListModels.swift +16 -2
  34. package/ios/NativeListRendererRegistry.swift +1 -0
  35. package/ios/NativeListResolvedText.swift +2 -1
  36. package/ios/NativeListRowHost.swift +14 -0
  37. package/ios/NativeListSectionHeaderRenderer.swift +88 -0
  38. package/ios/RNCNativeListView.swift +331 -29
  39. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
  40. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
  41. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
  42. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
  43. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
  44. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
  45. package/ios/tests/NativeListActivityPresentationTests.swift +56 -0
  46. package/ios/tests/NativeListLifecycleTests.swift +890 -3
  47. package/lib/module/NativeList.js +64 -27
  48. package/lib/module/NativeList.web.js +84 -17
  49. package/lib/module/models.js +1 -0
  50. package/lib/module/selection.js +1 -1
  51. package/lib/module/validation.js +532 -18
  52. package/lib/module/web/NativeListWebEngine.js +391 -24
  53. package/lib/module/web/templates/ActivityRowRenderer.js +8 -7
  54. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  55. package/lib/module/web/templates/DataRowRenderer.js +40 -5
  56. package/lib/module/web/templates/IdentityRowRenderer.js +90 -4
  57. package/lib/module/web/templates/MessageRowRenderer.js +18 -2
  58. package/lib/module/web/templates/RowContainerStyle.js +1 -0
  59. package/lib/module/web/templates/RowRendererRegistry.js +3 -0
  60. package/lib/module/web/templates/SectionHeaderRowRenderer.js +36 -2
  61. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +9 -0
  62. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
  63. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
  64. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
  65. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
  66. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
  67. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
  68. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
  69. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
  70. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
  71. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
  72. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
  73. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
  74. package/lib/typescript/src/NativeList.d.ts +2 -2
  75. package/lib/typescript/src/NativeList.nitro.d.ts +1 -0
  76. package/lib/typescript/src/NativeList.types.d.ts +8 -0
  77. package/lib/typescript/src/models.d.ts +101 -9
  78. package/lib/typescript/src/validation.d.ts +13 -0
  79. package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -0
  80. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  81. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  82. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +9 -3
  83. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +9 -0
  84. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
  85. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
  86. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
  87. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
  88. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
  89. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
  90. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
  91. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
  92. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
  93. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
  94. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
  95. package/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
  96. package/package.json +3 -3
  97. package/react-native-native-list.podspec +1 -0
  98. package/src/NativeList.nitro.ts +1 -0
  99. package/src/NativeList.tsx +155 -69
  100. package/src/NativeList.types.ts +9 -0
  101. package/src/NativeList.web.tsx +159 -49
  102. package/src/models.ts +113 -3
  103. package/src/selection.ts +1 -0
  104. package/src/validation.ts +1156 -18
  105. package/src/web/NativeListWebEngine.ts +594 -28
  106. package/src/web/templates/ActivityRowRenderer.ts +14 -6
  107. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  108. package/src/web/templates/DataRowRenderer.ts +93 -20
  109. package/src/web/templates/IdentityRowRenderer.ts +150 -5
  110. package/src/web/templates/MessageRowRenderer.ts +23 -7
  111. package/src/web/templates/RowContainerStyle.ts +2 -0
  112. package/src/web/templates/RowRendererRegistry.ts +11 -1
  113. package/src/web/templates/SectionHeaderRowRenderer.ts +47 -4
@@ -22,6 +22,7 @@ internal class NativeListDataRowView(context: ThemedReactContext, fonts: NativeL
22
22
  gravity = Gravity.CENTER_VERTICAL
23
23
  }
24
24
  private val cells = List(4) { NativeListTableColumnView(context, fonts) }
25
+ private val trailingAccessories = NativeListAccessoryStack(context, fonts)
25
26
 
26
27
  override fun unselectedBackground(
27
28
  item: NativeListItem,
@@ -54,16 +55,20 @@ internal class NativeListDataRowView(context: ThemedReactContext, fonts: NativeL
54
55
  addView(visual)
55
56
  addView(accessories)
56
57
  addView(columns, LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f))
58
+ addView(trailingAccessories)
57
59
  accessories.onAction = { key, view, slot, target ->
58
60
  emitAction(key, view, "trailingAccessory", slot, target)
59
61
  }
62
+ trailingAccessories.onAction = { key, view, slot, target ->
63
+ emitAction(key, view, "trailingAccessory", slot, target)
64
+ }
60
65
  }
61
66
 
62
67
  override fun defaultHeight(item: NativeListItem, layout: String): Int {
63
68
  val values = item.json.optJSONArray("columns") ?: JSONArray()
64
69
  val secondary =
65
70
  (0 until values.length()).any {
66
- values.getJSONObject(it).optString("secondaryText").isNotEmpty()
71
+ nativeListDataColumnText(values.getJSONObject(it), "secondaryText").isNotEmpty()
67
72
  }
68
73
  return if (layout == "table") if (secondary) 60 else 52 else if (secondary) 64 else 56
69
74
  }
@@ -127,6 +132,9 @@ internal class NativeListDataRowView(context: ThemedReactContext, fonts: NativeL
127
132
  val accessoryStyle = JSONObject().put("value", style.optJSONObject("index"))
128
133
  accessories.bind(item, descriptors, theme, accessoryStyle, sourceScale, checkboxState)
129
134
  accessories.visibility = if (descriptors.length() == 0) GONE else VISIBLE
135
+ val trailing = data.optJSONArray("trailing") ?: JSONArray()
136
+ trailingAccessories.bind(item, trailing, theme, style, sourceScale, checkboxState)
137
+ trailingAccessories.visibility = if (trailing.length() == 0) GONE else VISIBLE
130
138
  accessories.layoutParams =
131
139
  LayoutParams(dp(32), LayoutParams.WRAP_CONTENT).apply { marginEnd = dp(10) }
132
140
  val values = data.getJSONArray("columns")
@@ -159,6 +167,7 @@ internal class NativeListDataRowView(context: ThemedReactContext, fonts: NativeL
159
167
  style,
160
168
  fixedTableGeometry = unstyled,
161
169
  )
170
+ cell.bindTitleIcons(value, theme, sourceScale)
162
171
  // Legacy table default: every column is a fixed 40dp, top-aligned block.
163
172
  cell.layoutParams =
164
173
  LayoutParams(
@@ -194,17 +203,20 @@ internal class NativeListDataRowView(context: ThemedReactContext, fonts: NativeL
194
203
  checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String,
195
204
  ) {
196
205
  accessories.updateSelection(item, checkboxState)
206
+ trailingAccessories.updateSelection(item, checkboxState)
197
207
  }
198
208
 
199
209
  override fun recycleContent() {
200
210
  visual.recycle()
201
211
  accessories.reset()
212
+ trailingAccessories.reset()
202
213
  cells.forEach { it.reset() }
203
214
  }
204
215
 
205
216
  override fun disposeContent() {
206
217
  visual.dispose()
207
218
  accessories.reset()
219
+ trailingAccessories.reset()
208
220
  }
209
221
 
210
222
  private companion object {
@@ -215,6 +227,8 @@ internal class NativeListDataRowView(context: ThemedReactContext, fonts: NativeL
215
227
  private class NativeListTableColumnView(context: android.content.Context, private val fonts: NativeListFonts) : LinearLayout(context) {
216
228
  private val primaryLine = LinearLayout(context)
217
229
  private val primary = NativeListTextView(context)
230
+ private val titleIcon = OneKeyIconView(context)
231
+ private val secondaryTitleIcon = OneKeyIconView(context)
218
232
  private val badges = LinearLayout(context)
219
233
  private val secondaryLine = LinearLayout(context)
220
234
  private val secondaryLeading = NativeListTextView(context)
@@ -256,6 +270,13 @@ private class NativeListTableColumnView(context: android.content.Context, privat
256
270
  },
257
271
  )
258
272
  primaryLine.addView(primary, LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT))
273
+ for (icon in listOf(titleIcon, secondaryTitleIcon)) {
274
+ icon.visibility = GONE
275
+ primaryLine.addView(
276
+ icon,
277
+ LayoutParams(dp(20), dp(20)).apply { marginStart = dp(4) },
278
+ )
279
+ }
259
280
  primaryLine.addView(
260
281
  badges,
261
282
  LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT).apply {
@@ -270,6 +291,13 @@ private class NativeListTableColumnView(context: android.content.Context, privat
270
291
  }
271
292
 
272
293
  fun reset() {
294
+ primaryLine.gravity = Gravity.CENTER_VERTICAL
295
+ for (icon in listOf(titleIcon, secondaryTitleIcon)) {
296
+ icon.visibility = GONE
297
+ icon.iconName = ""
298
+ icon.contentDescription = null
299
+ icon.setOnClickListener(null)
300
+ }
273
301
  primaryLine.layoutParams.width = LayoutParams.WRAP_CONTENT
274
302
  primaryLine.layoutParams.height = LayoutParams.WRAP_CONTENT
275
303
  secondaryLine.layoutParams.height = LayoutParams.WRAP_CONTENT
@@ -292,6 +320,26 @@ private class NativeListTableColumnView(context: android.content.Context, privat
292
320
  badges.visibility = GONE
293
321
  }
294
322
 
323
+ fun bindTitleIcons(column: JSONObject, theme: JSONObject?, sourceScale: Boolean) {
324
+ for ((field, icon) in listOf(
325
+ "titleIcon" to titleIcon,
326
+ "secondaryTitleIcon" to secondaryTitleIcon,
327
+ )) {
328
+ val descriptor = column.optJSONObject(field) ?: continue
329
+ icon.iconName = descriptor.optString("name")
330
+ icon.glyphSizeDp = 20
331
+ icon.useSourceScale = sourceScale
332
+ icon.tintColor = parseNativeListColor(
333
+ descriptor.optString("tintColor").takeIf(String::isNotEmpty)
334
+ ?: theme?.optString("iconSubdued", "#00000072") ?: "#00000072"
335
+ )
336
+ icon.contentDescription = descriptor.optString("accessibilityLabel").takeIf(String::isNotEmpty)
337
+ icon.visibility = VISIBLE
338
+ }
339
+ if (primary.maxLines > 1 && (titleIcon.visibility == VISIBLE || secondaryTitleIcon.visibility == VISIBLE))
340
+ primaryLine.gravity = Gravity.TOP
341
+ }
342
+
295
343
  fun bind(
296
344
  column: JSONObject,
297
345
  rowBadges: JSONArray?,
@@ -326,7 +374,7 @@ private class NativeListTableColumnView(context: android.content.Context, privat
326
374
  .bind(view)
327
375
  if (resolved.optString("truncate") != "clip") view.ellipsize = TextUtils.TruncateAt.END
328
376
  }
329
- bindText(primary, column.optString("text"), "columns", primarySize, "medium", primaryColor, 20)
377
+ bindText(primary, nativeListDataColumnText(column, "text"), "columns", primarySize, "medium", primaryColor, 20)
330
378
  bindText(
331
379
  secondaryLeading,
332
380
  column.optString("secondaryLeadingText"),
@@ -338,13 +386,15 @@ private class NativeListTableColumnView(context: android.content.Context, privat
338
386
  )
339
387
  bindText(
340
388
  secondary,
341
- column.optString("secondaryText"),
389
+ nativeListDataColumnText(column, "secondaryText"),
342
390
  "columnSecondary",
343
391
  12f,
344
392
  "regular",
345
393
  secondaryColor,
346
394
  16,
347
395
  )
396
+ primary.text = dataSegments(primary.text, column.optJSONArray("textSegments"), primary.textSize)
397
+ secondary.text = dataSegments(secondary.text, column.optJSONArray("secondaryTextSegments"), secondary.textSize)
348
398
  if (rowBadges != null && rowBadges.length() > 0) {
349
399
  badges.visibility = VISIBLE
350
400
  for (index in 0 until minOf(2, rowBadges.length())) {
@@ -377,7 +427,7 @@ private class NativeListTableColumnView(context: android.content.Context, privat
377
427
  secondaryLeading.visibility = VISIBLE
378
428
  secondaryLine.visibility = VISIBLE
379
429
  }
380
- val secondaryText = column.optString("secondaryText")
430
+ val secondaryText = nativeListDataColumnText(column, "secondaryText")
381
431
  if (secondaryText.isNotEmpty()) {
382
432
  secondary.visibility = VISIBLE
383
433
  secondaryLine.visibility = VISIBLE
@@ -404,7 +454,9 @@ private class NativeListTableColumnView(context: android.content.Context, privat
404
454
  ) {
405
455
  reset()
406
456
  gravity = Gravity.START
407
- val value = android.text.SpannableStringBuilder(column.optString("text"))
457
+ val value = android.text.SpannableStringBuilder(dataSegments(
458
+ nativeListDataColumnText(column, "text"), column.optJSONArray("textSegments"),
459
+ sp(16f) * resources.displayMetrics.scaledDensity))
408
460
  value.setSpan(
409
461
  android.text.style.ForegroundColorSpan(primaryColor),
410
462
  0,
@@ -428,10 +480,12 @@ private class NativeListTableColumnView(context: android.content.Context, privat
428
480
  android.text.Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
429
481
  )
430
482
  }
431
- val secondaryText = column.optString("secondaryText")
483
+ val secondaryText = nativeListDataColumnText(column, "secondaryText")
432
484
  if (secondaryText.isNotEmpty()) {
433
485
  val start = value.length
434
- value.append("\n$secondaryText")
486
+ value.append("\n")
487
+ value.append(dataSegments(secondaryText, column.optJSONArray("secondaryTextSegments"),
488
+ sp(16f) * resources.displayMetrics.scaledDensity))
435
489
  value.setSpan(
436
490
  android.text.style.ForegroundColorSpan(secondaryColor),
437
491
  start,
@@ -461,6 +515,24 @@ private class NativeListTableColumnView(context: android.content.Context, privat
461
515
  primary.visibility = VISIBLE
462
516
  }
463
517
 
518
+ private fun dataSegments(fallback: CharSequence, segments: JSONArray?, fontSizePx: Float): CharSequence {
519
+ if (segments == null || segments.length() == 0) return fallback
520
+ val value = android.text.SpannableStringBuilder(fallback)
521
+ var offset = 0
522
+ for (index in 0 until segments.length()) {
523
+ val segment = segments.getJSONObject(index)
524
+ val end = offset + segment.optString("text").length
525
+ if (segment.optString("style") == "subscript" && end > offset) {
526
+ val density = resources.displayMetrics.density
527
+ val size = (kotlin.math.ceil(fontSizePx / density * 0.6f) * density).roundToInt()
528
+ value.setSpan(android.text.style.AbsoluteSizeSpan(size), offset, end,
529
+ android.text.Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
530
+ }
531
+ offset = end
532
+ }
533
+ return value
534
+ }
535
+
464
536
  private fun applyStyle(style: JSONObject) {
465
537
  style.optJSONObject("columns")?.let {
466
538
  if (it.has("alignment")) {
@@ -485,3 +557,11 @@ private class NativeListTableColumnView(context: android.content.Context, privat
485
557
 
486
558
  private fun sp(value: Float): Float = NativeListScale.font(resources, value)
487
559
  }
560
+
561
+ private fun nativeListDataColumnText(column: JSONObject, field: String): String {
562
+ val segments = column.optJSONArray("${field}Segments")
563
+ if (segments == null || segments.length() == 0) return column.optString(field)
564
+ return buildString {
565
+ for (index in 0 until segments.length()) append(segments.getJSONObject(index).optString("text"))
566
+ }
567
+ }
@@ -28,9 +28,12 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
28
28
  private val mainColumn = LinearLayout(context)
29
29
  private val titleLine = PackedTitleLineLayout(context)
30
30
  private val title = NativeListTextView(context)
31
+ private val titleIcon = OneKeyIconView(context)
31
32
  private val subtitle = NativeListTextView(context)
32
33
  private val tertiary = NativeListTextView(context)
33
34
  private val badgeLine = NativeListTextView(context)
35
+ private val titleSuffixLabels = mutableListOf<NativeListTextView>()
36
+ private val titleSuffixMaxWidths = mutableListOf<Int>()
34
37
  private val trailingColumn = NativeListAccessoryStack(context, fonts)
35
38
  private val semanticBadgeLabels = mutableListOf<TextView>()
36
39
  private val semanticSubtitleLabels = mutableListOf<TextView>()
@@ -83,6 +86,7 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
83
86
  titleLine.orientation = HORIZONTAL
84
87
  titleLine.gravity = Gravity.CENTER_VERTICAL
85
88
  titleLine.addView(title, LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f))
89
+ titleLine.addView(titleIcon, LayoutParams(dp(20), dp(20)).apply { marginStart = dp(4) })
86
90
  titleLine.addView(badgeLine)
87
91
  trailingColumn.onAction = { key, view, slot, target ->
88
92
  emitAction(key, view, "trailingAccessory", slot, target, trailingColumn.anchorInset(view))
@@ -111,7 +115,7 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
111
115
 
112
116
  private fun showText(view: TextView, text: String, lines: Int) {
113
117
  view.text = text
114
- view.maxLines = lines
118
+ view.maxLines = if (lines == 0) Int.MAX_VALUE else lines
115
119
  view.visibility = if (text.isEmpty()) GONE else VISIBLE
116
120
  }
117
121
 
@@ -136,9 +140,25 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
136
140
  checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String,
137
141
  ) {
138
142
  currentItem = item
143
+ val longPressActionKey = item.json.optString("longPressActionKey")
144
+ setOnLongClickListener(
145
+ if (longPressActionKey.isNotEmpty())
146
+ OnLongClickListener {
147
+ if (!isEnabled || !item.isRowPressEnabled || currentItem?.key != item.key) false
148
+ else {
149
+ emitAction(longPressActionKey, this, "row")
150
+ true
151
+ }
152
+ }
153
+ else null
154
+ )
155
+ isLongClickable = longPressActionKey.isNotEmpty()
139
156
  currentTheme = theme
140
157
  removeAllViews()
141
158
  mainColumn.removeAllViews()
159
+ titleSuffixLabels.forEach(titleLine::removeView)
160
+ titleSuffixLabels.clear()
161
+ titleSuffixMaxWidths.clear()
142
162
  semanticBadgeLabels.clear()
143
163
  semanticSubtitleLabels.clear()
144
164
  walletBadgeLine = null
@@ -157,8 +177,12 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
157
177
  mainColumn.gravity = Gravity.CENTER_VERTICAL
158
178
  titleLine.gravity = Gravity.CENTER_VERTICAL
159
179
  titleLine.packsChildrenAtStart = false
180
+ titleLine.leadingTextMaxWidth = Int.MAX_VALUE
160
181
  titleLine.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
161
182
  title.layoutParams = LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f)
183
+ titleIcon.visibility = GONE
184
+ titleIcon.contentDescription = null
185
+ titleIcon.setOnClickListener(null)
162
186
  for (view in listOf(title, subtitle, tertiary, badgeLine)) {
163
187
  view.text = ""
164
188
  view.visibility = GONE
@@ -294,6 +318,19 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
294
318
  private fun addLeading(visual: JSONObject?, sizeDp: Int, spacingDp: Int = 12) {
295
319
  // Legacy: a missing visual still reserves an empty, transparent leading slot.
296
320
  val descriptor = visual ?: JSONObject().put("backgroundColor", "#00000000")
321
+ val overlays = descriptor.optJSONArray("overlays")
322
+ if (overlays != null && (0 until minOf(2, overlays.length())).any { index ->
323
+ val overlay = overlays.optJSONObject(index) ?: return@any false
324
+ overlay.optInt("offsetX", overlay.optInt("offset", 2)) > 0 ||
325
+ overlay.optInt("offsetY", overlay.optInt("offset", 2)) > 0
326
+ }) {
327
+ // The badge extends beyond the avatar and the row's padded content box.
328
+ clipChildren = false
329
+ clipToPadding = false
330
+ }
331
+ leadingFrame.bitmapBorderWidth =
332
+ if (descriptor.optString("borderColor").isNotEmpty() &&
333
+ descriptor.optString("borderStyle") != "dashed") dp(1) else 0
297
334
  if (visual == null) leadingFrame.recycle()
298
335
  val item = currentItem!!
299
336
  val style = item.json.optJSONObject("style")?.optJSONObject("image") ?: JSONObject()
@@ -356,7 +393,58 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
356
393
  }
357
394
 
358
395
  override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
396
+ val ratio = currentItem?.json?.optJSONObject("style")
397
+ ?.optDouble("leadingContentMaxWidthRatio", Double.NaN) ?: Double.NaN
398
+ titleLine.leadingTextMaxWidth =
399
+ if (ratio.isFinite() && ratio > 0.0 && ratio <= 1.0 && leadingFrame.parent === this) {
400
+ val inner = (MeasureSpec.getSize(widthMeasureSpec) - paddingLeft - paddingRight)
401
+ .coerceAtLeast(0)
402
+ val leading = leadingFrame.layoutParams as LayoutParams
403
+ val icon = if (titleIcon.visibility == VISIBLE) dp(24) else 0
404
+ (inner * ratio).roundToInt()
405
+ .minus(leading.width + leading.marginEnd + icon)
406
+ .coerceAtLeast(0)
407
+ } else Int.MAX_VALUE
408
+ titleSuffixLabels.forEachIndexed { index, label ->
409
+ label.maxWidth = titleSuffixMaxWidths[index]
410
+ }
359
411
  super.onMeasure(widthMeasureSpec, heightMeasureSpec)
412
+ if (titleSuffixLabels.isNotEmpty()) {
413
+ val fixedWidth =
414
+ (1 until titleLine.childCount).sumOf { index ->
415
+ val view = titleLine.getChildAt(index)
416
+ if (view.visibility == GONE || titleSuffixLabels.any { it === view }) 0
417
+ else {
418
+ val margins = view.layoutParams as MarginLayoutParams
419
+ view.measuredWidth + margins.leftMargin + margins.rightMargin
420
+ }
421
+ }
422
+ val suffixMargins = titleSuffixLabels.sumOf {
423
+ val margins = it.layoutParams as MarginLayoutParams
424
+ margins.leftMargin + margins.rightMargin
425
+ }
426
+ val available =
427
+ (titleLine.measuredWidth - fixedWidth - suffixMargins - dp(80)).coerceAtLeast(0)
428
+ val desired = titleSuffixLabels.mapIndexed { index, label ->
429
+ label.paint.measureText(label.text.toString()).roundToInt()
430
+ .coerceAtMost(titleSuffixMaxWidths[index])
431
+ }
432
+ val total = desired.sum()
433
+ var remaining = available
434
+ var changed = false
435
+ titleSuffixLabels.forEachIndexed { index, label ->
436
+ val share =
437
+ if (total <= available) desired[index]
438
+ else if (index == titleSuffixLabels.lastIndex) remaining
439
+ else (desired[index].toLong() * available / total).toInt()
440
+ remaining -= share
441
+ if (label.maxWidth != share) {
442
+ label.maxWidth = share
443
+ changed = true
444
+ }
445
+ }
446
+ if (changed) super.onMeasure(widthMeasureSpec, heightMeasureSpec)
447
+ }
360
448
  val item = currentItem ?: return
361
449
  if (
362
450
  item.hasExplicitHeight &&
@@ -582,6 +670,48 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
582
670
  titleLine.packsChildrenAtStart = true
583
671
  title.ellipsize = TextUtils.TruncateAt.END
584
672
  showText(title, item.json.optString("title"), item.json.optInt("titleLines", 1))
673
+ item.json.optJSONArray("titleSuffixes")?.let { suffixes ->
674
+ for (index in 0 until suffixes.length()) {
675
+ val suffix = suffixes.optJSONObject(index) ?: continue
676
+ val label = NativeListTextView(context).apply {
677
+ text = suffix.optString("text")
678
+ typeface = fonts.regular(context)
679
+ textSize = sp(12f)
680
+ includeFontPadding = false
681
+ maxLines = 1
682
+ ellipsize = TextUtils.TruncateAt.END
683
+ setTextColor(
684
+ color(
685
+ theme,
686
+ if (suffix.optString("tone") == "disabled") "disabledText" else "secondaryText",
687
+ "#0000009B",
688
+ )
689
+ )
690
+ }
691
+ TextViewCompat.setLineHeight(label, dp(16))
692
+ val maxWidth =
693
+ if (suffix.has("maxWidth")) stylePx(suffix.optDouble("maxWidth")) else Int.MAX_VALUE
694
+ label.maxWidth = maxWidth
695
+ titleSuffixMaxWidths.add(maxWidth)
696
+ titleSuffixLabels.add(label)
697
+ titleLine.addView(
698
+ label,
699
+ titleLine.childCount - 1,
700
+ LayoutParams(LayoutParams.WRAP_CONTENT, dp(16)).apply { marginStart = dp(8) },
701
+ )
702
+ }
703
+ }
704
+ item.json.optJSONObject("titleIcon")?.let { icon ->
705
+ titleIcon.iconName = icon.optString("name")
706
+ titleIcon.glyphSizeDp = 20
707
+ titleIcon.useSourceScale = sourceScale
708
+ titleIcon.tintColor = safeColor(
709
+ icon.optString("tintColor").takeIf(String::isNotEmpty),
710
+ color(theme, "iconSubdued", "#00000072"),
711
+ )
712
+ titleIcon.contentDescription = icon.optString("accessibilityLabel").takeIf(String::isNotEmpty)
713
+ titleIcon.visibility = VISIBLE
714
+ }
585
715
  if (item.json.optString("presentation") == "accountSelector") {
586
716
  title.typeface = fonts.regular(context)
587
717
  }
@@ -701,6 +831,10 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
701
831
  .let { kinds ->
702
832
  kinds.containsAll(listOf("value", "checkbox")) ||
703
833
  kinds == listOf("valuePair", "menu") ||
834
+ kinds == listOf("valuePair", "chevron") ||
835
+ (kinds == listOf("icon", "chevron") &&
836
+ accessories.getJSONObject(0).optString("name") == "RefreshCcwOutline" &&
837
+ accessories.getJSONObject(0).optString("actionKey").isEmpty()) ||
704
838
  (kinds == listOf("icon", "icon") &&
705
839
  accessories.getJSONObject(0).optString("name") == "PencilOutline" &&
706
840
  accessories.getJSONObject(1).optString("name") == "DragOutline")
@@ -27,6 +27,7 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
27
27
  private val cornerBackdrop = View(context)
28
28
  private val slots = mutableListOf<NativeListImageSlot>()
29
29
  private val overlaySlots = mutableListOf<NativeListImageSlot>()
30
+ private val overlayFallbackIcons = mutableListOf<OneKeyIconView>()
30
31
  private val overlays = mutableListOf<Pair<FrameLayout, JSONObject>>()
31
32
  private var visual = JSONObject()
32
33
  private var style = JSONObject()
@@ -150,6 +151,8 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
150
151
  }
151
152
  val placeholder = theme?.optString("strongBackground", "#0000000F") ?: "#0000000F"
152
153
  val fallbackIcon = visual.optJSONObject("fallbackIcon")
154
+ val fallbackBackground = fallbackIcon?.optString("backgroundColor")
155
+ ?.takeIf(String::isNotEmpty) ?: placeholder
153
156
  val sourceFallback =
154
157
  sources.firstOrNull()?.first?.optString("loadingStrategy", "none")?.let { it != "none" } ==
155
158
  true && (visual.has("fallbackText") || fallbackIcon != null)
@@ -170,7 +173,7 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
170
173
  val restored = fallbackKey?.let(NativeListSourceFallbackState::has) == true
171
174
  fallback.textSize = if (sourceScale) 13f else NativeListScale.font(resources, 13f)
172
175
  fallback.text = visual.optString("fallbackText").take(2)
173
- fallback.setTextColor(color("#00000072"))
176
+ fallback.setTextColor(color(visual.optString("fallbackTextColor", "#00000072")))
174
177
  fallback.visibility =
175
178
  if (kind != "icon" && fallbackIcon == null && (sources.isEmpty() || restored)) VISIBLE
176
179
  else GONE
@@ -184,7 +187,9 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
184
187
  color(
185
188
  visual.optString("backgroundColor", if (sources.isEmpty()) placeholder else "#00000000")
186
189
  )
187
- val backgroundColor = if (sourceFallback) color(placeholder) else visualBackground
190
+ val backgroundColor =
191
+ if (sources.isEmpty() && fallbackIcon?.has("backgroundColor") == true || restored) color(fallbackBackground)
192
+ else if (sourceFallback) color(placeholder) else visualBackground
188
193
  background =
189
194
  fill(backgroundColor, 0f).apply {
190
195
  if (kind == "icon" && iconBorder) setStroke(1, color("#0000001F"))
@@ -201,7 +206,7 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
201
206
  slot.recycle()
202
207
  slot.view.visibility = GONE
203
208
  } else {
204
- slot.view.visibility = if (index > 0 || sourceFallback) INVISIBLE else VISIBLE
209
+ slot.view.visibility = if (index > 0 || restored) INVISIBLE else VISIBLE
205
210
  slot.bind(
206
211
  sources[index].first,
207
212
  "$key:leading:$index",
@@ -220,7 +225,7 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
220
225
  else NativeListSourceFallbackState.remember(it)
221
226
  }
222
227
  (background as? GradientDrawable)?.setColor(
223
- if (loaded) visualBackground else color(placeholder)
228
+ if (loaded) visualBackground else color(fallbackBackground)
224
229
  )
225
230
  fallback.visibility = if (!loaded && fallbackIcon == null) VISIBLE else GONE
226
231
  icon.visibility = if (!loaded && fallbackIcon != null) VISIBLE else GONE
@@ -256,8 +261,18 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
256
261
  ?.let { values -> (0 until minOf(2, values.length())).map { values.getJSONObject(it) } }
257
262
  .orEmpty()
258
263
  while (overlaySlots.size < descriptors.size) overlaySlots.add(NativeListImageSlot(reactContext))
264
+ while (overlayFallbackIcons.size < descriptors.size)
265
+ overlayFallbackIcons.add(OneKeyIconView(context))
259
266
  descriptors.forEachIndexed { index, data ->
260
267
  val frame = previousOverlays.getOrNull(index)?.first ?: FrameLayout(context)
268
+ val image = data.optJSONObject("image")
269
+ val fallbackData = data.optJSONObject("fallbackIcon")
270
+ val fallbackGlyph = overlayFallbackIcons[index].apply {
271
+ visibility = GONE
272
+ iconName = fallbackData?.optString("name") ?: ""
273
+ tintColor = color(fallbackData?.optString("tintColor", "#0000009B") ?: "#0000009B")
274
+ useSourceScale = sourceScale
275
+ }
261
276
  frame.background =
262
277
  fill(
263
278
  color(data.optString("backgroundColor", "#00000000")),
@@ -269,11 +284,15 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
269
284
  frame.outlineProvider = ViewOutlineProvider.BACKGROUND
270
285
  frame.clipToOutline = true
271
286
  val child: View =
272
- data.optJSONObject("image")?.let { image ->
287
+ image?.let { source ->
273
288
  val slot = overlaySlots[index]
274
289
  slot.view.visibility = INVISIBLE
275
- slot.bind(image, "$key:overlay:$index", placeholder = placeholder) {
290
+ val circularImage = data.optInt("padding", 0) > 0 &&
291
+ data.optInt("width", data.optInt("size", 20)) == overlayHeight(data)
292
+ slot.bind(source, "$key:overlay:$index", placeholder = placeholder,
293
+ round = circularImage) {
276
294
  slot.view.visibility = if (it) VISIBLE else INVISIBLE
295
+ fallbackGlyph.visibility = if (!it && fallbackData != null) VISIBLE else GONE
277
296
  }
278
297
  slot.view
279
298
  }
@@ -290,8 +309,13 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
290
309
  if (walletText) androidx.core.widget.TextViewCompat.setLineHeight(this, dp(16))
291
310
  else setLineSpacing(0f, 1f)
292
311
  typeface =
293
- if (isWalletText(data)) fonts.regular(context)
294
- else fonts.medium(context)
312
+ when (data.optString("fontWeight")) {
313
+ "regular" -> fonts.regular(context)
314
+ "medium" -> fonts.medium(context)
315
+ "semibold" -> fonts.semibold(context)
316
+ "bold" -> fonts.bold(context)
317
+ else -> if (isWalletText(data)) fonts.regular(context) else fonts.medium(context)
318
+ }
295
319
  setTextColor(color(data.optString("tintColor", "#0000009B")))
296
320
  }
297
321
  } else {
@@ -305,11 +329,13 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
305
329
  val inset = data.optInt("padding", 0)
306
330
  if (isWalletText(data)) frame.setPadding(dp(2), 0, dp(2), 0)
307
331
  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))
332
+ frame.removeAllViews()
333
+ // A reused slot view may still belong to a frame dropped by an earlier bind.
334
+ (child.parent as? android.view.ViewGroup)?.removeView(child)
335
+ frame.addView(child, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
336
+ if (image != null && fallbackData != null) {
337
+ (fallbackGlyph.parent as? android.view.ViewGroup)?.removeView(fallbackGlyph)
338
+ frame.addView(fallbackGlyph, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
313
339
  }
314
340
  if (frame.parent == null) addView(frame)
315
341
  overlays.add(frame to data)
@@ -367,8 +393,11 @@ internal class NativeListLeadingVisual(private val reactContext: ThemedReactCont
367
393
  )
368
394
  }
369
395
  place(fallback, 0, 0, w, h)
396
+ val explicitFallbackSize = visual.optJSONObject("fallbackIcon")
397
+ ?.optDouble("size", Double.NaN)?.takeIf { it.isFinite() && it > 0.0 }
370
398
  val iconSize =
371
- if (sources.isNotEmpty() && visual.optJSONObject("fallbackIcon") != null)
399
+ if (explicitFallbackSize != null) dp(explicitFallbackSize.roundToInt())
400
+ else if (sources.isNotEmpty() && visual.optJSONObject("fallbackIcon") != null)
372
401
  (minOf(w, h) *
373
402
  if (visual.optJSONObject("fallbackIcon")?.optString("name") == "GlobusOutline") 1.2f
374
403
  else 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
  }
@@ -13,7 +13,7 @@ internal fun isNativeListRowPressEnabled(
13
13
  variant: String,
14
14
  disabled: Boolean,
15
15
  pressDisabled: Boolean,
16
- ): Boolean = !disabled && !pressDisabled && (type != "system" || variant == "retry")
16
+ ): Boolean = !disabled && !pressDisabled && type != "buttonGroup" && (type != "system" || variant == "retry")
17
17
 
18
18
  internal fun isNativeListWholeRowInteractive(
19
19
  type: String,
@@ -57,7 +57,7 @@ private fun updateLengthPrefixed(digest: MessageDigest, value: String) {
57
57
  }
58
58
 
59
59
  // 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 }
60
+ internal enum class NativeListRendererKey { MESSAGE, RAIL, MEDIA_TILE, ACTION, SYSTEM, ACTIVITY, DATA_ROW, METRIC_CARD, MARKET, IDENTITY, SECTION_HEADER, WALLET_GROUP, BUTTON_GROUP }
61
61
 
62
62
  internal data class NativeListItem(
63
63
  val key: String,
@@ -142,6 +142,7 @@ internal data class NativeListItem(
142
142
 
143
143
  internal data class NativeListConfig(
144
144
  val generation: Int,
145
+ val structuralTransition: StructuralTransition?,
145
146
  val layout: String,
146
147
  val orientation: String,
147
148
  val gridColumns: Int,
@@ -168,9 +169,22 @@ internal data class NativeListConfig(
168
169
  val fixedFooter: NativeListItem?,
169
170
  val items: List<NativeListItem>,
170
171
  ) {
172
+ internal data class StructuralTransition(
173
+ val id: String,
174
+ val durationMs: Long,
175
+ val anchorKey: String?,
176
+ )
171
177
  companion object {
172
178
  fun parse(snapshotJson: String): NativeListConfig {
173
179
  val root = JSONObject(snapshotJson)
180
+ val transition = root.optJSONObject("structuralTransition")
181
+ val structuralTransition = transition?.optString("id")?.takeIf(String::isNotEmpty)?.let { id ->
182
+ StructuralTransition(
183
+ id = id,
184
+ durationMs = transition.optDouble("durationMs", 220.0).coerceIn(0.0, 2000.0).toLong(),
185
+ anchorKey = transition.optString("anchorKey").takeIf(String::isNotEmpty),
186
+ )
187
+ }
174
188
  require(root.getInt("schemaVersion") == 1) { "Unsupported schemaVersion" }
175
189
  val layout = root.getJSONObject("layout")
176
190
  val selection = root.optJSONObject("selection")
@@ -193,6 +207,7 @@ internal data class NativeListConfig(
193
207
  val fixedFooter = root.optJSONObject("fixedFooter")?.let(NativeListItem::parse)
194
208
  return NativeListConfig(
195
209
  generation = root.getInt("generation"),
210
+ structuralTransition = structuralTransition,
196
211
  layout = layout.getString("kind"),
197
212
  orientation = layout.optString("orientation", "vertical"),
198
213
  gridColumns = layout.optInt("gridColumns", 1).coerceIn(1, 7),