Giter Site home page Giter Site logo

Comments (27)

raamcosta avatar raamcosta commented on May 22, 2024 3

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.

raamcosta avatar raamcosta commented on May 22, 2024 1

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.

raamcosta avatar raamcosta commented on May 22, 2024 1

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.

raamcosta avatar raamcosta commented on May 22, 2024 1

Cool, then use popUpTo(NavGraphs.root)

there is an extension function that will accept this directly, no need to do “.route”

from compose-destinations.

miduch avatar miduch commented on May 22, 2024 1

thanks for helping out. Now it works

from compose-destinations.

raamcosta avatar raamcosta commented on May 22, 2024

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.

jmadaminov avatar jmadaminov commented on May 22, 2024

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.

raamcosta avatar raamcosta commented on May 22, 2024
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.

jmadaminov avatar jmadaminov commented on May 22, 2024

No, unfortunately it didn't work

from compose-destinations.

miduch avatar miduch commented on May 22, 2024

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.

miduch avatar miduch commented on May 22, 2024

@raamcosta

from compose-destinations.

raamcosta avatar raamcosta commented on May 22, 2024

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.

raamcosta avatar raamcosta commented on May 22, 2024

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.

miduch avatar miduch commented on May 22, 2024

not sure if i understood what to do with :

  val destination = navController.appCurrentDestinationAsState().value
       ?: startRoute.startAppDestination

i have multi module project

from compose-destinations.

raamcosta avatar raamcosta commented on May 22, 2024

Oh ok sorry

from compose-destinations.

raamcosta avatar raamcosta commented on May 22, 2024
    LaunchedEffect(key1 = Unit) {
        navController.currentBackStackEntryFlow.collect {
            navController.backQueue.print()
        }
    }

from compose-destinations.

raamcosta avatar raamcosta commented on May 22, 2024

Do this instead sorry :)

from compose-destinations.

miduch avatar miduch commented on May 22, 2024

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.

miduch avatar miduch commented on May 22, 2024

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.

raamcosta avatar raamcosta commented on May 22, 2024

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.

raamcosta avatar raamcosta commented on May 22, 2024

With above LaunchedEffect and the print methods you should see the back stack in real time, as the current screen changes.

from compose-destinations.

miduch avatar miduch commented on May 22, 2024

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.

miduch avatar miduch commented on May 22, 2024
/**
 * 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:

  1. pops up all previously visited screens from backstack , including find screen if it was visited
  2. navigate to findscreen

what would be correct way to navigate Findscreen + get rid of all history ?

Thanks a lot!

from compose-destinations.

raamcosta avatar raamcosta commented on May 22, 2024

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.

miduch avatar miduch commented on May 22, 2024

and i guess i need to use navController to get first entry from backstack, DestinationsNavigator doesn't have such list

from compose-destinations.

miduch avatar miduch commented on May 22, 2024

yes i do have "root"

from compose-destinations.

raamcosta avatar raamcosta commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.