Comments (27)
navigator.navigate(
direction = FindScreenDestination,
onlyIfResumed = false
) {
popUpTo(FindScreenDestination.route) {
inclusive = true
}
}
this is not how popUpTo works. You are trying to pop up to find screen while navigating to find screen? I’m confused 😅
Imagine a stack and you need to tell from the top of the stack up to which route you want to pop. And at the time of navigating find screen is not yet on the stack (even if it was, it would be the first, so you’d be popping up only find screen xD).
from compose-destinations.
Other than that, the implementation just calls NavController directly, so I don't see another way that the equivalent code using NavController would work and now with DestinationsNavigator wouldn't.
Try it with NavController again, like this:
@Destination
@Composable
fun MyScreen(
navController: NavController // <----- switch DestinationsNavigator with NavController
) {
/....
navController.navigate(destination.route) {
popUpTo(...Destination.route) {
inclusive = true
}
}
}
from compose-destinations.
You cannot use backQueue in production either. It’s marked as restricted.
You should know at all times what is the first route in your back stack. I’m not sure of how your nav graphs setup is like, but usually with Compose Destinations there is always a “root” route as the first, so you could just use that 😉
from compose-destinations.
Cool, then use popUpTo(NavGraphs.root)
there is an extension function that will accept this directly, no need to do “.route”
from compose-destinations.
thanks for helping out. Now it works
from compose-destinations.
You don't need to use navController.
Use DestinationsNavigator like this:
navigator.navigate(destination) {
popUpTo(SummaryScreenDestination.route) {
inclusive = true
}
}
So just one navigate call :)
And be suspicious of using strings like that with Compose Destinations. In most cases we have better solutions ;)
from compose-destinations.
I'm also observing this issue, and I am using
navigator.navigate(destination) {
popUpTo(...Destination.route) {
inclusive = true
}
}
but when I tried with navController it is working...
from compose-destinations.
navigator.navigate(direction = destination, onlyIfResumed = false) {
popUpTo(...Destination.route) {
inclusive = true
}
}
@jahongir9779 can you try this code and let me know? thank you.
from compose-destinations.
No, unfortunately it didn't work
from compose-destinations.
also facing same issue. for me even directly using navController isn't working
tried
navigator.navigate(direction = destination) {
popUpTo(...Destination.route) {
inclusive = true
}
}
navigator.navigate(direction = destination, onlyIfResumed = false) {
popUpTo(...Destination.route) {
inclusive = true
}
}
and also
navController.navigate(destination.route) {
popUpTo(...Destination.route) {
inclusive = true
}
}
from compose-destinations.
from compose-destinations.
Hey!
Well, this pretty much has to work :D
Can you add these lines right before calling the DestinationsNavHost?
val destination = navController.appCurrentDestinationAsState().value
?: startRoute.startAppDestination
navController.backQueue.print()
then somewhere in same file:
private fun ArrayDeque<NavBackStackEntry>.print(prefix: String = "stack") {
val stack = map { it.destination.route }.toTypedArray().contentToString()
println("$prefix = $stack")
}
from compose-destinations.
This will print the back stack routes everytime they change, so add that, then reproduce the issue and paste here the logs starting with stack =
from compose-destinations.
not sure if i understood what to do with :
val destination = navController.appCurrentDestinationAsState().value
?: startRoute.startAppDestination
i have multi module project
from compose-destinations.
Oh ok sorry
from compose-destinations.
LaunchedEffect(key1 = Unit) {
navController.currentBackStackEntryFlow.collect {
navController.backQueue.print()
}
}
from compose-destinations.
Do this instead sorry :)
from compose-destinations.
i see this line
Ignoring popBackStack to destination -1928565755 as it was not found on the current back stack
when i'm trying to navigate to screen (by pressing bottom Navigation item) with no navigation/cleared history
from compose-destinations.
app has bottom navigation , from content i can click on an item -> go deep -> deeper -> press bottom navigation -> history cleared and you're back on one of main/root level screens/destinations
from compose-destinations.
It would be helpful to see the back stack routes right before navigating with your pasted code snippet and right after. Also check the route you’re trying to pop up from the back stack and see if that route is actually on the back stack.
from compose-destinations.
With above LaunchedEffect and the print methods you should see the back stack in real time, as the current screen changes.
from compose-destinations.
stack = [newsfeed_route, newsfeed_screen?feedTypes={feedTypes}]
stack = [newsfeed_route, newsfeed_screen?feedTypes={feedTypes}, article_route, article_screen/{assetUrl}]
stack = [newsfeed_route, newsfeed_screen?feedTypes={feedTypes}, article_route, article_screen/{assetUrl}, find_route, section_newsfeed_route, section_newsfeed_screen/{title}?sections={sections}]
navigator.navigate(
direction = FindScreenDestination,
onlyIfResumed = false
) {
popUpTo(FindScreenDestination.route) {
inclusive = true
}
}
expected this above popUpTo call to cleanup backstack but everything is still on backstack + just navigated find_screen
Ignoring popBackStack to destination -1928565755 as it was not found on the current back stack
stack = [newsfeed_route, newsfeed_screen?feedTypes={feedTypes}, article_route, article_screen/{assetUrl}, find_route, section_newsfeed_route, section_newsfeed_screen/{title}?sections={sections}, find_screen]
from compose-destinations.
/**
* Pop up to a given destination before navigating. This pops all non-matching destination routes
* from the back stack until the destination with a matching route is found.
*/
I thought it would work like this:
- pops up all previously visited screens from backstack , including find screen if it was visited
- navigate to findscreen
what would be correct way to navigate Findscreen + get rid of all history ?
Thanks a lot!
from compose-destinations.
You need to popUpTo the first entry in the back stack. Remember it pops from the top to bottom. So if you want to pop all, then you need to give it the one in the bottom of the stack 🙂
from compose-destinations.
and i guess i need to use navController to get first entry from backstack, DestinationsNavigator doesn't have such list
from compose-destinations.
yes i do have "root"
from compose-destinations.
So no, you don’t need NavController. It doesn’t make a difference which you use if you do it well, both will work 🙂
from compose-destinations.
Related Issues (20)
- Theme doesn't carry over to other destinations HOT 1
- Navigate to another module with args HOT 3
- NavTypeSerializer HOT 3
- ModuleDestinations$Includes is defined multiple times in Multi-Module project HOT 4
- [ksp] java.lang.NullPointerException when using custom NavArgument type HOT 13
- No NavGraphs in V2 HOT 14
- Support for Shared Element Transition. HOT 2
- Tab navigation support. HOT 1
- Can not make dependenciesContainerBuilder example work HOT 2
- Serializer for class 'DirectionImpl' is not found in v2 HOT 10
- [2.1.0-beta03] Navgraphs.* cannot be imported in the generated NavGraphs HOT 3
- navargs.* cannot be imported in ArgsToSavedStateHandle.kt HOT 2
- HorizontalPager pageContent can't save state HOT 2
- NavGraphArhs are visible only in "start" destination HOT 6
- Removing from composition and re-adding when navigating HOT 3
- java.lang.IllegalStateException: Duplicate route found X_destination'. Routes must be unique!. In Muli-module project. HOT 2
- Missing classes detected while running R8 on AGP 8.4.0 HOT 2
- Video tutorials for using the library. HOT 1
- [KSP][2.1.0] _ModuleRegistry missing visibility modifiers HOT 4
- [DEEPLINK][2.1.0] Request to bring back withDeepLink() HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compose-destinations.