Hello, I was thinking about rewritting the `ViewMo...
# androidx
d
Hello, I was thinking about rewritting the
ViewModel
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 library
j
As soon as I get my GitHub account unlocked I will share my project but my view model looks like this:
Copy code
@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.
d
I have created a library for navigation only in the meantime: https://github.com/dragossusi/navigation-compose
👍 1