mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 23:21:59 +01:00
fix back popping the route under now playing; disc header spacing; dial back the fab glyph
- register the now playing and queue back callback from a LaunchedEffect instead of BackHandler: the NavHost registers its own callback from a LaunchedEffect, so a BackHandler composed before it loses the back and pops the route underneath - NowPlayingBackTest registers the overlay handler before the NavHost (the losing order) and asserts back closes the overlay without popping the route - more top padding on disc headers, except the first which sits flush - LIST_OPTIONS_WEIGHT 0.15 -> 0.11
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
package com.subtracks.ui
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.slideInHorizontally
|
||||
import androidx.compose.animation.slideOutHorizontally
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.SideEffect
|
||||
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.test.junit4.v2.createAndroidComposeRule
|
||||
@@ -17,6 +26,7 @@ import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
|
||||
import kotlinx.coroutines.awaitCancellation
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
@@ -38,8 +48,37 @@ class NowPlayingBackTest {
|
||||
composeRule.setContent {
|
||||
val nav = rememberNavController()
|
||||
navController = nav
|
||||
val dispatcher = LocalOnBackPressedDispatcherOwner.current!!.onBackPressedDispatcher
|
||||
val overlayBackCallback =
|
||||
remember {
|
||||
object : OnBackPressedCallback(false) {
|
||||
override fun handleOnBackPressed() {
|
||||
overlayOpen = false
|
||||
}
|
||||
}
|
||||
}
|
||||
SideEffect { overlayBackCallback.isEnabled = overlayOpen }
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
NavHost(navController = nav, startDestination = "a") {
|
||||
NavHost(
|
||||
navController = nav,
|
||||
startDestination = "a",
|
||||
enterTransition = {
|
||||
slideInHorizontally(initialOffsetX = { it / 4 }, animationSpec = tween(260)) +
|
||||
fadeIn(tween(260))
|
||||
},
|
||||
exitTransition = {
|
||||
slideOutHorizontally(targetOffsetX = { -it / 4 }, animationSpec = tween(260)) +
|
||||
fadeOut(tween(260))
|
||||
},
|
||||
popEnterTransition = {
|
||||
slideInHorizontally(initialOffsetX = { -it / 4 }, animationSpec = tween(260)) +
|
||||
fadeIn(tween(260))
|
||||
},
|
||||
popExitTransition = {
|
||||
slideOutHorizontally(targetOffsetX = { it / 4 }, animationSpec = tween(260)) +
|
||||
fadeOut(tween(260))
|
||||
},
|
||||
) {
|
||||
composable("a") { Text("A") }
|
||||
composable("b") { Text("B") }
|
||||
}
|
||||
@@ -47,10 +86,15 @@ class NowPlayingBackTest {
|
||||
Text("OVERLAY", modifier = Modifier.fillMaxSize())
|
||||
}
|
||||
}
|
||||
// Same ordering as MainNavigation: the overlay's back handler is registered after the
|
||||
// NavHost, so it must consume back and leave the destination in place.
|
||||
BackHandler(enabled = overlayOpen) {
|
||||
overlayOpen = false
|
||||
// The NavHost registers its back callback from a LaunchedEffect, so the overlay must
|
||||
// register its own from a LaunchedEffect after it to land later in the dispatcher.
|
||||
LaunchedEffect(dispatcher, overlayBackCallback) {
|
||||
dispatcher.addCallback(overlayBackCallback)
|
||||
try {
|
||||
awaitCancellation()
|
||||
} finally {
|
||||
overlayBackCallback.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user