dave08
09/16/2024, 9:41 AMMuaz KADAN
09/16/2024, 9:47 AMval backStackEntry by navController.currentBackStackEntryAsState()
if(backStackEntry?.destination?.route == Screen.Home::class.qualifiedName){
// do something
}
dave08
09/16/2024, 9:48 AMroute
is the qualifiedName...Kari Kähkönen
09/16/2024, 9:51 AMval navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
when {
destination.hasRoute(FooRoute::class) -> TODO()
destination.hasRoute(BarRoute::class) -> TODO()
else -> TODO()
}
Muaz KADAN
09/16/2024, 9:52 AMif(backStackEntry?.toRoute<Screen>() == Screen.Home){
// do something
}
I don't know if this works yet or not. Haven't tried it recentlydave08
09/16/2024, 9:55 AMKari Kähkönen
09/16/2024, 9:59 AMdestination._hasRoute_(FooRoute::class)
approach I haven’t had any issues.dave08
09/16/2024, 10:00 AM@Serializable
and there's a descriminator field in the nav component's Kotlinx serialization decoder...Muaz KADAN
09/16/2024, 10:02 AMMuaz KADAN
09/16/2024, 10:02 AMMuaz KADAN
09/16/2024, 10:02 AMdave08
09/16/2024, 10:03 AMannotating screens with @Serializable as the official documentation says should be enoughYou tried?
Muaz KADAN
09/16/2024, 10:05 AMval showAppBar: Boolean
@Composable get() =
BottomNavigationScreen.entries.any { bottomNavScreen ->
currentDestination?.route == bottomNavScreen.screen::class.qualifiedName
} || currentDestination?.route == Screen.Tasks::class.qualifiedName ||
currentBackStack.value.any { it.destination.route == Screen.Profile::class.qualifiedName }
Muaz KADAN
09/16/2024, 10:05 AMdave08
09/16/2024, 10:07 AMbackStackEntry?.toRoute<Screen>() == Screen.Home
...dave08
09/16/2024, 10:07 AMdave08
09/16/2024, 10:07 AMIan Lake
09/16/2024, 2:08 PMhasRoute
, as explained in the docs: https://developer.android.com/develop/ui/compose/navigation#bottom-navdave08
09/16/2024, 2:20 PMIan Lake
09/16/2024, 2:34 PMdave08
09/16/2024, 2:38 PMIan Lake
09/16/2024, 2:46 PMdave08
09/16/2024, 3:22 PM