@onekeyfe/react-native-native-list 6.7.0-39 → 6.7.0-40

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.
@@ -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
@@ -291,8 +291,10 @@ stacked (phone) table (wide)
291
291
  supplies one or two distinct `image`/`video` candidates. It takes precedence
292
292
  over `image`; explicit `imageState: empty | error` still suppresses loading.
293
293
  A video candidate uses a muted paused native player, with no playback/controls or
294
- touch target. Detail playback remains caller-owned. Failure advances once to
295
- the next candidate, then displays the standard error placeholder. The same
294
+ touch target. Detail playback remains caller-owned. While loading the slot
295
+ shows a synchronized sheen placeholder; failure advances once to the next
296
+ candidate, then shows the hatched failed placeholder (SPEC: Media loading
297
+ and failure placeholders). The same
296
298
  media box and caption diagram apply; this adds no new layout region.
297
299
  Web keeps the existing `image` field and does not execute media probing.
298
300
  - **Native lifetime:** request identity includes row key, full source, fit,
package/docs/SPEC.md CHANGED
@@ -71,15 +71,44 @@ prevention; there is no automatic fitting or shrinking pass.
71
71
 
72
72
  ## Public API and defaults
73
73
 
74
- ### Media failure placeholder — Implemented
75
-
76
- Native media-tile failures use the current theme's `disabledText` color for the
77
- existing local `ImageSquareWavesOutline` icon, including explicit `imageState:
78
- 'error'` and exhausted media probes. A theme rebind updates that tint. Image
79
- content and SVG decoding remain owned by OneKeyImage; no per-cell WebView or
80
- fallback network source is added.
81
- Full-wallet dark/light placeholder acceptance remains a runtime check; source
82
- completion does not establish that visual result.
74
+ ### Media loading and failure placeholders — Implemented
75
+
76
+ Gallery media tiles draw one placeholder layer over the media slot on iOS
77
+ (`NativeListMediaPlaceholderView.swift`), Android
78
+ (`NativeListMediaPlaceholderView.kt`) and Web (`MediaTileRowRenderer.ts`). All
79
+ three share one geometry so the states read the same everywhere:
80
+
81
+ - **Loading** — from bind until the first candidate loads or every candidate
82
+ fails. Fill: `strongBackground`. A sheen band 60% of the tile wide, skewed
83
+ -12°, sweeps left to right over 1.6s (70% travel with `cubic-bezier(0.4, 0,
84
+ 0.2, 1)`, 30% rest). Every tile derives its phase from one shared clock
85
+ (`CACurrentMediaTime` / `SystemClock.uptimeMillis` / `performance.now`), so a
86
+ grid sweeps in step, recycled cells included. The sheen is white at 75% on a
87
+ light `rowBackground` (Web: `background`) and 7% on a dark one. Reduced
88
+ motion (iOS Reduce Motion, Android animator scale 0, Web
89
+ `prefers-reduced-motion`) holds the band still at 60% strength.
90
+ - **Failed** — explicit `imageState: 'error'` or exhausted probes. Fill:
91
+ `strongBackground`, plus 1pt `primaryText` lines at 4.5% alpha along 135°,
92
+ 7pt apart, masked by a radial gradient that is clear inside 22% of the
93
+ half-diagonal and opaque from 70%. No text is shown, so there is no copy to
94
+ localize.
95
+ - **Loaded / empty** — the placeholder is hidden; `imageState: 'empty'`
96
+ without a source keeps the slot transparent as before.
97
+
98
+ Both visible states draw a 24-unit glyph at 28% of the tile width, capped at
99
+ 44pt, stroked 1.5 units in `disabledText` at 70% of its alpha: a rounded frame
100
+ (3,3,18,18, r4), a sun (9,9 r1.6) and a ridge (5,20.5 → 14.5,11 → 21,17.5).
101
+ The failed glyph adds a slash (3,3 → 21,21) and cuts a 1.6-unit gap into the
102
+ frame on both sides of it. A 1px `separator` hairline at 60% of its alpha
103
+ outlines the slot in both states.
104
+
105
+ The placeholder owns the slot fill while visible. On Android the media view
106
+ is made invisible in the failed state, because OneKeyImage may paint its own
107
+ terminal state symbol after a probe advances. Image content and SVG decoding
108
+ remain owned by OneKeyImage; no per-cell WebView or fallback network source is
109
+ added. A theme rebind updates every color. Runtime acceptance (2026-11-10):
110
+ iOS dark and Android light on a watch-only wallet NFT grid, Web light/dark in
111
+ the standalone engine harness.
83
112
 
84
113
  ### Recipient identity and inline warning rows
85
114
 
@@ -1392,8 +1421,8 @@ There are no controls or video touch targets; the row owns press interaction.
1392
1421
  Android preserves a black letterbox and iOS a transparent one, matching the
1393
1422
  existing native Video views. No code calls play or requests audio focus.
1394
1423
 
1395
- A failed candidate advances once; exhaustion displays the existing error
1396
- placeholder. New source/row identity resets probing; binding, candidate and
1424
+ A failed candidate advances once; exhaustion displays the failed media
1425
+ placeholder (see Media loading and failure placeholders). New source/row identity resets probing; binding, candidate and
1397
1426
  player generations reject stale callbacks, including A→B→A. Text-only updates
1398
1427
  preserve the current request. On Android, terminal image/player completion is
1399
1428
  posted to the next UI queue turn before advancing probes or notifying the row;
@@ -2002,8 +2031,9 @@ imageState explicitly selects that state.
2002
2031
 
2003
2032
  Web gallery media preserves the consuming NFT card presentation: healthy image
2004
2033
  and exhausted fallback surfaces have a10px radius, while a healthy video surface
2005
- has square corners. The image/video frame uses the list page background; only
2006
- the exhausted fallback surface uses the strong background. Rebinding the same
2034
+ has square corners. The image/video frame uses the list page background; the
2035
+ loading and exhausted fallback surfaces use the strong background and the
2036
+ shared media placeholders. Rebinding the same
2007
2037
  video key retains square corners, and failed-video fallback to an image restores
2008
2038
  the image radius. This is Web renderer behavior; native media presentation and
2009
2039
  probe-order contracts are unchanged.
@@ -535,6 +535,9 @@ defaults applied when `style` is absent.
535
535
  | image radius | 10 | 10 | dp(10) | 10px **=** |
536
536
  | tile radius | 16 | 16 | 16 | 16px **=** |
537
537
  | network badge | 14 | 14×14, r7 | dp(14), circle | 14px, r50% **=** |
538
+ | placeholder glyph | 28% of width, max 44 | CAShapeLayer | Canvas path | inline SVG **=** |
539
+ | loading sheen | 60% wide, -12°, 1.6s | CAKeyframeAnimation | `postInvalidateOnAnimation` | CSS keyframes **=** |
540
+ | failed hatch | 1 / 7, 135°, 4.5% | CAShapeLayer + radial mask | `saveLayer` + `DST_IN` | repeating gradient + mask **=** |
538
541
 
539
542
  ### metricCard
540
543
 
