What are the thoughts on using something like `Loc...
# compose-android
d
What are the thoughts on using something like
LocalView.current.findNavController()
vs passing the
navController
down as an argument?
a
You can always expose your navcontroller as a composition local
But imo, I’d always expose it as an argument, even if it has a default impl that either consumes the composition local, or receives it directly
Grants more flexibility in testing and usage, depending on the component
i
Don't do either, ever, as explained in the testing guide: https://developer.android.com/develop/ui/compose/navigation#testing
2
Keep all of your screens completely independent of whatever navigation code you are using
a
I have overloads with generic functionality that are independent from the nav library
I always make sure I have an onBack or onSelect parameter or whatever, and then I also keep a convenience method for the navigation to fill in reasonable defaults
I should have been more specific!
I always make sure state can be hoisted
And events
i
We have a specific page on the approach you need once you get beyond just a single module (where multiple modules define their own nested graphs and you need to cross link them) - you'll note that the NavController never goes beyond the
NavGraphBuilder
extensions you build: https://developer.android.com/guide/navigation/design/encapsulate
very nice 1