Comments (6)
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.
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.
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.
@raamcosta can you tell me how i can do this? #633 (comment)
from compose-destinations.
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.
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)
- 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
- 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
- Can compose-destinations used in compose for desktop project ? HOT 1
- Accompanist Navigation Material functionality now available in androidx.compose.material.navigation.* HOT 2
- "Reproducible build" possible with Compose Destinations? HOT 5
- popUpTo matches navArgs exactly HOT 4
- Multiple Backstacks HOT 1
- [Improvement] moduleName could be automatically raname to "main" HOT 1
- Multiple NavGraphs with shared routes on V2 HOT 1
- Sharing a view model between destinations but with a view model factory HOT 3
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.