https://kotlinlang.org logo
Title
r

Raghav

04/20/2023, 11:47 AM
hey guys, can you recommend any libraries to share ViewModels between iOS and Android? I discovered this great library https://github.com/rickclephas/KMM-ViewModel from one of @John O'Reilly's article. I'm also interested in learning how an iOS app's View Lifecycle is different from that of Android so that I can actually identify the challenges that occur when sharing ViewModels between platforms. Are there any plans for releasing an official library for the same
a

Anonymike

04/20/2023, 3:46 PM
@Rick Clephas has done a fantastic job with that library and KMPNativeCoroutines given the limitations of multiplatform coroutines. We have been using it successfully to share our View Models between Android and iOS. The biggest issue we experience is that our coroutines autocomplete perfectly, but none of our stateflow properties do so any references to them show up red and do not autocomplete even though the code compiles fine.
r

Rick Clephas

04/20/2023, 4:17 PM
@Anonymike thanks! Could you possibly provide a reproducer for that issue?
r

Raghav

04/20/2023, 4:19 PM
I didn't knew that @Rick Clephas is on the server. Will try the library then
a

Anonymike

04/20/2023, 5:01 PM
Absolutely @Rick Clephas and if there is anyway we can help contribute to the library, my team is happy to do so. We've been learning more and more about what it generates and the reasons it is done that way so that we can help. I'll see if we can make a hello world app to minimally reproduce the issue. At the very least we can use one of our view model and ios screens to show the situation. Up until now we assumed it was an AppCode / IntelliJ Kotlin Multiplatform tools issue with autocompleting the generated extension properties.
a

Arkadii Ivanov

04/20/2023, 5:13 PM
a

Anonymike

04/20/2023, 5:17 PM
Yes @Arkadii Ivanov Decompose is fantastic as well. We've been looking at the navigation and testing many of its features as well. We very much appreciate your work!
s

Stefan Oltmann

04/20/2023, 8:49 PM
I may do it all wrong, but for my app I felt no need for an extra library. I use the NanoRedux pattern from https://github.com/Kotlin/kmm-production-sample/blob/master/shared/src/commonMain/kotlin/com/github/jetbrains/rssreader/app/NanoRedux.kt and it works pretty good for me. Especially it was a good way to overcome the limitations of the old native memory model.
m

Marcello Galhardo

04/22/2023, 11:26 AM
If the goal is to share the VM code, I maintain Retained, which I use for my side projects. https://github.com/marcellogalhardo/retained
a

Anonymike

04/23/2023, 1:37 AM
That's great to hear @Stefan Oltmann. We did the exact same thing! We moved to KMP Native Coroutines and KMM View Model primarily to reduce the boiler plate we were writing around the store mechanism because those had a KSP plugin that prevented us from having to see the glue code. For coroutine methods, we are now at a point where we can call them from multiplatform without any wrappers so progress is being made towards a solution that is both lightweight AND simple across all the libraries. For the larger apps we just needed something we could manage a bit easier but we hunted for quite a while to find NanoRedux because the alternatives at the time we started seemed heavier in comparison.