Git Product home page Git Product logo

Comments (6)

raamcosta avatar raamcosta commented on June 12, 2024

Hi!

NavGraph args are a bit tricky with official Compose Navigation as well. You need the back stack entry correspondent to the nav graph to make sure you'll have the args. If you navigate directly to another graph screen that is not the start one, the args will also not be there. That's why Compose Destinations APIs return nullable type in this case.

So, this is expected and how it works with official navigation library as well. You'll need to adapt to it.

from compose-destinations.

raamcosta avatar raamcosta commented on June 12, 2024

See also here:
https://composedestinations.rafaelcosta.xyz/v2/arguments/navigation-arguments#navgraph-navigation-arguments

NAV GRAPH ARGUMENTS ARE ALWAYS NULLABLE
Navigation arguments of nav graphs are tricky. They will be present if you navigate to the graph itself (for above example, doing navigator.navigate(ProfileNavGraph(id = "some id"))) and they will not be present if you navigate to one of its destinations directly.
This is how official compose navigation works as well, Compose Destinations makes it clear by returning nullable.
If you know in your case you always navigate to the Graph, you can do requireNavGraphArgs instead which will throw an exception instead of returning nullable type.

from compose-destinations.

KarolCieslar avatar KarolCieslar commented on June 12, 2024

So i have to navigate to NavGraphs every time when i want to retrive NavGraphsArgs?
For example: I have LoginNavGraphs where i have LoginDestination(start), ForgotPasswordDestination, RegisterDestination.
App start and i navigate to LoginNavGraph (i have arguments filled) then I want to redirect user to ForgotPasswordDestination with LoginNavGraph arguments so how i can navigate to this destination with arguments?

Sorry for my english ;/

from compose-destinations.

KarolCieslar avatar KarolCieslar commented on June 12, 2024

@raamcosta can you tell me how i can do this? #633 (comment)

from compose-destinations.

raamcosta avatar raamcosta commented on June 12, 2024

You can also get a hold of the NavBackStackEntry correspondent to your NavGraph, and that one will contain all nav graph arguments.

Something like this:

destinationsNavigator.getBackStackEntry(ProfileNavGraph)?.navGraphArgs<ProfileNavGraphArgs>()

from compose-destinations.

KarolCieslar avatar KarolCieslar commented on June 12, 2024

You can also get a hold of the NavBackStackEntry correspondent to your NavGraph, and that one will contain all nav graph arguments.

Something like this:

destinationsNavigator.getBackStackEntry(ProfileNavGraph)?.navGraphArgs<ProfileNavGraphArgs>()

How about get arguments in ViewModel without pass navigator to ViewModel?

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.