Dragos Rachieru
04/04/2022, 12:06 PMViewModel
logic in kotlin to make it multiplatform.
I was thinking about making the ViewModel
available for multiplatform applications(like compose for desktop) so I can reuse more code for my app.
My use case is a multiplatform navigation for Compose for Desktop
that will work on android and desktop(js and ios in the future). I need to create the ViewModelStoreOwner
to be part of the navigation libraryJames Black
04/07/2022, 3:08 AM@Suppress("EmptyDefaultConstructor")
expect open class SharedViewModel() {
protected val sharedScope: CoroutineScope
protected val weatherRepository: WeatherRepository
var city: String
open fun onCleared()
}
Then in each of the parts of the shared library they create the actual code that they need, but I do end up creating another one in my iOS project so I can have ObservableObjects, but it uses this as a base. I got the idea from:
https://github.com/MartinRajniak/CatViewerDemo
The idea is that you then create a new shared view model that uses the platform specific libraries so it works across the different clients.Dragos Rachieru
04/19/2022, 9:58 AM