@onekeyfe/react-native-native-list 6.8.0-25 → 6.8.0-27

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.
@@ -22,7 +22,10 @@ internal class NativeListActivityDetailsView(private val reactContext: ThemedRea
22
22
  var leadingOverhangs = false
23
23
  private set
24
24
  private val identity = LinearLayout(context).apply { orientation = VERTICAL }
25
- private val titleLine = LinearLayout(context).apply { orientation = HORIZONTAL; gravity = Gravity.CENTER_VERTICAL }
25
+ // Packs the title at its intrinsic width so badges follow the text (OK-67497).
26
+ private val titleLine = PackedTitleLineLayout(context).apply {
27
+ orientation = HORIZONTAL; gravity = Gravity.CENTER_VERTICAL; packsChildrenAtStart = true
28
+ }
26
29
  private val title = NativeListTextView(context)
27
30
  private val description = NativeListTextView(context)
28
31
  private val status = NativeListTextView(context)
@@ -125,6 +128,14 @@ internal class NativeListActivityDetailsView(private val reactContext: ThemedRea
125
128
  titleLine.addView(label, LayoutParams(-2, -2).apply { marginStart = if (style.has("titleBadgeGap")) px(style.optDouble("titleBadgeGap")) else dp(4) })
126
129
  badges.add(label)
127
130
  }
131
+ // PackedTitleLineLayout rewrites the title's params and cap only while badges follow it.
132
+ // Without badges, restore the fresh-row state so the title keeps the whole line and its
133
+ // `alignment` (center/end) behaves the same on a recycled row as on a new one.
134
+ if (badges.isEmpty()) {
135
+ (title.layoutParams as LayoutParams).apply { width = 0; weight = 1f }
136
+ title.maxWidth = Int.MAX_VALUE
137
+ title.requestLayout()
138
+ }
128
139
  val amountData = data.optJSONArray("amounts")
129
140
  val count = amountData?.length() ?: 0
130
141
  while (amountViews.size > count) { val child = amountViews.removeAt(amountViews.lastIndex); child.recycle(); amounts.removeView(child) }
@@ -31,6 +31,8 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
31
31
  private val titleLine = PackedTitleLineLayout(context)
32
32
  private val title = NativeListTextView(context)
33
33
  private val titleIcon = OneKeyIconView(context)
34
+ private val titleLeadingIcon = OneKeyIconView(context)
35
+ private val titleSegments = NativeListTitleSegmentsView(context)
34
36
  private var titleImage: NativeListImageSlot? = null
35
37
  private val subtitle = NativeListTextView(context)
36
38
  private val tertiary = NativeListTextView(context)
@@ -109,8 +111,13 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
109
111
  mainColumn.gravity = Gravity.CENTER_VERTICAL
110
112
  titleLine.orientation = HORIZONTAL
111
113
  titleLine.gravity = Gravity.CENTER_VERTICAL
114
+ titleLine.addView(titleLeadingIcon, LayoutParams(dp(16), dp(16)).apply { marginEnd = dp(6) })
112
115
  titleLine.addView(title, LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f))
116
+ titleLine.addView(titleSegments, LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f))
113
117
  titleLine.addView(titleIcon, LayoutParams(dp(20), dp(20)).apply { marginStart = dp(4) })
118
+ titleLine.titleChild = title
119
+ titleLeadingIcon.visibility = GONE
120
+ titleSegments.visibility = GONE
114
121
  titleLine.addView(badgeLine)
115
122
  trailingColumn.onAction = { key, view, slot, target ->
116
123
  emitAction(key, view, "trailingAccessory", slot, target, trailingColumn.anchorInset(view))
@@ -244,6 +251,12 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
244
251
  titleIcon.visibility = GONE
245
252
  titleIcon.contentDescription = null
246
253
  titleIcon.setOnClickListener(null)
254
+ titleLeadingIcon.visibility = GONE
255
+ titleLeadingIcon.contentDescription = null
256
+ titleSegments.visibility = GONE
257
+ titleSegments.clearRuns()
258
+ titleSegments.layoutParams = LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f)
259
+ titleLine.titleChild = title
247
260
  for (view in listOf(title, subtitle, tertiary, badgeLine)) {
248
261
  view.text = ""
249
262
  view.visibility = GONE
@@ -364,6 +377,52 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
364
377
  }