@@ -0,0 +1,189 @@
1
+ import UIKit
2
+
3
+ /// Loading sheen and failed hatch drawn over a media tile while it has no picture.
4
+ /// Geometry mirrors the Web renderer (`MediaTileRowRenderer.ts`) and Android
5
+ /// (`NativeListMediaPlaceholderView.kt`) so every platform draws the same placeholder.
6
+ final class NativeListMediaPlaceholderView: UIView {
7
+ enum State { case hidden, loading, failed }
8
+
9
+ private static let sweepPeriod: CFTimeInterval = 1.6
10
+ private static let sweepKey = "nativeListMediaSweep"
11
+
12
+ private let sheen = CAGradientLayer()
13
+ private let hatch = CAShapeLayer()
14
+ private let hatchMask = CAGradientLayer()
15
+ private let picture = CAShapeLayer()
16
+ private let pictureCut = CAShapeLayer()
17
+ private let slash = CAShapeLayer()
18
+ private(set) var state: State = .hidden
19
+ private var laidOutSize: CGSize = .zero
20
+ private var loadingFill: UIColor = .clear
21
+
22
+ override init(frame: CGRect) {
23
+ super.init(frame: frame)
24
+ isUserInteractionEnabled = false
25
+ isHidden = true
26
+ clipsToBounds = true
27
+ layer.borderWidth = 1 / UIScreen.main.scale
28
+ sheen.startPoint = CGPoint(x: 0, y: 0.5)
29
+ sheen.endPoint = CGPoint(x: 1, y: 0.5)
30
+ sheen.locations = [0, 0.5, 1]
31
+ hatch.lineWidth = 1
32
+ hatch.fillColor = nil
33
+ hatchMask.type = .radial
34
+ hatchMask.startPoint = CGPoint(x: 0.5, y: 0.5)
35
+ // CSS `radial-gradient(circle ...)` defaults to the farthest corner.
36
+ hatchMask.endPoint = CGPoint(x: 0.5 + 0.7071, y: 0.5 + 0.7071)
37
+ hatchMask.colors = [UIColor.clear.cgColor, UIColor.clear.cgColor, UIColor.black.cgColor, UIColor.black.cgColor]
38
+ hatchMask.locations = [0, 0.22, 0.7, 1]
39
+ hatch.mask = hatchMask
40
+ for shape in [picture, slash] {
41
+ shape.fillColor = nil
42
+ shape.lineCap = .round
43
+ shape.lineJoin = .round
44
+ }
45
+ pictureCut.fillRule = .evenOdd
46
+ pictureCut.fillColor = UIColor.black.cgColor
47
+ [hatch, sheen, picture, slash].forEach(layer.addSublayer)
48
+ NotificationCenter.default.addObserver(
49
+ self, selector: #selector(restartSweep),
50
+ name: UIApplication.willEnterForegroundNotification, object: nil)
51
+ }
52
+ required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
53
+
54
+ func applyTheme(_ theme: [String: Any]?) {
55
+ loadingFill = nativeListColor(theme, "strongBackground", "#0000000F")
56
+ if state == .loading { backgroundColor = loadingFill }
57
+ let glyph = nativeListColor(theme, "disabledText", "#8C8C8C")
58
+ let glyphColor = glyph.withAlphaComponent(glyph.cgAlpha * 0.7).cgColor
59
+ picture.strokeColor = glyphColor
60
+ slash.strokeColor = glyphColor
61
+ let separator = nativeListColor(theme, "separator", "#E5E7EB")
62
+ layer.borderColor = separator.withAlphaComponent(separator.cgAlpha * 0.6).cgColor
63
+ hatch.strokeColor = nativeListColor(theme, "primaryText", "#202020").withAlphaComponent(0.045).cgColor
64
+ let dark = nativeListIsDark(nativeListColor(theme, "rowBackground", "#FFFFFF"))
65
+ let shine = UIColor.white.withAlphaComponent(dark ? 0.07 : 0.75)
66
+ sheen.colors = [shine.withAlphaComponent(0).cgColor, shine.cgColor, shine.withAlphaComponent(0).cgColor]
67
+ }
68
+
69
+ func setState(_ next: State) {
70
+ guard next != state else { return }
71
+ state = next
72
+ isHidden = next == .hidden
73
+ // The failed state sits on the cell's own fill; while loading nothing else paints the slot.
74
+ backgroundColor = next == .loading ? loadingFill : .clear
75
+ CATransaction.begin()
76
+ CATransaction.setDisableActions(true)
77
+ sheen.isHidden = next != .loading
78
+ hatch.isHidden = next != .failed
79
+ slash.isHidden = next != .failed
80
+ picture.mask = next == .failed ? pictureCut : nil
81
+ CATransaction.commit()
82
+ restartSweep()
83
+ }
84
+
85
+ override func layoutSubviews() {
86
+ super.layoutSubviews()
87
+ guard bounds.size != laidOutSize else { return }
88
+ laidOutSize = bounds.size
89
+ CATransaction.begin()
90
+ CATransaction.setDisableActions(true)
91
+ layoutHatch()
92
+ layoutGlyph()
93
+ let width = bounds.width, height = bounds.height
94
+ sheen.bounds = CGRect(x: 0, y: 0, width: width * 0.6, height: height * 2)
95
+ sheen.position = CGPoint(x: width * 0.6, y: height / 2)
96
+ // CSS skewX(-12deg).
97
+ sheen.setAffineTransform(CGAffineTransform(a: 1, b: 0, c: -tan(12 * .pi / 180), d: 1, tx: 0, ty: 0))
98
+ CATransaction.commit()
99
+ restartSweep()
100
+ }
101
+
102
+ override func didMoveToWindow() {
103
+ super.didMoveToWindow()
104
+ restartSweep()
105
+ }
106
+
107
+ @objc private func restartSweep() {
108
+ sheen.removeAnimation(forKey: Self.sweepKey)
109
+ guard state == .loading, window != nil, bounds.width > 0 else { return }
110
+ let width = bounds.width
111
+ guard !UIAccessibility.isReduceMotionEnabled else {
112
+ sheen.opacity = 0.6
113
+ return
114
+ }
115
+ sheen.opacity = 1
116
+ let sweep = CAKeyframeAnimation(keyPath: "position.x")
117
+ // Band left edge travels from -80% to 130% of the tile, then rests for 30% of the period.
118
+ sweep.values = [width * -0.5, width * 1.6, width * 1.6]
119
+ sweep.keyTimes = [0, 0.7, 1]
120
+ sweep.timingFunctions = [
121
+ CAMediaTimingFunction(controlPoints: 0.4, 0, 0.2, 1), CAMediaTimingFunction(name: .linear),
122
+ ]
123
+ sweep.duration = Self.sweepPeriod
124
+ sweep.repeatCount = .infinity
125
+ sweep.isRemovedOnCompletion = false
126
+ // Every tile derives its phase from the shared media clock so the grid sweeps in step,
127
+ // including cells that are recycled mid-period.
128
+ sweep.timeOffset = CACurrentMediaTime().truncatingRemainder(dividingBy: Self.sweepPeriod)
129
+ sheen.add(sweep, forKey: Self.sweepKey)
130
+ }
131
+
132
+ private func layoutHatch() {
133
+ hatch.frame = bounds
134
+ hatchMask.frame = bounds
135
+ let path = UIBezierPath()
136
+ // Lines along x + y = c, 7pt apart measured perpendicular to the stripes.
137
+ let step = 7 * CGFloat(2).squareRoot()
138
+ var c: CGFloat = 0
139
+ while c <= bounds.width + bounds.height {
140
+ path.move(to: CGPoint(x: c, y: 0))
141
+ path.addLine(to: CGPoint(x: 0, y: c))
142
+ c += step
143
+ }
144
+ hatch.path = path.cgPath
145
+ }
146
+
147
+ private func layoutGlyph() {
148
+ let size = min(bounds.width * 0.28, 44)
149
+ let scale = size / 24
150
+ let origin = CGPoint(x: (bounds.width - size) / 2, y: (bounds.height - size) / 2)
151
+ var transform = CGAffineTransform(translationX: origin.x, y: origin.y).scaledBy(x: scale, y: scale)
152
+ let frame = UIBezierPath(roundedRect: CGRect(x: 3, y: 3, width: 18, height: 18), cornerRadius: 4)
153
+ frame.append(UIBezierPath(ovalIn: CGRect(x: 7.4, y: 7.4, width: 3.2, height: 3.2)))
154
+ let ridge = UIBezierPath()
155
+ ridge.move(to: CGPoint(x: 5, y: 20.5))
156
+ ridge.addLine(to: CGPoint(x: 14.5, y: 11))
157
+ ridge.addLine(to: CGPoint(x: 21, y: 17.5))
158
+ frame.append(ridge)
159
+ picture.frame = bounds
160
+ picture.lineWidth = 1.5 * scale
161
+ picture.path = frame.cgPath.copy(using: &transform)
162
+ let line = UIBezierPath()
163
+ line.move(to: CGPoint(x: 3, y: 3))
164
+ line.addLine(to: CGPoint(x: 21, y: 21))
165
+ slash.frame = bounds
166
+ slash.lineWidth = 1.5 * scale
167
+ slash.path = line.cgPath.copy(using: &transform)
168
+ let band = UIBezierPath()
169
+ band.move(to: CGPoint(x: 2.6, y: -0.6))
170
+ band.addLine(to: CGPoint(x: 24.6, y: 21.4))
171
+ band.addLine(to: CGPoint(x: 21.4, y: 24.6))
172
+ band.addLine(to: CGPoint(x: -0.6, y: 2.6))
173
+ band.close()
174
+ let cut = UIBezierPath(rect: bounds)
175
+ if let bandPath = band.cgPath.copy(using: &transform) { cut.append(UIBezierPath(cgPath: bandPath)) }
176
+ pictureCut.frame = bounds
177
+ pictureCut.path = cut.cgPath
178
+ }
179
+ }
180
+
181
+ private extension UIColor {
182
+ var cgAlpha: CGFloat { cgColor.alpha }
183
+ }
184
+
185
+ func nativeListIsDark(_ color: UIColor) -> Bool {
186
+ var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
187
+ guard color.getRed(&red, green: &green, blue: &blue, alpha: &alpha) else { return false }
188
+ return red * 299 + green * 587 + blue * 114 < 500
189
+ }
@@ -11,7 +11,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
11
11
  private let picture = UIView()
