@onekeyfe/react-native-native-list 6.7.0-alpha.475 → 6.8.0-10

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 (54) hide show
  1. package/README.md +312 -379
  2. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +15 -6
  3. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +3 -87
  4. package/android/src/main/java/com/onekey/nativelist/NativeListMediaPlaceholderView.kt +244 -0
  5. package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +32 -11
  6. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +60 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +3 -6
  8. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +5 -1
  9. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +75 -0
  10. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +25 -19
  11. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListDescriptionTouchPolicyTest.kt +153 -0
  12. package/docs/ROW_TEMPLATES.md +12 -12
  13. package/docs/SPEC.md +226 -110
  14. package/docs/STYLE_SPEC.md +7 -0
  15. package/ios/NativeListActivityDetailsView.swift +13 -5
  16. package/ios/NativeListIdentityRenderer.swift +6 -94
  17. package/ios/NativeListMediaPlaceholderView.swift +189 -0
  18. package/ios/NativeListMediaTileRenderer.swift +13 -13
  19. package/ios/NativeListResolvedText.swift +15 -4
  20. package/ios/NativeListTextLabel.swift +106 -0
  21. package/ios/RNCNativeListView.swift +129 -32
  22. package/ios/tests/NativeListActivityPresentationTests.swift +270 -0
  23. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +0 -95
  24. package/ios/tests/NativeListLifecycleTests.swift +369 -40
  25. package/ios/tests/NativeListMediaVisibilityTests.swift +16 -7
  26. package/lib/module/NativeList.js +17 -4
  27. package/lib/module/NativeList.web.js +3 -1
  28. package/lib/module/models.js +0 -2
  29. package/lib/module/validation.js +54 -71
  30. package/lib/module/web/NativeListGeneratedIcons.js +1 -0
  31. package/lib/module/web/NativeListWebEngine.js +13 -11
  32. package/lib/module/web/templates/ActivityRowRenderer.js +29 -23
  33. package/lib/module/web/templates/DataRowRenderer.js +54 -1
  34. package/lib/module/web/templates/IdentityRowRenderer.js +3 -92
  35. package/lib/module/web/templates/MediaTileRowRenderer.js +84 -15
  36. package/lib/typescript/src/models.d.ts +19 -22
  37. package/package.json +1 -1
  38. package/scripts/generate-icons.test.mjs +1 -0
  39. package/scripts/native-list-icons.json +1 -1
  40. package/src/NativeList.tsx +25 -4
  41. package/src/NativeList.web.tsx +1 -1
  42. package/src/models.ts +18 -23
  43. package/src/validation.ts +89 -113
  44. package/src/web/NativeListGeneratedIcons.ts +1 -0
  45. package/src/web/NativeListWebEngine.ts +16 -11
  46. package/src/web/templates/ActivityRowRenderer.ts +42 -32
  47. package/src/web/templates/DataRowRenderer.ts +76 -1
  48. package/src/web/templates/IdentityRowRenderer.ts +3 -141
  49. package/src/web/templates/MediaTileRowRenderer.ts +90 -15
  50. package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentLayout.kt +0 -49
  51. package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentsView.kt +0 -105
  52. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListTitleSegmentLayoutTest.kt +0 -80
  53. package/ios/NativeListTitleSegmentLayout.swift +0 -45
  54. package/ios/NativeListTitleSegmentsLabel.swift +0 -80
@@ -78,9 +78,9 @@ internal class NativeListActivityDetailsView(private val reactContext: ThemedRea
78
78
  return parseNativeListColor(theme?.optString(key, fallback) ?: fallback)
79
79
  }
