Raed Ghazal
09/29/2024, 7:37 AMinit
is called)Meet
09/29/2024, 7:46 AMViewModelModule.android.kt
use viewmodel and other platform use factory
Notes: It is possible to directly initialize the ViewModel in the commonMain
source set. I tested this approach, and while it worked perfectly on Android, there were issues on iOS and Desktop. Specifically, when using nested NavGraph or nested NavHost, the ViewModel may be recreated unexpectedly without any error, leading to unexpected behavior. Additionally, avoid using singleton for ViewModels on iOS and Desktop, as the ViewModelScope
is destroyed when using singletons.
In the future, there may be official ViewModel support for commonMain
, making this process more seamless.Raed Ghazal
09/29/2024, 7:49 AMIn the future, there may be official ViewModel support forisn't that already implemented? so compose added viewmodels in commonMain, and koin have a, making this process more seamless.commonMain
viewModelOf
that we can now use in commonMain, apparently its buggy, but its supportedRaed Ghazal
09/29/2024, 7:51 AMorg.jetbrains.androidx.lifecycle:lifecycle-viewmodel
while in the documentation they say we need to add
org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose
let me try thatRaed Ghazal
09/29/2024, 7:54 AMMeet
09/29/2024, 7:55 AMRaed Ghazal
09/29/2024, 7:58 AMfactoryOf
in IOS, didn't work