raamcosta / compose-destinations

Annotation processing library for type-safe Jetpack Compose navigation with no boilerplate.
https://composedestinations.rafaelcosta.xyz
Apache License 2.0
3.23k stars 134 forks source link

How to get currentDestination using DestinationsNavigator ? #693

Open yoobi opened 1 month ago

yoobi commented 1 month ago

Hello !

My current use case is something like this, navigating to another destination and removing the current one from the backstack, I don't see any currentDestination using DestinationsNavigator.

navigator.navigate(NextScreenDestination) {
    popUpTo(currentDestination) {
        inclusive = true
    }
}
DimitarGR8 commented 1 month ago

Based on what I came up with as a solution, I guess it should be something like this. You should directly pass the destination.

navigator.navigate(NextScreenDestination) { popUpTo(CurrentScreenDestination) { inclusive = true } }

yoobi commented 1 month ago

Yes that could be a solution, this composable is used by many destination, it would require to add a new parameter currentDestination

As DestinationsNavigator is meant to be a wrapper around NavController, it could be nice to have currentDestination in it as well

DimitarGR8 commented 1 month ago

Previously I used to pull it off like this:

private fun executeNavigation( navController: NavHostController, direction: Direction?, addToBackstack: Boolean? ) { direction?.let { dir -> navController.navigate(dir) { if (addToBackstack != true) { this.popUpTo(navController.currentBackStackEntry?.destination?.route.toString()) { inclusive = true } } } } }

However, it is no longer available in the v2.

Oh and btw, I just submitted a new issue, could you please revise it and tell me if you have met the problem as well?

yoobi commented 1 month ago

I'm not using v2 sorry :/