mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-07-22 07:48:27 +00:00
Compare commits
2 Commits
a3e239d33f
...
claude/fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f7fbb3ddb | ||
|
|
dfc897abd3 |
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.ui.navigation.navs
|
||||
|
||||
import androidx.compose.material3.DrawerState
|
||||
import androidx.compose.material3.DrawerValue
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
import com.vitorpamplona.amethyst.ui.navigation.routes.Route
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -46,6 +47,7 @@ class EmptyNav : INav {
|
||||
|
||||
override fun navBottomBar(route: Route) {}
|
||||
|
||||
@Composable
|
||||
override fun canPop(): Boolean = false
|
||||
|
||||
override fun popBack() {}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
package com.vitorpamplona.amethyst.ui.navigation.navs
|
||||
|
||||
import androidx.compose.material3.DrawerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
import com.vitorpamplona.amethyst.ui.navigation.routes.Route
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -43,6 +44,7 @@ interface INav {
|
||||
|
||||
fun navBottomBar(route: Route)
|
||||
|
||||
@Composable
|
||||
fun canPop(): Boolean
|
||||
|
||||
fun popBack()
|
||||
|
||||
@@ -23,8 +23,12 @@ package com.vitorpamplona.amethyst.ui.navigation.navs
|
||||
import android.annotation.SuppressLint
|
||||
import androidx.compose.material3.DrawerState
|
||||
import androidx.compose.material3.DrawerValue
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import com.vitorpamplona.amethyst.ui.navigation.BOTTOM_NAV_ROOT_KEY
|
||||
import com.vitorpamplona.amethyst.ui.navigation.isBottomNavRoot
|
||||
import com.vitorpamplona.amethyst.ui.navigation.routes.Route
|
||||
@@ -93,9 +97,20 @@ class Nav(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun canPop(): Boolean {
|
||||
val current = controller.currentBackStackEntry ?: return false
|
||||
if (current.isBottomNavRoot()) return false
|
||||
// Observe the current entry as State so consumers recompose when the
|
||||
// back stack settles after a navigation or back-swipe transition.
|
||||
// A non-reactive read would leave a stale value behind: e.g. on
|
||||
// back-swipe to Home, previousBackStackEntry is still the popping
|
||||
// entry until the gesture finishes, and nothing would re-evaluate
|
||||
// canPop afterwards.
|
||||
val current by controller.currentBackStackEntryAsState()
|
||||
val entry = current ?: return false
|
||||
if (entry.isBottomNavRoot()) return false
|
||||
// Home is the graph's start destination and nothing can sit below
|
||||
// it, so a back arrow there is never meaningful.
|
||||
if (entry.destination.id == controller.graph.findStartDestination().id) return false
|
||||
return controller.previousBackStackEntry != null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user