@onekeyfe/react-native-native-list 6.7.0-alpha.344 → 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
@@ -31,6 +31,13 @@ class HybridNativeList(context: ThemedReactContext) : HybridNativeListSpec() {
31
31
  dispatchToUi { hostView.setContainerSlotHeightsJson(value) }
32
32
  }
33
33
 
34
+ override var sidecarLayoutJson: String = ""
35
+ set(value) {
36
+ if (field == value) return
37
+ field = value
38
+ dispatchToUi { hostView.setSidecarLayoutJson(value) }
39
+ }
40
+
34
41
  private var fontsChanged = false
35
42
  private var snapshotChanged = false
36
43
 
@@ -8,11 +8,14 @@ import android.graphics.drawable.StateListDrawable
8
8
  import android.text.Spannable
9
9
  import android.text.SpannableStringBuilder
10
10
  import android.text.TextUtils
11
+ import android.text.TextPaint
11
12
  import android.text.style.AbsoluteSizeSpan
12
13
  import android.text.style.ForegroundColorSpan
14
+ import android.text.style.MetricAffectingSpan
13
15
  import android.util.TypedValue
14
16
  import android.view.Gravity
15
17
  import android.view.View
18
+ import android.view.MotionEvent
16
19
  import android.widget.LinearLayout
17
20
  import android.widget.ProgressBar
18
21
  import android.widget.TextView
@@ -29,11 +32,14 @@ import org.json.JSONObject
29
32
  // Bounded controls only. Event ownership and epochs stay with the row host.
30
33
  internal class NativeListAccessoryStack(context: android.content.Context, val fonts: NativeListFonts) : LinearLayout(context) {
31
34
  private val trailingViews = List(2) { NativeListTextView(context) }
35
+ private val buttonDownEpochs = IntArray(2) { -1 }
36
+ private var bindingEpoch = 0
32
37
  private val trailingIcons = List(2) { OneKeyIconView(context) }
33
38
  private val checkbox = OneKeyCheckboxView(context)
34
39
  private val spinner = ProgressBar(context)
35
40
  private var boundCheckboxData: JSONObject? = null
36
41
  private val semanticValueViews = mutableListOf<TextView>()
42
+ private val segmentedValuePairs = mutableMapOf<TextView, JSONObject>()
37
43
  private var selectorUsesSourceScale = false
38
44
  private var checkboxUsesSelectorStyle = false
39
45
  private var checkboxCheckedColor = Color.BLACK
@@ -66,6 +72,19 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
66
72
  info.viewIdResourceName = host.getTag(com.facebook.react.R.id.react_test_id) as? String
67
73
  }
68
74
  }
75
+ private val buttonAccessibilityDelegate =
76
+ object : View.AccessibilityDelegate() {
77
+ override fun onInitializeAccessibilityNodeInfo(
78
+ host: View,
79
+ info: android.view.accessibility.AccessibilityNodeInfo,
80
+ ) {
81
+ super.onInitializeAccessibilityNodeInfo(host, info)
82
+ info.className = android.widget.Button::class.java.name
83
+ info.isEnabled = host.isEnabled
84
+ info.isClickable = host.isEnabled && host.isClickable
85
+ info.viewIdResourceName = host.getTag(com.facebook.react.R.id.react_test_id) as? String
86
+ }
87
+ }
69
88
 
70
89
  private val trailingPaintFlags = trailingViews.map { it.paintFlags }
71
90
 
@@ -130,7 +149,12 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
130
149
  (checkbox.layoutParams as LayoutParams).marginStart = dp(12)
131
150
  for ((index, key) in listOf("value", "valueSecondary").withIndex()) {
132
151
  style.optJSONObject(key)?.let { value ->
133
- semanticValueViews.getOrNull(index)?.let { applyStyledText(it, value) }
152
+ semanticValueViews.getOrNull(index)?.let { view ->
153
+ applyStyledText(view, value)
154
+ if (value.has("fontSize")) segmentedValuePairs[view]?.let { accessory ->
155
+ restorePairSubscriptSizes(view, accessory, value.optDouble("fontSize").toFloat())
156
+ }
157
+ }
134
158
  }
135
159
  }