80
80
  private fun text(label: NativeListTextView, value: String, style: JSONObject?, size: Float,
81
- ink: Int, line: Int, weight: String = "regular", lines: Int = 1) {
82
- NativeListResolvedText.resolve(context, fonts, value, style, size, weight, ink, line, lines, sourceScale).bind(label)
83
- }
81
+ ink: Int, line: Int, weight: String = "regular", lines: Int = 1): NativeListResolvedText =
82
+ NativeListResolvedText.resolve(context, fonts, value, style, size, weight, ink, line, lines, sourceScale)
83
+ .also { it.bind(label) }
84
84
  fun bind(item: NativeListItem, theme: JSONObject?, sourceScale: Boolean) {
85
85
  this.sourceScale = sourceScale
86
86
  val data = item.json
@@ -98,12 +98,20 @@ internal class NativeListActivityDetailsView(private val reactContext: ThemedRea
98
98
  setClipping(nativeListActivityHostClips(leadingOverhangs))
99
99
  amounts.layoutParams = if (table) LayoutParams(0, -2, 1f).apply { marginStart = gap } else LayoutParams(-2, -2).apply { marginStart = gap }
100
100
  text(title, data.optString("title"), style.optJSONObject("title"), 16f, color("primary", theme), 24, "medium")
101
- text(description, data.optString("description"), style.optJSONObject("description"), 14f, color("secondary", theme), 20, lines = 2)
101
+ val descriptionText = text(description, data.optString("description"), style.optJSONObject("description"), 14f, color("secondary", theme), 20, lines = 2)
102
102
  text(status, data.optString("status"), style.optJSONObject("status"), 12f, color("secondary", theme), 16)
103
103
  description.setOnClickListener(null)
104
104
  val descriptionKey = data.optString("descriptionActionKey")
105
- description.isClickable = descriptionKey.isNotEmpty()
106
- if (descriptionKey.isNotEmpty()) description.setOnClickListener { onAction?.invoke(descriptionKey, description, "description", 0) }
105
+ // The view spans the identity column, so with an action only its text from
106
+ // the caller's `descriptionActionStart` on takes touches. The start is
107
+ // never read out of the string, and one at the end leaves no action.
108
+ val actionStart =
109
+ if (descriptionKey.isEmpty()) null
110
+ else descriptionText.displayOffset(data.optLong("descriptionActionStart"), data.optString("description"))
111
+ val hasActionText = actionStart != null && actionStart < descriptionText.text.length
112
+ description.touchableTextStart = actionStart
113
+ description.isClickable = hasActionText
114
+ if (hasActionText) description.setOnClickListener { onAction?.invoke(descriptionKey, description, "description", 0) }
107
115
  for (view in listOf(description, status)) (view.layoutParams as LayoutParams).topMargin = if (style.has("lineGap")) px(style.optDouble("lineGap")) else 0
108
116
  badges.forEach(titleLine::removeView); badges.clear()
109
117
  val badgeData = data.optJSONArray("badges")
@@ -172,6 +180,7 @@ internal class NativeListActivityDetailsView(private val reactContext: ThemedRea
172
180
  }
173
181
  fun recycle() {
174
182
  visual.recycle(); visual.visibility = VISIBLE; amountViews.forEach { it.recycle() }; description.setOnClickListener(null); actions.removeAllViews()
183
+ description.touchableTextStart = null
175
184
  leadingOverhangs = false
176
185
  setClipping(true)
177
186
  }
@@ -31,8 +31,6 @@ 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)
36
34
  private var titleImage: NativeListImageSlot? = null
37
35
  private val subtitle = NativeListTextView(context)
38
36
  private val tertiary = NativeListTextView(context)
@@ -111,13 +109,8 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
111
109
  mainColumn.gravity = Gravity.CENTER_VERTICAL
112
110
  titleLine.orientation = HORIZONTAL
113
111
  titleLine.gravity = Gravity.CENTER_VERTICAL
114
- titleLine.addView(titleLeadingIcon, LayoutParams(dp(16), dp(16)).apply { marginEnd = dp(6) })
115
112
  titleLine.addView(title, LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f))
116
- titleLine.addView(titleSegments, LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f))
117
113
  titleLine.addView(titleIcon, LayoutParams(dp(20), dp(20)).apply { marginStart = dp(4) })
118
- titleLine.titleChild = title
119
- titleLeadingIcon.visibility = GONE
120
- titleSegments.visibility = GONE
121
114
  titleLine.addView(badgeLine)
122
115
  trailingColumn.onAction = { key, view, slot, target ->
123
116
  emitAction(key, view, "trailingAccessory", slot, target, trailingColumn.anchorInset(view))
@@ -230,12 +223,6 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
230
223
  titleIcon.visibility = GONE
231
224
  titleIcon.contentDescription = null
232
225
  titleIcon.setOnClickListener(null)
233
- titleLeadingIcon.visibility = GONE
234
- titleLeadingIcon.contentDescription = null
235
- titleSegments.visibility = GONE
236
- titleSegments.clearRuns()
237
- titleSegments.layoutParams = LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f)
238
- titleLine.titleChild = title
239
226
  for (view in listOf(title, subtitle, tertiary, badgeLine)) {
240
227
  view.text = ""
241
228
  view.visibility = GONE
@@ -356,46 +343,6 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
356
343
  }
357
344
  // Legacy: overhanging selector icons/checkboxes must not be clipped by row padding.
358
345
  if (trailingColumn.parent === this && trailingColumn.requestsUnclippedHost) clipToPadding = false
