icerockdev / moko-mvvm

Model-View-ViewModel architecture components for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
995 stars 95 forks source link

How to do something similar to observeAsState? #154

Closed antranapp closed 2 years ago

antranapp commented 2 years ago

I'm learning KMM and Jetpack Compose simultaneously.

I was able to create a ViewModel using AndroidX Lifecycle, where I can expose a property as state to Jetpack Compose View by using observeAsState

Now I want to move the ViewModel to common layer to share it with the iOS target, but I have no idea how I can expose the same property to Jetpack Compose again since observeAsState doesn't seem to be available.

Alex009 commented 2 years ago

hello! our LiveData have method ld() for android. this method return androidx.lifecycle.LiveData. so you can use https://developer.android.com/reference/kotlin/androidx/compose/runtime/livedata/package-summary#(androidx.lifecycle.LiveData).observeAsState()