Skip to content

Native Android client for Spotify, built with Jetpack Compose

fix: prevent backdrop flashing and maintain layer coordinates during tab transitions

noNameDS09697956ef4c57
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/motion/ImmersiveMotion.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/motion/ImmersiveMotion.kt
index f1661e57..d33b5471 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/motion/ImmersiveMotion.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/motion/ImmersiveMotion.kt
@@ -6,6 +6,7 @@ import androidx.compose.animation.ExitTransition
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
+import androidx.compose.animation.fadeIn
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.foundation.lazy.LazyItemScope
@@ -93,7 +94,8 @@ object ImmersiveMotion {
fun enter(reduce: Boolean): AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition = {
val still = reduce || isTabSwitch()
PageFade.enterMs = if (still) FADE_MS else PAGE_MS / 2
- if (still) EnterTransition.None else slideInHorizontally(spring(stiffness = Spring.StiffnessMediumLow, visibilityThreshold = IntOffset(1, 1))) { it }
+ // Tabs cross-fade over FADE_MS; without an enter transition, Compose detaches the outgoing tab immediately (#172).
+ if (still) fadeIn(tween(FADE_MS)) else slideInHorizontally(spring(stiffness = Spring.StiffnessMediumLow, visibilityThreshold = IntOffset(1, 1))) { it }
}
fun exit(reduce: Boolean): AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition = {
@@ -105,7 +107,8 @@ object ImmersiveMotion {
fun popEnter(reduce: Boolean): AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition = {
val still = reduce || isTabSwitch()
PageFade.enterMs = if (still) FADE_MS else PAGE_MS
- if (still) EnterTransition.None else slideInHorizontally(tween(PAGE_MS)) { -it / 3 }
+ // Tabs cross-fade over FADE_MS; without an enter transition, Compose detaches the outgoing tab immediately (#172).
+ if (still) fadeIn(tween(FADE_MS)) else slideInHorizontally(tween(PAGE_MS)) { -it / 3 }
}
fun popExit(reduce: Boolean): AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition = {
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/shell/backdrop/DrawBackdropModifier.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/shell/backdrop/DrawBackdropModifier.kt
index 0fcc3d9d..209e7921 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/shell/backdrop/DrawBackdropModifier.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/shell/backdrop/DrawBackdropModifier.kt
@@ -390,6 +390,8 @@ private class DrawBackdropNode(
onDrawSurface?.invoke(this)
onDrawFront?.invoke(this)
}
+ // Signal readers (e.g. the lifted selection pill) to redraw over the newly recorded bar glass (#172).
+ exportedBackdrop?.moves = (exportedBackdrop?.moves ?: 0) + 1
}
}
@@ -403,6 +405,8 @@ private class DrawBackdropNode(
}
}
exportedBackdrop?.layerCoordinates = coordinates
+ // Invalidate readers when the exported surface moves or repositions (#172).
+ exportedBackdrop?.moves = (exportedBackdrop?.moves ?: 0) + 1
}
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/shell/backdrop/backdrops/LayerBackdrop.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/shell/backdrop/backdrops/LayerBackdrop.kt
index d1ba24fe..8f2f7e09 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/shell/backdrop/backdrops/LayerBackdrop.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/shell/backdrop/backdrops/LayerBackdrop.kt
@@ -83,13 +83,16 @@ class LayerBackdrop internal constructor(
internal var moves by androidx.compose.runtime.mutableIntStateOf(0)
internal fun publish(source: Source) {
- if (sources.lastOrNull() === source) layerCoordinates = source.coordinates
+ // Track the latest attached coordinates; avoid blanking coordinates during transitions (#172).
+ if (source.coordinates != null) layerCoordinates = source.coordinates
moves++
}
internal fun retire(source: Source) {
sources.remove(source)
- layerCoordinates = sources.lastOrNull()?.coordinates
+ // Keep the latest valid coordinates when an outgoing source detaches during a tab transition (#172).
+ val remaining = sources.lastOrNull { it.coordinates != null }?.coordinates
+ if (remaining != null) layerCoordinates = remaining
moves++
}
@@ -113,6 +116,8 @@ class LayerBackdrop internal constructor(
* transition both pages are drawn where they are this frame, so the glass sees what is on screen.
*/
internal fun DrawScope.drawSources(offsetOf: (LayoutCoordinates) -> Offset) {
+ var drew = false
+ var holdover: Pair<LayoutCoordinates, GraphicsLayer>? = null
for (s in sources.toList()) {
val c = s.coordinates ?: continue
val layer = s.layer ?: continue
@@ -122,7 +127,11 @@ class LayerBackdrop internal constructor(
}
if (!c.isAttached || layer.size.width <= 0) continue
val a = s.alpha().coerceIn(0f, 1f)
- if (a <= 0f) continue
+ if (a <= 0f) {
+ holdover = c to layer
+ continue
+ }
+ drew = true
val o = offsetOf(c)
withTransform({ translate(-o.x, -o.y) }) {
if (a >= 1f) drawLayer(layer)
@@ -135,6 +144,14 @@ class LayerBackdrop internal constructor(
}
}
}
+ if (!drew && holdover != null) {
+ // Draw the last valid frame if all sources are zero-alpha or unrecorded during cross-fade (#172).
+ val (c, layer) = holdover
+ val o = offsetOf(c)
+ withTransform({ translate(-o.x, -o.y) }) {
+ drawLayer(layer)
+ }
+ }
}
override fun DrawScope.drawBackdrop(
@@ -149,11 +166,27 @@ class LayerBackdrop internal constructor(
with(obtainInverseLayerScope()) { inverseTransform(density, layerBlock) }
}
}) {
- drawSources { src ->
- try {
- src.localPositionOf(coordinates)
- } catch (_: Exception) {
- coordinates.positionInWindow() - src.positionInWindow()
+ if (sources.isNotEmpty()) {
+ drawSources { src ->
+ try {
+ src.localPositionOf(coordinates)
+ } catch (_: Exception) {
+ coordinates.positionInWindow() - src.positionInWindow()
+ }
+ }
+ } else {
+ // Exported backdrops (e.g. barGlass) record directly into graphicsLayer without separate sources (#172).
+ val c = layerCoordinates
+ val layer = graphicsLayer
+ if (c != null && c.isAttached && layer.size.width > 0 && !layer.isReleased) {
+ val o = try {
+ c.localPositionOf(coordinates)
+ } catch (_: Exception) {
+ coordinates.positionInWindow() - c.positionInWindow()
+ }
+ withTransform({ translate(-o.x, -o.y) }) {
+ drawLayer(layer)
+ }
}
}
}