Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get currentDestination using DestinationsNavigator ? #693

Open
yoobi opened this issue Oct 22, 2024 · 4 comments
Open

How to get currentDestination using DestinationsNavigator ? #693

yoobi opened this issue Oct 22, 2024 · 4 comments

Comments

@yoobi
Copy link

yoobi commented Oct 22, 2024

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
Copy link

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
Copy link
Author

yoobi commented Oct 23, 2024

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
Copy link

DimitarGR8 commented Oct 23, 2024

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
Copy link
Author

yoobi commented Oct 23, 2024

I'm not using v2 sorry :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants