conference-app-2021
conference-app-2021 copied to clipboard
Migrate ViewModel to hiltViewModel() in navigation compose
Kind (Required)
- Improvement
Overview (Required)
- Now, We can use navigation destination scoped ViewModel. (Currently we use Activity scoped ViewModels)
- We are using Dagger Hilt already. So I think we can use it 😄
Links
- https://www.youtube.com/watch?v=0z_dwBGQQWQ
Preferably you would not use AAC ViewModels nor Hilt within your composables because both couple your composables to your platform/application respectively. Build your widgets with the assumption they will be cross-compiled to other platforms and used in other applications. 😉
https://twitter.com/JimSproch/status/1396429288493109248
Thank you for your opinion. Ideally I would do that too. 👍
Currently, it is easy for an Android engineer to work with Android Navigation and ViewModel, and there are practices introduced in I/O.
Also, although not ideal, DroidKaigi uses modularization to reduce platform dependency a bit.
For details, narrow the scope where you can see Android ViewModel and Hilt as much as possible, create an interface, and make Android ViewModel invisible from the Composable function of the screen. 👀
Originally Hilt and ViewModel and Navigation are used in this app, and since the only thing that changes in this issue is the scope of ViewModel, there should be no change in terms of platform dependency.🙏