Git Product home page Git Product logo

Comments (4)

lucanicoletti avatar lucanicoletti commented on June 12, 2024

I've read this comment and I just double-checked.
My ShowRootScreen is a destination, but the call to DestinationNavHost inside of it uses another NavGraph

DestinationsNavHost(
        navGraph = NavGraphs.showRoot,
        [...],
)

from compose-destinations.

raamcosta avatar raamcosta commented on June 12, 2024

Hi @lucanicoletti , I'm sorry it took me so long to get back to you. I hope you found a workaround in the mean time 🙏

Let me start by making something clear:

Inside this inner DestinationsNavHost the screens marked with the ShowRootNavGraph are added with the composable(Destination) { Screen() } function.

This is not adding screens. Differently from official compose navigation library, the screens are added when you pass one NavGraph to the DestinationsNavHost, since that nav graph has information needed to add all its nested graphs and destinations.
This is just overriding the common way the library calls the annotated Composables, by manually calling them. Usually useful when you want to pass some compose state from the NavHost level down to the screen level.

Besides this, it's really hard for me to understand exactly what's happening, but it does sound like a complicated setup, probably unwarranted.
The "show root" nav graph, passed to the inner DestinationsNavHost, means that all screens of that nav host, can only navigate to other screens of that graph. So, if you're trying to navigate to a screen registered to the outer "root" graph, that would require using a NavController from that graph, otherwise the crash you're experience is to be expected (I can't answer to the seemingly random factor, if it is indeed there, it will be caused by official library that we use to navigate, not caused by Compose Destinations).

Maybe you can show me the contents of your NavGraphs generated object.

Let me know if this helps!

from compose-destinations.

lucanicoletti avatar lucanicoletti commented on June 12, 2024

No worries for the late reply. As you've guessed, I found a "solution". I would like to contribute more, but I'm unsure with what I can share.
The "solution" was to inline a function.
The "outer" DestinationNavHost in the MainActivity was navigating the ShowRootSceen, and that screen had a Scaffold, which called a function MyNavHost which inside used the second and inner DestinationNavHost.
I don't know why, but moving the code from MyNavHost inline inside the Scaffold of the ShowRootScreen removed the problem.
Perhaps without having the composable(destination) { MyScreen } directly inside of it, the navHost wasn't able to recognise the graph and its routes/destinations?

from compose-destinations.

raamcosta avatar raamcosta commented on June 12, 2024

No, that’s not needed.

anyway, glad you found a solution! I’ll close this, don’t hesitate to open something if you find another issue

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.