mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
fix(ui): a page only drains into its control when that control comes back
This commit is contained in:
1 parent
96d7c66535
commit
adc3369975
3 files changed
+88
-11
No files matched your search
@@ -124,14 +124,15 @@ internal fun Pane(
|
||||
val paneAt = remember { arrayOf(Offset.Zero) }
|
||||
val livePage by rememberUpdatedState(s.pageKey)
|
||||
// Picking another game changes the detail beside the list, not the whole page.
|
||||
val target = if (page != null && s.pageKey != null) s.pageKey else if (selected.startsWith("app:")) "games" else selected
|
||||
val railContent = if (selected.startsWith("app:")) "games" else selected
|
||||
val target = if (page != null && s.pageKey != null) s.pageKey else railContent
|
||||
// The game the Games page shows. It must outlive the selection: while the page animates out,
|
||||
// drawing it with what is selected now (another rail item) turned it into a copy of that page.
|
||||
val gameShown = remember { arrayOf("games") }
|
||||
if (selected == "games" || selected.startsWith("app:")) gameShown[0] = selected
|
||||
if (page != null && s.pageKey != null) {
|
||||
pages[s.pageKey] = page
|
||||
if (s.pageKey !in origins) PageOrigin.take()?.let { origins[s.pageKey] = it.translate(-paneAt[0]) }
|
||||
if (s.pageKey !in origins) PageOrigin.take()?.let { origins[s.pageKey] = it.translate(-paneAt[0]).ownedBy(railContent) }
|
||||
}
|
||||
AnimatedContent(
|
||||
targetState = target,
|
||||
@@ -143,9 +144,14 @@ internal fun Pane(
|
||||
.togetherWith(fadeOut(Motion.tw(320, 80)) + scaleOut(Motion.tw(480), targetScale = 0.95f))
|
||||
.apply { targetContentZIndex = 1f }
|
||||
// Back out of it: the flood draws back into the control as the pane comes forward again.
|
||||
initialState in origins -> (fadeIn(Motion.tw(300, 100)) + scaleIn(Motion.tw(460, 40), initialScale = 0.95f))
|
||||
.togetherWith(ExitTransition.None)
|
||||
.apply { targetContentZIndex = -1f }
|
||||
initialState in origins && pageExit(origins[initialState]?.owner, targetState, PageLeave.Ordinary) == PageExit.Drain ->
|
||||
(fadeIn(Motion.tw(300, 100)) + scaleIn(Motion.tw(460, 40), initialScale = 0.95f))
|
||||
.togetherWith(ExitTransition.None)
|
||||
.apply { targetContentZIndex = -1f }
|
||||
// Away to something else: the control is not coming back, so the page sinks with the pane.
|
||||
initialState in origins -> (fadeIn(Motion.tw(300, 80)) + slideInVertically(Motion.tw(420, 80)) { it / 24 })
|
||||
.togetherWith(fadeOut(Motion.tw(170)) + scaleOut(Motion.tw(170), targetScale = 0.95f))
|
||||
.apply { targetContentZIndex = 1f }
|
||||
else -> (fadeIn(Motion.tw(300, 80)) + slideInVertically(Motion.tw(420, 80)) { it / 24 })
|
||||
.togetherWith(fadeOut(Motion.tw(170)) + slideOutVertically(Motion.tw(170)) { -it / 40 })
|
||||
.apply { targetContentZIndex = 1f }
|
||||
@@ -159,12 +165,15 @@ internal fun Pane(
|
||||
val from = origins[key]
|
||||
if (from == null) shown()
|
||||
else {
|
||||
val leaving = transition.targetState == EnterExitState.PostExit
|
||||
// Settled as the page starts to leave, from what is coming in, not from where it came in.
|
||||
val drains = remember(leaving) { !leaving || pageExit(from.owner, target, PageLeave.Ordinary) == PageExit.Drain }
|
||||
// Keeps a leaving page on screen while its flood draws back into the control.
|
||||
transition.animateFloat(
|
||||
transitionSpec = { if (targetState == EnterExitState.PostExit) Motion.tw(PAGE_RETURN_MS) else snap() },
|
||||
transitionSpec = { if (targetState == EnterExitState.PostExit && drains) Motion.tw(PAGE_RETURN_MS) else snap() },
|
||||
label = "pageReturn",
|
||||
) { if (it == EnterExitState.PostExit) 1f else 0f }
|
||||
PageFlood(from, leaving = transition.targetState == EnterExitState.PostExit) { shown() }
|
||||
PageFlood(from, leaving = leaving, sinks = !drains) { shown() }
|
||||
}
|
||||
}
|
||||
else Content(s, if (key == "games") gameShown[0] else key, a, Modifier.fillMaxSize(), onSelect, onAndroidAppClick, onOpenDeveloperOptions, onRequestWirelessAdb)
|
||||
|
||||
@@ -44,9 +44,37 @@ import kotlin.math.sin
|
||||
// Play (LaunchFlood): the control stretches out over the pane on loose springs, the far edges
|
||||
// first, and the page rises into it once it is covered. Back draws it down into the control again.
|
||||
|
||||
/** Where a page opened from: the control's bounds and corner radius, in px. */
|
||||
internal class Origin(val bounds: Rect, val corner: Float) {
|
||||
fun translate(by: Offset) = Origin(bounds.translate(by), corner)
|
||||
/**
|
||||
* Where a page opened from: the control's bounds and corner radius, in px, and the rail item that
|
||||
* was showing it ([owner]), so the page only draws back into it when that content returns.
|
||||
*/
|
||||
internal class Origin(val bounds: Rect, val corner: Float, val owner: String? = null) {
|
||||
fun translate(by: Offset) = Origin(bounds.translate(by), corner, owner)
|
||||
fun ownedBy(key: String) = Origin(bounds, corner, key)
|
||||
}
|
||||
|
||||
/** How a page that opened from a control leaves. */
|
||||
internal enum class PageExit {
|
||||
/** Back into the control it came from, which is on screen again. */
|
||||
Drain,
|
||||
/** Out through a link into another section, which takes the page there itself. */
|
||||
Hop,
|
||||
/** Away with the pane, as any page goes: the control it came from is not coming back. */
|
||||
Sink,
|
||||
}
|
||||
|
||||
/** Why a page is leaving: an ordinary change of page, or a link into another section. */
|
||||
internal enum class PageLeave { Ordinary, Link }
|
||||
|
||||
/**
|
||||
* The exit for a page opened from a control on [owner]'s content, leaving for [incoming]. It only
|
||||
* draws back into the control when the content that control belongs to is what comes back; a page
|
||||
* left for another rail item or another page drained into a control that was no longer there.
|
||||
*/
|
||||
internal fun pageExit(owner: String?, incoming: String, leave: PageLeave): PageExit = when {
|
||||
owner != null && incoming == owner -> PageExit.Drain
|
||||
leave == PageLeave.Link -> PageExit.Hop
|
||||
else -> PageExit.Sink
|
||||
}
|
||||
|
||||
internal object PageOrigin {
|
||||
@@ -70,6 +98,7 @@ internal const val PAGE_RETURN_MS = 900
|
||||
* [content], a page that opened from the control at [from] (in this element's coordinates): the
|
||||
* control's tile stretching over it until covered, then the page rising in as the tile fades.
|
||||
* Once [leaving], the reverse: the tile comes back over the page and draws down into the control.
|
||||
* A page that [sinks] instead goes with the pane and draws no tile at all.
|
||||
* The focus ring stays out of it until it is done.
|
||||
*/
|
||||
@Composable
|
||||
@@ -78,6 +107,7 @@ internal fun PageFlood(
|
||||
leaving: Boolean,
|
||||
/** What the tile shows instead of the control's fill: a game card's art, cropped to the tile as it grows. */
|
||||
art: Painter? = null,
|
||||
sinks: Boolean = false,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val pal = LocalPalette.current
|
||||
@@ -87,7 +117,14 @@ internal fun PageFlood(
|
||||
val shown = remember { Animatable(0f) }
|
||||
val tile = remember { Animatable(1f) }
|
||||
var size by remember { mutableStateOf(Size.Zero) }
|
||||
LaunchedEffect(size != Size.Zero, leaving) {
|
||||
LaunchedEffect(size != Size.Zero, leaving, sinks) {
|
||||
if (sinks) {
|
||||
// Whatever the flood in was doing, the page is shown whole and leaves with the pane.
|
||||
tile.snapTo(0f)
|
||||
shown.snapTo(1f)
|
||||
glide?.hidden = false
|
||||
return@LaunchedEffect
|
||||
}
|
||||
if (size == Size.Zero) return@LaunchedEffect
|
||||
glide?.hidden = true
|
||||
val b = from.bounds
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class PageExitTest {
|
||||
@Test fun backToTheSameRailItemDrainsIntoTheControl() {
|
||||
assertEquals(PageExit.Drain, pageExit("steam", "steam", PageLeave.Ordinary))
|
||||
}
|
||||
|
||||
@Test fun anotherRailItemSinks() {
|
||||
assertEquals(PageExit.Sink, pageExit("steam", "games", PageLeave.Ordinary))
|
||||
}
|
||||
|
||||
@Test fun anotherPageSinks() {
|
||||
// The GPU drivers row in Steam's settings opens Components over the same rail item.
|
||||
assertEquals(PageExit.Sink, pageExit("steam", "components", PageLeave.Ordinary))
|
||||
}
|
||||
|
||||
@Test fun aLinkIntoAnotherSectionHops() {
|
||||
assertEquals(PageExit.Hop, pageExit("steam", "components", PageLeave.Link))
|
||||
}
|
||||
|
||||
@Test fun drainingWinsWhenTheOwnerComesBackAnyway() {
|
||||
assertEquals(PageExit.Drain, pageExit("desktop", "desktop", PageLeave.Link))
|
||||
}
|
||||
|
||||
@Test fun aPageWithNoOwnerNeverDrains() {
|
||||
assertEquals(PageExit.Sink, pageExit(null, "steam", PageLeave.Ordinary))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user