mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 15:29:15 +01:00
disable the NavHost back handling and drive back ourselves
Keeps the NavHost composed (the dropped-NavHost version left the still-transparent overlay over black) while stopping the controller from winning the back over the overlay's BackHandler. Back now: queue -> now playing -> pop the route.
This commit is contained in:
@@ -183,15 +183,11 @@ private fun MainNavigation() {
|
|||||||
ArtworkTheme(artwork) {
|
ArtworkTheme(artwork) {
|
||||||
Box(Modifier.fillMaxSize()) {
|
Box(Modifier.fillMaxSize()) {
|
||||||
Column(Modifier.fillMaxSize().imePadding()) {
|
Column(Modifier.fillMaxSize().imePadding()) {
|
||||||
Box(Modifier.weight(1f)) {
|
|
||||||
// The now playing overlay covers this, and while it is up we drop the NavHost so
|
|
||||||
// it cannot steal the back from the overlay's BackHandler.
|
|
||||||
if (!nowPlayingOpen) {
|
|
||||||
NavHost(
|
NavHost(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
modifier =
|
modifier =
|
||||||
Modifier
|
Modifier
|
||||||
.fillMaxSize()
|
.weight(1f)
|
||||||
.then(
|
.then(
|
||||||
if (playerVisible) {
|
if (playerVisible) {
|
||||||
Modifier.consumeWindowInsets(WindowInsets.navigationBars)
|
Modifier.consumeWindowInsets(WindowInsets.navigationBars)
|
||||||
@@ -291,8 +287,6 @@ private fun MainNavigation() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
visible = showMiniPlayer,
|
visible = showMiniPlayer,
|
||||||
@@ -377,8 +371,15 @@ private fun MainNavigation() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BackHandler(enabled = showingQueue) { showingQueue = false }
|
// The NavHost registers its own back callback, and OnBackPressedDispatcher hands the back to
|
||||||
BackHandler(enabled = nowPlayingOpen && !showingQueue) {
|
// the last-registered enabled callback, so it can win over the overlay's BackHandler and pop
|
||||||
settleNowPlaying(false)
|
// the route underneath. Disable the controller's back and drive navigation ourselves.
|
||||||
|
LaunchedEffect(navController) { navController.enableOnBackPressed(false) }
|
||||||
|
BackHandler(enabled = showingQueue || nowPlayingOpen || navController.previousBackStackEntry != null) {
|
||||||
|
when {
|
||||||
|
showingQueue -> showingQueue = false
|
||||||
|
nowPlayingOpen -> settleNowPlaying(false)
|
||||||
|
else -> navController.popBackStack()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user