icerockdev / moko-mvvm

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

Add optionals for new iOS view bindings #40

Closed Alex009 closed 3 years ago

Alex009 commented 4 years ago

with new ios view bindings required write

let errorText: LiveData<StringDesc> = viewModel.state.error().map { $0 as? StringDesc ?? StringDesc.Raw(string: "") } as! LiveData<StringDesc>
errorLabel.bindText(liveData: errorText)

because optionals not supported

Alex009 commented 4 years ago

i think in this issue we should try remove requirement of naming MultiPlatformLibrary for kotlin framework. to do it i suggest: revert action of binding extensions. now we add extension function to UIKit classes and Kotlin/Native can't add it as extension...but when we add extension of kotlin class - it exported correct. so i suggest to change:

fun UIButton.bindEnabled(
    liveData: LiveData<Boolean>,
    enabledColor: UIColor? = null,
    disabledColor: UIColor? = null
) {
    ...
}

to

fun LiveData<Boolean>.bindEnabled(
    button: UIButton,
    enabledColor: UIColor? = null,
    disabledColor: UIColor? = null
) {
    ...
}
Dorofeev commented 3 years ago

In version 0.9.0 new iOS bindings still have same problem. For example this bindings not support optional values

Alex009 commented 3 years ago

implemented in #100 and released in 0.9.1