Mirror the Android pane close animation
Give every pane one shared slide spec, a fixed 300 ms duration and a symmetric cubic-bezier easing, so a close is the open curve run backwards at the same duration; several levels that pop in one tap now stagger so each reverses in order from the top. The stack mounts a level while it is open or still sliding out and calls the pane only then, and rememberPaneContent retains each closing pane's full parent identity (item/version/section, stage key, visit). A closing pane therefore keeps rendering the content that opened it instead of vanishing or falling back to an empty node, and a fully closed level composes nothing. Geometry, tokens and insets are unchanged. Adds three pure unit cases for the symmetric easing and the stagger rule; documents the change and its emulator verification in android/README.md.
This commit is contained in:
@@ -1438,3 +1438,180 @@ Not verified: the two app appearances are dark-only (`PipelinesTheme` defaults t
|
||||
dark), so the `surfaceContainer` step was checked in the dark scheme only; the
|
||||
pane's leading-edge shadow is not used (the tonal step is the separation) so no
|
||||
new elevation token was introduced.
|
||||
|
||||
### Re-verification of the committed sheet (`1fece88`, 16 Oct 2026, run 73)
|
||||
|
||||
The change above is committed at `1fece88`; this run rebuilt and re-installed it
|
||||
and re-captured the pane on `emulator-5554` (fold AVD; narrow `wm size
|
||||
1080x1920`, wide `wm size reset` = 2076x2152 / 390dpi ≈ 852dp; **never** the
|
||||
attached Pixel) against the live server, using `android/scripts/capture_png.sh -s
|
||||
emulator-5554` (every image validated):
|
||||
|
||||
- `gradle :app:assembleDebug` → `BUILD SUCCESSFUL` (JDK 17, Gradle 8.11.1,
|
||||
`--offline`); `app/build/outputs/apk/debug/app-debug.apk` is 17,846,953 bytes,
|
||||
sha256 `d47c5bf993ca28293b188829c7fd5eec709fac49f04cca520377df96d393c887`.
|
||||
- `gradle :app:testDebugUnitTest --rerun-tasks` → `BUILD SUCCESSFUL`; the 18
|
||||
test-result XMLs aggregate to **137 tests, 0 failures, 0 errors, 0 skipped**.
|
||||
- `pane-opaque-wide-over-graph.png` / `pane-opaque-wide-over-timeline.png` and
|
||||
`pane-opaque-narrow-over-graph.png` / `pane-opaque-narrow-over-timeline.png`:
|
||||
the `implementer` pane opened over run 72's Graph and Timeline is one opaque
|
||||
`surfaceContainer` sheet — on the wide window from the fixed peek budget to the
|
||||
right edge, on the narrow window full-window — with the headline rows, section
|
||||
headers and the tonal step clearly readable.
|
||||
- `pane-opaque-narrow-over-running-graph.png`: the pane over run 73's running
|
||||
graph (`Status running`) is equally opaque.
|
||||
- `adb -s emulator-5554 logcat -d` contained 0 `FATAL EXCEPTION` / `E
|
||||
AndroidRuntime` lines during the sweep.
|
||||
- **APK publish.** Copied to
|
||||
`~/.local/share/pipelines/data/artifacts/73/1/pipelines-debug-wip-1fece88.apk`
|
||||
(`1fece88` = `git rev-parse --short HEAD`). `curl -I
|
||||
http://10.0.0.249:8080/artifacts/73/1/pipelines-debug-wip-1fece88.apk` returned
|
||||
`HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
|
||||
`Content-Length: 17846953`; a streamed `GET | shasum -a 256` returned the same
|
||||
`d47c5bf…` hash.
|
||||
|
||||
### Re-verification on the current tree (`1fece88`, 16 Oct 2026, run 77)
|
||||
|
||||
Same committed sheet, rebuilt and re-driven this run on `emulator-5554` only
|
||||
against the live server:
|
||||
|
||||
- `gradle :app:assembleDebug :app:testDebugUnitTest --offline` → `BUILD
|
||||
SUCCESSFUL` (Gradle 9.7.1, JDK 17 from the Android Studio JBR,
|
||||
`ANDROID_HOME=~/Library/Android/sdk`); `gradle :app:testDebugUnitTest
|
||||
--rerun-tasks --offline` re-ran all 18 result XMLs to **137 tests, 0 failures, 0
|
||||
errors, 0 skipped**. The fresh `app-debug.apk` is 17,846,953 bytes, sha256
|
||||
`8ff68d24…` — the same size but a different hash from `d47c5bf…` above, because
|
||||
APK signing is not byte-reproducible (called out in the run-73 review).
|
||||
- `pane-opaque-wide-over-graph.png` / `pane-opaque-wide-over-timeline.png`
|
||||
(2076x2152 @ 390dpi ≈ 852dp) and `pane-opaque-narrow-over-graph.png` /
|
||||
`pane-opaque-narrow-over-timeline.png` (`wm size 1080x1920`, `wm density 480` ≈
|
||||
360dp): run 76's running `implementer` pane is one solid `surfaceContainer`
|
||||
sheet, from the fixed peek budget (546 px) to the right edge on the wide window
|
||||
and full-window on the narrow one, with the headline rows and section headers
|
||||
readable and the covered panes' peeks untouched. `adb -s emulator-5554 logcat -d`
|
||||
held 0 `FATAL EXCEPTION` / `E AndroidRuntime` lines; `wm size`/`density` were
|
||||
reset afterwards.
|
||||
- **APK publish.** Copied to
|
||||
`~/.local/share/pipelines/data/artifacts/77/1/pipelines-debug-wip-1fece88.apk`
|
||||
(`1fece88` = `git rev-parse --short HEAD`); local and streamed `shasum -a 256`
|
||||
both return `8ff68d24…`. `curl -I
|
||||
http://10.0.0.249:8080/artifacts/77/1/pipelines-debug-wip-1fece88.apk` returned
|
||||
`HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
|
||||
`Content-Length: 17846953`.
|
||||
|
||||
### Mirror the open/close pane animation (16 Oct 2026, run 82)
|
||||
|
||||
A pane used to vanish on close: the destination cleared the selection that named
|
||||
it (a null `itemId`/`stageKey`) in the same recomposition that lowered the depth,
|
||||
so the sliding box carried no content, while the pane underneath swapped between
|
||||
its compact peek and its full body at the transition instant. The slide also used
|
||||
the default `spring()`, so it had no fixed duration or easing to run backwards.
|
||||
|
||||
- `SlidingPaneStack` now slides every pane with one shared spec
|
||||
(`paneSlideSpec`): a fixed `PANE_SLIDE_MILLIS` (300) duration and a symmetric
|
||||
`PANE_SLIDE_EASING` (`CubicBezierEasing(0.42, 0, 0.58, 1)`), so the same curve
|
||||
run from the open offset back to the closed one is the open curve travelled
|
||||
backwards. A single close is therefore the exact time-reverse of the open.
|
||||
- The stack reports a level **mounted** while it is open or has not yet finished
|
||||
sliding out, and only then calls the caller's `pane`. The destinations name a
|
||||
level's content through the new `rememberPaneContent(value)`, which keeps the
|
||||
last non-null value, so a closing pane keeps rendering the content that opened
|
||||
it until it is off-screen instead of vanishing. A fully closed level composes
|
||||
nothing, so a closed pane does no work and shows no stale content.
|
||||
- When one tap pops several levels, `paneSlideDelayMillis` waits
|
||||
`PANE_POP_STEP_MILLIS` (60) longer for each level below the topmost, so the
|
||||
cascade reverses in order. A level that is open or opening never waits, so a
|
||||
single-level open/close is unaffected.
|
||||
- Compose already maps the system animator duration scale onto its animations, so
|
||||
with animations disabled the slide is instant without a special case.
|
||||
- The covered pane's compact-vs-full presentation still swaps at the transition
|
||||
instant, exactly as opening already did (a styled change, not empty content);
|
||||
that presentation swap was not altered.
|
||||
|
||||
Verified on `emulator-5554` only against the live server (wide fold layout,
|
||||
2076x2152 / 390dpi ≈ 852dp; never the attached Pixel):
|
||||
|
||||
- `gradle :app:assembleDebug :app:testDebugUnitTest --offline` → `BUILD
|
||||
SUCCESSFUL`; `gradle :app:testDebugUnitTest --rerun-tasks --offline` re-ran all
|
||||
18 result XMLs to **140 tests, 0 failures, 0 errors, 0 skipped** (3 new pure
|
||||
cases: the easing is its own reverse, a single close starts at once, several
|
||||
closing levels stagger from the top).
|
||||
- Open/close pair: `input tap <timeline row>` then `input keyevent KEYCODE_BACK`
|
||||
on run 80's Timeline, captured with `screenrecord` and split into
|
||||
`open-1x-frames.png` / `close-1x-frames.png`; the stage pane slides in from the
|
||||
right on open and slides back out to the right on close, revealing the run
|
||||
detail underneath, instead of vanishing.
|
||||
- Multi-level pop: at depth 2, tapping the list peek (`onPopTo(0)`) captured in
|
||||
`multi-level-pop-1x-frames.png`; the stage pane leaves first and the list is
|
||||
revealed level by level.
|
||||
- Slow motion (`animator_duration_scale 10`): `open-close-slow10x.mp4` /
|
||||
`open-close-slow10x-frames.png`; the close frames are the open frames reversed.
|
||||
- Reduced motion: `animator_duration_scale 0`; 0.2 s after the open tap the stage
|
||||
pane is already at its final offset (title at `x=585`), and 0.2 s after Back the
|
||||
detail is already restored — unchanged 0.6 s later.
|
||||
- Narrow window (`wm size 1080x1920`, `wm density 480` ≈ 360dp):
|
||||
`narrow-open-1x-frames.png` / `narrow-close-1x-frames.png` — the full-window run
|
||||
detail slides in from the right on open and back out to the right on close,
|
||||
revealing the runs list underneath; `wm size`/`density` reset afterwards.
|
||||
- Stability: tapping Back mid-open (0.8 s in at `animator_duration_scale 10`)
|
||||
settles fully at the detail, never half-slid.
|
||||
- `adb -s emulator-5554 logcat -d` held 0 `FATAL EXCEPTION` / `E
|
||||
AndroidRuntime` lines; `animator_duration_scale` was left at 1.
|
||||
- **APK publish.** `app-debug.apk` (18,012,493 bytes, sha256 `d1c5506f…`) copied
|
||||
to `~/.local/share/pipelines/data/artifacts/82/1/pipelines-debug-wip-1fece88.apk`
|
||||
(`1fece88` = `git rev-parse --short HEAD`); `curl -I
|
||||
http://10.0.0.249:8080/artifacts/82/1/pipelines-debug-wip-1fece88.apk` returned
|
||||
`HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
|
||||
`Content-Length: 18012493`.
|
||||
|
||||
### Retain the parent identity of a closing pane (16 Oct 2026, run 82/3)
|
||||
|
||||
Review of the change above found a blocking defect: `popTo(0)` returns a bare
|
||||
`PaneSelection` (`itemId=0`, `stageKey=null`), and only the level-1 pane retained
|
||||
its `itemId`/version pair; the level-2 pane still read its parent id **live** from
|
||||
the selection, so closing a two-level stack to the list fed `runId=0` /
|
||||
`pipelineId=0` into the stage pane. The run was then `null`, the graph empty, the
|
||||
node not found, and the whole exit animation showed the `terminal` chip plus "No
|
||||
details recorded for this node." (captured in `repro-pop-050.png` /
|
||||
`pl-pop-090.png`); the same live read also reset the closing detail pane's section
|
||||
to Summary.
|
||||
|
||||
- `rememberPaneContent` now retains the **full** parent identity at every level:
|
||||
pipeline detail `(itemId, version, sectionIndex)`, pipeline stage
|
||||
`(itemId, version, stageKey)`, run detail `(itemId, sectionIndex)` and run stage
|
||||
`(itemId, stageKey, stageVisit)`. Each closing pane therefore keeps rendering
|
||||
the content, section and visit that opened it until it is off-screen; nothing a
|
||||
pane displays is read live from the selection while it exits.
|
||||
- No timing, easing or geometry changed — only what a closing pane reads.
|
||||
|
||||
Verified on `emulator-5554` only (2076x2152 / 390dpi fold layout, live server),
|
||||
`animator_duration_scale 10` for the frame work:
|
||||
|
||||
- `gradle :app:assembleDebug :app:testDebugUnitTest --offline` → `BUILD
|
||||
SUCCESSFUL`; `gradle :app:testDebugUnitTest --rerun-tasks --offline` re-ran all
|
||||
18 result XMLs to **140 tests, 0 failures, 0 errors, 0 skipped**.
|
||||
- Pipeline multi-level pop (tapping the list peek, `onPopTo(0)`, from depth 2):
|
||||
`before-after-pipeline-pop.png` puts the review's empty `pl-pop-090.png` (left)
|
||||
beside a frame of this build (right); every frame in
|
||||
`multi-level-pop-pipelines-sheet.png` shows the closing stage pane still
|
||||
rendering `implementer` / `model` / `Stage definition` with its Prompt, instead
|
||||
of the empty `terminal` state.
|
||||
- Runs multi-level pop: `multi-level-pop-runs-sheet.png` /
|
||||
`multi-level-pop-runs-stage-mid-exit.png` — the closing run stage pane keeps its
|
||||
run identity (`Status completed`, `Outcome success`, `Duration 5m18s`,
|
||||
`Visit 2 / 5`, `Target reviewer`, the Artifacts gallery), so `runId` is retained
|
||||
and the empty-node fallback never appears.
|
||||
- Single-level close (`single-level-close-runs-sheet.png`): the run detail slides
|
||||
back out to the right with its Summary section and rows intact, revealing the
|
||||
runs list underneath.
|
||||
- Reduced motion: `animator_duration_scale 0`; two captures 0.15 s and 0.6 s
|
||||
after Back are byte-identical (`sha256 692437bc…`), i.e. the close is instant.
|
||||
- `adb -s emulator-5554 logcat -d` held 0 `FATAL EXCEPTION` / `E
|
||||
AndroidRuntime` lines; `animator_duration_scale` was left at 1.
|
||||
- **APK publish.** `app-debug.apk` (18,012,767 bytes, sha256 `b3b7d948…`) copied
|
||||
to `~/.local/share/pipelines/data/artifacts/82/3/pipelines-debug-wip-1fece88.apk`
|
||||
(`1fece88` = `git rev-parse --short HEAD`); `curl -I
|
||||
http://10.0.0.249:8080/artifacts/82/3/pipelines-debug-wip-1fece88.apk` returned
|
||||
`HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
|
||||
`Content-Length: 18012767`; a streamed `GET | shasum -a 256` returned the same
|
||||
`b3b7d948…`.
|
||||
|
||||
@@ -49,6 +49,7 @@ import net.awan.pipelines.ui.components.ConnectionBanner
|
||||
import net.awan.pipelines.ui.components.SlidingPaneStack
|
||||
import net.awan.pipelines.ui.components.clampTabIndex
|
||||
import net.awan.pipelines.ui.components.pipelineDetailTabs
|
||||
import net.awan.pipelines.ui.components.rememberPaneContent
|
||||
import net.awan.pipelines.ui.components.runDetailTabs
|
||||
import net.awan.pipelines.ui.graph.PipelineStagePane
|
||||
import net.awan.pipelines.ui.graph.RunStagePane
|
||||
@@ -222,14 +223,18 @@ private fun PipelineDestination(vm: AppViewModel, wide: Boolean, onOpenRun: (Lon
|
||||
selectedId = selection.itemId.takeIf { depth >= 1 },
|
||||
covered = covered,
|
||||
)
|
||||
1 -> if (selection.itemId != 0L) {
|
||||
1 -> rememberPaneContent(
|
||||
selection.itemId.takeIf { it != 0L }?.let {
|
||||
Triple(it, selection.itemVersion, selection.sectionIndex)
|
||||
},
|
||||
)?.let { (itemId, version, sectionIndex) ->
|
||||
PipelineDetailScreen(
|
||||
vm = vm,
|
||||
pipelineId = selection.itemId,
|
||||
version = selection.itemVersion,
|
||||
pipelineId = itemId,
|
||||
version = version,
|
||||
onBack = onBack,
|
||||
onOpenRun = onOpenRun,
|
||||
selectedSection = clampTabIndex(selection.sectionIndex, pipelineDetailTabs.size),
|
||||
selectedSection = clampTabIndex(sectionIndex, pipelineDetailTabs.size),
|
||||
onSelectSection = { selection = selection.copy(sectionIndex = it) },
|
||||
modifier = paneModifier,
|
||||
wide = wide,
|
||||
@@ -239,11 +244,15 @@ private fun PipelineDestination(vm: AppViewModel, wide: Boolean, onOpenRun: (Lon
|
||||
covered = covered,
|
||||
)
|
||||
}
|
||||
2 -> selection.stageKey?.let { key ->
|
||||
2 -> rememberPaneContent(
|
||||
selection.stageKey?.let {
|
||||
Triple(selection.itemId, selection.itemVersion, it)
|
||||
},
|
||||
)?.let { (itemId, version, key) ->
|
||||
PipelineStagePane(
|
||||
vm = vm,
|
||||
pipelineId = selection.itemId,
|
||||
version = selection.itemVersion,
|
||||
pipelineId = itemId,
|
||||
version = version,
|
||||
stageKey = key,
|
||||
onBack = onBack,
|
||||
wide = wide,
|
||||
@@ -290,12 +299,14 @@ private fun RunsDestination(
|
||||
selectedRunId = selection.itemId.takeIf { depth >= 1 },
|
||||
covered = covered,
|
||||
)
|
||||
1 -> if (selection.itemId != 0L) {
|
||||
1 -> rememberPaneContent(
|
||||
selection.itemId.takeIf { it != 0L }?.let { it to selection.sectionIndex },
|
||||
)?.let { (itemId, sectionIndex) ->
|
||||
RunDetailScreen(
|
||||
vm = vm,
|
||||
runId = selection.itemId,
|
||||
runId = itemId,
|
||||
onBack = onBack,
|
||||
selectedSection = clampTabIndex(selection.sectionIndex, runDetailTabs.size),
|
||||
selectedSection = clampTabIndex(sectionIndex, runDetailTabs.size),
|
||||
onSelectSection = { onSelectionChange(selection.copy(sectionIndex = it)) },
|
||||
modifier = paneModifier,
|
||||
wide = wide,
|
||||
@@ -307,12 +318,16 @@ private fun RunsDestination(
|
||||
covered = covered,
|
||||
)
|
||||
}
|
||||
2 -> selection.stageKey?.let { key ->
|
||||
2 -> rememberPaneContent(
|
||||
selection.stageKey?.let {
|
||||
Triple(selection.itemId, it, selection.stageVisit)
|
||||
},
|
||||
)?.let { (itemId, key, visit) ->
|
||||
RunStagePane(
|
||||
vm = vm,
|
||||
runId = selection.itemId,
|
||||
runId = itemId,
|
||||
stageKey = key,
|
||||
visitIndex = selection.stageVisit,
|
||||
visitIndex = visit,
|
||||
onBack = onBack,
|
||||
wide = wide,
|
||||
modifier = paneModifier,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package net.awan.pipelines.ui.components
|
||||
|
||||
import androidx.compose.animation.core.CubicBezierEasing
|
||||
import androidx.compose.animation.core.Easing
|
||||
import androidx.compose.animation.core.TweenSpec
|
||||
import androidx.compose.animation.core.animateDpAsState
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
@@ -18,6 +21,7 @@ import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material3.LocalMinimumInteractiveComponentSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.pointer.PointerEventPass
|
||||
@@ -52,6 +56,43 @@ internal val PEEK_BUDGET_DP = 224.dp
|
||||
internal val MIN_ACTIVE_PANE_WIDTH_DP = 320.dp
|
||||
internal val MIN_COVERED_PANE_WIDTH_DP = 112.dp
|
||||
|
||||
/**
|
||||
* The one slide timing every pane shares. [PANE_SLIDE_EASING] is a symmetric
|
||||
* ease (its control points mirror about the centre), so the same curve run from
|
||||
* the open offset back to the closed one is exactly the open curve travelled
|
||||
* backwards: closing a pane is the time-reverse of opening it, at the same
|
||||
* [PANE_SLIDE_MILLIS] duration. When several levels close in one tap the levels
|
||||
* below the topmost wait [PANE_POP_STEP_MILLIS] each, so they reverse in order.
|
||||
*/
|
||||
internal const val PANE_SLIDE_MILLIS = 300
|
||||
internal const val PANE_POP_STEP_MILLIS = 60
|
||||
internal val PANE_SLIDE_EASING: Easing = CubicBezierEasing(0.42f, 0f, 0.58f, 1f)
|
||||
|
||||
/**
|
||||
* The extra delay, in milliseconds, before the pane at [level] starts reversing
|
||||
* for a stack whose visible depth just moved from [previousDepth] to [depth]. A
|
||||
* single closing level is the exact reverse of opening it and starts at once;
|
||||
* when more than one level was open and several are leaving, the topmost leaves
|
||||
* first and each lower level waits one more [PANE_POP_STEP_MILLIS] so the
|
||||
* cascade reads in order. A level that is open or opening never waits. Pure, so
|
||||
* the mirror/stagger rule needs no device.
|
||||
*/
|
||||
internal fun paneSlideDelayMillis(level: Int, depth: Int, previousDepth: Int): Int {
|
||||
if (level <= depth) return 0
|
||||
val closing = previousDepth - depth
|
||||
return if (closing > 1) (previousDepth - level) * PANE_POP_STEP_MILLIS else 0
|
||||
}
|
||||
|
||||
/**
|
||||
* The slide spec for the pane at [level]: one shared duration and easing in both
|
||||
* directions, plus [paneSlideDelayMillis] when several levels pop together.
|
||||
*/
|
||||
internal fun paneSlideSpec(level: Int, depth: Int, previousDepth: Int): TweenSpec<Dp> = tween(
|
||||
durationMillis = PANE_SLIDE_MILLIS,
|
||||
delayMillis = paneSlideDelayMillis(level, depth, previousDepth),
|
||||
easing = PANE_SLIDE_EASING,
|
||||
)
|
||||
|
||||
/**
|
||||
* The peek budget actually spent on a wide window: the fixed [PEEK_BUDGET_DP]
|
||||
* token, reduced only when that would leave the active pane narrower than
|
||||
@@ -156,21 +197,24 @@ internal fun peekStripsDp(
|
||||
* squeezed.
|
||||
*
|
||||
* [depth] is the number of visible panes minus one (0..[MAX_PANE_DEPTH]);
|
||||
* [pane] composes the level's content and is expected to render nothing for a
|
||||
* level whose selection is empty (so a closing pane simply slides back out). On
|
||||
* a wide window, tapping a covered pane's peek calls [onPopTo] with that pane's
|
||||
* level, closing every pane to its right; [backContentDescription] names each
|
||||
* strip. On a narrow window there is no strip and Back/gesture/the pane's own
|
||||
* back control pop the level.
|
||||
* [pane] composes the level's content. The stack mounts a level while it is open
|
||||
* or still sliding out, and calls [pane] only then, so the caller can name the
|
||||
* level's content with [rememberPaneContent]: the level keeps rendering the
|
||||
* content that opened it until it is fully closed, and a fully closed level is
|
||||
* not composed at all (no work, no stale content). On a wide window, tapping a
|
||||
* covered pane's peek calls [onPopTo] with that pane's level, closing every pane
|
||||
* to its right; [backContentDescription] names each strip. On a narrow window
|
||||
* there is no strip and Back/gesture/the pane's own back control pop the level.
|
||||
*
|
||||
* Every pane is always composed and each level has its own long-lived
|
||||
* [animateDpAsState], so opening slides in and closing slides back out with no
|
||||
* first-frame hack, and a rapid run of taps only retargets an existing animator
|
||||
* (never half-slid). Opening and closing are exact mirrors: the same offsets and
|
||||
* [spring] retarget in reverse. A covered pane is hidden from accessibility and
|
||||
* made non-interactive so TalkBack focus follows the top pane and a tap can never
|
||||
* leak through to a covered one; on a wide window only its peek strip stays
|
||||
* tappable.
|
||||
* Each level has its own long-lived [animateDpAsState], so opening slides in and
|
||||
* closing slides back out with no first-frame hack, and a rapid run of taps only
|
||||
* retargets an existing animator (never half-slid). Opening and closing are exact
|
||||
* mirrors: the same offsets and the one shared [paneSlideSpec] (a fixed duration
|
||||
* and a symmetric easing, so running it backwards is the same curve reversed)
|
||||
* are retargeted in reverse, and several levels closing in one tap reverse in
|
||||
* order. A covered pane is hidden from accessibility and made non-interactive so
|
||||
* TalkBack focus follows the top pane and a tap can never leak through to a
|
||||
* covered one; on a wide window only its peek strip stays tappable.
|
||||
*/
|
||||
@Composable
|
||||
fun SlidingPaneStack(
|
||||
@@ -206,6 +250,11 @@ fun SlidingPaneStack(
|
||||
val folded = strips.firstOrNull()?.takeIf { it.folded > 1 }?.folded ?: 0
|
||||
// The active pane always opens at the whole budget (or 0 when narrow).
|
||||
val activeStart = strips.fold(0.dp) { acc, strip -> acc + strip.width }
|
||||
// The depth just before the current one, so a pop knows how many levels
|
||||
// were open (to stagger their reversal). Held stable for a given depth so
|
||||
// the slide spec never changes part-way through a slide.
|
||||
val depthTrack = remember { PaneDepthTrack(depth) }
|
||||
val closingFrom = remember(depth) { depthTrack.previous.also { depthTrack.previous = depth } }
|
||||
|
||||
// The folded older levels as one edge indicator with a count, clear of the
|
||||
// status/nav bars and of the left gesture area; tapping it jumps back to
|
||||
@@ -232,8 +281,11 @@ fun SlidingPaneStack(
|
||||
}
|
||||
}
|
||||
|
||||
// Panes 0..MAX are always composed in order (the animator stays warm); a
|
||||
// level beyond the depth sits off-screen and the caller renders nothing.
|
||||
// Panes 0..MAX are always given their own long-lived animator, in order,
|
||||
// even while closed, so a retarget slides rather than jumps and the
|
||||
// animator stays warm; a level beyond the depth waits exactly off the
|
||||
// right edge. The one shared spec (see [paneSlideSpec]) makes closing the
|
||||
// exact time-reverse of opening.
|
||||
for (level in 0..MAX_PANE_DEPTH) {
|
||||
val covered = level < depth
|
||||
// A level folded into the edge indicator is not drawn on its own.
|
||||
@@ -252,32 +304,41 @@ fun SlidingPaneStack(
|
||||
val openWidth = paneWidthDp(hostWidth, if (level <= depth) openOffset else budget)
|
||||
val offset by animateDpAsState(
|
||||
targetValue = openOffset,
|
||||
animationSpec = spring(),
|
||||
animationSpec = paneSlideSpec(level, depth, closingFrom),
|
||||
label = "pane-slide-$level",
|
||||
)
|
||||
Box(
|
||||
Modifier
|
||||
.offset(x = offset)
|
||||
.width(openWidth)
|
||||
.fillMaxHeight()
|
||||
.then(if (level < depth) Modifier.blockPointerInput() else Modifier),
|
||||
) {
|
||||
if (strip != null) {
|
||||
// Constrain the compact identity to the visible strip so it is
|
||||
// centred in the space the covered pane actually has. It rides
|
||||
// with the pane's own offset and so slides in and out with it.
|
||||
val stripInset = if (level == 0) startInset else 0.dp
|
||||
Box(
|
||||
Modifier
|
||||
.align(Alignment.TopStart)
|
||||
.offset(x = stripInset, y = topInset)
|
||||
.width(maxOf(0.dp, strip.width - stripInset))
|
||||
.height(stripHeight),
|
||||
) {
|
||||
pane(level, true, Modifier.fillMaxSize())
|
||||
// A level is mounted while it is open or has not yet finished sliding
|
||||
// out. An unmounted level keeps its animator warm but composes no
|
||||
// content, so a fully closed pane does no work; a closing pane keeps
|
||||
// rendering its content (retained by the caller) until it is off the
|
||||
// screen, so it slides back out instead of vanishing.
|
||||
val mounted = level <= depth || offset.value < hostWidth.value
|
||||
if (mounted) {
|
||||
Box(
|
||||
Modifier
|
||||
.offset(x = offset)
|
||||
.width(openWidth)
|
||||
.fillMaxHeight()
|
||||
.then(if (level < depth) Modifier.blockPointerInput() else Modifier),
|
||||
) {
|
||||
if (strip != null) {
|
||||
// Constrain the compact identity to the visible strip so it
|
||||
// is centred in the space the covered pane actually has. It
|
||||
// rides with the pane's own offset and slides in so it also
|
||||
// slides back out with it.
|
||||
val stripInset = if (level == 0) startInset else 0.dp
|
||||
Box(
|
||||
Modifier
|
||||
.align(Alignment.TopStart)
|
||||
.offset(x = stripInset, y = topInset)
|
||||
.width(maxOf(0.dp, strip.width - stripInset))
|
||||
.height(stripHeight),
|
||||
) {
|
||||
pane(level, true, Modifier.fillMaxSize())
|
||||
}
|
||||
} else {
|
||||
pane(level, false, Modifier.fillMaxSize())
|
||||
}
|
||||
} else {
|
||||
pane(level, false, Modifier.fillMaxSize())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,3 +386,28 @@ private fun Modifier.blockPointerInput(): Modifier = this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A tiny non-observable cell, so remembering a value never schedules recomposition. */
|
||||
private class PaneMemory<T> {
|
||||
var value: T? = null
|
||||
}
|
||||
|
||||
/** The depth before the current one, tracked without scheduling recomposition. */
|
||||
private class PaneDepthTrack(initial: Int) {
|
||||
var previous: Int = initial
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps the last non-null [value] a pane was given, so a pane that is sliding
|
||||
* out still renders the content that opened it after the selection naming it
|
||||
* has been cleared. It is only called while the stack has the level mounted
|
||||
* (open or still finishing its exit), so once the level is fully closed the
|
||||
* remembered value is discarded and a closed pane does no work. A pane that
|
||||
* opens later sets a fresh value, so nothing stale is ever shown.
|
||||
*/
|
||||
@Composable
|
||||
internal fun <T : Any> rememberPaneContent(value: T?): T? {
|
||||
val memory = remember { PaneMemory<T>() }
|
||||
if (value != null) memory.value = value
|
||||
return memory.value
|
||||
}
|
||||
|
||||
@@ -131,4 +131,43 @@ class SlidingPaneStackTest {
|
||||
assertDp(355.dp, paneWidthDp(411.dp, 56.dp))
|
||||
assertDp(0.dp, paneWidthDp(100.dp, 200.dp))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theSlideEasingIsItsOwnReverse() {
|
||||
// A symmetric easing means running the one shared spec from the open
|
||||
// offset back to the closed one is the open curve travelled backwards,
|
||||
// so closing mirrors opening exactly rather than merely looking similar.
|
||||
for (i in 0..100) {
|
||||
val t = i / 100f
|
||||
assertEquals(
|
||||
"easing is not symmetric at $t",
|
||||
1f,
|
||||
PANE_SLIDE_EASING.transform(t) + PANE_SLIDE_EASING.transform(1f - t),
|
||||
1e-4f,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSingleLevelCloseIsTheExactMirrorAndStartsAtOnce() {
|
||||
// Opening never waits; closing one level is its reverse, so it never
|
||||
// waits either.
|
||||
assertEquals(0, paneSlideDelayMillis(level = 1, depth = 0, previousDepth = 1))
|
||||
assertEquals(0, paneSlideDelayMillis(level = 2, depth = 1, previousDepth = 2))
|
||||
// A level at or below the depth is open/opening: no stagger.
|
||||
assertEquals(0, paneSlideDelayMillis(level = 1, depth = 1, previousDepth = 0))
|
||||
assertEquals(0, paneSlideDelayMillis(level = 0, depth = 2, previousDepth = 1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun severalClosingLevelsReverseInOrderFromTheTop() {
|
||||
// Popping the whole stack to the list: the top pane leaves first and the
|
||||
// level beneath waits one step, so the cascade reads in order.
|
||||
assertEquals(0, paneSlideDelayMillis(level = 2, depth = 0, previousDepth = 2))
|
||||
assertEquals(
|
||||
PANE_POP_STEP_MILLIS,
|
||||
paneSlideDelayMillis(level = 1, depth = 0, previousDepth = 2),
|
||||
)
|
||||
assertTrue(PANE_SLIDE_MILLIS > 0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user