android / architecture-components-samples

Samples for Android Architecture Components.
https://d.android.com/arch
Apache License 2.0
23.4k stars 8.29k forks source link

Navigation between different navgraph fragments + hiltnavgraphVM #980

Open sdfgsdfgd opened 3 years ago

sdfgsdfgd commented 3 years ago

Hi, similar to the navigation sample I'm using different navigation graphs and the extensions provided in the sample and I need to findController().navigate() between the second fragment of Navgraph A and third fragment of Navgraph B.

Since I'm also using Hilt dependency injection, the navigation graphs are injected with the VM initialisation inside fragments. I don't know how nicely this plays with advanced navigation ? private val viewModel: ExampleViewModel by hiltNavGraphViewModels(R.id.navgraphId)

I noticed I can't just do a global action.... Simply include NavGraph B's fragment in navgraph A and then simply navigate() to it, you get all sorts of errors about the backstackentry or navgraph not being included. How would you navigate in this particular case ?

nareto commented 3 years ago

I'm very interested in doing exactly the same thing but haven't yet been able to.

@sdfgsdfgd did you manage to make it work?