365
378
  // Legacy: overhanging selector icons/checkboxes must not be clipped by row padding.
366
379
  if (trailingColumn.parent === this && trailingColumn.requestsUnclippedHost) clipToPadding = false
380
+ if (titleSegments.visibility == VISIBLE)
381
+ bindTitleRuns(item, theme, style.optJSONObject("title"))
382
+ }
383
+
384
+ // Runs take the title's final text appearance and color unless they set
385
+ // their own tone or weight.
386
+ private fun bindTitleRuns(item: NativeListItem, theme: JSONObject?, titleStyle: JSONObject?) {
387
+ titleSegments.typeface = title.typeface
388
+ titleSegments.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, title.textSize)
389
+ titleSegments.includeFontPadding = title.includeFontPadding
390
+ titleSegments.letterSpacing = title.letterSpacing
391
+ titleSegments.opticalOffsetY = title.opticalOffsetY
392
+ titleSegments.maxLines = 1
393
+ titleSegments.ellipsize = TextUtils.TruncateAt.END
394
+ TextViewCompat.setLineHeight(titleSegments, title.lineHeight)
395
+ // An explicit line height is a span on the title's text, which
396
+ // `title.lineHeight` does not report.
397
+ titleSegments.explicitLineHeight =
398
+ titleStyle?.takeIf { it.has("lineHeight") }?.let { stylePx(it.optDouble("lineHeight")) }
399
+ if (titleSegments.explicitLineHeight != null) titleSegments.setLineSpacing(0f, 1f)
400
+ val baseColor = title.currentTextColor
401
+ titleSegments.setTextColor(baseColor)
402
+ val segments = item.json.optJSONArray("titleSegments") ?: return
403
+ val runs =
404
+ (0 until segments.length()).mapNotNull { index ->
405
+ val segment = segments.optJSONObject(index) ?: return@mapNotNull null
406
+ NativeListTitleSegmentsView.Run(
407
+ text = nativeListTitleRunText(segment.optString("text")),
408
+ typeface =
409
+ when (segment.optString("fontWeight")) {
410
+ "medium" -> fonts.medium(context)
411
+ "regular" -> fonts.regular(context)
412
+ else -> null
413
+ },
414
+ color =
415
+ when (segment.optString("tone")) {
416
+ "secondary" -> color(theme, "secondaryText", "#0000009B")
417
+ "primary" -> color(theme, "primaryText", "#000000DF")
418
+ else -> baseColor
419
+ },
420
+ shrink = segment.optBoolean("shrink", false),
421
+ maxWidthRatio =
422
+ if (segment.has("maxWidthRatio")) segment.optDouble("maxWidthRatio").toFloat() else null,
423
+ )
424
+ }
425
+ titleSegments.setRuns(runs, item.json.optString("title"))
367
426
  }
368
427
 
369
428
  private fun styleGap(column: LinearLayout, gap: Int) {
@@ -505,7 +564,8 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
505
564
  val imageWidth = titleImage?.view?.takeIf { it.visibility == VISIBLE }?.let {
506
565
  it.layoutParams.width + dp(4)
507
566
  } ?: 0
508
- val icon = (if (titleIcon.visibility == VISIBLE) dp(24) else 0) + imageWidth
567
+ val icon = (if (titleIcon.visibility == VISIBLE) dp(24) else 0) + imageWidth +
568
+ (if (titleLeadingIcon.visibility == VISIBLE) dp(22) else 0)
509
569
  (inner * ratio).roundToInt()
510
570
  .minus(leading.width + leading.marginEnd + icon)
511
571
  .coerceAtLeast(0)
@@ -516,9 +576,10 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
516
576
  super.onMeasure(widthMeasureSpec, heightMeasureSpec)
517
577
  if (titleSuffixLabels.isNotEmpty()) {
518
578
  val fixedWidth =
519
- (1 until titleLine.childCount).sumOf { index ->
579
+ (0 until titleLine.childCount).sumOf { index ->
520
580
  val view = titleLine.getChildAt(index)
521
- if (view.visibility == GONE || titleSuffixLabels.any { it === view }) 0
581
+ if (view.visibility == GONE || view === titleLine.titleChild ||
582
+ titleSuffixLabels.any { it === view }) 0
522
583
  else {
523
584
  val margins = view.layoutParams as MarginLayoutParams
524
585
  view.measuredWidth + margins.leftMargin + margins.rightMargin
@@ -782,6 +843,38 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
782
843
  titleLine.packsChildrenAtStart = true
783
844
  title.ellipsize = TextUtils.TruncateAt.END
784
845
  showText(title, item.json.optString("title"), item.json.optInt("titleLines", 1))
846
+ // Runs replace the drawn title except where `title` itself is highlighted;
847
+ // their content is bound once the title style is final.
848
+ if (nativeListShowsTitleRuns(
849
+ item.json.optString("presentation"),
850
+ item.json.optJSONArray("titleSegments")?.length() ?: 0,
851
+ item.json.optJSONArray("titleMatch")?.length() ?: 0,
852
+ )
853
+ ) {
854
+ title.visibility = GONE
855
+ titleSegments.visibility = VISIBLE
856
+ titleLine.titleChild = titleSegments
857
+ }
858
+ val leadingIcon = item.json.optJSONObject("titleLeadingIcon")
859
+ ?.takeIf { nativeListAllowsTitleDecorations(item.json.optString("presentation")) }
860
+ leadingIcon?.let { icon ->
861
+ titleLeadingIcon.iconName = icon.optString("name")
862
+ titleLeadingIcon.glyphSizeDp = 16
863
+ titleLeadingIcon.useSourceScale = sourceScale
864
+ // The slot was created before this row's scale was known; it follows the
865
+ // scale the glyph is drawn with.
866
+ titleLeadingIcon.layoutParams = LayoutParams(dp(16), dp(16)).apply { marginEnd = dp(6) }
867
+ titleLeadingIcon.tintColor = safeColor(
868
+ icon.optString("tintColor").takeIf(String::isNotEmpty),
869
+ color(theme, "iconSubdued", "#00000072"),
870
+ )
871
+ titleLeadingIcon.contentDescription =
872
+ icon.optString("accessibilityLabel").takeIf(String::isNotEmpty)
873
+ titleLeadingIcon.importantForAccessibility =
874
+ if (titleLeadingIcon.contentDescription == null) View.IMPORTANT_FOR_ACCESSIBILITY_NO
875
+ else View.IMPORTANT_FOR_ACCESSIBILITY_YES
876
+ titleLeadingIcon.visibility = VISIBLE
877
+ }
785
878
  item.json.optJSONArray("titleSuffixes")?.let { suffixes ->
786
879
  for (index in 0 until suffixes.length()) {
787
880
  val suffix = suffixes.optJSONObject(index) ?: continue
@@ -109,6 +109,9 @@ internal class PackedTitleLineLayout(context: android.content.Context) : LinearL
109
109
  var packsChildrenAtStart = false
110
110
  // OneKey patch: optional cap for the Market subtitle's localized name.
111
111
  var leadingTextMaxWidth = Int.MAX_VALUE
112
+ // The text view that takes what the other children leave; the first child
113
+ // when unset, so a glyph may precede the title once this names it.
114
+ var titleChild: TextView? = null
112
115
 
113
116
  override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
114
117
  if (!packsChildrenAtStart || childCount < 2) {
@@ -116,13 +119,13 @@ internal class PackedTitleLineLayout(context: android.content.Context) : LinearL
116
119
  return
117
120
  }
118
121
 
119
- val title = getChildAt(0)
122
+ val title = titleChild?.takeIf { it.parent === this } ?: getChildAt(0)
120
123
  val widthMode = MeasureSpec.getMode(widthMeasureSpec)
121
124
  val widthSize = MeasureSpec.getSize(widthMeasureSpec)
122
125
  var accessoryWidth = 0
123
- for (index in 1 until childCount) {
126
+ for (index in 0 until childCount) {
124
127
  val child = getChildAt(index)
125
- if (child.visibility == GONE) continue
128
+ if (child === title || child.visibility == GONE) continue
126
129
  measureChildWithMargins(
127
130
  child,
128
131
  widthMeasureSpec,
@@ -0,0 +1,71 @@
1
+ package com.margelo.nitro.nativelist
2
+
3
+ /**
4
+ * Widths for identity title runs (docs/SPEC.md, "Identity title segments and
5
+ * leading title icon"). A run's base width is its natural width under its cap;
6
+ * the one shrinking run takes what the others leave; runs that do not shrink
7
+ * and still overflow are cut from the end of the line.
8
+ */
9
+ internal fun nativeListTitleSegmentWidths(
10
+ natural: List<Float>,
11
+ shrink: List<Boolean>,
12
+ maxWidthRatio: List<Float?>,
13
+ available: Float,
14
+ ): List<Float> {
15
+ val line = available.coerceAtLeast(0f)
16
+ val widths =
17
+ natural.indices
18
+ .map { index ->
19
+ val width = natural[index].coerceAtLeast(0f)
20
+ val ratio = maxWidthRatio.getOrNull(index)
21
+ if (ratio == null) width else minOf(width, ratio * line)
22
+ }
23
+ .toMutableList()
24
+ val shrinking = shrink.indexOf(true)
25
+ if (shrinking in widths.indices) {
26
+ val others = widths.indices.filter { it != shrinking }.sumOf { widths[it].toDouble() }.toFloat()
27
+ widths[shrinking] = minOf(widths[shrinking], line - others).coerceAtLeast(0f)
28
+ }
29
+ var overflow = widths.sum() - line
30
+ var index = widths.lastIndex
31
+ while (overflow > 0f && index >= 0) {
32
+ val cut = minOf(widths[index], overflow)
33
+ widths[index] -= cut
34
+ overflow -= cut
35
+ index -= 1
36
+ }
37
+ return widths
38
+ }
39
+
40
+ /** Wallet sidebar rows keep the plain title: no runs and no leading glyph (docs/SPEC.md). */
41
+ internal fun nativeListAllowsTitleDecorations(presentation: String): Boolean =
42
+ presentation != "walletSidebar"
43
+
44
+ /**
45
+ * Whether the runs replace `title`: not where `title` itself is highlighted
46
+ * (`titleMatch` indexes it), and never on a wallet sidebar row.
47
+ */
48
+ internal fun nativeListShowsTitleRuns(presentation: String, runCount: Int, matchCount: Int): Boolean =
49
+ runCount > 0 && matchCount == 0 && nativeListAllowsTitleDecorations(presentation)
50
+
51
+ /**
52
+ * The run that has to end with an ellipsis because the line was cut exactly
53
+ * after it: a run that does not shrink lost its whole width, and this one is
54
+ * drawn in full, so nothing else would show that the title goes on. Null when
55
+ * the line is not cut, when it is cut inside a run, which then truncates by
56
+ * itself, and when only the shrinking run gave up its width, which it may.
57
+ */
58
+ internal fun nativeListTitleSegmentOverflowIndex(
59
+ natural: List<Float>,
60
+ shrink: List<Boolean>,
61
+ widths: List<Float>,
62
+ ): Int? {
63
+ val last = widths.indexOfLast { it > 0f }
64
+ if (last !in natural.indices) return null
65
+ val cutsAFixedRun =
66
+ natural.indices.any { it > last && natural[it] > 0f && shrink.getOrNull(it) != true }
67
+ return if (cutsAFixedRun && widths[last] >= natural[last]) last else null
68
+ }
69
+
70
+ /** A run is one line: a hard break folds into one space, as in a one-line title. */
71
+ internal fun nativeListTitleRunText(text: String): String = text.replace(Regex("\\r\\n|[\\r\\n]"), " ")
@@ -0,0 +1,126 @@
1
+ package com.margelo.nitro.nativelist
2
+
3
+ import android.graphics.Typeface
4
+ import android.text.SpannableStringBuilder
5
+ import android.text.Spanned
6
+ import android.text.TextPaint
7
+ import android.text.TextUtils
8
+ import android.text.style.ForegroundColorSpan
9
+ import android.text.style.MetricAffectingSpan
10
+
11
+ /**
12
+ * Identity title runs on one line. The text is rebuilt for each measured width
13
+ * from the widths `nativeListTitleSegmentWidths` allocates, so a run gives up
14
+ * width without the others; accessibility reads the row's `title` instead.
15
+ */
16
+ internal class NativeListTitleSegmentsView(context: android.content.Context) :
17
+ NativeListTextView(context) {
18
+ class Run(
19
+ val text: String,
20
+ // Null keeps the view's typeface, which follows the title's.
21
+ val typeface: Typeface?,
22
+ val color: Int,
23
+ val shrink: Boolean,
24
+ val maxWidthRatio: Float?,
25
+ )
26
+
27
+ private var runs: List<Run> = emptyList()
28
+ private var builtForWidth = -1
29
+
30
+ // `style.title.lineHeight` in pixels. The plain title carries it as a span
31
+ // on its text, so the rebuilt text here needs the same span to match.
32
+ var explicitLineHeight: Int? = null
33
+ set(value) {
34
+ if (field == value) return
35
+ field = value
36
+ builtForWidth = -1
37
+ }
38
+
39
+ fun setRuns(runs: List<Run>, spokenText: String) {
40
+ this.runs = runs
41
+ builtForWidth = -1
42
+ contentDescription = spokenText.takeIf(String::isNotEmpty)
43
+ text = runs.joinToString("") { it.text }
44
+ requestLayout()
45
+ }
46
+
47
+ fun clearRuns() {
48
+ runs = emptyList()
49
+ builtForWidth = -1
50
+ explicitLineHeight = null
51
+ contentDescription = null
52
+ text = ""
53
+ }
54
+
55
+ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
56
+ if (runs.isEmpty()) {
57
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec)
58
+ return
59
+ }
60
+ var outer =
61
+ if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED) Int.MAX_VALUE
62
+ else MeasureSpec.getSize(widthMeasureSpec)
63
+ if (maxWidth in 0 until outer) outer = maxWidth
64
+ val available =
65
+ if (outer == Int.MAX_VALUE) outer
66
+ else (outer - compoundPaddingLeft - compoundPaddingRight).coerceAtLeast(0)
67
+ if (available != builtForWidth) {
68
+ builtForWidth = available
69
+ // The same width rebuilds the same text, so the relayout this asks for
70
+ // measures once more and stops.
71
+ setText(build(available), BufferType.SPANNABLE)
72
+ }
73
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec)
74
+ // The runs fill what the title line leaves, so a ratio is a share of it.
75
+ if (outer != Int.MAX_VALUE) setMeasuredDimension(outer, measuredHeight)
76
+ }
77
+
78
+ private fun build(available: Int): CharSequence {
79
+ val paints = runs.map { run -> TextPaint(paint).apply { run.typeface?.let { typeface = it } } }
80
+ val natural = runs.mapIndexed { index, run -> paints[index].measureText(run.text) }
81
+ val widths =
82
+ nativeListTitleSegmentWidths(
83
+ natural,
84
+ runs.map { it.shrink },
85
+ runs.map { it.maxWidthRatio },
86
+ if (available == Int.MAX_VALUE) Float.MAX_VALUE else available.toFloat(),
87
+ )
88
+ val overflowing = nativeListTitleSegmentOverflowIndex(natural, runs.map { it.shrink }, widths)
89
+ val built = SpannableStringBuilder()
90
+ runs.forEachIndexed { index, run ->
91
+ val width = widths[index]
92
+ if (width <= 0f) return@forEachIndexed
93
+ val shown =
94
+ // Text after this run is hidden: one character more than fits makes
95
+ // the truncation show it. A run too narrow for the ellipsis itself
96
+ // would come back empty, so it is drawn whole instead.
97
+ if (index == overflowing)
98
+ TextUtils.ellipsize(run.text + "\u2026", paints[index], width, TextUtils.TruncateAt.END)
99
+ .takeIf { it.isNotEmpty() } ?: run.text
100
+ else if (width >= natural[index]) run.text
101
+ else TextUtils.ellipsize(run.text, paints[index], width, TextUtils.TruncateAt.END)
102
+ if (shown.isEmpty()) return@forEachIndexed
103
+ val start = built.length
104
+ built.append(shown)
105
+ built.setSpan(ForegroundColorSpan(run.color), start, built.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
106
+ run.typeface?.let {
107
+ built.setSpan(TypefaceRunSpan(it), start, built.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
108
+ }
109
+ }
110
+ explicitLineHeight?.let {
111
+ if (built.isNotEmpty())
112
+ built.setSpan(NativeListLineHeightSpan(it), 0, built.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
113
+ }
114
+ return built
115
+ }
116
+ }
117
+
118
+ private class TypefaceRunSpan(private val typeface: Typeface) : MetricAffectingSpan() {
119
+ override fun updateMeasureState(paint: TextPaint) {
120
+ paint.typeface = typeface
121
+ }
122
+
123
+ override fun updateDrawState(paint: TextPaint) {
124
+ paint.typeface = typeface
125
+ }
126
+ }
@@ -0,0 +1,130 @@
1
+ package com.margelo.nitro.nativelist
2
+
3
+ import org.junit.Assert.assertEquals
4
+ import org.junit.Assert.assertFalse
5
+ import org.junit.Assert.assertNull
6
+ import org.junit.Assert.assertTrue
7
+ import org.junit.Test
8
+
9
+ class NativeListTitleSegmentLayoutTest {
10
+ // Wallet / Account as recipient rows send it: the wallet shrinks, the
11
+ // account is capped at 70% of the line.
12
+ private fun walletFirst(wallet: Float, account: Float, line: Float) =
13
+ nativeListTitleSegmentWidths(
14
+ listOf(wallet, 20f, account),
15
+ listOf(true, false, false),
16
+ listOf(null, null, 0.7f),
17
+ line,
18
+ )
19
+
20
+ private fun assertWidths(expected: List<Float>, actual: List<Float>) {
21
+ assertEquals(expected.size, actual.size)
22
+ expected.zip(actual).forEach { (want, got) -> assertEquals(want, got, 0.001f) }
23
+ }
24
+
25
+ @Test
26
+ fun keepsNaturalWidthsWhenTheyFit() = assertWidths(listOf(80f, 20f, 90f), walletFirst(80f, 90f, 300f))
27
+
28
+ @Test
29
+ fun theShrinkingRunGivesWayFirst() = assertWidths(listOf(130f, 20f, 100f), walletFirst(200f, 100f, 250f))
30
+
31
+ @Test
32
+ fun aCappedRunStopsAtItsShareOfTheLine() = assertWidths(listOf(70f, 20f, 210f), walletFirst(100f, 400f, 300f))
33
+
34
+ @Test
35
+ fun theAccountShrinksWhenTheWalletMustStayWhole() =
36
+ assertWidths(
37
+ listOf(210f, 20f, 70f),
38
+ nativeListTitleSegmentWidths(
39
+ listOf(300f, 20f, 150f),
40
+ listOf(false, false, true),
41
+ listOf(0.7f, null, null),
42
+ 300f,
43
+ ),
44
+ )
45
+
46
+ @Test
47
+ fun runsThatDoNotShrinkAreCutFromTheEnd() {
48
+ assertWidths(
49
+ listOf(100f, 50f, 0f),
50
+ nativeListTitleSegmentWidths(
51
+ listOf(100f, 100f, 100f),
52
+ listOf(false, false, true),
53
+ listOf(null, null, null),
54
+ 150f,
55
+ ),
56
+ )
57
+ assertWidths(
58
+ listOf(100f, 20f),
59
+ nativeListTitleSegmentWidths(listOf(100f, 100f), listOf(false, false), listOf(null, null), 120f),
60
+ )
61
+ }
62
+
63
+ @Test
64
+ fun aNonPositiveLineLeavesNothing() {
65
+ assertWidths(listOf(0f, 0f, 0f), walletFirst(80f, 90f, 0f))
66
+ assertWidths(listOf(0f, 0f, 0f), walletFirst(80f, 90f, -10f))
67
+ }
68
+
69
+ // Runs replace `title` except where `title` is highlighted; wallet sidebar
70
+ // rows keep the plain title without runs or a leading glyph.
71
+ @Test
72
+ fun titleDecorationsFollowTheRowContract() {
73
+ assertTrue(nativeListShowsTitleRuns("", 2, 0))
74
+ assertTrue(nativeListShowsTitleRuns("accountSelector", 2, 0))
75
+ assertFalse(nativeListShowsTitleRuns("", 0, 0))
76
+ assertFalse(nativeListShowsTitleRuns("", 2, 1))
77
+ assertFalse(nativeListShowsTitleRuns("walletSidebar", 2, 0))
78
+ assertTrue(nativeListAllowsTitleDecorations(""))
79
+ assertFalse(nativeListAllowsTitleDecorations("walletSidebar"))
80
+ }
81
+
82
+ // Two runs that do not shrink and one line that holds only the first: the
83
+ // first is drawn in full, so it has to carry the ellipsis.
84
+ @Test
85
+ fun aWholeRunCutFromTheEndPutsTheEllipsisOnTheLastRunShown() {
86
+ val natural = listOf(100f, 100f)
87
+ val widths = nativeListTitleSegmentWidths(natural, listOf(false, false), listOf(null, null), 100f)
88
+ assertWidths(listOf(100f, 0f), widths)
89
+ assertEquals(0, nativeListTitleSegmentOverflowIndex(natural, listOf(false, false), widths))
90
+ }
91
+
92
+ // The shrinking run may give up its whole width: the runs that stay whole
93
+ // fit, so none of them is cut for an ellipsis.
94
+ @Test
95
+ fun noEllipsisIsAddedWhenOnlyTheShrinkingRunDisappears() {
96
+ val natural = listOf(100f, 60f)
97
+ val shrink = listOf(false, true)
98
+ val widths = nativeListTitleSegmentWidths(natural, shrink, listOf(null, null), 100f)
99
+ assertWidths(listOf(100f, 0f), widths)
100
+ assertNull(nativeListTitleSegmentOverflowIndex(natural, shrink, widths))
101
+ // A fixed run cut behind the shrinking one still counts.
102
+ assertEquals(
103
+ 0,
104
+ nativeListTitleSegmentOverflowIndex(
105
+ listOf(100f, 50f, 100f),
106
+ listOf(false, true, false),
107
+ listOf(100f, 0f, 0f),
108
+ ),
109
+ )
110
+ }
111
+
112
+ @Test
113
+ fun noEllipsisIsAddedWhenTheLineFitsOrIsCutInsideARun() {
114
+ val fixed = listOf(false, false, false)
115
+ assertNull(nativeListTitleSegmentOverflowIndex(listOf(80f, 20f, 90f), fixed, listOf(80f, 20f, 90f)))
116
+ // Cut inside a run: that run truncates by itself.
117
+ assertNull(nativeListTitleSegmentOverflowIndex(listOf(100f, 100f), fixed, listOf(100f, 40f)))
118
+ assertNull(
119
+ nativeListTitleSegmentOverflowIndex(listOf(100f, 100f, 100f), fixed, listOf(100f, 40f, 0f))
120
+ )
121
+ assertNull(nativeListTitleSegmentOverflowIndex(listOf(100f, 100f), fixed, listOf(0f, 0f)))
122
+ }
123
+
124
+ @Test
125
+ fun aRunFoldsLineBreaksIntoSpaces() {
126
+ assertEquals("Main Wallet", nativeListTitleRunText("Main\nWallet"))
127
+ assertEquals("a b c", nativeListTitleRunText("a\r\nb\rc"))
128
+ assertEquals("Account #1", nativeListTitleRunText("Account #1"))
129
+ }
130
+ }
@@ -54,7 +54,14 @@ separately from source implementation in STYLE_SPEC §9.
54
54
 
55
55
  - **Use:** an identifiable asset, account, wallet, network or setting.
56
56
  - **Required data:** `leading`, `title`; optional `subtitle`, `tertiary`, `badges`,
57
- `trailing`, `leadingAction`, `titleIcon`, Web-only `secondaryTitleIcon`, match ranges and structured subtitle segments.
57
+ `trailing`, `leadingAction`, `titleIcon`, Web-only `secondaryTitleIcon`, `titleSegments`,
58
+ `titleLeadingIcon`, match ranges and structured subtitle segments.
59
+ - **Title runs:** optional `titleSegments` draw 1...4 runs with their own tone and
60
+ weight in place of `title`, on one line. One run may shrink; the others keep
61
+ their width under an optional `maxWidthRatio` cap. `title` stays the spoken
62
+ text. See SPEC.md.
63
+ - **Leading title icon:** optional `titleLeadingIcon` draws a 16-point glyph 6
64
+ points before the title; it is decorative unless labelled.
58
65
  - **Static title icon:** optional 20-point icon immediately after the title with
59
66
  a 4-point gap. It has no click action; an optional Web `hoverActionKey`
60
67
  emits an icon-anchored tooltip request on hover or touch. A trailing `button` is the fixed small