I’m new to Kotlin / Compose but find myself in a p...
# multiplatform
a
I’m new to Kotlin / Compose but find myself in a position where I need move to something more modern for my clients (use case is mostly line of business cross platform apps, so simple shared UI and as much code and logic sharing as possible) - until recently we’ve been happy ish with Xamarin / .net MAUI which has worked a treat, but the migration has eaten a lot of time and MAUI seems to have no roadmap around Swift / SwiftUI so a lot of newer functionality is not availble, Objective C bindings only. So, Kotlin, KMP, Compose MP seems to be a good fit, but having researched it seems the shared Viewmodel story is unclear (Typically MVVM in MAUI), certainly when you break out into Swift UI, my interpretation is native view, native viewmodel and shared data layers, is that still the current situation or old news? Anything we do with KMP is a clean slate from today, so pointers to current (or imminent) best practice examples appreciated. TIA
e
With CMP you can have a shared ViewModel without any problems, androidx ViewModel supports multiplatform now. With KMP it’s a bit different, there are open source libraries that provide a common ViewModel abstraction. Personally on KMP, I’ve used native ViewModels, but they were almost empty, with an addition layer that handles actions and provides data in common code.
👍 1
p
Your team decide how much to share. You can use AndroidX ViewModel which supports KMP already, check here: https://github.com/android/kotlin-multiplatform-samples But you can also leave the ViewModel in swift and just share domain/data layer. I have gotten some feedback in the past from iOS devs. And they seem to like this last approach more. Because it gives them more freedom and speed to modify the ViewModel without having to wait for a Kotlin dev to do the changes. And I don't think this approach will get old, specially considering that ViewModel is part of the View layer, and KMP says keep the View layer native 🤷‍♂️
👍 1