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

Support for bindText(flow: <CStateFlow<T>) on IOS #226

Open masimfacebook2 opened 1 year ago

masimfacebook2 commented 1 year ago

I can't use this function on the IOS side, it gives an error: Instance method 'bindText(flow:)' requires that 'StringDesc' inherit from 'NSString'

Solution: In mmp-library / src I created iosMain and there a file with the extension

import dev.icerock.moko.mvvm.flow.CStateFlow
import dev.icerock.moko.mvvm.flow.binding.bind
import dev.icerock.moko.resources.desc.StringDesc
import platform.UIKit.UILabel

fun UILabel.bindFlow(flow: CStateFlow<StringDesc?>) = bind(flow) {
    if (it != null) {
        this.text = it.localized()
    }
}
kramlex commented 1 year ago

@masimfacebook2 please create this issue in moko-mvvm. this one will be closed

binding functions is moko-mvvm-flow: https://github.com/icerockdev/moko-mvvm/tree/master/mvvm-flow/src/iosMain/kotlin/dev/icerock/moko/mvvm/flow/binding