The use case is the following:
? -> ... -> ?
? -> ... -> ? -> F
if (skipFoo)
? -> ... -> ? -> B
else
? -> ... -> ? -> F -> B
Can this be achieved using the NavOptionsBuilder
from androidx.navigation
?
I know that I can use popUpTo(0) { inclusive = true }
to remove everything but the new destination from the stack but I just want to prevent the current screen to be added when I'm navigating out of it, and only when a certain condition is satisfied.
Also, the content of the stack of destinations is dynamic (the Foo screen can be added at any time) so I can't simply hardcode a popUpToId
with a fixed destination, since I don't know what is the destination immediately before Foo screen on the stack.
It can be done using popUpTo
:
navController.navigate(Screens.Bar.route) {
popUpTo(Screens.Foo.route) {
inclusive = true
}
}