359
- if (titleSegments.visibility == VISIBLE) bindTitleRuns(item, theme)
360
- }
361
-
362
- // Runs take the title's final text appearance and color unless they set
363
- // their own tone or weight.
364
- private fun bindTitleRuns(item: NativeListItem, theme: JSONObject?) {
365
- titleSegments.typeface = title.typeface
366
- titleSegments.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, title.textSize)
367
- titleSegments.includeFontPadding = title.includeFontPadding
368
- titleSegments.letterSpacing = title.letterSpacing
369
- titleSegments.opticalOffsetY = title.opticalOffsetY
370
- titleSegments.maxLines = 1
371
- titleSegments.ellipsize = TextUtils.TruncateAt.END
372
- TextViewCompat.setLineHeight(titleSegments, title.lineHeight)
373
- val baseColor = title.currentTextColor
374
- titleSegments.setTextColor(baseColor)
375
- val segments = item.json.optJSONArray("titleSegments") ?: return
376
- val runs =
377
- (0 until segments.length()).mapNotNull { index ->
378
- val segment = segments.optJSONObject(index) ?: return@mapNotNull null
379
- NativeListTitleSegmentsView.Run(
380
- text = segment.optString("text"),
381
- typeface =
382
- when (segment.optString("fontWeight")) {
383
- "medium" -> fonts.medium(context)
384
- "regular" -> fonts.regular(context)
385
- else -> null
386
- },
387
- color =
388
- when (segment.optString("tone")) {
389
- "secondary" -> color(theme, "secondaryText", "#0000009B")
390
- "primary" -> color(theme, "primaryText", "#000000DF")
391
- else -> baseColor
392
- },
393
- shrink = segment.optBoolean("shrink", false),
394
- maxWidthRatio =
395
- if (segment.has("maxWidthRatio")) segment.optDouble("maxWidthRatio").toFloat() else null,
396
- )
397
- }
398
- titleSegments.setRuns(runs, item.json.optString("title"))
399
346
  }
400
347
 