136
160
  if (style.has("trailingGap")) {
@@ -146,6 +170,13 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
146
170
  }
147
171
  }
148
172
  }
173
+ val pairedChevron = horizontal && (kinds == listOf("valuePair", "chevron") ||
174
+ (kinds == listOf("icon", "chevron") &&
175
+ descriptors.getJSONObject(0).optString("name") == "RefreshCcwOutline" &&
176
+ descriptors.getJSONObject(0).optString("actionKey").isEmpty()))
177
+ if (pairedChevron) {
178
+ (trailingIcons[1].layoutParams as LayoutParams).marginEnd = 0
179
+ }
149
180
  visibility =
150
181
  if ((0 until childCount).any { getChildAt(it).visibility != GONE }) VISIBLE else GONE
151
182
  }
@@ -167,32 +198,52 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
167
198
 
168
199
  fun anchorInset(view: View): Int =
169
200
  if (
170
- (tag as? NativeListItem)?.json?.optString("presentation") == "accountSelector" &&
171
- view in trailingIcons &&
172
- (view.layoutParams as MarginLayoutParams).marginStart < 0
201
+ view in trailingIcons &&
202
+ (view.layoutParams as MarginLayoutParams).marginStart < 0 &&
203
+ ((tag as? NativeListItem)?.json?.optString("presentation") == "accountSelector" ||
204
+ (tag as? NativeListItem)?.json?.optJSONArray("trailing")?.let { trailing ->
205
+ (0 until trailing.length()).any { index ->
206
+ trailing.optJSONObject(index)?.optString("buttonStyle") == "tertiary"
207
+ }
208
+ } == true)
173
209
  )
174
210
  dp(7)
175
211
  else 0
176
212
 