12
12
  private let image = NativeListMediaPreviewSlot()
13
13
  private let network = NativeListImageSlot()
14
- private let errorIcon = NativeListIconImageView()
14
+ private let placeholderView = NativeListMediaPlaceholderView()
15
15
  private let title = NativeListTextLabel()
16
16
  private let subtitle = NativeListTextLabel()
17
17
  private let badge = NativeListTextLabel()
@@ -50,7 +50,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
50
50
  closeStack.addArrangedSubview(close)
51
51
  [picture, metadata, closeStack].forEach(root.addArrangedSubview)
52
52
  picture.translatesAutoresizingMaskIntoConstraints = false
53
- [image.view, errorIcon, badge].forEach {
53
+ [image.view, placeholderView, badge].forEach {
54
54
  picture.addSubview($0)
55
55
  $0.translatesAutoresizingMaskIntoConstraints = false
56
56
  }
@@ -60,17 +60,16 @@ final class NativeListMediaTileCell: NativeListRendererCell {
60
60
  image.view.leadingAnchor.constraint(equalTo: picture.leadingAnchor),
61
61
  image.view.topAnchor.constraint(equalTo: picture.topAnchor),
62
62
  image.view.heightAnchor.constraint(equalTo: picture.heightAnchor), imageWidth, imageHeight,
63
- errorIcon.centerXAnchor.constraint(equalTo: image.view.centerXAnchor),
64
- errorIcon.centerYAnchor.constraint(equalTo: image.view.centerYAnchor),
65
- errorIcon.widthAnchor.constraint(equalToConstant: 24),
66
- errorIcon.heightAnchor.constraint(equalToConstant: 24),
63
+ placeholderView.leadingAnchor.constraint(equalTo: image.view.leadingAnchor),
64
+ placeholderView.trailingAnchor.constraint(equalTo: image.view.trailingAnchor),
65
+ placeholderView.topAnchor.constraint(equalTo: image.view.topAnchor),
66
+ placeholderView.bottomAnchor.constraint(equalTo: image.view.bottomAnchor),
67
67
  badge.trailingAnchor.constraint(equalTo: image.view.trailingAnchor),
68
68
  badge.bottomAnchor.constraint(equalTo: image.view.bottomAnchor),
69
69
  badge.heightAnchor.constraint(equalToConstant: 24),
70
70
  network.view.widthAnchor.constraint(equalToConstant: 14),
71
71
  network.view.heightAnchor.constraint(equalToConstant: 14),
72
72
  ])
73
- errorIcon.contentMode = .scaleAspectFit
74
73
  badge.textAlignment = .center
75
74
  badge.layer.cornerRadius = 10
76
75
  badge.layer.borderWidth = 2
@@ -87,8 +86,6 @@ final class NativeListMediaTileCell: NativeListRendererCell {
87
86
  _ item: NativeListItem, theme: [String: Any]?, layout: String,
88
87
  checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
89
88
  ) {
90
- let iconUpdate = NativeListIconUpdate(self)
91
- defer { iconUpdate.finish() }
92
89
 
93
90
  let style = item.data.dictionary("style") ?? [:]
94
91
  imageStyle = style.dictionary("image") ?? [:]
@@ -124,9 +121,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
124
121
  badge.layer.borderColor = nativeListColor(theme, "rowBackground", "#FFFFFF").cgColor
125
122
  let state = item.data.string("imageState")
126
123
  let placeholder = theme?.string("strongBackground", default: "#0000000F") ?? "#0000000F"
127
- errorIcon.isHidden = state != "error"
128
- errorIcon.bindIcon("ImageSquareWavesOutline")
129
- errorIcon.tintColor = nativeListColor(theme, "disabledText", "#8C8C8C")
124
+ placeholderView.applyTheme(theme)
130
125
  let media = item.data.dictionary("media")
131
126
  if state != "empty", state != "error", let source = media?.dictionary("source") ?? item.data.dictionary("image") {
132
127
  // Legacy source-backed media had a transparent container. Clear only a fill this
@@ -135,11 +130,13 @@ final class NativeListMediaTileCell: NativeListRendererCell {
135
130
  image.view.backgroundColor = .clear
136
131
  ownsImageFill = false
137
132
  }
133
+ // Set before binding: a cached result completes synchronously inside bind.
134
+ placeholderView.setState(.loading)
138
135
  image.bind(
139
136
  source, key: "\(item.key):media", fit: imageStyle["contentFit"] as? String,
140
137
  placeholder: placeholder, probeOrder: media?["probeOrder"] as? [String] ?? ["image"]
141
138
  ) { [weak self] loaded in
142
- self?.errorIcon.isHidden = loaded
139
+ self?.placeholderView.setState(loaded ? .hidden : .failed)
143
140
  self?.ownsImageFill = !loaded
144
141
  self?.image.view.backgroundColor = loaded ? .clear : UIColor(nativeListHex: placeholder, fallback: .lightGray)
145
142
  }
@@ -147,6 +144,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
147
144
  image.recycle()
148
145
  image.view.backgroundColor =
149
146
  state == "error" ? nativeListColor(theme, "strongBackground", "#0000000F") : .clear
147
+ placeholderView.setState(state == "error" ? .failed : .hidden)
150
148
  ownsImageFill = true
151
149
  }
152
150
  if let source = item.data.dictionary("networkImage") {
@@ -184,6 +182,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
184
182
  default: shape == "circle"
185
183
  ? Double(min(width, imageHeight.constant) / 2) : shape == "square" ? 0 : 10))
