diff --git a/change-logs/1.28.0/changesets/web-page-loading-bar-flat.md b/change-logs/1.28.0/changesets/web-page-loading-bar-flat.md deleted file mode 100644 index 140f5b36e6..0000000000 --- a/change-logs/1.28.0/changesets/web-page-loading-bar-flat.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -type: improved -area: navigation -platforms: - - android - - ios - - desktop -pull_request: 5167 -rollout: full ---- - -## zh-CN - -App 内网页(应用内浏览器、设置里的网页)加载时,顶部的进度条改为贴着上边缘的一条细线,两端平直并延伸到屏幕两侧,不再是圆角的胶囊形。 - -## en - -While a web page loads in the app (the in-app browser and the settings web pages), the progress bar is now a thin line flush with the top edge, with square ends reaching both sides of the screen, instead of a rounded pill. - -## ja - -アプリ内の Web ページ(アプリ内ブラウザ、設定の Web ページ)の読み込み中に表示される進捗バーが、上端に沿った細い線になりました。両端は角のない直線で画面の左右いっぱいに伸び、角丸のピル形ではなくなりました。 diff --git a/change-logs/1.28.0/changesets/web-page-loading-line.md b/change-logs/1.28.0/changesets/web-page-loading-line.md new file mode 100644 index 0000000000..4c7c0d278e --- /dev/null +++ b/change-logs/1.28.0/changesets/web-page-loading-line.md @@ -0,0 +1,22 @@ +--- +type: improved +area: navigation +platforms: + - android + - ios + - desktop +pull_request: 5172 +rollout: full +--- + +## zh-CN + +App 内网页(应用内浏览器、设置里的网页)加载时,顶部的进度条改为贴着上边缘的一条细线,两端平直,不再是圆角的胶囊形,也不再来回滑动。页面还没有进度时,细线停在左侧一小段不动;有进度后跟着页面向前走,不会倒退;加载完成时走到头再淡出,加载失败时立即消失。很快就加载完的页面不再闪出这条线。打开系统的“减少动态效果”后,细线不做动画。 + +## en + +While a web page loads in the app (the in-app browser and the settings web pages), the progress bar is now a thin line flush with the top edge, with square ends, instead of a rounded pill, and it no longer sweeps back and forth. Before the page reports progress, the line rests as a short still segment; it then follows the page forward and never moves back. When the page finishes, the line runs to the end and fades out; when the page fails, it disappears at once. A page that loads very quickly no longer flashes the line. With the system's reduced motion setting on, the line does not animate. + +## ja + +アプリ内の Web ページ(アプリ内ブラウザ、設定の Web ページ)の読み込み中に表示される進捗バーが、上端に沿った細い線になりました。両端は角のない直線で、角丸のピル形ではなくなり、左右に往復する動きもなくなりました。ページの進捗がまだないときは、短い線が動かずに表示されます。進捗が届くとページに合わせて前に進み、後ろには戻りません。読み込みが終わると線は端まで進んでからフェードアウトし、失敗したときはすぐに消えます。すぐに読み込みが終わるページでは、線は表示されません。システムの「視差効果を減らす」などの動きを減らす設定がオンのときは、線はアニメーションしません。 diff --git a/compose/designsystem/README.md b/compose/designsystem/README.md index 40a74850c6..4ad224fe02 100644 --- a/compose/designsystem/README.md +++ b/compose/designsystem/README.md @@ -258,7 +258,7 @@ Other checks: | `RaftSkeleton`, `RaftSkeletonList`, `rememberRaftSkeletonDelayPassed` | Skeleton, InboxItemSkeletonList `delay` | Done | Line, block, square; pulse (all in phase, one shared frame loop per theme), or still for screenshots / reduced motion. A list skeleton waits `RaftListSkeletonDelayMillis` (1s, raft-ui 0.22.1 #720) before it shows, so a fast load doesn't flash it: `RaftSkeletonList` wraps the rows, `rememberRaftSkeletonDelayPassed(loading)` gates lazy rows. `delayMillis = 0` or `LocalRaftListSkeletonDelayMillis provides 0L` shows them at once (screenshot fixtures). A single `RaftSkeleton` is not delayed | | `RaftLocatedState`, `Modifier.raftLocated`, `raftLocatedStrength` | located (`useLocated`, `LOCATED_MS`) | Done | raft-ui 0.22.1 #719: the item a jump took someone to shows `info-soft` at once, held 1.2s, then an ease-out fade, gone at 2s (`RaftLocatedMillis`); reduced motion holds it still for 2s, then off. `locate(key)` once the item is on screen (a new call restarts it); `raftLocated` paints it over the item's fill in its shape (draw phase only); `raftLocatedStrength(active)` for a row that lays it in its own fill (a message). A stronger mark (selected, menu open, search match, checked) wins: don't paint it there. Used by the thread jump, the search return row and Activity's unread jump | | `RaftProgressBar` | Progress | Done | `fill-muted` track (sticker radius), `info` fill with the 1.5dp `sticker-ink` inset edge; sm / md / lg (6 / 8 / 10dp); primary and warning; complete turns `success`; optional header (label, mono value); indeterminate half-width sweep (`animated = false` freezes it); progress-bar semantics | -| `RaftPageLoadingBar` | — (mobile; a browser's load line) | Done | The load line on the top edge of a loading page (in-app web pages): a flat 2dp (`RaftStroke.Strong`) line in the Progress `info` fill, square ends, edge to edge, no track, no radius, no ink edge; determinate, or the Progress indeterminate half-width sweep (`animated = false` freezes it); progress-bar semantics. Progress inside a page stays `RaftProgressBar` | +| `RaftPageLoadingBar`, `RaftPageLoadState` | PageLoadingLine (being added to raft-design to match) | Done | The load line on the top edge of a loading page (in-app web pages): a flat 2dp (`RaftStroke.Strong`) line in the Progress `info` fill, square ends, from the start edge, no track, no radius, no ink edge. It stays composed and is told the load (`RaftPageLoadState`: `Idle`, `Loading(progress?, load)`, `Finished`, `Failed`); it owns the rest: it first shows 200ms into a load (a faster page draws no line; `appearDelayMillis = 0` for screenshots), rests still at 8% with no progress, then follows the page forward only, each change over 200ms `ease-out`, up to 95% while the load runs (a new load, named by the host changing `load`, never guessed from the progress, starts again from the beginning; a line already up stays up); `Finished` runs it to the end and fades it out over 200ms, `Failed` / `Idle` drop it at once; reduced motion jumps the width and drops a finished line at once. No room and no semantics while nothing is drawn, progress-bar semantics while it is. Where a placeholder gives way to the page, the container that swaps them owns the one line (the app's `RaftWebPageLoadLineHost`), so it stays up across the swap. Progress inside a page stays `RaftProgressBar`; screenshot `page_loading_bar`, timing in `RaftPageLoadingBarUiTest` | | `RaftSlider` | (none) | Done | No raft-ui counterpart yet: built from Progress and Switch parts. Progress header row (label, mono value), 6dp `fill-muted` track with the `selected` fill and its 1.5dp `sticker-ink` inset edge up to the thumb, the Switch knob (22dp `sticker-paper`, 1.5dp ink ring) as thumb; 44dp touch target; drag, tap, arrow / Home / End keys, `setProgress`; disabled greys it. Used by Share preview's custom width | | `RaftSteps`, `RaftStep`, `RaftStepStatus` | Steps (0.24, `vertical`) | Done | A short flow of 3 to 5 steps in a column: 20dp square markers (sticker radius) with the number in Space Mono 12 bold, the title `text-footnote` semibold 8dp after it, an optional `text-caption` description, 16dp between steps and a 1dp `line-seam` from 4dp under each marker to 4dp above the next. Ahead (`wait`): seam outline, hint ink; current (`process`): the yellow `brand-400` sticker with a 1.5dp ink edge; done (`finish`): solid ink with a paper check; failed (`error`): the orange sticker with a cross. A step's `icon` replaces its number while waiting or in progress (a `RaftSpinner` for the step running now). Each step is one screen-reader item, its title then the finish / error label. Not ported: the row layout and clickable steps | | `RaftOtterIndicator`, `RaftOtterIndicatorDefaults` | OtterIndicator (steps) | Done | Ottie, one pose per `RaftStepStatus`: resting (`wait`), typing (`process`), a head tilt with a question mark (`error`), after its hop (`finish`); 40dp by default, never smaller. Decorative (no semantics): the status is said in text beside it. raft-ui's own WebP sheets (`composeResources/drawable/ottie_*.webp`, 256px a frame), fixed brand art in light and dark. Not ported: the motion (breathing, the typing loop, the one-time tilt and hop); every pose is the still raft-ui shows with reduced motion | @@ -490,9 +490,14 @@ Checked with `git diff v0.7.1 v0.8.0` in raft-design: toolbar's (raft-design responsive.md), so a page can't reorder the steps. It has no arrow-key roving focus (each control is its own focus stop), the scrolling filter line has no edge fade, and a split button's pair has no `role="group"` name. -- **Page loading bar.** raft-ui has no page load line; `RaftPageLoadingBar` is the Progress - `info` fill as a flat 2dp line without the track, the sticker radius and the ink edge, so - it reads as a browser's load line on the top edge of an in-app web page. +- **Page loading bar.** raft-ui has no page load line yet; a raft-design `PageLoadingLine` is + being added upstream to match `RaftPageLoadingBar` (2dp, square ends, edge to edge, `info`; + an 8% rest, forward-only progress over 200ms `ease-out`, a 200ms delay before it shows, a + run to the end and a 200ms fade when the load finishes, at once when it fails or with + reduced motion at the end). Until it ships, the numbers here are the approved spec, not + raft-ui tokens. One mobile addition to check against it: while the load still runs the line + stops at 95% (`RaftPageLoadingBarLoadingMaxFraction`), because web engines report 100% some + time before the load ends and the full line is kept for the finish. - **Slider.** raft-ui has no slider; `RaftSlider` (Share preview's custom image width) is assembled from the Progress track and fill and the Switch knob until raft-ui designs one. - **Sheet actions side by side.** raft-ui's DrawerActions stack in a bottom sheet; the web diff --git a/compose/designsystem/screenshots/page_loading_bar_dark.png b/compose/designsystem/screenshots/page_loading_bar_dark.png index faa1ae9f7d..7f75ae3d9d 100644 Binary files a/compose/designsystem/screenshots/page_loading_bar_dark.png and b/compose/designsystem/screenshots/page_loading_bar_dark.png differ diff --git a/compose/designsystem/screenshots/page_loading_bar_light.png b/compose/designsystem/screenshots/page_loading_bar_light.png index 8fd5c44e4d..5e5f5422cb 100644 Binary files a/compose/designsystem/screenshots/page_loading_bar_light.png and b/compose/designsystem/screenshots/page_loading_bar_light.png differ diff --git a/compose/designsystem/src/commonMain/kotlin/build/raft/designsystem/components/RaftPageLoadingBar.kt b/compose/designsystem/src/commonMain/kotlin/build/raft/designsystem/components/RaftPageLoadingBar.kt index 731360ac0f..0c3fb4f9ec 100644 --- a/compose/designsystem/src/commonMain/kotlin/build/raft/designsystem/components/RaftPageLoadingBar.kt +++ b/compose/designsystem/src/commonMain/kotlin/build/raft/designsystem/components/RaftPageLoadingBar.kt @@ -1,58 +1,274 @@ package build.raft.designsystem.components +import androidx.compose.animation.core.Animatable +import androidx.compose.animation.core.CubicBezierEasing +import androidx.compose.animation.core.Easing +import androidx.compose.animation.core.tween import androidx.compose.foundation.Canvas import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.runtime.Composable +import androidx.compose.runtime.Immutable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size -import androidx.compose.ui.graphics.drawscope.clipRect import androidx.compose.ui.semantics.ProgressBarRangeInfo import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.progressBarRangeInfo import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.unit.LayoutDirection +import build.raft.designsystem.motion.rememberRaftReducedMotion import build.raft.designsystem.tokens.RaftStroke import build.raft.designsystem.tokens.RaftUiPalette +import kotlin.math.max +import kotlin.math.min +import kotlinx.coroutines.delay + +/** What the page under a [RaftPageLoadingBar] is doing; the caller reports it, the line plays it. */ +@Immutable +sealed interface RaftPageLoadState { + /** No load: no line. Also a load that was stopped, when the caller can't call it finished. */ + data object Idle : RaftPageLoadState + + /** + * A load is running. [progress] is the fraction the page reports (0..1), or null while it + * has reported none yet. [load] names the load: the host changes it when the page starts + * another one (a link followed or a redirect while this one still runs), and the line + * then starts again from the beginning. The line never guesses that from [progress]. + */ + data class Loading(val progress: Float? = null, val load: Int = 0) : RaftPageLoadState + + /** The load ended well: the line runs to the end and fades out. */ + data object Finished : RaftPageLoadState + + /** The load failed: the line goes at once. */ + data object Failed : RaftPageLoadState +} + +/** How long a load runs before its line first shows; a load that ends sooner draws no line. */ +const val RaftPageLoadingBarAppearDelayMillis: Int = 200 + +/** How long each change of the line's width takes (`ease-out`), the run to the end included. */ +const val RaftPageLoadingBarProgressMillis: Int = 200 + +/** How long the full line takes to fade out after a finished load. */ +const val RaftPageLoadingBarFadeOutMillis: Int = 200 + +/** The line's width while the page has reported no progress, and its least width while loading. */ +const val RaftPageLoadingBarRestFraction: Float = 0.08f + +/** + * The line's greatest width while the load still runs. Engines report 100% some time before + * the load ends; the full line is kept for [RaftPageLoadState.Finished], so a full line always + * means done and the run to the end can always be seen. + */ +const val RaftPageLoadingBarLoadingMaxFraction: Float = 0.95f + +/** CSS `ease-out`, `cubic-bezier(0, 0, 0.58, 1)`: the line's width changes and its fade. */ +private val RaftPageLoadingBarEaseOut: Easing = CubicBezierEasing(0f, 0f, 0.58f, 1f) + +/** Where a [RaftPageLoadingBar] is in one load's life. */ +internal enum class RaftPageLoadingBarPhase { + /** No line. */ + Hidden, + + /** A load runs, inside the appear delay: no line yet. */ + Waiting, + + /** The line shows the load. */ + Shown, + + /** The load finished: the line runs to the end and fades out. */ + Leaving, +} + +/** + * The line's state, kept apart from the clock so it can be tested as plain data: [onState] + * takes what the caller reports, [onAppearDelayPassed] and [onLeft] what the component's + * timers report. + * + * - [fraction] is the width the line is going to (0..1); it never gets smaller within a load. + * - [reported] is whether this load has reported progress. + * - [loadId] is the [RaftPageLoadState.Loading.load] the line is showing. + * - [load] counts the loads this line has started: a change means the line starts again from + * the beginning. + */ +@Immutable +internal data class RaftPageLoadingBarLine( + val phase: RaftPageLoadingBarPhase = RaftPageLoadingBarPhase.Hidden, + val fraction: Float = 0f, + val reported: Boolean = false, + val loadId: Int = 0, + val load: Int = 0, +) { + /** Whether the line is drawn. */ + val visible: Boolean + get() = phase == RaftPageLoadingBarPhase.Shown || phase == RaftPageLoadingBarPhase.Leaving + + /** + * The line after the caller reports [state]. Reporting the same state again changes nothing. + * [appearDelay] = false shows a new load's line at once; [exitMotion] = false (reduced + * motion) drops a finished load's line at once instead of running it to the end. + */ + fun onState( + state: RaftPageLoadState, + appearDelay: Boolean = true, + exitMotion: Boolean = true, + ): RaftPageLoadingBarLine = + when (state) { + RaftPageLoadState.Idle, RaftPageLoadState.Failed -> hidden() + RaftPageLoadState.Finished -> + when (phase) { + RaftPageLoadingBarPhase.Shown -> + if (exitMotion) copy(phase = RaftPageLoadingBarPhase.Leaving, fraction = 1f) else hidden() + RaftPageLoadingBarPhase.Leaving -> this + // Finished inside the appear delay: a fast page draws no line. + RaftPageLoadingBarPhase.Waiting, RaftPageLoadingBarPhase.Hidden -> hidden() + } + is RaftPageLoadState.Loading -> { + val progress = state.progress?.takeUnless { it.isNaN() }?.coerceIn(0f, 1f) + val target = raftPageLoadingBarLoadingFraction(progress) + when { + // A load after none, or after one that finished: from the beginning. + phase == RaftPageLoadingBarPhase.Hidden || phase == RaftPageLoadingBarPhase.Leaving -> + RaftPageLoadingBarLine( + phase = if (appearDelay) RaftPageLoadingBarPhase.Waiting else RaftPageLoadingBarPhase.Shown, + fraction = target, + reported = progress != null, + loadId = state.load, + load = load + 1, + ) + // The host named another load: from the beginning, whatever the last one reached. + state.load != loadId -> + copy(fraction = target, reported = progress != null, loadId = state.load, load = load + 1) + // The same load: forward only. + else -> copy(fraction = max(fraction, target), reported = reported || progress != null) + } + } + } + + /** The appear delay of this load passed: its line shows. */ + fun onAppearDelayPassed(): RaftPageLoadingBarLine = + if (phase == RaftPageLoadingBarPhase.Waiting) copy(phase = RaftPageLoadingBarPhase.Shown) else this + + /** The finished line reached the end and faded out. */ + fun onLeft(): RaftPageLoadingBarLine = if (phase == RaftPageLoadingBarPhase.Leaving) hidden() else this + + private fun hidden(): RaftPageLoadingBarLine = + copy(phase = RaftPageLoadingBarPhase.Hidden, fraction = 0f, reported = false) +} + +/** + * The line's width for a running load that reports [progress] (0..1, null: none yet): at least + * [RaftPageLoadingBarRestFraction], at most [RaftPageLoadingBarLoadingMaxFraction]. + */ +internal fun raftPageLoadingBarLoadingFraction(progress: Float?): Float = + max(RaftPageLoadingBarRestFraction, min(progress ?: 0f, RaftPageLoadingBarLoadingMaxFraction)) /** * The load line on the top edge of a page that is loading (an in-app web page), as a browser * draws it: a flat [RaftStroke.Strong] (2dp) line in the Progress `info` fill, with square - * ends, reaching both edges of its parent. It has no track, no radius and no ink edge, so it - * must sit flush on the edge: put it at the top of the page, full width, with no padding. + * ends, starting at the start edge of its parent. It has no track, no radius and no ink edge, + * so it must sit flush on the edge: put it at the top of the page, full width, with no padding. * For progress inside a page (a download, a quota) use [RaftProgressBar]. * - * - [value] is the fraction loaded, 0..1. - * - [value] = null is the indeterminate line: a half-width segment sweeping across, with the - * timing of [RaftProgressBar]'s. [animated] = false freezes it (screenshots, reduced motion). + * Keep it in the composition for as long as the page is and report the load through [state]; + * the line owns its own life: + * - It first shows [appearDelayMillis] ([RaftPageLoadingBarAppearDelayMillis]) into a load, so + * a page that finishes sooner draws no line. `0` shows it at once (screenshots). + * - With no progress reported it rests, still, at [RaftPageLoadingBarRestFraction] of the width. + * - With progress it follows the page, forward only, each change over + * [RaftPageLoadingBarProgressMillis] with `ease-out`, up to + * [RaftPageLoadingBarLoadingMaxFraction]. A new load ([RaftPageLoadState.Loading.load] + * changed) starts again from the beginning: a line already up stays up and jumps back. + * - [RaftPageLoadState.Finished]: it runs to the end, then fades out over + * [RaftPageLoadingBarFadeOutMillis]. [RaftPageLoadState.Failed] and [RaftPageLoadState.Idle]: + * it goes at once. + * - With [reducedMotion] the width jumps to each value and a finished line goes at once. * - * Semantics: a progress bar with its value (indeterminate without one), named by + * It takes no room and has no semantics while no line is drawn. Semantics while it is: a + * progress bar with its value (indeterminate before the page reports any), named by * [contentDescription]. */ @Composable fun RaftPageLoadingBar( - value: Float?, + state: RaftPageLoadState, modifier: Modifier = Modifier, contentDescription: String? = null, - animated: Boolean = true, + reducedMotion: Boolean = rememberRaftReducedMotion(), + appearDelayMillis: Int = RaftPageLoadingBarAppearDelayMillis, ) { - val fraction = value?.coerceIn(0f, 1f) + val appearDelay = appearDelayMillis > 0 + var line by remember { mutableStateOf(RaftPageLoadingBarLine().onState(state, appearDelay, !reducedMotion)) } + // The line is derived from its last value and the reported state; onState is idempotent, + // so this settles in the same composition. + val reportedLine = line.onState(state, appearDelay, !reducedMotion) + if (reportedLine != line) line = reportedLine + val current = line + + val width = remember { Animatable(current.fraction) } + val alpha = remember { Animatable(1f) } + + val waiting = current.phase == RaftPageLoadingBarPhase.Waiting + LaunchedEffect(current.load, waiting, appearDelayMillis) { + if (!waiting) return@LaunchedEffect + delay(appearDelayMillis.toLong()) + line = line.onAppearDelayPassed() + } + + LaunchedEffect(current, reducedMotion) { + when (current.phase) { + RaftPageLoadingBarPhase.Hidden, RaftPageLoadingBarPhase.Waiting -> { + width.snapTo(current.fraction) + alpha.snapTo(1f) + } + RaftPageLoadingBarPhase.Shown -> { + alpha.snapTo(1f) + // Smaller than what is drawn only when a new load began: no travel backwards. + if (reducedMotion || current.fraction <= width.value) { + width.snapTo(current.fraction) + } else { + width.animateTo( + current.fraction, + tween(RaftPageLoadingBarProgressMillis, easing = RaftPageLoadingBarEaseOut), + ) + } + } + RaftPageLoadingBarPhase.Leaving -> { + width.animateTo(1f, tween(RaftPageLoadingBarProgressMillis, easing = RaftPageLoadingBarEaseOut)) + alpha.animateTo(0f, tween(RaftPageLoadingBarFadeOutMillis, easing = RaftPageLoadingBarEaseOut)) + line = line.onLeft() + } + } + } + + if (!current.visible) return val fill = RaftUiPalette.info - val sweep = if (fraction == null) raftProgressBarSweep(animated) else 0f + val indeterminate = current.phase == RaftPageLoadingBarPhase.Shown && !current.reported + val semanticFraction = current.fraction Canvas( modifier.fillMaxWidth().height(RaftStroke.Strong).semantics { progressBarRangeInfo = - if (fraction == null) ProgressBarRangeInfo.Indeterminate else ProgressBarRangeInfo(fraction, 0f..1f) + if (indeterminate) ProgressBarRangeInfo.Indeterminate else ProgressBarRangeInfo(semanticFraction, 0f..1f) contentDescription?.let { this.contentDescription = it } }, ) { - if (fraction == null) { - // The half-width segment enters from the start edge and leaves past the end. - val segment = size.width / 2f - val start = -segment + (size.width + segment) * sweep - clipRect { drawRect(color = fill, topLeft = Offset(start, 0f), size = Size(segment, size.height)) } - } else if (fraction > 0f) { - drawRect(color = fill, size = Size(size.width * fraction, size.height)) + // Read in the draw phase only: the width and the fade never recompose. + val drawn = size.width * width.value.coerceIn(0f, 1f) + if (drawn > 0f) { + // From the start edge: the right one in a right-to-left layout. + val left = if (layoutDirection == LayoutDirection.Rtl) size.width - drawn else 0f + drawRect( + color = fill, + topLeft = Offset(left, 0f), + size = Size(drawn, size.height), + alpha = alpha.value.coerceIn(0f, 1f), + ) } } } diff --git a/compose/designsystem/src/commonMain/kotlin/build/raft/designsystem/components/RaftProgressBar.kt b/compose/designsystem/src/commonMain/kotlin/build/raft/designsystem/components/RaftProgressBar.kt index 7039e2b448..40e414f840 100644 --- a/compose/designsystem/src/commonMain/kotlin/build/raft/designsystem/components/RaftProgressBar.kt +++ b/compose/designsystem/src/commonMain/kotlin/build/raft/designsystem/components/RaftProgressBar.kt @@ -151,11 +151,11 @@ fun RaftProgressBar( internal const val RaftProgressBarStillSweep = 0.5f /** - * The indeterminate sweep, 0..1 over [RaftProgressBarIndeterminateMillis], shared with - * [RaftPageLoadingBar]; [RaftProgressBarStillSweep] when not [animated]. + * The indeterminate sweep, 0..1 over [RaftProgressBarIndeterminateMillis]; + * [RaftProgressBarStillSweep] when not [animated]. */ @Composable -internal fun raftProgressBarSweep(animated: Boolean): Float { +private fun raftProgressBarSweep(animated: Boolean): Float { if (!animated) return RaftProgressBarStillSweep val transition = rememberInfiniteTransition(label = "raft-progress") return transition.animateFloat( diff --git a/compose/designsystem/src/commonTest/kotlin/build/raft/designsystem/RaftPageLoadingBarLineTest.kt b/compose/designsystem/src/commonTest/kotlin/build/raft/designsystem/RaftPageLoadingBarLineTest.kt new file mode 100644 index 0000000000..c5d4267663 --- /dev/null +++ b/compose/designsystem/src/commonTest/kotlin/build/raft/designsystem/RaftPageLoadingBarLineTest.kt @@ -0,0 +1,176 @@ +package build.raft.designsystem + +import build.raft.designsystem.components.RaftPageLoadState +import build.raft.designsystem.components.RaftPageLoadingBarAppearDelayMillis +import build.raft.designsystem.components.RaftPageLoadingBarFadeOutMillis +import build.raft.designsystem.components.RaftPageLoadingBarLine +import build.raft.designsystem.components.RaftPageLoadingBarLoadingMaxFraction +import build.raft.designsystem.components.RaftPageLoadingBarPhase +import build.raft.designsystem.components.RaftPageLoadingBarProgressMillis +import build.raft.designsystem.components.RaftPageLoadingBarRestFraction +import build.raft.designsystem.components.raftPageLoadingBarLoadingFraction +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +/** The page load line's life as plain data ([RaftPageLoadingBarLine]): no clock, no composition. */ +class RaftPageLoadingBarLineTest { + private fun loading(progress: Float? = null) = RaftPageLoadState.Loading(progress) + + /** A line that is past its appear delay, after these reports. */ + private fun shown(vararg progress: Float?): RaftPageLoadingBarLine { + var line = RaftPageLoadingBarLine().onState(loading(progress.first())).onAppearDelayPassed() + for (value in progress.drop(1)) line = line.onState(loading(value)) + return line + } + + @Test + fun theSpecNumbers() { + assertEquals(200, RaftPageLoadingBarAppearDelayMillis) + assertEquals(200, RaftPageLoadingBarProgressMillis) + assertEquals(200, RaftPageLoadingBarFadeOutMillis) + assertEquals(0.08f, RaftPageLoadingBarRestFraction) + assertEquals(0.95f, RaftPageLoadingBarLoadingMaxFraction) + } + + @Test + fun widthRestsAtEightPercentFollowsProgressAndStopsShortOfFullWhileLoading() { + val cases = + listOf>( + null to 0.08f, + 0f to 0.08f, + 0.03f to 0.08f, + 0.42f to 0.42f, + 0.95f to 0.95f, + 1f to 0.95f, + 7f to 0.95f, + -1f to 0.08f, + Float.NaN to 0.08f, + ) + for ((progress, expected) in cases) { + assertEquals(expected, shown(progress).fraction, "for $progress") + } + assertEquals(0.08f, raftPageLoadingBarLoadingFraction(null)) + assertEquals(0.95f, raftPageLoadingBarLoadingFraction(1f)) + } + + @Test + fun aLoadWaitsOutTheAppearDelayBeforeItsLineShows() { + val waiting = RaftPageLoadingBarLine().onState(loading()) + assertEquals(RaftPageLoadingBarPhase.Waiting, waiting.phase) + assertFalse(waiting.visible) + // Progress inside the delay is kept, and does not show the line early. + val progressed = waiting.onState(loading(0.3f)) + assertEquals(RaftPageLoadingBarPhase.Waiting, progressed.phase) + val shown = progressed.onAppearDelayPassed() + assertEquals(RaftPageLoadingBarPhase.Shown, shown.phase) + assertTrue(shown.visible) + assertEquals(0.3f, shown.fraction) + // With no delay (screenshots) it shows at once. + assertEquals(RaftPageLoadingBarPhase.Shown, RaftPageLoadingBarLine().onState(loading(), appearDelay = false).phase) + } + + @Test + fun aLoadThatEndsInsideTheAppearDelayDrawsNoLine() { + for (end in listOf(RaftPageLoadState.Finished, RaftPageLoadState.Failed, RaftPageLoadState.Idle)) { + val ended = RaftPageLoadingBarLine().onState(loading(0.6f)).onState(end) + assertEquals(RaftPageLoadingBarPhase.Hidden, ended.phase, "for $end") + // The delay's timer firing late must not bring it back. + assertEquals(RaftPageLoadingBarPhase.Hidden, ended.onAppearDelayPassed().phase, "for $end") + } + // A page that was never loading has no line to finish either. + assertEquals(RaftPageLoadingBarPhase.Hidden, RaftPageLoadingBarLine().onState(RaftPageLoadState.Finished).phase) + } + + @Test + fun progressOnlyMovesForwardWithinOneLoad() { + val line = shown(0.5f, 0.3f) + assertEquals(0.5f, line.fraction) + assertEquals(0.7f, line.onState(loading(0.7f)).fraction) + assertEquals(1, line.load, "still the first load") + assertTrue(line.reported) + } + + @Test + fun aNewLoadNamedByTheHostStartsFromTheBeginning() { + val first = shown(0.6f) + // Whatever the new load reports first: nothing yet, less than the last one, or more. + val cases = listOf>(null to 0.08f, 0.2f to 0.2f, 0.9f to 0.9f) + for ((progress, expected) in cases) { + val second = first.onState(RaftPageLoadState.Loading(progress, load = 1)) + assertEquals(expected, second.fraction, "for $progress") + assertEquals(first.load + 1, second.load, "for $progress") + assertEquals(progress != null, second.reported, "for $progress") + // The line was already up: the new load does not hide it for another delay. + assertEquals(RaftPageLoadingBarPhase.Shown, second.phase, "for $progress") + // The same report again is the same load. + assertEquals(second, second.onState(RaftPageLoadState.Loading(progress, load = 1)), "for $progress") + } + // The new load moves forward only, too. + val second = first.onState(RaftPageLoadState.Loading(0.2f, load = 1)) + assertEquals(0.2f, second.onState(RaftPageLoadState.Loading(0.1f, load = 1)).fraction) + // Inside the appear delay a new load restarts the wait (its count changes), still unseen. + val waiting = RaftPageLoadingBarLine().onState(loading(0.5f)) + val restarted = waiting.onState(RaftPageLoadState.Loading(null, load = 1)) + assertEquals(RaftPageLoadingBarPhase.Waiting, restarted.phase) + assertEquals(waiting.load + 1, restarted.load) + assertEquals(0.08f, restarted.fraction) + } + + @Test + fun progressGoingAwayIsNotReadAsANewLoad() { + // Only the host's load name starts the line again; "no progress" in the same load holds it. + val line = shown(0.6f) + val held = line.onState(loading(null)) + assertEquals(0.6f, held.fraction) + assertEquals(line.load, held.load) + assertTrue(held.reported) + } + + @Test + fun aFinishedLoadRunsToTheEndThenLeaves() { + val leaving = shown(0.4f).onState(RaftPageLoadState.Finished) + assertEquals(RaftPageLoadingBarPhase.Leaving, leaving.phase) + assertEquals(1f, leaving.fraction) + assertTrue(leaving.visible) + // Finished reported again keeps the exit going; it ends only when the fade has. + assertEquals(leaving, leaving.onState(RaftPageLoadState.Finished)) + val left = leaving.onLeft() + assertEquals(RaftPageLoadingBarPhase.Hidden, left.phase) + assertEquals(left, left.onState(RaftPageLoadState.Finished)) + // onLeft is only the end of an exit. + assertEquals(RaftPageLoadingBarPhase.Shown, shown(0.4f).onLeft().phase) + } + + @Test + fun aFailedOrStoppedLoadHidesTheLineAtOnce() { + for (end in listOf(RaftPageLoadState.Failed, RaftPageLoadState.Idle)) { + assertEquals(RaftPageLoadingBarPhase.Hidden, shown(0.4f).onState(end).phase, "shown, $end") + val leaving = shown(0.4f).onState(RaftPageLoadState.Finished) + assertEquals(RaftPageLoadingBarPhase.Hidden, leaving.onState(end).phase, "leaving, $end") + } + } + + @Test + fun reducedMotionDropsAFinishedLineAtOnce() { + val ended = shown(0.4f).onState(RaftPageLoadState.Finished, exitMotion = false) + assertEquals(RaftPageLoadingBarPhase.Hidden, ended.phase) + } + + @Test + fun aLoadAfterAnEndedOneStartsAgainWithItsOwnDelay() { + val ends = + listOf( + shown(0.9f).onState(RaftPageLoadState.Finished), + shown(0.9f).onState(RaftPageLoadState.Finished).onLeft(), + shown(0.9f).onState(RaftPageLoadState.Failed), + ) + for (ended in ends) { + val next = ended.onState(loading(0.1f)) + assertEquals(RaftPageLoadingBarPhase.Waiting, next.phase, "after $ended") + assertEquals(0.1f, next.fraction, "after $ended") + assertEquals(ended.load + 1, next.load, "after $ended") + } + } +} diff --git a/compose/designsystem/src/desktopTest/kotlin/build/raft/designsystem/RaftPageLoadingBarUiTest.kt b/compose/designsystem/src/desktopTest/kotlin/build/raft/designsystem/RaftPageLoadingBarUiTest.kt new file mode 100644 index 0000000000..91212e5069 --- /dev/null +++ b/compose/designsystem/src/desktopTest/kotlin/build/raft/designsystem/RaftPageLoadingBarUiTest.kt @@ -0,0 +1,129 @@ +package build.raft.designsystem + +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.semantics.ProgressBarRangeInfo +import androidx.compose.ui.test.ComposeUiTest +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.assertContentDescriptionEquals +import androidx.compose.ui.test.assertRangeInfoEquals +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.runComposeUiTest +import build.raft.designsystem.components.RaftPageLoadState +import build.raft.designsystem.components.RaftPageLoadingBar +import build.raft.designsystem.theme.RaftTheme +import kotlin.test.Test + +/** + * The page load line's timing on a real composition: the 200ms before it first shows, the run + * to the end and the fade when the load finishes, at once when it fails. On the test's main + * clock (virtual time), never the wall clock. The line is in the tree only while it is drawn. + */ +@OptIn(ExperimentalTestApi::class) +class RaftPageLoadingBarUiTest { + private var state by mutableStateOf(RaftPageLoadState.Loading()) + + private fun ComposeUiTest.setLine(reducedMotion: Boolean = false) { + mainClock.autoAdvance = false + setContent { + RaftTheme { + RaftPageLoadingBar( + state = state, + modifier = Modifier.testTag("line"), + contentDescription = "Loading", + reducedMotion = reducedMotion, + ) + } + } + mainClock.advanceTimeByFrame() + } + + private fun ComposeUiTest.report(next: RaftPageLoadState) { + state = next + mainClock.advanceTimeByFrame() + } + + @Test + fun theLineShowsOnlyAfterTheAppearDelay() = + runComposeUiTest { + setLine() + onNodeWithTag("line").assertDoesNotExist() + mainClock.advanceTimeBy(100) + onNodeWithTag("line").assertDoesNotExist() + mainClock.advanceTimeBy(200) + onNodeWithTag("line") + .assertExists() + .assertContentDescriptionEquals("Loading") + .assertRangeInfoEquals(ProgressBarRangeInfo.Indeterminate) + report(RaftPageLoadState.Loading(0.4f)) + onNodeWithTag("line").assertRangeInfoEquals(ProgressBarRangeInfo(0.4f, 0f..1f)) + } + + @Test + fun aLoadThatFinishesInsideTheDelayNeverShowsALine() = + runComposeUiTest { + setLine() + mainClock.advanceTimeBy(100) + report(RaftPageLoadState.Finished) + onNodeWithTag("line").assertDoesNotExist() + // Nothing shows later either: neither the delayed line nor an exit. + mainClock.advanceTimeBy(300) + onNodeWithTag("line").assertDoesNotExist() + } + + @Test + fun aFinishedLoadRunsToTheEndAndFadesBeforeTheLineGoes() = + runComposeUiTest { + state = RaftPageLoadState.Loading(0.5f) + setLine() + mainClock.advanceTimeBy(300) + onNodeWithTag("line").assertExists() + report(RaftPageLoadState.Finished) + onNodeWithTag("line").assertExists().assertRangeInfoEquals(ProgressBarRangeInfo(1f, 0f..1f)) + // 200ms to the end, then 200ms of fade: still there part way. + mainClock.advanceTimeBy(250) + onNodeWithTag("line").assertExists() + mainClock.advanceTimeBy(400) + onNodeWithTag("line").assertDoesNotExist() + } + + @Test + fun aFailedLoadDropsTheLineAtOnce() = + runComposeUiTest { + state = RaftPageLoadState.Loading(0.5f) + setLine() + mainClock.advanceTimeBy(300) + onNodeWithTag("line").assertExists() + report(RaftPageLoadState.Failed) + onNodeWithTag("line").assertDoesNotExist() + } + + @Test + fun reducedMotionKeepsTheDelayAndDropsAFinishedLineAtOnce() = + runComposeUiTest { + state = RaftPageLoadState.Loading(0.5f) + setLine(reducedMotion = true) + onNodeWithTag("line").assertDoesNotExist() + mainClock.advanceTimeBy(300) + onNodeWithTag("line").assertExists() + report(RaftPageLoadState.Finished) + onNodeWithTag("line").assertDoesNotExist() + } + + @Test + fun aNewLoadAfterAFinishedOneWaitsAgain() = + runComposeUiTest { + setLine() + mainClock.advanceTimeBy(300) + report(RaftPageLoadState.Finished) + mainClock.advanceTimeBy(700) + onNodeWithTag("line").assertDoesNotExist() + report(RaftPageLoadState.Loading(0.2f)) + onNodeWithTag("line").assertDoesNotExist() + mainClock.advanceTimeBy(300) + onNodeWithTag("line").assertExists() + } +} diff --git a/compose/designsystem/src/desktopTest/kotlin/build/raft/designsystem/screenshot/DisplayComponentScreenshotTest.kt b/compose/designsystem/src/desktopTest/kotlin/build/raft/designsystem/screenshot/DisplayComponentScreenshotTest.kt index 39a88a7d45..7964c968cb 100644 --- a/compose/designsystem/src/desktopTest/kotlin/build/raft/designsystem/screenshot/DisplayComponentScreenshotTest.kt +++ b/compose/designsystem/src/desktopTest/kotlin/build/raft/designsystem/screenshot/DisplayComponentScreenshotTest.kt @@ -132,6 +132,7 @@ import build.raft.designsystem.components.raftPressOverlayColor import build.raft.designsystem.components.RaftPressSurface import build.raft.designsystem.components.RaftMeter import build.raft.designsystem.components.RaftMeterSize +import build.raft.designsystem.components.RaftPageLoadState import build.raft.designsystem.components.RaftPageLoadingBar import build.raft.designsystem.components.RaftProgressBar import build.raft.designsystem.components.RaftProgressBarSize @@ -822,19 +823,27 @@ class DisplayComponentScreenshotTest { } /** - * The page load line on the top edge of a page (canvas, then card): just started, part way, - * nearly done, and the frozen indeterminate segment. Square ends, no track, edge to edge. + * The page load line on the top edge of a page (canvas, then card): no progress yet (the + * still 8% line), part way, and the most it shows while the load still runs (95%, for a + * page that reports 100%). Square ends, no track, from the start edge. Shown with no + * appear delay and no motion; the run to the end and the fade are covered by + * `RaftPageLoadingBarUiTest`. */ @Test fun pageLoadingBar() = capture("page_loading_bar") { val colors = RaftTheme.colors Column(verticalArrangement = Arrangement.spacedBy(12.dp)) { - listOf(0.08f, 0.42f, 0.95f, null).forEach { value -> + listOf(null, 0.42f, 1f).forEach { progress -> Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) { listOf(colors.layerCanvas, colors.layerCard).forEach { surface -> Box(Modifier.size(width = 240.dp, height = 32.dp).background(surface)) { - RaftPageLoadingBar(value = value, contentDescription = "Loading", animated = false) + RaftPageLoadingBar( + state = RaftPageLoadState.Loading(progress), + contentDescription = "Loading", + reducedMotion = true, + appearDelayMillis = 0, + ) } } } diff --git a/compose/shared/src/androidMain/kotlin/build/raft/app/RaftSandboxWebView.android.kt b/compose/shared/src/androidMain/kotlin/build/raft/app/RaftSandboxWebView.android.kt index bdc77ba0f2..fbdeef3352 100644 --- a/compose/shared/src/androidMain/kotlin/build/raft/app/RaftSandboxWebView.android.kt +++ b/compose/shared/src/androidMain/kotlin/build/raft/app/RaftSandboxWebView.android.kt @@ -151,6 +151,9 @@ internal class RaftAndroidSandboxWebView( private var currentTitle: String = "" private var currentProgress: Int = 0 private var currentIsLoading: Boolean = false + + /** Main-frame loads started ([RaftWebViewNavigationState.loadGeneration]); kept across a rebuilt WebView. */ + private var loadGeneration: Int = 0 private var lastNavigationStateKey: String = "" private var lastLoadFailureReason: String = "" private var hostMessageListener: WebViewCompat.WebMessageListener? = null @@ -475,6 +478,7 @@ internal class RaftAndroidSandboxWebView( currentTitle = "" currentProgress = 0 currentIsLoading = true + loadGeneration += 1 lastSuccessfulUrl = "" lastLoadFailureReason = "" notifyUrlChange(target) @@ -990,7 +994,8 @@ internal class RaftAndroidSandboxWebView( canGoBack = webView.canGoBack(), canGoForward = webView.canGoForward(), isLoading = currentIsLoading, - progress = currentProgress.coerceIn(0, 100) + progress = currentProgress.coerceIn(0, 100), + loadGeneration = loadGeneration, ) val stateKey = state.toString() if (!force && stateKey == lastNavigationStateKey) return diff --git a/compose/shared/src/androidUnitTest/kotlin/build/raft/app/SettingsWebViewStallRetryUiTest.kt b/compose/shared/src/androidUnitTest/kotlin/build/raft/app/SettingsWebViewStallRetryUiTest.kt index d02ea832e7..29c64c1a25 100644 --- a/compose/shared/src/androidUnitTest/kotlin/build/raft/app/SettingsWebViewStallRetryUiTest.kt +++ b/compose/shared/src/androidUnitTest/kotlin/build/raft/app/SettingsWebViewStallRetryUiTest.kt @@ -7,12 +7,17 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalView +import androidx.compose.ui.semantics.ProgressBarRangeInfo import androidx.compose.ui.test.ComposeUiTest import androidx.compose.ui.test.ExperimentalTestApi import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.assertRangeInfoEquals import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick @@ -25,6 +30,9 @@ import build.raft.app.components.RaftDesignSystemTheme import build.raft.app.data.AppLocale import build.raft.app.data.stringDescLocaleType import build.raft.app.resources.StringDesc +import build.raft.designsystem.components.RaftPageLoadingBarAppearDelayMillis +import build.raft.designsystem.components.RaftPageLoadingBarFadeOutMillis +import build.raft.designsystem.components.RaftPageLoadingBarProgressMillis import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test @@ -73,9 +81,10 @@ class SettingsWebViewStallRetryUiTest { assertEquals(1, webViews().size, "the page's WebView is attached") val first = webViews().single() onNodeWithText("Could not load this page").assertDoesNotExist() + showLoadLine() onNodeWithTag(RAFT_WEB_PAGE_LOADING_BAR_TAG).assertExists() - mainClock.advanceTimeBy(RAFT_WEB_VIEW_LOAD_STALL_TIMEOUT_MS - 1_000) + mainClock.advanceTimeBy(RAFT_WEB_VIEW_LOAD_STALL_TIMEOUT_MS - 1_000 - LOAD_LINE_APPEAR_MS) waitForIdle() onNodeWithText("Could not load this page").assertDoesNotExist() @@ -101,7 +110,8 @@ class SettingsWebViewStallRetryUiTest { /** * No cover: the WebView is attached and shown (not hidden behind anything) from before its - * first commit, under the progress bar; the bar goes once the load finished. + * first commit, under the load line (which shows once its appear delay has passed); the line + * goes once the load finished and it has played its end. */ @Test fun theWebViewShowsUnderTheProgressBarUntilTheLoadFinishes() = @@ -119,6 +129,7 @@ class SettingsWebViewStallRetryUiTest { waitForIdle() val webView = webViews().single() assertEquals(View.VISIBLE, webView.visibility) + showLoadLine() onNodeWithTag(RAFT_WEB_PAGE_LOADING_BAR_TAG).assertExists() runOnUiThread { @@ -133,11 +144,63 @@ class SettingsWebViewStallRetryUiTest { runOnUiThread { shadowOf(webView).webViewClient.onPageFinished(webView, url) } waitForIdle() + // The line runs to the end and fades (or, with animations off, goes at once). + mainClock.advanceTimeBy(LOAD_LINE_EXIT_MS) + waitForIdle() onNodeWithTag(RAFT_WEB_PAGE_LOADING_BAR_TAG).assertDoesNotExist() assertEquals(false, presentations.last().isLoading, "the finish reached the host: ${presentations.last()}") assertEquals(webView, webViews().single(), "the same WebView keeps showing the page") } + /** + * A page whose session is slow: the placeholder waits 500ms, then the page takes its place and + * loads. The host's one load line shows from its appear delay on and is never absent across the + * swap, frame by frame on the test clock (and never doubled: the lookup fails on two lines). + */ + @Test + fun theLoadLineStaysUpWhileThePlaceholderGivesWayToThePage() = + runRobolectricComposeUiTest { + var sessionKnown by mutableStateOf(false) + mainClock.autoAdvance = false + setContent { + Host { + RaftWebPageLoadLineHost(Modifier.fillMaxSize()) { + if (sessionKnown) { + SettingsWebViewContent(url = url, diagnosticsName = "settings_billing") + } else { + SettingsWebViewLoadingPlaceholder() + } + } + } + } + var elapsed = 0L + fun advanceTo(millis: Long, lineExpected: Boolean) { + while (elapsed < millis) { + mainClock.advanceTimeByFrame() + elapsed += FRAME_MS + if (lineExpected) { + val line = onNodeWithTag(RAFT_WEB_PAGE_LOADING_BAR_TAG) + runCatching { line.assertExists() } + .onFailure { throw AssertionError("no load line ${elapsed}ms in (sessionKnown=$sessionKnown)", it) } + } + } + } + advanceTo(LOAD_LINE_APPEAR_MS, lineExpected = false) + advanceTo(500, lineExpected = true) + sessionKnown = true + advanceTo(1_000, lineExpected = true) + assertEquals(1, webViews().size, "the page took the placeholder's place") + + // The page's web view starts its load: the same line goes on, with the page's progress. + val webView = webViews().single() + runOnUiThread { + shadowOf(webView).webViewClient.onPageStarted(webView, url, null) + shadowOf(webView).webChromeClient.onProgressChanged(webView, 40) + } + advanceTo(1_300, lineExpected = true) + onNodeWithTag(RAFT_WEB_PAGE_LOADING_BAR_TAG).assertRangeInfoEquals(ProgressBarRangeInfo(0.4f, 0f..1f)) + } + @Test fun aFinishedLoadIsNotReadyUntilTheContentProbeSaysSo() = runRobolectricComposeUiTest { @@ -180,6 +243,12 @@ class SettingsWebViewStallRetryUiTest { assertEquals(1, webViews().size) } + /** Lets the load line's appear delay pass. */ + private fun ComposeUiTest.showLoadLine() { + mainClock.advanceTimeBy(LOAD_LINE_APPEAR_MS) + waitForIdle() + } + private fun ComposeUiTest.webViews(): List { val found = mutableListOf() runOnUiThread { root?.let { collectWebViews(it, found) } } @@ -191,6 +260,17 @@ class SettingsWebViewStallRetryUiTest { if (view is ViewGroup) for (index in 0 until view.childCount) collectWebViews(view.getChildAt(index), into) } + private companion object { + /** Past the line's appear delay, with room for the frames around it. */ + const val LOAD_LINE_APPEAR_MS = RaftPageLoadingBarAppearDelayMillis + 100L + + /** One frame of the test clock. */ + const val FRAME_MS = 16L + + /** Past the line's run to the end and its fade. */ + const val LOAD_LINE_EXIT_MS = RaftPageLoadingBarProgressMillis + RaftPageLoadingBarFadeOutMillis + 200L + } + @Composable private fun Host(content: @Composable () -> Unit) { val pager = remember { object : Pager() {}.apply { pageData = PageData(JSONObject().apply { put("slockVisualZeroSafeArea", true) }) } } diff --git a/compose/shared/src/commonMain/kotlin/build/raft/app/InAppBrowserPage.kt b/compose/shared/src/commonMain/kotlin/build/raft/app/InAppBrowserPage.kt index b8c8968c30..aaa73c9d2d 100644 --- a/compose/shared/src/commonMain/kotlin/build/raft/app/InAppBrowserPage.kt +++ b/compose/shared/src/commonMain/kotlin/build/raft/app/InAppBrowserPage.kt @@ -202,9 +202,18 @@ private fun RaftInAppBrowserScreen() { // The frame before the WebView attaches: the progress bar below already shows. else -> Unit } - // Over the page (not above it), so the page does not jump when the load ends. - if (launchUrl != null && loadError == null && navigationState.isLoading) { - RaftWebPageLoadingBar(navigationState.progress) + // Over the page (not above it), so the page does not jump when the load ends. Always + // composed: the line plays its own end when the load finishes, and goes at once when it + // fails or is stopped. + if (launchUrl != null) { + RaftWebPageLoadingBar( + raftWebPageLoadState( + isLoading = navigationState.isLoading, + progress = navigationState.progress, + failed = loadError != null, + loadGeneration = navigationState.loadGeneration, + ), + ) } } } diff --git a/compose/shared/src/commonMain/kotlin/build/raft/app/RaftWebView.kt b/compose/shared/src/commonMain/kotlin/build/raft/app/RaftWebView.kt index ab0c788479..b1bda09861 100644 --- a/compose/shared/src/commonMain/kotlin/build/raft/app/RaftWebView.kt +++ b/compose/shared/src/commonMain/kotlin/build/raft/app/RaftWebView.kt @@ -15,7 +15,14 @@ internal data class RaftWebViewNavigationState( val canGoBack: Boolean = false, val canGoForward: Boolean = false, val isLoading: Boolean = false, - val progress: Int = 0 + val progress: Int = 0, + /** + * Counts the main-frame loads this web view has started (Android `onPageStarted`, iOS + * `didStartProvisionalNavigation`, desktop the not-loading to loading edge). A change means a + * new load began, also when the last one never ended (a link or a redirect mid-load); the load + * line starts again on it ([raftWebPageLoadState]). + */ + val loadGeneration: Int = 0, ) { companion object { fun decode(params: Any?): RaftWebViewNavigationState { diff --git a/compose/shared/src/commonMain/kotlin/build/raft/app/settings/AppUpdatePage.kt b/compose/shared/src/commonMain/kotlin/build/raft/app/settings/AppUpdatePage.kt index 8f4acf51de..ca5f2e3cca 100644 --- a/compose/shared/src/commonMain/kotlin/build/raft/app/settings/AppUpdatePage.kt +++ b/compose/shared/src/commonMain/kotlin/build/raft/app/settings/AppUpdatePage.kt @@ -26,7 +26,6 @@ import build.raft.app.data.raftSharedPreferenceStore import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize @@ -190,7 +189,8 @@ private fun AppUpdateScreen(pageVisibleResumeTick: Int, pageVisible: Boolean) { } } ) - Box(modifier = Modifier.weight(1f).fillMaxWidth()) { + // One load line for the notes: it stays up while the cover gives way to the page. + RaftWebPageLoadLineHost(modifier = Modifier.weight(1f).fillMaxWidth()) { val versionCode = snapshot?.latestVersionCode?.takeIf { it > 0L }?.toString().orEmpty() if (versionCode.isNotBlank()) { ReleaseNotesWebViewBody(versionCode) diff --git a/compose/shared/src/commonMain/kotlin/build/raft/app/settings/SettingsStandaloneWebViewHost.kt b/compose/shared/src/commonMain/kotlin/build/raft/app/settings/SettingsStandaloneWebViewHost.kt index 8180e40938..7aae61725c 100644 --- a/compose/shared/src/commonMain/kotlin/build/raft/app/settings/SettingsStandaloneWebViewHost.kt +++ b/compose/shared/src/commonMain/kotlin/build/raft/app/settings/SettingsStandaloneWebViewHost.kt @@ -3,10 +3,15 @@ package build.raft.app import build.raft.designsystem.theme.RaftTheme import build.raft.app.resources.* import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.SideEffect +import androidx.compose.runtime.Stable +import androidx.compose.runtime.compositionLocalOf import androidx.compose.runtime.getValue import androidx.compose.runtime.key +import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue @@ -14,6 +19,7 @@ import androidx.compose.runtime.withFrameNanos import build.raft.app.base.Utils import build.raft.designsystem.components.RaftButton import build.raft.designsystem.components.RaftButtonSize +import build.raft.designsystem.components.RaftPageLoadState import build.raft.designsystem.components.RaftPageLoadingBar import build.raft.designsystem.components.RaftIconTileSize import build.raft.designsystem.components.RaftStickerTile @@ -27,6 +33,7 @@ import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize @@ -140,7 +147,7 @@ internal fun performSettingsWebViewBack( /** * What a Settings web page shows over its WebView. There is no cover: the WebView is shown as soon * as it is attached (it paints the page as it arrives, like the system browser), with a thin - * progress bar on top while the document is loading. Only a failed, stalled or crashed load + * load line on top while the document is loading. Only a failed, stalled or crashed load * replaces it, with the error state. */ internal enum class SettingsWebViewPresentation { @@ -368,7 +375,8 @@ internal fun SettingsWebViewPageScaffold( onBack = if (settingsWebViewHandlesBack(wideDetail, navigationState.canGoBack)) ::goBackOrClose else null, ) } - Box( + // One load line for the body: it stays composed while the placeholder gives way to the page. + RaftWebPageLoadLineHost( modifier = Modifier .weight(1f) @@ -537,31 +545,34 @@ internal fun StandaloneSettingsWebViewContent( var documentReady by remember(webUrl, hostAuthBinding?.webViewGeneration) { mutableStateOf(false) } // The page's session goes in at document start (injectedJavaScript), so it cannot load before - // the session is known (it would open signed out). The load starts as soon as it is. - if (session == null) { - SettingsWebViewLoadingPlaceholder() - return + // the session is known (it would open signed out). The load starts as soon as it is. One load + // line for both (the page scaffold's, when there is one): it stays up across the swap. + RaftWebPageLoadLineHost(Modifier.fillMaxSize()) { + if (session == null) { + SettingsWebViewLoadingPlaceholder() + } else { + SettingsWebViewContent( + url = webUrl, + modifier = modifier, + diagnosticsName = "settings_${spec.surface.diagnosticsName}", + allowedNavigationSchemes = spec.allowedNavigationSchemes, + allowNavigation = spec.allowNavigation, + hostEventsEnabled = spec.hostEventsEnabled, + bottomContentPadding = spec.bottomContentPadding, + injectedJavaScript = injectedJavaScript, + controller = controller, + generationKey = hostAuthBinding?.webViewGeneration, + onLoadCommit = onLoadCommit, + onLoadSuccess = onLoadSuccess, + onUrlChange = onUrlChange, + onLoadFailure = onLoadFailure, + onNavigationStateChange = onNavigationStateChange, + onHostMessage = onHostMessage, + onDocumentReadyChange = { documentReady = it }, + ) + } } - - SettingsWebViewContent( - url = webUrl, - modifier = modifier, - diagnosticsName = "settings_${spec.surface.diagnosticsName}", - allowedNavigationSchemes = spec.allowedNavigationSchemes, - allowNavigation = spec.allowNavigation, - hostEventsEnabled = spec.hostEventsEnabled, - bottomContentPadding = spec.bottomContentPadding, - injectedJavaScript = injectedJavaScript, - controller = controller, - generationKey = hostAuthBinding?.webViewGeneration, - onLoadCommit = onLoadCommit, - onLoadSuccess = onLoadSuccess, - onUrlChange = onUrlChange, - onLoadFailure = onLoadFailure, - onNavigationStateChange = onNavigationStateChange, - onHostMessage = onHostMessage, - onDocumentReadyChange = { documentReady = it }, - ) + if (session == null) return SettingsWebViewAccessTokenSyncEffect( snapshot = authSnapshot, @@ -728,23 +739,30 @@ internal fun SettingsWebViewContent( ) } } - when ( + val presentation = settingsWebViewPresentation( committed = committed, isLoading = navigationState.isLoading, hasLoadError = loadError != null || loadWatchdog.showsError, ) - ) { - SettingsWebViewPresentation.Error -> - SettingsWebViewErrorContent( - actionLabel = stringResource(Res.string.common_retry), - actionIcon = RaftLucideIconName.RefreshCw, - body = settingsWebViewErrorBody(loadWatchdog.state.phase), - onAction = { reloadKey += 1 }, - ) - SettingsWebViewPresentation.Loading -> RaftWebPageLoadingBar(navigationState.progress) - SettingsWebViewPresentation.Content -> Unit + if (presentation == SettingsWebViewPresentation.Error) { + SettingsWebViewErrorContent( + actionLabel = stringResource(Res.string.common_retry), + actionIcon = RaftLucideIconName.RefreshCw, + body = settingsWebViewErrorBody(loadWatchdog.state.phase), + onAction = { reloadKey += 1 }, + ) } + // Always composed: the line plays its own end when the load finishes, and goes at once + // when it fails. Drawn by the host around this page when there is one, else here. + RaftWebPageLoadLine( + raftWebPageLoadState( + isLoading = presentation == SettingsWebViewPresentation.Loading, + progress = navigationState.progress, + failed = presentation == SettingsWebViewPresentation.Error, + loadGeneration = navigationState.loadGeneration, + ), + ) } } @@ -754,34 +772,136 @@ internal fun SettingsWebViewLoadingCover() { Box(modifier = Modifier.fillMaxSize().background(RaftTheme.colors.layerCanvas)) } -/** A web page that cannot start its load yet (its session or URL is not known): canvas and the progress bar. */ +/** + * A web page that cannot start its load yet (its session or URL is not known): canvas, and the load + * line resting with no progress. Inside a [RaftWebPageLoadLineHost] the line is the host's, so it + * stays up when the page takes this placeholder's place. + */ @Composable internal fun SettingsWebViewLoadingPlaceholder() { Box(modifier = Modifier.fillMaxSize().background(RaftTheme.colors.layerCanvas)) { - RaftWebPageLoadingBar(progress = 0) + RaftWebPageLoadLine(RaftPageLoadState.Loading()) } } /** - * The load line on the top edge of a loading in-app web page ([RaftPageLoadingBar]: flat, square - * ends, edge to edge): the page's load progress, or the indeterminate sweep before the engine - * reports any. It stays short of full; it goes away when the load ends. + * The one load line of a web page host: what the pieces under a [RaftWebPageLoadLineHost] report + * with [RaftWebPageLoadLine]. The piece that entered last speaks (a page that took its + * placeholder's place); with none, there is no load. + */ +@Stable +internal class RaftWebPageLoadLineHostState { + private val reports = mutableStateListOf() + + val state: RaftPageLoadState + get() = reports.lastOrNull()?.state ?: RaftPageLoadState.Idle + + fun add(report: RaftWebPageLoadLineReport) { + if (report !in reports) reports += report + } + + fun remove(report: RaftWebPageLoadLineReport) { + reports -= report + } +} + +/** One piece's word on the load, under a [RaftWebPageLoadLineHost]. */ +@Stable +internal class RaftWebPageLoadLineReport(state: RaftPageLoadState) { + var state: RaftPageLoadState by mutableStateOf(state) +} + +internal val LocalRaftWebPageLoadLineHost = compositionLocalOf { null } + +/** + * The container in which a web page's placeholder gives way to the page: a Box with one load line + * over its [content], on its top edge. The line belongs to the container, not to the placeholder + * or the page, so it stays composed while one replaces the other and goes on from where it was. + * Inside another host this is a plain Box: the outer host keeps the line. + */ +@Composable +internal fun RaftWebPageLoadLineHost(modifier: Modifier = Modifier, content: @Composable BoxScope.() -> Unit) { + if (LocalRaftWebPageLoadLineHost.current != null) { + Box(modifier, content = content) + return + } + val host = remember { RaftWebPageLoadLineHostState() } + Box(modifier) { + CompositionLocalProvider(LocalRaftWebPageLoadLineHost provides host) { content() } + RaftWebPageLoadingBar(host.state) + } +} + +/** + * Reports [state] as the load of the in-app web page this is part of. Under a + * [RaftWebPageLoadLineHost] the host draws the line (and this takes no room); with no host the + * line is drawn here, on the top edge of the parent. + */ +@Composable +internal fun RaftWebPageLoadLine(state: RaftPageLoadState) { + val host = LocalRaftWebPageLoadLineHost.current + if (host == null) { + RaftWebPageLoadingBar(state) + return + } + val report = remember(host) { RaftWebPageLoadLineReport(state) } + SideEffect { if (report.state != state) report.state = state } + DisposableEffect(host, report) { + host.add(report) + onDispose { host.remove(report) } + } +} + +/** + * The load line on the top edge of an in-app web page ([RaftPageLoadingBar]: flat, square ends, + * from the start edge). Keep it composed for as long as the page is and report the load with + * [raftWebPageLoadState]: the line waits before it first shows, follows the page's progress, runs + * to the end and fades out when the load finishes, and goes at once when it fails. A page whose + * placeholder and content swap uses [RaftWebPageLoadLineHost] and [RaftWebPageLoadLine] instead. */ @Composable -internal fun RaftWebPageLoadingBar(progress: Int, modifier: Modifier = Modifier) { +internal fun RaftWebPageLoadingBar(state: RaftPageLoadState, modifier: Modifier = Modifier) { RaftPageLoadingBar( - value = raftWebPageLoadingBarValue(progress), + state = state, modifier = modifier.testTag(RAFT_WEB_PAGE_LOADING_BAR_TAG), contentDescription = stringResource(Res.string.common_loading), ) } -/** The bar's fraction for an engine [progress] (0..100): null (indeterminate) until it moves. */ -internal fun raftWebPageLoadingBarValue(progress: Int): Float? = - progress.takeIf { it > 0 }?.let { (it.coerceAtMost(100) / 100f).coerceAtMost(RAFT_WEB_PAGE_LOADING_BAR_MAX) } +/** + * What a web view's navigation state means for the load line. [progress] is the engine's 0..100, + * [loadGeneration] the web view's count of main-frame loads started + * ([RaftWebViewNavigationState.loadGeneration]). + * + * - [failed] (the page shows its error state): [RaftPageLoadState.Failed]. + * - [isLoading]: [RaftPageLoadState.Loading] with the progress (none while the engine reports 0) + * and [loadGeneration] as the load's name: when the web view starts another load, the line + * starts again. That is the host's own signal, the same on every platform; nothing is read + * into the progress going down. + * - Not loading at 100: [RaftPageLoadState.Finished]. Android and iOS set 100 only when the + * load finished (`onPageFinished`, `didFinish`). + * - Not loading short of 100: the load was stopped, or it failed and the failure callback has + * not arrived yet (the engines report "not loading" first). These cannot be told apart from + * the state, so the line goes at once ([RaftPageLoadState.Idle]) instead of running to the end. + */ +internal fun raftWebPageLoadState( + isLoading: Boolean, + progress: Int, + failed: Boolean, + loadGeneration: Int = 0, +): RaftPageLoadState = + when { + failed -> RaftPageLoadState.Failed + isLoading -> + RaftPageLoadState.Loading( + progress = progress.takeIf { it > 0 }?.let { it.coerceAtMost(100) / 100f }, + load = loadGeneration, + ) + progress >= 100 -> RaftPageLoadState.Finished + else -> RaftPageLoadState.Idle + } internal const val RAFT_WEB_PAGE_LOADING_BAR_TAG = "raft_web_page_loading_bar" -private const val RAFT_WEB_PAGE_LOADING_BAR_MAX = 0.95f @Composable internal fun SettingsWebViewErrorContent( diff --git a/compose/shared/src/commonTest/kotlin/build/raft/app/SettingsStandaloneWebViewHostTest.kt b/compose/shared/src/commonTest/kotlin/build/raft/app/SettingsStandaloneWebViewHostTest.kt index 61d52e8ab6..b7072179f4 100644 --- a/compose/shared/src/commonTest/kotlin/build/raft/app/SettingsStandaloneWebViewHostTest.kt +++ b/compose/shared/src/commonTest/kotlin/build/raft/app/SettingsStandaloneWebViewHostTest.kt @@ -2,6 +2,7 @@ package build.raft.app import build.raft.app.data.RaftShellStoreScope import build.raft.app.compat.json.JSONObject +import build.raft.designsystem.components.RaftPageLoadState import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse @@ -117,11 +118,46 @@ class SettingsStandaloneWebViewHostTest { } @Test - fun loadingBarIsIndeterminateUntilProgressAndNeverReachesComplete() { - assertEquals(null, raftWebPageLoadingBarValue(0)) - assertEquals(0.4f, raftWebPageLoadingBarValue(40)) - assertEquals(0.95f, raftWebPageLoadingBarValue(100)) - assertEquals(0.95f, raftWebPageLoadingBarValue(140)) + fun loadLineHostSpeaksForThePieceThatEnteredLast() { + val host = RaftWebPageLoadLineHostState() + assertEquals(RaftPageLoadState.Idle, host.state) + val placeholder = RaftWebPageLoadLineReport(RaftPageLoadState.Loading()) + val page = RaftWebPageLoadLineReport(RaftPageLoadState.Loading(0.3f, load = 1)) + host.add(placeholder) + assertEquals(RaftPageLoadState.Loading(), host.state) + // The swap, in either order of leaving and entering, ends on the page's word. + host.add(page) + host.remove(placeholder) + assertEquals(RaftPageLoadState.Loading(0.3f, load = 1), host.state) + page.state = RaftPageLoadState.Finished + assertEquals(RaftPageLoadState.Finished, host.state) + host.remove(page) + assertEquals(RaftPageLoadState.Idle, host.state) + } + + @Test + fun loadLineStateFollowsTheNavigationState() { + // Loading: no progress until the engine reports some, then its fraction. + assertEquals(RaftPageLoadState.Loading(null), raftWebPageLoadState(isLoading = true, progress = 0, failed = false)) + assertEquals(RaftPageLoadState.Loading(0.4f), raftWebPageLoadState(isLoading = true, progress = 40, failed = false)) + assertEquals(RaftPageLoadState.Loading(1f), raftWebPageLoadState(isLoading = true, progress = 140, failed = false)) + // The web view's load count names the load: another one starts the line again. + assertEquals( + RaftPageLoadState.Loading(0.1f, load = 3), + raftWebPageLoadState(isLoading = true, progress = 10, failed = false, loadGeneration = 3), + ) + assertEquals( + RaftPageLoadState.Loading(null, load = 3), + raftWebPageLoadState(isLoading = true, progress = 0, failed = false, loadGeneration = 3), + ) + // Ended at 100: finished, the line plays its end. + assertEquals(RaftPageLoadState.Finished, raftWebPageLoadState(isLoading = false, progress = 100, failed = false)) + // Ended short of 100 (stopped, or failed before the failure callback): gone at once. + assertEquals(RaftPageLoadState.Idle, raftWebPageLoadState(isLoading = false, progress = 60, failed = false)) + assertEquals(RaftPageLoadState.Idle, raftWebPageLoadState(isLoading = false, progress = 0, failed = false)) + // A failure wins over whatever the engine still reports. + assertEquals(RaftPageLoadState.Failed, raftWebPageLoadState(isLoading = true, progress = 40, failed = true)) + assertEquals(RaftPageLoadState.Failed, raftWebPageLoadState(isLoading = false, progress = 100, failed = true)) } @Test diff --git a/compose/shared/src/desktopMain/kotlin/build/raft/app/RaftSandboxWebView.desktop.kt b/compose/shared/src/desktopMain/kotlin/build/raft/app/RaftSandboxWebView.desktop.kt index 4d86f67e5c..f33e4affa2 100644 --- a/compose/shared/src/desktopMain/kotlin/build/raft/app/RaftSandboxWebView.desktop.kt +++ b/compose/shared/src/desktopMain/kotlin/build/raft/app/RaftSandboxWebView.desktop.kt @@ -146,6 +146,9 @@ internal class RaftDesktopWryWebView( private var currentTitle = "" private var loading = false private var progress = 0 + + /** Main-frame loads started ([RaftWebViewNavigationState.loadGeneration]). */ + private var loadGeneration = 0 private var commitSent = false private var lastStateKey = "" @@ -225,6 +228,7 @@ internal class RaftDesktopWryWebView( if (nowLoading && !loading) { loading = true progress = 10 + loadGeneration += 1 commitSent = false } else if (!nowLoading && loading) { loading = false @@ -355,6 +359,7 @@ internal class RaftDesktopWryWebView( canGoForward = panel.canGoForward(), isLoading = loading, progress = progress.coerceIn(0, 100), + loadGeneration = loadGeneration, ) val key = state.toString() if (!force && key == lastStateKey) return diff --git a/compose/shared/src/iosMain/kotlin/build/raft/app/RaftSandboxWebView.ios.kt b/compose/shared/src/iosMain/kotlin/build/raft/app/RaftSandboxWebView.ios.kt index f469971223..b7157f2956 100644 --- a/compose/shared/src/iosMain/kotlin/build/raft/app/RaftSandboxWebView.ios.kt +++ b/compose/shared/src/iosMain/kotlin/build/raft/app/RaftSandboxWebView.ios.kt @@ -148,6 +148,9 @@ internal class RaftIosSandboxWebView( private var currentTitle = "" private var currentLoading = false private var currentProgress = 0 + + /** Main-frame loads started ([RaftWebViewNavigationState.loadGeneration]). */ + private var loadGeneration = 0 private var lastNavigationStateKey = "" private var lastSuccessfulURL = "" private var lastLoadFailureKey = "" @@ -613,6 +616,8 @@ internal class RaftIosSandboxWebView( currentTitle = "" currentProgress = (source.estimatedProgress * 100.0 + 0.5).toInt().coerceIn(0, 100) currentLoading = true + // The new load's own signal: WebKit's progress need not pass through 0 between two loads. + loadGeneration += 1 lastSuccessfulURL = "" lastLoadFailureKey = "" notifyNavigationState(force = false) @@ -781,7 +786,8 @@ internal class RaftIosSandboxWebView( canGoBack = view?.let(::canGoBack) ?: false, canGoForward = view?.canGoForward ?: false, isLoading = currentLoading, - progress = currentProgress.coerceIn(0, 100) + progress = currentProgress.coerceIn(0, 100), + loadGeneration = loadGeneration, ) val stateKey = state.toString() if (!force && stateKey == lastNavigationStateKey) return