177
213
  fun reset() {
214
+ bindingEpoch += 1
178
215
  tag = null
179
216
  endInset = null
180
217
  requestsUnclippedHost = false
181
218
  clipChildren = true
182
219
  clipToPadding = true
183
220
  semanticValueViews.clear()
221
+ segmentedValuePairs.clear()
184
222
  boundCheckboxData = null
185
223
  trailingViews.forEachIndexed { index, v ->
224
+ buttonDownEpochs[index] = -1
186
225
  v.paintFlags = trailingPaintFlags[index]
187
226
  v.visibility = GONE
188
227
  v.text = ""
189
228
  v.layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
190
229
  v.setOnClickListener(null)
230
+ v.setOnTouchListener(null)
231
+ v.isPressed = false
232
+ v.isClickable = false
233
+ v.isEnabled = true
234
+ v.alpha = 1f
235
+ v.contentDescription = null
236
+ v.setTag(com.facebook.react.R.id.react_test_id, null)
237
+ v.accessibilityDelegate = null
191
238
  v.background = null
192
239
  v.setPadding(0, 0, 0, 0)
193
240
  // Legacy trailing text: END gravity, one line, no ellipsis.
194
241
  v.gravity = Gravity.END
195
242
  v.opticalOffsetY = 0f
243
+ v.helpBindingGeneration += 1
244
+ v.guardsHelpTouches = false
245
+ v.primaryHelpOnly = false
246
+ v.showsHelpUnderline = false
196
247
  v.maxLines = 1
197
248
  v.setHorizontallyScrolling(false)
198
249
  v.ellipsize = null
@@ -252,6 +303,83 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
252
303
  for (index in 0 until minOf(2, accessories.length())) {
253
304
  val accessory = accessories.getJSONObject(index)
254
305
  when (accessory.optString("kind")) {
306
+ "button" -> {
307
+ if (textIndex !in trailingViews.indices) continue
308
+ val view = trailingViews[textIndex]
309
+ val buttonIndex = textIndex
310
+ val epoch = bindingEpoch
311
+ val disabled =
312
+ item.json.optBoolean("disabled", false) || accessory.optBoolean("disabled", false)
313
+ showTrailing(textIndex, accessory.optString("label"), false)
314
+ view.typeface = fonts.medium(context)
315
+ view.gravity = Gravity.CENTER
316
+ view.setTextColor(
317
+ safeColor(
318
+ accessory.optString("textColor").takeIf(String::isNotEmpty),
319
+ color(theme, "primaryText", "#000000DF"),
320
+ )
321
+ )
322
+ view.layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, dp(30))
323
+ view.setPadding(dp(11), dp(4), dp(11), dp(4))
324
+ view.background =
325
+ StateListDrawable().apply {
326
+ fun fill(value: Int) =
327
+ GradientDrawable().apply {
328
+ setColor(value)
329
+ cornerRadius = dp(15).toFloat()
330
+ setStroke(dp(1), Color.TRANSPARENT)
331
+ }
332
+ addState(
333
+ intArrayOf(android.R.attr.state_pressed),
334
+ fill(safeColor(accessory.optString("pressedBackgroundColor").takeIf(String::isNotEmpty),
335
+ color(theme, "rowPressedBackground", "#00000017"))),
336
+ )
337
+ addState(
338
+ intArrayOf(),
339
+ fill(safeColor(accessory.optString("backgroundColor").takeIf(String::isNotEmpty),
340
+ color(theme, "strongBackground", "#0000000F"))),
341
+ )
342
+ }
343
+ view.setTag(
344
+ com.facebook.react.R.id.react_test_id,
345
+ accessory.optString("testID").takeIf(String::isNotEmpty),
346
+ )
347
+ view.accessibilityDelegate = buttonAccessibilityDelegate
348
+ view.contentDescription =
349
+ accessory.optString("accessibilityLabel").ifEmpty { accessory.optString("label") }
350
+ view.isEnabled = !disabled
351
+ view.alpha = if (disabled) 0.4f else 1f
352
+ view.isClickable = true
353
+ view.setOnTouchListener { _, event ->
354
+ when (event.actionMasked) {
355
+ MotionEvent.ACTION_DOWN -> {
356
+ buttonDownEpochs[buttonIndex] = epoch
357
+ false
358
+ }
359
+ MotionEvent.ACTION_UP -> {
360
+ if (buttonDownEpochs[buttonIndex] != bindingEpoch) {
361
+ view.isPressed = false
362
+ true
363
+ } else false
364
+ }
365
+ MotionEvent.ACTION_CANCEL -> {
366
+ buttonDownEpochs[buttonIndex] = -1
367
+ false
368
+ }
369
+ else -> false
370
+ }
371
+ }
372
+ view.setOnClickListener {
373
+ if (epoch != bindingEpoch) return@setOnClickListener
374
+ (tag as? NativeListItem)?.takeUnless { it.json.optBoolean("disabled", false) }
375
+ ?.takeUnless { accessory.optBoolean("disabled", false) }
376
+ ?.let {
377
+ emitAction(it, accessory.optString("actionKey"), null, view,
378
+ "trailingAccessory", index)
379
+ }
380
+ }
381
+ textIndex++
382
+ }
255
383
  "value" -> {
256
384
  showTrailing(
257
385
  textIndex,
@@ -264,6 +392,21 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
264
392
  }
265
393
  "valuePair" -> {
266
394
  showTrailingValuePair(textIndex, accessory, theme)
395
+ accessory.optJSONObject("primaryHelp")?.let { help ->
396
+ val view = trailingViews[textIndex]
397
+ val epoch = bindingEpoch
398
+ view.primaryHelpOnly = true
399
+ view.guardsHelpTouches = true
400
+ view.showsHelpUnderline = help.optString("underline") == "dashed"
401
+ if (help.optString("presentation") == "popover") {
402
+ view.setOnClickListener {
403
+ if (epoch == bindingEpoch && !item.json.optBoolean("disabled")) {
404
+ emitAction(item, help.optString("actionKey"), null, view, "trailingAccessory", index)
405
+ }
406
+ }
407
+ }
408
+ }
409
+ segmentedValuePairs[trailingViews[textIndex]] = accessory
267
410
  semanticValueViews.add(trailingViews[textIndex++])
268
411
  }
269
412
  "checkbox" -> bindCheckbox(item, accessory, checkboxState)
@@ -421,8 +564,10 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
421
564
 
422
565
  private fun showTrailingValuePair(index: Int, accessory: JSONObject, theme: JSONObject?) {
423
566
  if (index !in trailingViews.indices) return
424
- val primary = accessory.optString("primary")
425
- val secondary = accessory.optString("secondary")
567
+ val primarySegments = accessory.optJSONArray("primaryTextSegments")
568
+ val secondarySegments = accessory.optJSONArray("secondaryTextSegments")
569
+ val primary = segmentTextOrFallback(primarySegments, accessory.optString("primary"))
570
+ val secondary = segmentTextOrFallback(secondarySegments, accessory.optString("secondary"))
426
571
  if (primary.isEmpty() && secondary.isEmpty()) return
427
572
  val value = SpannableStringBuilder()
428
573
  val primaryStart = value.length
@@ -442,6 +587,15 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
442
587
  value.length,
443
588
  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
444
589
  )
590
+ if (primary.isNotEmpty() && accessory.optString("primaryFontWeight") == "medium") {
591
+ value.setSpan(
592
+ ValuePairTypefaceSpan(fonts.medium(context)),
593
+ primaryStart,
594
+ value.length,
595
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
596
+ )
597
+ }
598
+ applyPairSubscriptSizes(value, primarySegments, primaryStart, 16f)
445
599
  if (primary.isNotEmpty() && secondary.isNotEmpty()) value.append('\n')
446
600
  val secondaryStart = value.length
447
601
  value.append(secondary)
@@ -462,6 +616,7 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
462
616
  value.length,
463
617
  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
464
618
  )
619
+ applyPairSubscriptSizes(value, secondarySegments, secondaryStart, 14f)
465
620
  val view = trailingViews[index]
466
621
  view.text = value
467
622
  view.maxLines = 2
@@ -473,6 +628,48 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
473
628
  view.visibility = VISIBLE
474
629
  }
475
630
 
631
+ private fun segmentTextOrFallback(segments: JSONArray?, fallback: String): String {
632
+ if (segments == null || segments.length() == 0) return fallback
633
+ return buildString {
634
+ for (index in 0 until segments.length()) append(segments.getJSONObject(index).optString("text"))
635
+ }
636
+ }
637
+
638
+ private fun applyPairSubscriptSizes(
639
+ value: SpannableStringBuilder,
640
+ segments: JSONArray?,
641
+ start: Int,
642
+ baseSize: Float,
643
+ ) {
644
+ if (segments == null) return
645
+ var offset = start
646
+ for (index in 0 until segments.length()) {
647
+ val segment = segments.getJSONObject(index)
648
+ val end = offset + segment.optString("text").length
649
+ if (end > offset && segment.optString("style") == "subscript")
650
+ value.setSpan(
651
+ AbsoluteSizeSpan(sp(kotlin.math.ceil(baseSize * 0.6).toFloat()).roundToInt(), true),
652
+ offset,
653
+ end,
654
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
655
+ )
656
+ offset = end
657
+ }
658
+ }
659
+
660
+ private fun restorePairSubscriptSizes(view: TextView, accessory: JSONObject, baseSize: Float) {
661
+ val primary = accessory.optJSONArray("primaryTextSegments")
662
+ val secondary = accessory.optJSONArray("secondaryTextSegments")
663
+ if ((primary?.length() ?: 0) == 0 && (secondary?.length() ?: 0) == 0) return
664
+ val value = SpannableStringBuilder(view.text)
665
+ applyPairSubscriptSizes(value, primary, 0, baseSize)
666
+ val primaryText = segmentTextOrFallback(primary, accessory.optString("primary"))
667
+ val secondaryStart = primaryText.length + if (primaryText.isNotEmpty() &&
668
+ segmentTextOrFallback(secondary, accessory.optString("secondary")).isNotEmpty()) 1 else 0
669
+ applyPairSubscriptSizes(value, secondary, secondaryStart, baseSize)
670
+ view.text = value
671
+ }
672
+
476
673
  private fun showTrailingMenu(index: Int, actionKey: String) {
477
674
  showTrailing(index, "⋮", true, actionKey)
478
675
  if (index !in trailingViews.indices) return
@@ -512,7 +709,26 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
512
709
  )
513
710
  icon.accessibilityDelegate = selectorAccessibilityDelegate
514
711
  icon.contentDescription = data.optString("accessibilityLabel").takeIf { it.isNotEmpty() }
515
- if (item.json.optString("presentation") == "accountSelector") {
712
+ if (data.optString("buttonStyle") == "tertiary") {
713
+ icon.glyphSizeDp = 24
714
+ icon.layoutParams = LayoutParams(dp(38), dp(38)).apply {
715
+ gravity = Gravity.CENTER_VERTICAL
716
+ marginStart = -dp(7)
717
+ marginEnd = -dp(7)
718
+ }
719
+ icon.background = StateListDrawable().apply {
720
+ addState(intArrayOf(android.R.attr.state_pressed),
721
+ roundedFill(color(theme, "rowPressedBackground", "#00000017"), 19f).apply {
722
+ setStroke(dp(1), Color.TRANSPARENT)
723
+ })
724
+ addState(intArrayOf(), roundedFill(Color.TRANSPARENT, 19f).apply {
725
+ setStroke(dp(1), Color.TRANSPARENT)
726
+ })
727
+ }
728
+ clipChildren = false
729
+ clipToPadding = false
730
+ requestsUnclippedHost = true
731
+ } else if (item.json.optString("presentation") == "accountSelector") {
516
732
  icon.glyphSizeDp = 24
517
733
  val isSourceMenu = item.hasExplicitHeight && icon.iconName == "DotHorOutline"
518
734
  val size = if (item.hasExplicitHeight && icon.iconName == "PlusSmallOutline") 36 else 38
@@ -538,6 +754,13 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
538
754
  addState(intArrayOf(), roundedFill(Color.TRANSPARENT, 19f))
539
755
  }
540
756
  }
757
+ } else if (icon.iconName == "RefreshCcwOutline" && data.optString("actionKey").isEmpty()) {
758
+ icon.glyphSizeDp = 16
759
+ icon.isClickable = false
760
+ icon.isFocusable = false
761
+ icon.layoutParams = LayoutParams(dp(16), dp(16)).apply {
762
+ gravity = Gravity.CENTER_VERTICAL
763
+ }
541
764
  } else if (icon.iconName == "ChevronRightSmallOutline") {
542
765
  icon.glyphSizeDp = null
543
766
  // ListItem.DrillIn is a 24dp icon with mx=-6, for a 12dp layout footprint.
@@ -709,3 +932,13 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
709
932
  cornerRadius = scaledDp(radiusDp)
710
933
  }
711
934
  }
