I'm using navigation components in a large complex...
# android
r
I'm using navigation components in a large complex app. It provides an extension function
by navGraphs()
which lets you scope 1 viewmodel to all the screens inside a specific navgraph. Normally you would have 1 viewmodel for each screen. Besides the benefits (easy state/data sharing between all your screens) what is a potential drawback of this approach?
d
encapsulation comes to mind – screen A can access some ViewModel function that only screen B is supposed to use?
👍 1
z
if you don't use SavedStateHandle, then any assumptions regarding state that was set by Fragment A will be lost when you try to access it in Fragment B or Fragment C
otherwise, using a shared controller for a shared flow is a really good idea
r
Your answer makes sense after reading the docs. Will go for this approach.