https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
d

Darryl Pierce

12/07/2023, 2:08 PM
Hey, all, what is the right way to access the ViewModel using KMP? I'm trying to pull examples from two sources (the KMP book from Kodeco and also their Jetpack Compose book) and I'm not sure if I'm doing it right. Can someone point me to a nice, definitive example for writing a cross-platform app?
p

Pablichjenkov

12/07/2023, 2:13 PM
In kmp architectures differ a bit from traditional Android MVVM architecture. I would suggest starting by selecting one of the recommended state management libraries Voyager PreCompose Decompose Appyx Circuit Check them out and pick one according to your preferences. They all integrate with ViewModel and DI well
👍 2
d

Darryl Pierce

12/07/2023, 2:15 PM
Is it possible to target an Android specific solution first and then refactor that model to use one of the ones you recommended when adding the iOS target?
p

Pablichjenkov

12/07/2023, 2:18 PM
I believe is possible, Appyx for instance offer a separate aar only for Android if you want to integrate only Android. In general the multiplatform project structure will change a little bit from a pure Android project. But that is basically directory names.
d

Darryl Pierce

12/07/2023, 2:19 PM
kk - thank you for the advice. I'll look into them. Do you recommend any one over the others?
p

Pablichjenkov

12/07/2023, 2:22 PM
I personally like Appyx the most but most of the people I know use Voyager for its simplicity. If you are familiar with Android jetpack navigation then PreCompose is basically the same API so you will feel like in Android land
👍 1
d

Darryl Pierce

12/07/2023, 2:22 PM
kk - again, thank you for the advice. I appreciate it.
👍 1
I tried messing around with Appyx, PreCompose, and briefly Circuit. But couldn't find a good example or tutorial that clicked with me. I did, however, manage to reread the chapter on both dependency injection (Ch. 9) in Kotlin Multiplatform By Tutorials and got things working on my end. Thanks again for the help!
😸 1
p

Pablichjenkov

12/08/2023, 3:13 PM
Great!
🙌 1
I kind of built on top of my own solution too. I started putting together a framework that includes a bit of navigation + ViewModel + server driven UI. Nothing better than when you made it with your own hands 😁
👍 1