Hi there, I'm developing an app which has a similar architecture to the Now In Android app. The thing is, my NavHost is wrapped by a Navigation Drawer, and I would like to provide the item for that navigation drawer via a ViewModel. Would it be a good practice to have a ViewModel inside the app module, or should I rather create a new module exclusively for the Navigation Drawer?
m
Manuel Vivo
06/16/2022, 7:08 AM
Hi! What’s the reason you want a ViewModel to own that state?
d
Dylan
06/16/2022, 8:11 AM
The navigation items are retrieved from a repository which I need to inject so I inject the repository in a ViewModel
m
Manuel Vivo
06/16/2022, 8:30 AM
Ah! I see, yes, that ViewModel is fine to have it at the app level with Compose. It’ll be scoped to the View host (either Activity or Fragment)
Manuel Vivo
06/16/2022, 8:32 AM
you can call
rememberNavController
/
rememberScaffoldState
in the UI, and then have the ViewModel expose some state with the list of items to have in the drawer
d
Dylan
06/16/2022, 8:43 AM
So in that case it means the Content of the Navigation Drawer and the ViewModel should have their own module 🤔
m
Manuel Vivo
06/16/2022, 10:02 AM
oh! I think it’s fine if they’re part of the same
app
module
d
Dylan
06/16/2022, 10:08 AM
mmh unfortunately that would also mean having to implement various modules into