Hi there, I'm developing an app which has a simila...
# compose
d
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
Hi! What’s the reason you want a ViewModel to own that state?
d
The navigation items are retrieved from a repository which I need to inject so I inject the repository in a ViewModel
m
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)
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
So in that case it means the Content of the Navigation Drawer and the ViewModel should have their own module 🤔
m
oh! I think it’s fine if they’re part of the same
app
module
d
mmh unfortunately that would also mean having to implement various modules into
:app
though