Peter
10/02/2024, 8:29 PMNavHostController
route as KClass
?
For example:
private sealed interface Destination {
@Serializable data object Home : Destination
@Serializable data object Settings : Destination
}
val controller = rememberNavController()
NavHost(navController = controller, startDestination = Destination.Home) {
composable<Destination.Home> {
// TODO
}
composable<Destination.Settings> {
// TODO
}
}
LaunchedEffect(controller.currentDestination) {
// How to get current route of type [Destination]?
}
Ian Lake
10/02/2024, 8:32 PMPeter
10/02/2024, 8:55 PMhasRoute()
can be used to solve my problem, thanks.
I was trying to do it a bit differently. I basically wanted to do something like following, while keeping NavHostController
source of truth for current Destination
private sealed interface Destination {
@Serializable data object Home : Destination
@Serializable data object Settings : Destination
}
val controller = rememberNavController()
NavHost(navController = controller, startDestination = Destination.Home) {
composable<Destination.Home> {
// TODO
}
composable<Destination.Settings> {
// TODO
}
}
val currentDestination = controller.somehowGetCurrentDestination()
MyBottomNavigation(
currentDestination = currentDestination,
onSelectDestination = controller::navigate,
)
Ian Lake
10/02/2024, 8:58 PMIan Lake
10/02/2024, 8:58 PMselected
and onClick
into a style close to what you have for currentDestination
and onSelectDestination
Peter
10/02/2024, 9:06 PM