Hey, all, what is the right way to access the View...
# multiplatform
d
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
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
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
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
kk - thank you for the advice. I'll look into them. Do you recommend any one over the others?
p
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
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
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