Tlaster / PreCompose

Compose Multiplatform Navigation && State Management

Home Page:https://tlaster.github.io/PreCompose/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clear whole backstack

sawil314 opened this issue · comments

Hi,
is it possible to clear the whole backstack?
For example after Logout.
If I understand it corrctly in Jetpack Navigation it is possible to access the navGraph which is always the first BackstackEntry and Pop up to it.
Is something similar possible in Precompose Navigation?

You can use PopUpTo with inclusive = true when navigating to new route.

But it doesn't work if a destination is multiple times or not at all on the BackStack, does it?
For example I have the Screens:
Login -> A -> B -> A -> Login
When I first open Screen A, it shouldn't be possible to go back to the Login Screen, so I pop it, my Backstack only contains A.
But after the second time Screen A (my Backstack contains A,B,A) I want to pop the whole backstack, so that it is not possible to go back to the screens A or B.
How would I achieve that, PopUpTo(A) would only remove the first A.

Seems like a new use case I've never think of, I'll add a way to clear back stacks in navigator.

Thank you!

@sawil314 You can try using PopUpTo.First(inclusive = true) when navigating to the new route. This would remove all screens from the stack barring the new navigation destination.

@priyanshuhere Thank you, that was the function I was looking for!