935
+
936
+ private class ValuePairTypefaceSpan(private val face: Typeface) : MetricAffectingSpan() {
937
+ override fun updateDrawState(paint: TextPaint) {
938
+ paint.typeface = face
939
+ }
940
+
941
+ override fun updateMeasureState(paint: TextPaint) {
942
+ paint.typeface = face
943
+ }
944
+ }
@@ -70,10 +70,13 @@ internal class NativeListActivityDetailsView(private val reactContext: ThemedRea
70
70
  val style = data.optJSONObject("style") ?: JSONObject()
71
71
  val image = style.optJSONObject("image") ?: JSONObject()
72
72
  val table = data.optString("presentation") == "table"
73
+ val hideLeading = data.optBoolean("hideLeading")
73
74
  val gap = if (style.has("leadingGap")) px(style.optDouble("leadingGap")) else dp(12)
74
75
  val iw = if (image.has("width")) px(image.optDouble("width")) else dp(40)
75
- visual.layoutParams = LayoutParams(iw, if (image.has("height")) px(image.optDouble("height")) else dp(40)).apply { marginEnd = gap }
76
- visual.bind(data.optJSONObject("leading") ?: JSONObject(), image, item.key, theme, false, sourceScale, data.optJSONObject("secondaryLeading"))
76
+ visual.layoutParams = LayoutParams(iw, if (image.has("height")) px(image.optDouble("height")) else dp(40)).apply { marginEnd = if (hideLeading) 0 else gap }
77
+ visual.visibility = if (hideLeading) GONE else VISIBLE
78
+ if (hideLeading) visual.recycle()
79
+ else visual.bind(data.optJSONObject("leading") ?: JSONObject(), image, item.key, theme, false, sourceScale, data.optJSONObject("secondaryLeading"))
77
80
  amounts.layoutParams = if (table) LayoutParams(0, -2, 1f).apply { marginStart = gap } else LayoutParams(-2, -2).apply { marginStart = gap }
78
81
  text(title, data.optString("title"), style.optJSONObject("title"), 16f, color("primary", theme), 24, "medium")
79
82
  text(description, data.optString("description"), style.optJSONObject("description"), 14f, color("secondary", theme), 20, lines = 2)
@@ -117,7 +120,7 @@ internal class NativeListActivityDetailsView(private val reactContext: ThemedRea
117
120
  actions.removeAllViews()
118
121
  val actionData = data.optJSONArray("footerActions")
119
122
  actions.visibility = if ((actionData?.length() ?: 0) == 0) GONE else VISIBLE
120
- actions.layoutParams = LayoutParams(-1, -2).apply { marginStart = iw + gap; topMargin = dp(8) }
123
+ actions.layoutParams = LayoutParams(-1, -2).apply { marginStart = if (hideLeading) 0 else iw + gap; topMargin = dp(8) }
121
124
  for (index in 0 until (actionData?.length() ?: 0)) {
122
125
  val descriptor = actionData!!.getJSONObject(index)
123
126
  val button = NativeListTextView(context)
@@ -146,7 +149,7 @@ internal class NativeListActivityDetailsView(private val reactContext: ThemedRea
146
149
  }
147
150
  label.text = styled
148
151
  }
149
- fun recycle() { visual.recycle(); amountViews.forEach { it.recycle() }; description.setOnClickListener(null); actions.removeAllViews() }
152
+ fun recycle() { visual.recycle(); visual.visibility = VISIBLE; amountViews.forEach { it.recycle() }; description.setOnClickListener(null); actions.removeAllViews() }
150
153
  fun dispose() { recycle(); visual.dispose(); amountViews.forEach { it.dispose() } }
151
154
 
152
155
  private inner class AmountView : LinearLayout(context) {
@@ -81,6 +81,7 @@ internal class NativeListActivityRowView(context: ThemedReactContext, fonts: Nat
81
81
  details.recycle()
82
82
  val style = data.optJSONObject("style") ?: JSONObject()
83
83
  val image = style.optJSONObject("image") ?: JSONObject()
84
+ val hideLeading = data.optBoolean("hideLeading")
84
85
  fun color(name: String, fallback: String) =
85
86
  parseNativeListColor(theme?.optString(name, fallback) ?: fallback)
86
87
  fun fill(value: Int, radius: Int) =
@@ -143,8 +144,10 @@ internal class NativeListActivityRowView(context: ThemedReactContext, fonts: Nat
143
144
  val iw = if (image.has("width")) stylePx(image.optDouble("width")) else dp(40)
144
145
  val ih = if (image.has("height")) stylePx(image.optDouble("height")) else dp(40)
145
146
  val gap = if (style.has("leadingGap")) stylePx(style.optDouble("leadingGap")) else dp(12)
146
- visual.layoutParams = LayoutParams(iw, ih).apply { marginEnd = gap }
147
- visual.bind(
147
+ visual.layoutParams = LayoutParams(iw, ih).apply { marginEnd = if (hideLeading) 0 else gap }
148
+ visual.visibility = if (hideLeading) GONE else VISIBLE
149
+ if (hideLeading) visual.recycle()
150
+ else visual.bind(
148
151
  // Legacy: a missing visual still reserves an empty, transparent slot.
149
152
  data.optJSONObject("leading") ?: JSONObject().put("backgroundColor", "#00000000"),
150
153
  image,
@@ -212,7 +215,7 @@ internal class NativeListActivityRowView(context: ThemedReactContext, fonts: Nat
212
215
  actions.visibility = if (count == 0) GONE else VISIBLE
213
216
  actions.layoutParams =
214
217
  LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT).apply {
215
- marginStart = if (style.has("leadingGap") || image.has("width")) iw + gap else dp(52)
218
+ marginStart = if (hideLeading) 0 else if (style.has("leadingGap") || image.has("width")) iw + gap else dp(52)
216
219
  topMargin = if (style.has("lineGap")) stylePx(style.optDouble("lineGap")) else dp(8)
217
220
  bottomMargin = dp(4)
218
221
  }
@@ -0,0 +1,102 @@
1
+ package com.margelo.nitro.nativelist
2
+
3
+ import android.content.res.ColorStateList
4
+ import android.graphics.Color
5
+ import android.graphics.drawable.GradientDrawable
6
+ import android.graphics.drawable.StateListDrawable
7
+ import android.view.Gravity
8
+ import android.view.View
9
+ import android.widget.FrameLayout
10
+ import android.widget.LinearLayout
11
+ import android.widget.ProgressBar
12
+ import androidx.core.widget.TextViewCompat
13
+ import com.facebook.react.uimanager.ThemedReactContext
14
+ import org.json.JSONObject
15
+
16
+ internal class NativeListButtonGroupRowView(context: ThemedReactContext, fonts: NativeListFonts) :
17
+ NativeListRendererRowView(context, fonts) {
18
+ private var generation = 0
19
+ private var rowOpacity = 1f
20
+
21
+ override fun appearance() {
22
+ super.appearance()
23
+ alpha = rowOpacity
24
+ }
25
+ override fun defaultHeight(item: NativeListItem, layout: String) = 64
26
+
27
+ override fun bindContent(
28
+ item: NativeListItem,
29
+ theme: JSONObject?,
30
+ layout: String,
31
+ checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String,
32
+ ) {
33
+ recycleContent()
34
+ rowOpacity = (item.json.optJSONObject("style")?.optJSONObject("container")?.optDouble("opacity", item.json.optDouble("opacity", 1.0)) ?: item.json.optDouble("opacity", 1.0)).toFloat()
35
+ orientation = HORIZONTAL
36
+ gravity = Gravity.CENTER_VERTICAL
37
+ setPadding(0, dp(8), 0, dp(8))
38
+ val info = parseNativeListColor(theme?.optString("info", "#0F69F6") ?: "#0F69F6")
39
+ val descriptors = item.json.optJSONArray("buttons") ?: return
40
+ val epoch = generation
41
+ for (index in 0 until descriptors.length()) {
42
+ val descriptor = descriptors.getJSONObject(index)
43
+ val enabled = !item.json.optBoolean("disabled") && !descriptor.optBoolean("disabled") && !descriptor.optBoolean("loading")
44
+ val button = FrameLayout(context).apply {
45
+ isEnabled = enabled
46
+ alpha = if (enabled) 1f else 0.4f
47
+ contentDescription = descriptor.optString("accessibilityLabel", descriptor.optString("label"))
48
+ setTag(com.facebook.react.R.id.react_test_id, descriptor.optString("testID").takeIf { it.isNotEmpty() })
49
+ background = StateListDrawable().apply {
50
+ fun fill(pressed: Boolean) = GradientDrawable().apply {
51
+ setColor(if (pressed) (info and 0x00FFFFFF) or (43 shl 24) else Color.TRANSPARENT)
52
+ cornerRadius = dp(12).toFloat()
53
+ setStroke(dp(1), (info and 0x00FFFFFF) or (89 shl 24))
54
+ }
55
+ addState(intArrayOf(android.R.attr.state_pressed), fill(true))
56
+ addState(intArrayOf(), fill(false))
57
+ }
58
+ }
59
+ val label = NativeListTextView(context).apply {
60
+ text = descriptor.optString("label")
61
+ textSize = NativeListScale.font(resources, 14f)
62
+ typeface = fonts.medium(context)
63
+ setTextColor(info)
64
+ gravity = Gravity.CENTER
65
+ includeFontPadding = false
66
+ maxLines = 1
67
+ ellipsize = android.text.TextUtils.TruncateAt.END
68
+ TextViewCompat.setLineHeight(this, dp(20))
69
+ importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
70
+ }
71
+ val content = LinearLayout(context).apply {
72
+ orientation = HORIZONTAL
73
+ gravity = Gravity.CENTER
74
+ setPadding(dp(8), dp(12), dp(8), dp(12))
75
+ importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
76
+ }
77
+ button.addView(content, FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
78
+ if (descriptor.optBoolean("loading")) {
79
+ val spinner = ProgressBar(context, null, android.R.attr.progressBarStyleSmall).apply {
80
+ isIndeterminate = true
81
+ indeterminateTintList = ColorStateList.valueOf(info)
82
+ importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
83
+ }
84
+ content.addView(spinner, LayoutParams(dp(20), dp(20)).apply { marginEnd = dp(8) })
85
+ }
86
+ content.addView(label, LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT))
87
+ button.setOnClickListener {
88
+ if (generation == epoch && enabled) emitAction(descriptor.optString("actionKey"), button, "buttonGroup", index)
89
+ }
90
+ button.isClickable = enabled
91
+ addView(button, LayoutParams(0, dp(48), 1f).apply { if (index > 0) marginStart = dp(10) })
92
+ }
93
+ }
94
+
95
+ override fun recycleContent() {
96
+ generation += 1
97
+ for (index in 0 until childCount) getChildAt(index).setOnClickListener(null)
98
+ removeAllViews()
99
+ }
100
+
101
+ override fun disposeContent() = recycleContent()
102
+ }
@@ -11,6 +11,15 @@ internal class NativeListContainerSlotAdapter : RecyclerView.Adapter<NativeListC
11
11
  private var content: View? = null
12
12
  private var height = 0
13
13
  private var enabled = true
14
+ private var boundHolder: Holder? = null
15
+ private var visualTranslationY = 0f
16
+
17
+ fun contentView(): View? = content
18
+
19
+ fun setVisualTranslationY(value: Float) {
20
+ visualTranslationY = value
21
+ boundHolder?.container?.translationY = value
22
+ }
14
23
 
15
24
  fun update(view: View?, heightPx: Int, visible: Boolean) {
16
25
  val previousCount = itemCount
@@ -39,6 +48,8 @@ internal class NativeListContainerSlotAdapter : RecyclerView.Adapter<NativeListC
39
48
  }
40
49
 
41
50
  override fun onBindViewHolder(holder: Holder, position: Int) {
51
+ boundHolder = holder
52
+ holder.container.translationY = visualTranslationY
42
53
  holder.container.layoutParams = RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height)
43
54
  holder.container.removeAllViews()
44
55
  content?.let { view ->
@@ -48,6 +59,7 @@ internal class NativeListContainerSlotAdapter : RecyclerView.Adapter<NativeListC
48
59
  }
49
60
 
50
61
  override fun onViewRecycled(holder: Holder) {
62
+ if (boundHolder === holder) boundHolder = null
51
63
  holder.container.removeAllViews()
52
64
  }
53
65
  }