186
184
  image.view.clipsToBounds = true
185
+ placeholderView.layer.cornerRadius = image.view.layer.cornerRadius
187
186
  super.layoutSubviews()
188
187
  }
189
188
  @objc private func closePressed() {
@@ -191,6 +190,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
191
190
  }
192
191
  override func recycleContent() {
193
192
  image.recycle()
193
+ placeholderView.setState(.hidden)
194
194
  network.recycle()
195
195
  closeKey = ""
196
196
  picture.alpha = 1
@@ -183,6 +183,14 @@ function effectiveRows(snapshot) {
183
183
  if (snapshot.rows.length > 0) return snapshot.rows;
184
184
  return snapshot.emptyState ? [snapshot.emptyState] : [];
185
185
  }
186
+ function isDarkBackground(color) {
187
+ const rgb = color ? /^#([0-9a-f]{6})/i.exec(color)?.[1] : undefined;
188
+ if (!rgb) return false;
189
+ const red = Number.parseInt(rgb.slice(0, 2), 16);
190
+ const green = Number.parseInt(rgb.slice(2, 4), 16);
191
+ const blue = Number.parseInt(rgb.slice(4, 6), 16);
192
+ return red * 299 + green * 587 + blue * 114 < 128_000;
193
+ }
186
194
  function resolvedTheme(snapshot) {
187
195
  return {
188
196
  ...defaultTheme,
@@ -482,7 +490,7 @@ export const WEB_LIST_CSS = `
482
490
  .ok-native-list-account-action-row{justify-content:flex-start;gap:12px;padding:0 12px}.ok-native-list-account-action-row .ok-native-list-action-title{color:var(--nl-secondary);font-size:16px;line-height:24px;font-weight:400;font-family:var(--nl-font-regular)}
483
491
  .ok-native-list-system{justify-content:center;padding:8px 12px;background:var(--nl-bg);color:var(--nl-secondary);cursor:default}.ok-native-list-system[data-variant="retry"],.ok-native-list-system[data-variant="noMatch"],.ok-native-list-system[data-variant="end"]{justify-content:flex-start}.ok-native-list-system[data-variant="retry"]{cursor:pointer}
484
492
  .ok-native-list-rail{padding:4px;gap:6px;border-radius:8px}.ok-native-list-rail .ok-native-list-visual{width:20px;height:20px;flex-basis:20px}.ok-native-list-rail .ok-native-list-visual>img,.ok-native-list-rail .ok-native-list-visual-main{width:20px;height:20px}.ok-native-list-rail-title{font-size:12px;font-weight:500;white-space:nowrap;font-family:var(--nl-font-medium)}
485
- .ok-native-list-media{display:block;padding:0 5px;background:transparent;border-radius:16px}.ok-native-list-media-image{display:block;width:100%;aspect-ratio:1;border-radius:10px;background:var(--nl-strong);object-fit:cover}.ok-native-list-media-image[data-state="empty"]{background:transparent}.ok-native-list-media-image[data-state="error"]{display:flex;align-items:center;justify-content:center;color:var(--nl-icon-subdued);font-size:24px}.ok-native-list-media-meta{padding-top:7px}.ok-native-list-media-subtitle-row{display:flex;align-items:center;gap:6px}.ok-native-list-media-subtitle{flex:1;min-width:0;font-size:12px;color:var(--nl-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ok-native-list-media-network{width:14px;height:14px;border-radius:50%}.ok-native-list-media-title{font-size:16px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--nl-font-medium)}.ok-native-list-media-close{position:absolute;right:9px;top:4px;border:0;background:color-mix(in srgb,var(--nl-inverse) 72%,transparent);color:var(--nl-inverse-text);width:24px;height:24px;border-radius:50%;cursor:pointer;font:18px/20px var(--nl-font-regular)}
493
+ .ok-native-list-media{display:block;padding:0 5px;background:transparent;border-radius:16px}.ok-native-list-media-image{display:block;width:100%;aspect-ratio:1;border-radius:10px;background:var(--nl-strong);object-fit:cover}.ok-native-list-media-image[data-state="empty"]{background:transparent}.ok-native-list-media-image[data-state="error"]{display:flex;align-items:center;justify-content:center;color:var(--nl-icon-subdued);font-size:24px}.ok-native-list-media-meta{padding-top:7px}.ok-native-list-media-subtitle-row{display:flex;align-items:center;gap:6px}.ok-native-list-media-subtitle{flex:1;min-width:0;font-size:12px;color:var(--nl-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ok-native-list-media-network{width:14px;height:14px;border-radius:50%}.ok-native-list-media-title{font-size:16px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--nl-font-medium)}.ok-native-list-media-fallback{position:absolute;inset:0;overflow:hidden;border-radius:10px;background:var(--nl-strong);color:color-mix(in srgb,var(--nl-disabled) 70%,transparent)}.ok-native-list-media-fallback::after{content:"";position:absolute;inset:0;border-radius:inherit;box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--nl-separator) 60%,transparent);pointer-events:none}.ok-native-list-media-sheen,.ok-native-list-media-hatch,.ok-native-list-media-glyph{position:absolute;inset:0;pointer-events:none}.ok-native-list-media-glyph{display:none;align-items:center;justify-content:center}.ok-native-list-media-glyph svg{width:28%;max-width:44px;height:auto}.ok-native-list-media-fallback[data-state="loading"] .ok-native-list-media-glyph[data-glyph="loading"],.ok-native-list-media-fallback[data-state="failed"] .ok-native-list-media-glyph[data-glyph="failed"]{display:flex}.ok-native-list-media-sheen{display:none;overflow:hidden}.ok-native-list-media-fallback[data-state="loading"] .ok-native-list-media-sheen{display:block}.ok-native-list-media-sheen::before{content:"";position:absolute;top:-50%;bottom:-50%;left:0;width:60%;background:linear-gradient(100deg,transparent 0%,var(--nl-media-shine,rgba(255,255,255,.75)) 50%,transparent 100%);transform:translateX(-135%) skewX(-12deg);animation:ok-native-list-media-sweep 1.6s cubic-bezier(.4,0,.2,1) infinite;animation-delay:var(--nl-media-sweep-delay,0s)}@keyframes ok-native-list-media-sweep{0%{transform:translateX(-135%) skewX(-12deg)}70%,100%{transform:translateX(220%) skewX(-12deg)}}.ok-native-list-media-hatch{display:none;background-image:repeating-linear-gradient(135deg,color-mix(in srgb,var(--nl-primary) 4.5%,transparent) 0 1px,transparent 1px 7px);-webkit-mask-image:radial-gradient(circle at 50% 50%,transparent 0 22%,#000 70%);mask-image:radial-gradient(circle at 50% 50%,transparent 0 22%,#000 70%)}.ok-native-list-media-fallback[data-state="failed"] .ok-native-list-media-hatch{display:block}@media(prefers-reduced-motion:reduce){.ok-native-list-media-sheen::before{animation:none;transform:translateX(60%) skewX(-12deg);opacity:.6}}.ok-native-list-media-close{position:absolute;right:9px;top:4px;border:0;background:color-mix(in srgb,var(--nl-inverse) 72%,transparent);color:var(--nl-inverse-text);width:24px;height:24px;border-radius:50%;cursor:pointer;font:18px/20px var(--nl-font-regular)}
486
494
  .ok-native-list-metric{display:flex;flex-direction:column;align-items:flex-start;padding:12px;border-radius:12px;gap:5px;background:var(--nl-row)}.ok-native-list-metric-value{font-size:22px;line-height:28px;font-weight:700;font-family:var(--nl-font-bold)}.ok-native-list-composite{display:flex;flex-direction:column;align-items:stretch;padding:14px;border-radius:12px;gap:12px;background:var(--nl-subdued)}.ok-native-list-composite-heading{font-size:14px;letter-spacing:1px;color:var(--nl-secondary)}.ok-native-list-composite-row{display:flex;gap:12px}.ok-native-list-composite-cell{flex:1;min-width:0}.ok-native-list-composite-cell[data-shaded="true"]{padding:10px;border-radius:10px;background:color-mix(in srgb,var(--nl-primary) 5%,transparent)}.ok-native-list-composite-value{font-size:18px;font-weight:600;font-family:var(--nl-font-semibold)}.ok-native-list-divider{height:1px;background:var(--nl-separator)}.ok-native-list-progress{height:4px;border-radius:2px;overflow:hidden;background:var(--nl-negative)}.ok-native-list-progress>span{display:block;height:100%;border-radius:2px;background:var(--nl-positive)}
487
495
  .ok-native-list-data{padding:6px 12px}.ok-native-list-index{flex:0 0 28px;color:var(--nl-secondary);font-size:13px}.ok-native-list-favorite{flex:0 0 24px;color:var(--nl-icon-subdued);font-size:22px}.ok-native-list-favorite[data-active="true"]{color:var(--nl-accent)}.ok-native-list-data-cell{display:flex;flex-direction:column;min-width:0}.ok-native-list-data-cell[data-align="center"]{align-items:center}.ok-native-list-data-cell[data-align="end"]{align-items:flex-end}.ok-native-list-data-primary{display:flex;align-items:center;gap:5px;max-width:100%;font-size:16px;font-weight:500;white-space:nowrap;font-family:var(--nl-font-medium)}.ok-native-list-unread{width:7px;height:7px;flex:0 0 7px;border-radius:50%;background:var(--nl-accent)}.ok-native-list-thumbnail{width:64px;height:64px;border-radius:10px;object-fit:cover}
488
496
  .ok-native-list-item[data-native-list-row-press-enabled="true"]:active>.ok-native-list-history{background:var(--nl-selected)}
@@ -808,14 +816,7 @@ function createVisual(context, visual, selectorPresentation) {
808
816
  if (selectorPresentation) paintSelectorImageBackground(image, frame);
809
817
  if (source?.loadingStrategy === 'skeleton' && !(image.complete && image.naturalWidth > 0)) {
810
818
  const skeleton = createElement(context.document, 'span', 'ok-native-list-image-skeleton');
811
- const background = resolvedTheme(context.snapshot).background;
812
- const rgb = /^#([0-9a-f]{6})/i.exec(background)?.[1];
813
- if (rgb) {
814
- const red = Number.parseInt(rgb.slice(0, 2), 16);
815
- const green = Number.parseInt(rgb.slice(2, 4), 16);
816
- const blue = Number.parseInt(rgb.slice(4, 6), 16);
817
- if (red * 299 + green * 587 + blue * 114 < 128_000) skeleton.dataset.dark = 'true';
818
- }
819
+ if (isDarkBackground(resolvedTheme(context.snapshot).background)) skeleton.dataset.dark = 'true';
819
820
  frame.appendChild(skeleton);
820
821
  image.addEventListener('load', () => skeleton.remove(), {
821
822
  once: true
@@ -1966,7 +1967,8 @@ export class NativeListWebEngine {
1966
1967
  '--nl-critical': theme.criticalBackground,
1967
1968
  '--nl-inverse': theme.inverseBackground,
1968
1969
  '--nl-inverse-text': theme.inverseText,
1969
- '--nl-info': theme.info
1970
+ '--nl-info': theme.info,
1971
+ '--nl-media-shine': isDarkBackground(theme.background) ? 'rgba(255,255,255,0.07)' : 'rgba(255,255,255,0.75)'
1970
1972
  };
1971
1973
  Object.entries(values).forEach(([name, value]) => {
1972
1974
  if (!value) return;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
- import { createNamedIcon } from '@onekeyfe/react-native-image/icon/dom';
4
3
  const views = new WeakMap();
5
4
  function bindLegacy(body, row, primitives) {
6
5
  const v = views.get(body);
@@ -123,6 +122,79 @@ function recycleLegacy(body) {
123
122
  v.imageKey = v.networkKey = '';
124
123
  }
125
124
  const galleries = new WeakMap();
125
+ const SVG_NS = 'http://www.w3.org/2000/svg';
126
+ let glyphMaskId = 0;
127
+
128
+ /**
129
+ * Placeholder glyphs share one 24pt geometry with the iOS and Android renderers:
130
+ * a rounded frame with a sun and a ridge; the failed glyph adds a slash and cuts
131
+ * a gap into the frame around it.
132
+ */
133
+ function createMediaGlyph(document, state) {
134
+ const svg = document.createElementNS(SVG_NS, 'svg');
135
+ svg.setAttribute('viewBox', '0 0 24 24');
136
+ svg.setAttribute('fill', 'none');
137
+ svg.setAttribute('stroke', 'currentColor');
138
+ svg.setAttribute('stroke-width', '1.5');
139
+ svg.setAttribute('stroke-linecap', 'round');
140
+ svg.setAttribute('stroke-linejoin', 'round');
141
+ svg.setAttribute('aria-hidden', 'true');
142
+ const shape = (tag, attributes) => {
143
+ const node = document.createElementNS(SVG_NS, tag);
144
+ Object.entries(attributes).forEach(([key, value]) => node.setAttribute(key, value));
145
+ return node;
146
+ };
147
+ const picture = shape('g', {});
148
+ picture.append(shape('rect', {
149
+ x: '3',
150
+ y: '3',
151
+ width: '18',
152
+ height: '18',
153
+ rx: '4'
154
+ }), shape('circle', {
155
+ cx: '9',
156
+ cy: '9',
157
+ r: '1.6'
158
+ }), shape('path', {
159
+ d: 'M5 20.5L14.5 11L21 17.5'
160
+ }));
161
+ if (state === 'failed') {
162
+ glyphMaskId += 1;
163
+ const id = `ok-native-list-media-cut-${glyphMaskId}`;
164
+ const mask = shape('mask', {
165
+ id,
166
+ maskUnits: 'userSpaceOnUse'
167
+ });
168
+ mask.append(shape('rect', {
169
+ x: '0',
170
+ y: '0',
171
+ width: '24',
172
+ height: '24',
173
+ fill: '#fff',
174
+ stroke: 'none'
175
+ }), shape('path', {
176
+ d: 'M2.6 -0.6L24.6 21.4L21.4 24.6L-0.6 2.6Z',
177
+ fill: '#000',
178
+ stroke: 'none'
179
+ }));
180
+ picture.setAttribute('mask', `url(#${id})`);
181
+ svg.append(mask, picture, shape('path', {
182
+ d: 'M3 3L21 21'
183
+ }));
184
+ } else svg.append(picture);
185
+ const wrap = document.createElement('div');
186
+ wrap.className = 'ok-native-list-media-glyph';
187
+ wrap.dataset.glyph = state;
188
+ wrap.append(svg);
189
+ return wrap;
190
+ }
191
+ const SWEEP_PERIOD_MS = 1600;
192
+ function setPlaceholderState(v, state) {
193
+ v.fallback.dataset.state = state;
194
+ if (state === 'loading')
195
+ // Keep every loading tile on one sweep phase, including recycled rows.
196
+ v.fallback.style.setProperty('--nl-media-sweep-delay', `-${Math.round(performance.now() % SWEEP_PERIOD_MS)}ms`);
197
+ }
126
198
  const isGalleryMedia = row => row.variant === 'gallery' && (!row.image || !!row.media && !row.imageState);
127
199
  function clearGalleryMedia(v) {
128
200
  v.epoch += 1;
@@ -149,18 +221,7 @@ function initGallery(body, primitives) {
149
221
  };
150
222
  const frame = element('ok-native-list-media-image');
151
223
  const fallback = element('ok-native-list-media-fallback');
152
- const svg = createNamedIcon(document, 'ImageSquareWavesOutline');
153
- fallback.append(svg);
154
- Object.assign(fallback.style, {
155
- position: 'absolute',
156
- inset: '0',
157
- display: 'flex',
158
- alignItems: 'center',
159
- justifyContent: 'center',
160
- color: 'var(--nl-disabled)',
161
- borderRadius: '10px',
162
- background: 'var(--nl-strong)'
163
- });
224
+ fallback.append(element('ok-native-list-media-hatch'), element('ok-native-list-media-sheen'), createMediaGlyph(document, 'loading'), createMediaGlyph(document, 'failed'));
164
225
  const metadata = element('ok-native-list-media-meta');
165
226
  const subtitleLine = element('ok-native-list-media-subtitle-row');
166
227
  const subtitle = element('ok-native-list-media-subtitle');
@@ -240,10 +301,14 @@ function bindGallery(body, row, primitives) {
240
301
  v.fallback.style.visibility = 'visible';
241
302
  const epoch = v.epoch;
242
303
  const source = row.imageState ? undefined : row.media?.source;
304
+ setPlaceholderState(v, source?.uri && row.media?.probeOrder.length ? 'loading' : 'failed');
243
305
  const probe = attempt => {
244
306
  if (v.epoch !== epoch) return;
245
307
  const kind = row.media?.probeOrder[attempt];
246
- if (!source?.uri || !kind) return;
308
+ if (!source?.uri || !kind) {
309
+ setPlaceholderState(v, 'failed');
310
+ return;
311
+ }
247
312
  const media = body.ownerDocument.createElement(kind === 'video' ? 'video' : 'img');
248
313
  v.frame.style.borderRadius = kind === 'video' ? '0' : '10px';
249
314
  Object.assign(media.style, {
@@ -284,7 +349,11 @@ function bindGallery(body, row, primitives) {
284
349
  probe(attempt + 1);
285
350
  };
286
351
  const ready = () => {
287
- if (v.epoch === epoch && v.media === media) v.fallback.style.visibility = 'hidden';
352
+ if (v.epoch === epoch && v.media === media) {
353
+ v.fallback.style.visibility = 'hidden';
354
+ // Stops the sweep animation behind the picture.
355
+ setPlaceholderState(v, 'loaded');
356
+ }
288
357
  };
289
358
  if (media.tagName === 'VIDEO') media.onloadeddata = ready;else media.onload = ready;
290
359
  v.media = media;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-native-list",
3
- "version": "6.7.0-39",
3
+ "version": "6.7.0-40",
4
4
  "description": "Template-driven native RecyclerView and UICollectionView for React Native",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/module/index.js",
@@ -418,6 +418,15 @@ function effectiveRows(snapshot: NativeListSnapshot): readonly RowModel[] {
418
418
  return snapshot.emptyState ? [snapshot.emptyState] : [];
419
419
  }
420
420
 
421
+ function isDarkBackground(color: string | undefined) {
422
+ const rgb = color ? /^#([0-9a-f]{6})/i.exec(color)?.[1] : undefined;
423
+ if (!rgb) return false;
424
+ const red = Number.parseInt(rgb.slice(0, 2), 16);
425
+ const green = Number.parseInt(rgb.slice(2, 4), 16);
426
+ const blue = Number.parseInt(rgb.slice(4, 6), 16);
427
+ return red * 299 + green * 587 + blue * 114 < 128_000;
428
+ }
429
+
421
430
  function resolvedTheme(snapshot: NativeListSnapshot): NativeListTheme {
422
431
  return { ...defaultTheme, ...snapshot.theme };
423
432
  }
@@ -860,7 +869,7 @@ export const WEB_LIST_CSS = `
860
869
  .ok-native-list-account-action-row{justify-content:flex-start;gap:12px;padding:0 12px}.ok-native-list-account-action-row .ok-native-list-action-title{color:var(--nl-secondary);font-size:16px;line-height:24px;font-weight:400;font-family:var(--nl-font-regular)}
861
870
  .ok-native-list-system{justify-content:center;padding:8px 12px;background:var(--nl-bg);color:var(--nl-secondary);cursor:default}.ok-native-list-system[data-variant="retry"],.ok-native-list-system[data-variant="noMatch"],.ok-native-list-system[data-variant="end"]{justify-content:flex-start}.ok-native-list-system[data-variant="retry"]{cursor:pointer}
862
871
  .ok-native-list-rail{padding:4px;gap:6px;border-radius:8px}.ok-native-list-rail .ok-native-list-visual{width:20px;height:20px;flex-basis:20px}.ok-native-list-rail .ok-native-list-visual>img,.ok-native-list-rail .ok-native-list-visual-main{width:20px;height:20px}.ok-native-list-rail-title{font-size:12px;font-weight:500;white-space:nowrap;font-family:var(--nl-font-medium)}
863
- .ok-native-list-media{display:block;padding:0 5px;background:transparent;border-radius:16px}.ok-native-list-media-image{display:block;width:100%;aspect-ratio:1;border-radius:10px;background:var(--nl-strong);object-fit:cover}.ok-native-list-media-image[data-state="empty"]{background:transparent}.ok-native-list-media-image[data-state="error"]{display:flex;align-items:center;justify-content:center;color:var(--nl-icon-subdued);font-size:24px}.ok-native-list-media-meta{padding-top:7px}.ok-native-list-media-subtitle-row{display:flex;align-items:center;gap:6px}.ok-native-list-media-subtitle{flex:1;min-width:0;font-size:12px;color:var(--nl-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ok-native-list-media-network{width:14px;height:14px;border-radius:50%}.ok-native-list-media-title{font-size:16px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--nl-font-medium)}.ok-native-list-media-close{position:absolute;right:9px;top:4px;border:0;background:color-mix(in srgb,var(--nl-inverse) 72%,transparent);color:var(--nl-inverse-text);width:24px;height:24px;border-radius:50%;cursor:pointer;font:18px/20px var(--nl-font-regular)}
872
+ .ok-native-list-media{display:block;padding:0 5px;background:transparent;border-radius:16px}.ok-native-list-media-image{display:block;width:100%;aspect-ratio:1;border-radius:10px;background:var(--nl-strong);object-fit:cover}.ok-native-list-media-image[data-state="empty"]{background:transparent}.ok-native-list-media-image[data-state="error"]{display:flex;align-items:center;justify-content:center;color:var(--nl-icon-subdued);font-size:24px}.ok-native-list-media-meta{padding-top:7px}.ok-native-list-media-subtitle-row{display:flex;align-items:center;gap:6px}.ok-native-list-media-subtitle{flex:1;min-width:0;font-size:12px;color:var(--nl-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ok-native-list-media-network{width:14px;height:14px;border-radius:50%}.ok-native-list-media-title{font-size:16px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--nl-font-medium)}.ok-native-list-media-fallback{position:absolute;inset:0;overflow:hidden;border-radius:10px;background:var(--nl-strong);color:color-mix(in srgb,var(--nl-disabled) 70%,transparent)}.ok-native-list-media-fallback::after{content:"";position:absolute;inset:0;border-radius:inherit;box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--nl-separator) 60%,transparent);pointer-events:none}.ok-native-list-media-sheen,.ok-native-list-media-hatch,.ok-native-list-media-glyph{position:absolute;inset:0;pointer-events:none}.ok-native-list-media-glyph{display:none;align-items:center;justify-content:center}.ok-native-list-media-glyph svg{width:28%;max-width:44px;height:auto}.ok-native-list-media-fallback[data-state="loading"] .ok-native-list-media-glyph[data-glyph="loading"],.ok-native-list-media-fallback[data-state="failed"] .ok-native-list-media-glyph[data-glyph="failed"]{display:flex}.ok-native-list-media-sheen{display:none;overflow:hidden}.ok-native-list-media-fallback[data-state="loading"] .ok-native-list-media-sheen{display:block}.ok-native-list-media-sheen::before{content:"";position:absolute;top:-50%;bottom:-50%;left:0;width:60%;background:linear-gradient(100deg,transparent 0%,var(--nl-media-shine,rgba(255,255,255,.75)) 50%,transparent 100%);transform:translateX(-135%) skewX(-12deg);animation:ok-native-list-media-sweep 1.6s cubic-bezier(.4,0,.2,1) infinite;animation-delay:var(--nl-media-sweep-delay,0s)}@keyframes ok-native-list-media-sweep{0%{transform:translateX(-135%) skewX(-12deg)}70%,100%{transform:translateX(220%) skewX(-12deg)}}.ok-native-list-media-hatch{display:none;background-image:repeating-linear-gradient(135deg,color-mix(in srgb,var(--nl-primary) 4.5%,transparent) 0 1px,transparent 1px 7px);-webkit-mask-image:radial-gradient(circle at 50% 50%,transparent 0 22%,#000 70%);mask-image:radial-gradient(circle at 50% 50%,transparent 0 22%,#000 70%)}.ok-native-list-media-fallback[data-state="failed"] .ok-native-list-media-hatch{display:block}@media(prefers-reduced-motion:reduce){.ok-native-list-media-sheen::before{animation:none;transform:translateX(60%) skewX(-12deg);opacity:.6}}.ok-native-list-media-close{position:absolute;right:9px;top:4px;border:0;background:color-mix(in srgb,var(--nl-inverse) 72%,transparent);color:var(--nl-inverse-text);width:24px;height:24px;border-radius:50%;cursor:pointer;font:18px/20px var(--nl-font-regular)}
864
873
  .ok-native-list-metric{display:flex;flex-direction:column;align-items:flex-start;padding:12px;border-radius:12px;gap:5px;background:var(--nl-row)}.ok-native-list-metric-value{font-size:22px;line-height:28px;font-weight:700;font-family:var(--nl-font-bold)}.ok-native-list-composite{display:flex;flex-direction:column;align-items:stretch;padding:14px;border-radius:12px;gap:12px;background:var(--nl-subdued)}.ok-native-list-composite-heading{font-size:14px;letter-spacing:1px;color:var(--nl-secondary)}.ok-native-list-composite-row{display:flex;gap:12px}.ok-native-list-composite-cell{flex:1;min-width:0}.ok-native-list-composite-cell[data-shaded="true"]{padding:10px;border-radius:10px;background:color-mix(in srgb,var(--nl-primary) 5%,transparent)}.ok-native-list-composite-value{font-size:18px;font-weight:600;font-family:var(--nl-font-semibold)}.ok-native-list-divider{height:1px;background:var(--nl-separator)}.ok-native-list-progress{height:4px;border-radius:2px;overflow:hidden;background:var(--nl-negative)}.ok-native-list-progress>span{display:block;height:100%;border-radius:2px;background:var(--nl-positive)}
865
874
  .ok-native-list-data{padding:6px 12px}.ok-native-list-index{flex:0 0 28px;color:var(--nl-secondary);font-size:13px}.ok-native-list-favorite{flex:0 0 24px;color:var(--nl-icon-subdued);font-size:22px}.ok-native-list-favorite[data-active="true"]{color:var(--nl-accent)}.ok-native-list-data-cell{display:flex;flex-direction:column;min-width:0}.ok-native-list-data-cell[data-align="center"]{align-items:center}.ok-native-list-data-cell[data-align="end"]{align-items:flex-end}.ok-native-list-data-primary{display:flex;align-items:center;gap:5px;max-width:100%;font-size:16px;font-weight:500;white-space:nowrap;font-family:var(--nl-font-medium)}.ok-native-list-unread{width:7px;height:7px;flex:0 0 7px;border-radius:50%;background:var(--nl-accent)}.ok-native-list-thumbnail{width:64px;height:64px;border-radius:10px;object-fit:cover}
866
875
  .ok-native-list-item[data-native-list-row-press-enabled="true"]:active>.ok-native-list-history{background:var(--nl-selected)}
@@ -1311,15 +1320,8 @@ function createVisual(
1311
1320
  'span',
1312
1321
  'ok-native-list-image-skeleton'
1313
1322
  );
1314
- const background = resolvedTheme(context.snapshot).background;
1315
- const rgb = /^#([0-9a-f]{6})/i.exec(background)?.[1];
1316
- if (rgb) {
1317
- const red = Number.parseInt(rgb.slice(0, 2), 16);
1318
- const green = Number.parseInt(rgb.slice(2, 4), 16);
1319
- const blue = Number.parseInt(rgb.slice(4, 6), 16);
1320
- if (red * 299 + green * 587 + blue * 114 < 128_000)
1321
- skeleton.dataset.dark = 'true';
1322
- }
1323
+ if (isDarkBackground(resolvedTheme(context.snapshot).background))
1324
+ skeleton.dataset.dark = 'true';
1323
1325
  frame.appendChild(skeleton);
1324
1326
  image.addEventListener('load', () => skeleton.remove(), { once: true });
1325
1327
  image.addEventListener('error', () => skeleton.remove(), { once: true });
@@ -3165,6 +3167,9 @@ export class NativeListWebEngine {
3165
3167
  '--nl-inverse': theme.inverseBackground,
3166
3168
  '--nl-inverse-text': theme.inverseText,
3167
3169
  '--nl-info': theme.info,
3170
+ '--nl-media-shine': isDarkBackground(theme.background)
3171
+ ? 'rgba(255,255,255,0.07)'
3172
+ : 'rgba(255,255,255,0.75)',
3168
3173
  };
3169
3174
  Object.entries(values).forEach(([name, value]) => {
3170
3175
  if (!value) return;
@@ -1,4 +1,3 @@
1
- import { createNamedIcon } from '@onekeyfe/react-native-image/icon/dom';
2
1
  import type { MediaTileRow, NativeListTextStyle } from '../../models';
3
2
  import type { RowPrimitives } from './RowVisual';
4
3
 
@@ -192,6 +191,78 @@ type GalleryViews = {
192
191
  leave: () => void;
193
192
  };
194
193
  const galleries = new WeakMap<HTMLElement, GalleryViews>();
194
+ type MediaPlaceholderState = 'loading' | 'failed';
195
+ type MediaPlaceholderPhase = MediaPlaceholderState | 'loaded';
196
+ const SVG_NS = 'http://www.w3.org/2000/svg';
197
+ let glyphMaskId = 0;
198
+
199
+ /**
200
+ * Placeholder glyphs share one 24pt geometry with the iOS and Android renderers:
201
+ * a rounded frame with a sun and a ridge; the failed glyph adds a slash and cuts
202
+ * a gap into the frame around it.
203
+ */
204
+ function createMediaGlyph(document: Document, state: MediaPlaceholderState) {
205
+ const svg = document.createElementNS(SVG_NS, 'svg');
206
+ svg.setAttribute('viewBox', '0 0 24 24');
207
+ svg.setAttribute('fill', 'none');
208
+ svg.setAttribute('stroke', 'currentColor');
209
+ svg.setAttribute('stroke-width', '1.5');
210
+ svg.setAttribute('stroke-linecap', 'round');
211
+ svg.setAttribute('stroke-linejoin', 'round');
212
+ svg.setAttribute('aria-hidden', 'true');
213
+ const shape = (tag: string, attributes: Record<string, string>) => {
214
+ const node = document.createElementNS(SVG_NS, tag);
215
+ Object.entries(attributes).forEach(([key, value]) =>
216
+ node.setAttribute(key, value)
217
+ );
218
+ return node;
219
+ };
220
+ const picture = shape('g', {});
221
+ picture.append(
222
+ shape('rect', { x: '3', y: '3', width: '18', height: '18', rx: '4' }),
223
+ shape('circle', { cx: '9', cy: '9', r: '1.6' }),
224
+ shape('path', { d: 'M5 20.5L14.5 11L21 17.5' })
225
+ );
226
+ if (state === 'failed') {
227
+ glyphMaskId += 1;
228
+ const id = `ok-native-list-media-cut-${glyphMaskId}`;
229
+ const mask = shape('mask', { id, maskUnits: 'userSpaceOnUse' });
230
+ mask.append(
231
+ shape('rect', {
232
+ x: '0',
233
+ y: '0',
234
+ width: '24',
235
+ height: '24',
236
+ fill: '#fff',
237
+ stroke: 'none',
238
+ }),
239
+ shape('path', {
240
+ d: 'M2.6 -0.6L24.6 21.4L21.4 24.6L-0.6 2.6Z',
241
+ fill: '#000',
242
+ stroke: 'none',
243
+ })
244
+ );
245
+ picture.setAttribute('mask', `url(#${id})`);
246
+ svg.append(mask, picture, shape('path', { d: 'M3 3L21 21' }));
247
+ } else svg.append(picture);
248
+ const wrap = document.createElement('div');
249
+ wrap.className = 'ok-native-list-media-glyph';
250
+ wrap.dataset.glyph = state;
251
+ wrap.append(svg);
252
+ return wrap;
253
+ }
254
+
255
+ const SWEEP_PERIOD_MS = 1600;
256
+
257
+ function setPlaceholderState(v: GalleryViews, state: MediaPlaceholderPhase) {
258
+ v.fallback.dataset.state = state;
259
+ if (state === 'loading')
260
+ // Keep every loading tile on one sweep phase, including recycled rows.
261
+ v.fallback.style.setProperty(
262
+ '--nl-media-sweep-delay',
263
+ `-${Math.round(performance.now() % SWEEP_PERIOD_MS)}ms`
264
+ );
265
+ }
195
266
  const isGalleryMedia = (row: MediaTileRow) =>
196
267
  row.variant === 'gallery' && (!row.image || (!!row.media && !row.imageState));
197
268
 
@@ -221,18 +292,12 @@ function initGallery(body: HTMLElement, primitives: RowPrimitives) {
221
292
  };
222
293
  const frame = element('ok-native-list-media-image');
223
294
  const fallback = element('ok-native-list-media-fallback');
224
- const svg = createNamedIcon(document, 'ImageSquareWavesOutline');
225
- fallback.append(svg);
226
- Object.assign(fallback.style, {
227
- position: 'absolute',
228
- inset: '0',
229
- display: 'flex',
230
- alignItems: 'center',
231
- justifyContent: 'center',
232
- color: 'var(--nl-disabled)',
233
- borderRadius: '10px',
234
- background: 'var(--nl-strong)',
235
- });
295
+ fallback.append(
296
+ element('ok-native-list-media-hatch'),
297
+ element('ok-native-list-media-sheen'),
298
+ createMediaGlyph(document, 'loading'),
299
+ createMediaGlyph(document, 'failed')
300
+ );
236
301
  const metadata = element('ok-native-list-media-meta');
237
302
  const subtitleLine = element('ok-native-list-media-subtitle-row');
238
303
  const subtitle = element('ok-native-list-media-subtitle');
@@ -320,10 +385,17 @@ function bindGallery(
320
385
  v.fallback.style.visibility = 'visible';
321
386
  const epoch = v.epoch;
322
387
  const source = row.imageState ? undefined : row.media?.source;
388
+ setPlaceholderState(
389
+ v,
390
+ source?.uri && row.media?.probeOrder.length ? 'loading' : 'failed'
391
+ );
323
392
  const probe = (attempt: number) => {
324
393
  if (v.epoch !== epoch) return;
325
394
  const kind = row.media?.probeOrder[attempt];
326
- if (!source?.uri || !kind) return;
395
+ if (!source?.uri || !kind) {
396
+ setPlaceholderState(v, 'failed');
397
+ return;
398
+ }
327
399
  const media = body.ownerDocument.createElement(
328
400
  kind === 'video' ? 'video' : 'img'
329
401
  );
@@ -369,8 +441,11 @@ function bindGallery(
369
441
  probe(attempt + 1);
370
442
  };
371
443
  const ready = () => {
372
- if (v.epoch === epoch && v.media === media)
444
+ if (v.epoch === epoch && v.media === media) {
373
445
  v.fallback.style.visibility = 'hidden';
446
+ // Stops the sweep animation behind the picture.
447
+ setPlaceholderState(v, 'loaded');
448
+ }
374
449
  };
375
450
  if (media.tagName === 'VIDEO') media.onloadeddata = ready;
376
451
  else media.onload = ready;