401
348
  private fun styleGap(column: LinearLayout, gap: Int) {
@@ -529,8 +476,7 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
529
476
  val imageWidth = titleImage?.view?.takeIf { it.visibility == VISIBLE }?.let {
530
477
  it.layoutParams.width + dp(4)
531
478
  } ?: 0
532
- val icon = (if (titleIcon.visibility == VISIBLE) dp(24) else 0) + imageWidth +
533
- (if (titleLeadingIcon.visibility == VISIBLE) dp(22) else 0)
479
+ val icon = (if (titleIcon.visibility == VISIBLE) dp(24) else 0) + imageWidth
534
480
  (inner * ratio).roundToInt()
535
481
  .minus(leading.width + leading.marginEnd + icon)
536
482
  .coerceAtLeast(0)
@@ -541,10 +487,9 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
541
487
  super.onMeasure(widthMeasureSpec, heightMeasureSpec)
542
488
  if (titleSuffixLabels.isNotEmpty()) {
543
489
  val fixedWidth =
544
- (0 until titleLine.childCount).sumOf { index ->
490
+ (1 until titleLine.childCount).sumOf { index ->
545
491
  val view = titleLine.getChildAt(index)
546
- if (view.visibility == GONE || view === titleLine.titleChild ||
547
- titleSuffixLabels.any { it === view }) 0
492
+ if (view.visibility == GONE || titleSuffixLabels.any { it === view }) 0
548
493
  else {
549
494
  val margins = view.layoutParams as MarginLayoutParams
550
495
  view.measuredWidth + margins.leftMargin + margins.rightMargin
@@ -808,35 +753,6 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
808
753
  titleLine.packsChildrenAtStart = true
809
754
  title.ellipsize = TextUtils.TruncateAt.END
810
755
  showText(title, item.json.optString("title"), item.json.optInt("titleLines", 1))
811
- // Runs replace the drawn title except where `title` itself is highlighted;
812
- // their content is bound once the title style is final.
813
- if (nativeListShowsTitleRuns(
814
- item.json.optString("presentation"),
815
- item.json.optJSONArray("titleSegments")?.length() ?: 0,
816
- item.json.optJSONArray("titleMatch")?.length() ?: 0,
817
- )
818
- ) {
819
- title.visibility = GONE
820
- titleSegments.visibility = VISIBLE
821
- titleLine.titleChild = titleSegments
822
- }
823
- val leadingIcon = item.json.optJSONObject("titleLeadingIcon")
824
- ?.takeIf { nativeListAllowsTitleDecorations(item.json.optString("presentation")) }
825
- leadingIcon?.let { icon ->
826
- titleLeadingIcon.iconName = icon.optString("name")
827
- titleLeadingIcon.glyphSizeDp = 16
828
- titleLeadingIcon.useSourceScale = sourceScale
829
- titleLeadingIcon.tintColor = safeColor(
830
- icon.optString("tintColor").takeIf(String::isNotEmpty),
831
- color(theme, "iconSubdued", "#00000072"),
832
- )
833
- titleLeadingIcon.contentDescription =
834
- icon.optString("accessibilityLabel").takeIf(String::isNotEmpty)
835
- titleLeadingIcon.importantForAccessibility =
836
- if (titleLeadingIcon.contentDescription == null) View.IMPORTANT_FOR_ACCESSIBILITY_NO
837
- else View.IMPORTANT_FOR_ACCESSIBILITY_YES
838
- titleLeadingIcon.visibility = VISIBLE
839
- }
840
756
  item.json.optJSONArray("titleSuffixes")?.let { suffixes ->
841
757
  for (index in 0 until suffixes.length()) {
842
758
  val suffix = suffixes.optJSONObject(index) ?: continue
@@ -0,0 +1,244 @@
1
+ package com.margelo.nitro.nativelist
2
+
3
+ import android.content.Context
4
+ import android.graphics.Canvas
5
+ import android.graphics.Color
6
+ import android.graphics.LinearGradient
7
+ import android.graphics.Matrix
8
+ import android.graphics.Paint
9
+ import android.graphics.Path
10
+ import android.graphics.PorterDuff
11
+ import android.graphics.PorterDuffXfermode
12
+ import android.graphics.RadialGradient
13
+ import android.graphics.RectF
14
+ import android.graphics.Shader
15
+ import android.os.SystemClock
16
+ import android.provider.Settings
17
+ import android.view.View
18
+ import android.view.animation.PathInterpolator
19
+ import kotlin.math.sqrt
20
+ import kotlin.math.tan
21
+ import org.json.JSONObject
22
+
23
+ /**
24
+ * Loading sheen and failed hatch drawn over a media tile while it has no picture. Geometry mirrors
25
+ * the Web renderer (`MediaTileRowRenderer.ts`) and iOS (`NativeListMediaPlaceholderView.swift`) so
26
+ * every platform draws the same placeholder.
27
+ */
28
+ internal class NativeListMediaPlaceholderView(context: Context) : View(context) {
29
+ enum class State {
30
+ Hidden,
31
+ Loading,
32
+ Failed,
33
+ }
34
+
35
+ var state = State.Hidden
36
+ private set
37
+
38
+ var cornerRadius = 0f
39
+ set(value) {
40
+ if (field == value) return
41
+ field = value
42
+ invalidate()
43
+ }
44
+
45
+ private val density = resources.displayMetrics.density
46
+ private val clip = Path()
47
+ private val bounds = RectF()
48
+ private val hatchPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE }
49
+ private val hatchMaskPaint =
50
+ Paint(Paint.ANTI_ALIAS_FLAG).apply { xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_IN) }
51
+ private val sheenPaint = Paint(Paint.ANTI_ALIAS_FLAG)
52
+ private val fillPaint = Paint(Paint.ANTI_ALIAS_FLAG)
53
+ private val glyphPaint =
54
+ Paint(Paint.ANTI_ALIAS_FLAG).apply {
55
+ style = Paint.Style.STROKE
56
+ strokeCap = Paint.Cap.ROUND
57
+ strokeJoin = Paint.Join.ROUND
58
+ }
59
+ private val borderPaint =
60
+ Paint(Paint.ANTI_ALIAS_FLAG).apply {
61
+ style = Paint.Style.STROKE
62
+ strokeWidth = 1f
63
+ }
64
+ private val picture = Path()
65
+ private val slash = Path()
66
+ private val pictureClip = Path()
67
+ private var shine = Color.argb(191, 255, 255, 255)
68
+ private var laidOutWidth = -1
69
+ private var laidOutHeight = -1
70
+ private var reduceMotion = false
71
+
72
+ init {
73
+ visibility = GONE
74
+ setWillNotDraw(false)
75
+ importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_NO
76
+ }
77
+
78
+ fun applyTheme(theme: JSONObject?) {
79
+ fun tint(name: String, fallback: String) =
80
+ parseNativeListColor(theme?.optString(name, fallback)?.takeIf(String::isNotEmpty) ?: fallback)
81
+ glyphPaint.color = withAlpha(tint("disabledText", "#8C8C8C"), 0.7f)
82
+ fillPaint.color = tint("strongBackground", "#0000000F")
83
+ borderPaint.color = withAlpha(tint("separator", "#E5E7EB"), 0.6f)
84
+ val primary = tint("primaryText", "#202020")
85
+ hatchPaint.color = Color.argb(11, Color.red(primary), Color.green(primary), Color.blue(primary))
86
+ val row = tint("rowBackground", "#FFFFFF")
87
+ val dark = Color.red(row) * 299 + Color.green(row) * 587 + Color.blue(row) * 114 < 128_000
88
+ val nextShine = Color.argb(if (dark) 18 else 191, 255, 255, 255)
89
+ if (nextShine != shine) {
90
+ shine = nextShine
91
+ laidOutWidth = -1
92
+ }
93
+ invalidate()
94
+ }
95
+
96
+ fun setState(next: State) {
97
+ if (next == state) return
98
+ state = next
99
+ if (next == State.Loading) reduceMotion = animatorScale() == 0f
100
+ visibility = if (next == State.Hidden) GONE else VISIBLE
101
+ invalidate()
102
+ }
103
+
104
+ override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
105
+ super.onSizeChanged(w, h, oldw, oldh)
106
+ laidOutWidth = -1
107
+ }
108
+
109
+ private fun layoutShapes() {
110
+ if (laidOutWidth == width && laidOutHeight == height) return
111
+ laidOutWidth = width
112
+ laidOutHeight = height
113
+ val w = width.toFloat()
114
+ val h = height.toFloat()
115
+ val center = 0.5f * sqrt(w * w + h * h)
116
+ hatchMaskPaint.shader =
117
+ RadialGradient(
118
+ w / 2,
119
+ h / 2,
120
+ center.coerceAtLeast(1f),
121
+ intArrayOf(Color.TRANSPARENT, Color.TRANSPARENT, Color.BLACK, Color.BLACK),
122
+ floatArrayOf(0f, 0.22f, 0.7f, 1f),
123
+ Shader.TileMode.CLAMP,
124
+ )
125
+ val transparentShine = shine and 0x00FFFFFF
126
+ sheenPaint.shader =
127
+ LinearGradient(
128
+ 0f,
129
+ 0f,
130
+ w * 0.6f,
131
+ 0f,
132
+ intArrayOf(transparentShine, shine, transparentShine),
133
+ floatArrayOf(0f, 0.5f, 1f),
134
+ Shader.TileMode.CLAMP,
135
+ )
136
+ hatchPaint.strokeWidth = density
137
+ // Glyph geometry in a 24-unit box, scaled to 28% of the tile and capped at 44pt.
138
+ val size = minOf(w * 0.28f, 44f * density)
139
+ val scale = size / 24f
140
+ val matrix =
141
+ Matrix().apply {
142
+ setScale(scale, scale)
143
+ postTranslate((w - size) / 2, (h - size) / 2)
144
+ }
145
+ glyphPaint.strokeWidth = 1.5f * scale
146
+ picture.reset()
147
+ picture.addRoundRect(RectF(3f, 3f, 21f, 21f), 4f, 4f, Path.Direction.CW)
148
+ picture.addCircle(9f, 9f, 1.6f, Path.Direction.CW)
149
+ picture.moveTo(5f, 20.5f)
150
+ picture.lineTo(14.5f, 11f)
151
+ picture.lineTo(21f, 17.5f)
152
+ picture.transform(matrix)
153
+ slash.reset()
154
+ slash.moveTo(3f, 3f)
155
+ slash.lineTo(21f, 21f)
156
+ slash.transform(matrix)
157
+ val band =
158
+ Path().apply {
159
+ moveTo(2.6f, -0.6f)
160
+ lineTo(24.6f, 21.4f)
161
+ lineTo(21.4f, 24.6f)
162
+ lineTo(-0.6f, 2.6f)
163
+ close()
164
+ transform(matrix)
165
+ }
166
+ pictureClip.reset()
167
+ pictureClip.addRect(0f, 0f, w, h, Path.Direction.CW)
168
+ pictureClip.op(band, Path.Op.DIFFERENCE)
169
+ }
170
+
171
+ override fun onDraw(canvas: Canvas) {
172
+ if (state == State.Hidden || width == 0 || height == 0) return
173
+ layoutShapes()
174
+ val w = width.toFloat()
175
+ val h = height.toFloat()
176
+ bounds.set(0f, 0f, w, h)
177
+ clip.reset()
178
+ clip.addRoundRect(bounds, cornerRadius, cornerRadius, Path.Direction.CW)
179
+ canvas.save()
180
+ canvas.clipPath(clip)
181
+ // The placeholder owns the slot fill: the image view underneath is empty while
182
+ // loading and hidden once every probe failed.
183
+ canvas.drawRect(0f, 0f, w, h, fillPaint)
184
+ if (state == State.Failed) drawHatch(canvas, w, h) else drawSheen(canvas, w, h)
185
+ if (state == State.Failed) {
186
+ canvas.save()
187
+ canvas.clipPath(pictureClip)
188
+ canvas.drawPath(picture, glyphPaint)
189
+ canvas.restore()
190
+ canvas.drawPath(slash, glyphPaint)
191
+ } else canvas.drawPath(picture, glyphPaint)
192
+ canvas.restore()
193
+ val inset = borderPaint.strokeWidth / 2
194
+ bounds.inset(inset, inset)
195
+ canvas.drawRoundRect(bounds, cornerRadius - inset, cornerRadius - inset, borderPaint)
196
+ }
197
+
198
+ private fun drawHatch(canvas: Canvas, w: Float, h: Float) {
199
+ val layer = canvas.saveLayer(0f, 0f, w, h, null)
200
+ // Lines along x + y = c, 7pt apart measured perpendicular to the stripes.
201
+ val step = 7f * density * sqrt(2f)
202
+ var c = 0f
203
+ while (c <= w + h) {
204
+ canvas.drawLine(c, 0f, 0f, c, hatchPaint)
205
+ c += step
206
+ }
207
+ canvas.drawRect(0f, 0f, w, h, hatchMaskPaint)
208
+ canvas.restoreToCount(layer)
209
+ }
210
+
211
+ private fun drawSheen(canvas: Canvas, w: Float, h: Float) {
212
+ // Band left edge travels from -80% to 130% of the tile, then rests for 30% of the period.
213
+ // Every tile derives its phase from the shared uptime clock so the grid sweeps in step.
214
+ val phase = (SystemClock.uptimeMillis() % SWEEP_PERIOD_MS).toFloat() / SWEEP_PERIOD_MS
215
+ val progress = if (phase < 0.7f) SWEEP_EASING.getInterpolation(phase / 0.7f) else 1f
216
+ val left = if (reduceMotion) w * 0.2f else w * (-0.8f + 2.1f * progress)
217
+ sheenPaint.alpha = if (reduceMotion) 153 else 255
218
+ canvas.save()
219
+ canvas.translate(left + w * 0.3f, h / 2)
220
+ canvas.skew(SKEW, 0f)
221
+ canvas.translate(-w * 0.3f, 0f)
222
+ canvas.drawRect(0f, -h, w * 0.6f, h, sheenPaint)
223
+ canvas.restore()
224
+ if (!reduceMotion && isAttachedToWindow) postInvalidateOnAnimation()
225
+ }
226
+
227
+ private fun animatorScale() =
228
+ Settings.Global.getFloat(context.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f)
229
+
230
+ private fun withAlpha(color: Int, factor: Float) =
231
+ Color.argb(
232
+ (Color.alpha(color) * factor).toInt(),
233
+ Color.red(color),
234
+ Color.green(color),
235
+ Color.blue(color),
236
+ )
237
+
238
+ private companion object {
239
+ const val SWEEP_PERIOD_MS = 1600L
240
+ // CSS skewX(-12deg).
241
+ val SKEW = tan(Math.toRadians(-12.0)).toFloat()
242
+ val SWEEP_EASING = PathInterpolator(0.4f, 0f, 0.2f, 1f)
243
+ }
244
+ }
@@ -16,7 +16,7 @@ internal class NativeListMediaTileRowView(context: ThemedReactContext, fonts: Na
16
16
  private val picture = FrameLayout(context)
17
17
  private val image = NativeListMediaPreviewSlot(context)
18
18
  private val network = NativeListImageSlot(context)
19
- private val errorIcon = OneKeyIconView(context)
19
+ private val placeholderView = NativeListMediaPlaceholderView(context)
20
20
  private val title = NativeListTextView(context)
21
21
  private val subtitle = NativeListTextView(context)
22
22
  private val badge = NativeListTextView(context)
@@ -43,7 +43,7 @@ internal class NativeListMediaTileRowView(context: ThemedReactContext, fonts: Na
43
43
  init {
44
44
  orientation = VERTICAL
45
45
  picture.addView(image.view, FrameLayout.LayoutParams(-1, -1))
46
- picture.addView(errorIcon)
46
+ picture.addView(placeholderView, FrameLayout.LayoutParams(-1, -1))
47
47
  picture.addView(badge)
48
48
  subtitleLine.addView(subtitle, LayoutParams(0, -2, 1f))
49
49
  subtitleLine.addView(network.view)
@@ -136,17 +136,20 @@ internal class NativeListMediaTileRowView(context: ThemedReactContext, fonts: Na
136
136
  metadata.layoutParams = LayoutParams(-1, -2).apply { topMargin = size("leadingGap", 8) }
137
137
  (subtitle.layoutParams as LayoutParams).marginEnd = dp(8)
138
138
  val state = item.json.optString("imageState")
139
- errorIcon.visibility = if (state == "error") VISIBLE else GONE
140
- errorIcon.iconName = "ImageSquareWavesOutline"
141
- errorIcon.tintColor = tint("disabledText", "#8C8C8C")
142
- errorIcon.useSourceScale = sourceScale
143
- errorIcon.layoutParams = FrameLayout.LayoutParams(dp(24), dp(24), Gravity.CENTER)
139
+ placeholderView.applyTheme(theme)
140
+ placeholderView.cornerRadius =
141
+ if (imageStyle.optString("shape") == "circle" && !imageStyle.has("cornerRadius")) 10_000f
142
+ else if (imageStyle.has("cornerRadius")) stylePx(imageStyle.optDouble("cornerRadius")).toFloat()
143
+ else if (imageStyle.optString("shape") == "square") 0f
144
+ else dp(10).toFloat()
144
145
  val media = item.json.optJSONObject("media")
145
146
  val source = media?.optJSONObject("source") ?: item.json.optJSONObject("image")
146
147
  val order = media?.optJSONArray("probeOrder")?.let { values ->
147
148
  (0 until values.length()).map { values.optString(it) }
148
149
  } ?: listOf("image")
149
- if (state != "empty" && state != "error" && source != null)
150
+ if (state != "empty" && state != "error" && source != null) {
151
+ // Set before binding: a cached result completes synchronously inside bind.
152
+ showPlaceholder(NativeListMediaPlaceholderView.State.Loading)
150
153
  image.bind(
151
154
  source,
152
155
  "${item.key}:media",
@@ -156,17 +159,26 @@ internal class NativeListMediaTileRowView(context: ThemedReactContext, fonts: Na
156
159
  ?: "#0000000F",
157
160
  probeOrder = order,
158
161
  ) { loaded ->
159
- errorIcon.visibility = if (loaded) GONE else VISIBLE
162
+ showPlaceholder(
163
+ if (loaded) NativeListMediaPlaceholderView.State.Hidden
164
+ else NativeListMediaPlaceholderView.State.Failed
165
+ )
160
166
  if (!loaded) image.view.setBackgroundColor(tint("strongBackground", "#0000000F"))
161
167
  }
162
- else image.recycle()
168
+ } else {
169
+ image.recycle()
170
+ showPlaceholder(
171
+ if (state == "error") NativeListMediaPlaceholderView.State.Failed
172
+ else NativeListMediaPlaceholderView.State.Hidden
173
+ )
174
+ }
163
175
  // Legacy: only the empty/error states paint a slot fill; loaded images show
164
176
  // their own placeholder without a white backing.
165
177
  image.view.background =
166
178
  when (state) {
167
179
  "error" -> GradientDrawable().apply { setColor(tint("strongBackground", "#0000000F")) }
168
180
  "empty" -> GradientDrawable().apply { setColor(Color.WHITE) }
169
- else -> if (errorIcon.visibility == VISIBLE) GradientDrawable().apply { setColor(tint("strongBackground", "#0000000F")) } else null
181
+ else -> if (placeholderView.state == NativeListMediaPlaceholderView.State.Failed) GradientDrawable().apply { setColor(tint("strongBackground", "#0000000F")) } else null
170
182
  }
171
183
  image.view.outlineProvider =
172
184
  object : ViewOutlineProvider() {
@@ -229,8 +241,17 @@ internal class NativeListMediaTileRowView(context: ThemedReactContext, fonts: Na
229
241
  super.onMeasure(widthMeasureSpec, heightMeasureSpec)
230
242
  }
231
243
 
244
+ private fun showPlaceholder(state: NativeListMediaPlaceholderView.State) {
245
+ placeholderView.setState(state)
246
+ // OneKeyImage may paint its own terminal symbol once a probe fails; the failed
247
+ // placeholder replaces the slot entirely instead of drawing over it.
248
+ image.view.visibility =
249
+ if (state == NativeListMediaPlaceholderView.State.Failed) INVISIBLE else VISIBLE
250
+ }
251
+
232
252
  override fun recycleContent() {
233
253
  image.recycle()
254
+ showPlaceholder(NativeListMediaPlaceholderView.State.Hidden)
234
255
  network.recycle()
235
256
  closeKey = ""
236
257
  picture.alpha = 1f
@@ -62,6 +62,66 @@ internal fun nativeListLeadingVisualOverhangsFrame(
62
62
  */
63
63
  internal fun nativeListActivityHostClips(leadingOverhangs: Boolean): Boolean = !leadingOverhangs
64
64
 
65
+ /** A one-line text view shows each line break of its text as one space. */
66
+ internal fun nativeListFoldLineBreaks(text: String): String = text.replace(Regex("\\r\\n|[\\r\\n]"), " ")
67
+
68
+ /**
69
+ * Offset into the displayed text for [sourceOffset], a UTF-16 offset into the
70
+ * caller's [source], kept within the text. Folding line breaks
71
+ * ([nativeListFoldLineBreaks]) moves every offset after a CRLF. The offset is a
72
+ * Long because JSON carries any safe integer; narrowing it first would wrap a
73
+ * value past Int range instead of clamping it to the end.
74
+ */
75
+ internal fun nativeListDisplayOffset(source: String, sourceOffset: Long, foldsLineBreaks: Boolean): Int {
76
+ val clamped = sourceOffset.coerceIn(0L, source.length.toLong()).toInt()
77
+ return if (foldsLineBreaks) nativeListFoldLineBreaks(source.substring(0, clamped)).length else clamped
78
+ }
79
+
80
+ /** A horizontal run of laid-out text on one line, in view coordinates. */
81
+ internal data class NativeListTextRun(val left: Float, val right: Float)
82
+
83
+ /**
84
+ * One laid-out line of a text view, in view coordinates: its vertical extent,
85
+ * the runs of [touchable] text and the runs of [plain] text before it. A line
86
+ * holds one run of each, or several where mixed-direction text puts plain text
87
+ * between touchable text.
88
+ */
89
+ internal data class NativeListTextLine(
90
+ val top: Float,
91
+ val bottom: Float,
92
+ val touchable: List<NativeListTextRun>,
93
+ val plain: List<NativeListTextRun> = emptyList(),
94
+ )
95
+
96
+ internal data class NativeListTouchRegion(val left: Float, val top: Float, val right: Float, val bottom: Float) {
97
+ fun contains(x: Float, y: Float): Boolean = x in left..right && y in top..bottom
98
+ }
99
+
100
+ /** Runs are read back from pixel regions, so neighbours can be a pixel apart. */
101
+ private const val TEXT_RUN_EDGE = 1f
102
+
103
+ /**
104
+ * Parts of a stretched text view that take touches: every run of touchable
105
+ * text, widened by [slop] into blank space only. The widening stops at plain
106
+ * text on the same line, so text before the touchable text never takes the
107
+ * touch, however narrow it is. Touches outside the regions fall through to the
108
+ * row behind the view (OK-67219).
109
+ */
110
+ internal fun nativeListTouchableTextRegions(
111
+ lines: List<NativeListTextLine>,
112
+ slop: Float,
113
+ ): List<NativeListTouchRegion> = lines.flatMap { line ->
114
+ line.touchable.map { run ->
115
+ var left = run.left - slop
116
+ var right = run.right + slop
117
+ for (other in line.plain) {
118
+ if (other.right <= run.left + TEXT_RUN_EDGE) left = maxOf(left, other.right)
119
+ if (other.left >= run.right - TEXT_RUN_EDGE) right = minOf(right, other.left)
120
+ }
121
+ NativeListTouchRegion(left, line.top, right, line.bottom)
122
+ }
123
+ }
124
+
65
125
  internal data class NativeListSlotFrame(val x: Int, val y: Int, val width: Int, val height: Int)
66
126
 
67
127
  /** Side of one member of an Activity token pair inside a [frame]-unit box (24 in 40). */
@@ -109,9 +109,6 @@ 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
115
112
 
116
113
  override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
117
114
  if (!packsChildrenAtStart || childCount < 2) {
@@ -119,13 +116,13 @@ internal class PackedTitleLineLayout(context: android.content.Context) : LinearL
119
116
  return
120
117
  }
121
118
 
122
- val title = titleChild?.takeIf { it.parent === this } ?: getChildAt(0)
119
+ val title = getChildAt(0)
123
120
  val widthMode = MeasureSpec.getMode(widthMeasureSpec)
124
121
  val widthSize = MeasureSpec.getSize(widthMeasureSpec)
125
122
  var accessoryWidth = 0
126
- for (index in 0 until childCount) {
123
+ for (index in 1 until childCount) {
127
124
  val child = getChildAt(index)
128
- if (child === title || child.visibility == GONE) continue
125
+ if (child.visibility == GONE) continue
129
126
  measureChildWithMargins(
130
127
  child,
131
128
  widthMeasureSpec,
@@ -43,6 +43,10 @@ internal data class NativeListResolvedText(
43
43
  val gravity: Int,
44
44
  val offset: Float,
45
45
  ) {
46
+ /** Offset into [text] for a UTF-16 offset into the [source] it was resolved from. */
47
+ fun displayOffset(sourceOffset: Long, source: String): Int =
48
+ nativeListDisplayOffset(source, sourceOffset, foldsLineBreaks = lines == 1 && explicitTruncation)
49
+
46
50
  fun bind(view: NativeListTextView) {
47
51
  view.includeFontPadding = false
48
52
  view.fontFeatureSettings = "tnum"
@@ -119,7 +123,7 @@ internal data class NativeListResolvedText(
119
123
  else -> Gravity.TOP
120
124
  }
121
125
  return NativeListResolvedText(
122
- if (maxLines == 1 && truncation) text.replace(Regex("\\r\\n|[\\r\\n]"), " ") else text,
126
+ if (maxLines == 1 && truncation) nativeListFoldLineBreaks(text) else text,
123
127
  fontSize,
124
128
  face,
125
129
  style