Kotlin / anko

Pleasant Android application development
Apache License 2.0
15.89k stars 1.28k forks source link

Feature: Data Binding #367

Open mykola-dev opened 7 years ago

mykola-dev commented 7 years ago

First of all thank you for this great library. Still it is not very convenient to bind real data to the views. It would be nice to have some api to be able to do at least one way binding:

val textProperty by ObservableProperty()
...
editText {
 bind(text, textProperty)
}
...
// and then set text like:
textProperty = "Hello Wrold!"

btw looks like these libs built on top of anko https://github.com/agrosner/KBinding https://github.com/BennyWang/KBinding https://github.com/LewisRhine/AnkoDataBindingTest

mykola-dev commented 7 years ago

I've been playing with Anko and done some working POC example: https://github.com/deviant-studio/anko-binding-poc/blob/master/app/src/main/java/ds/ankobindings/MainLayout.kt#L32

Miha-x64 commented 6 years ago

Should it really be a part of Anko? Here's standalone implementation: https://github.com/Miha-x64/reactive-properties#sample-usage-in-gui-application

jlberrocal commented 6 years ago

it should, because is a basic feature in android, so most probably most of developers could want to use it too

Miha-x64 commented 6 years ago

@jlberrocal I don't think Anko should re-implement observables, bindings, etc. It's better to find one good implementation and contribute to it.

jlberrocal commented 6 years ago

i'm already using a small variant of this implementation and until now has been working fine

Miha-x64 commented 6 years ago

It looks extremely immature. With a single commit. It's just an idea, a prototype. Which way do you unbind views?

jlberrocal commented 6 years ago

Dude did you read the link I share? There is explained how to unbind, anyway is not very common stop listening for changes, if you're going in data binding direction is because you need to check for changes, no because you could want to be binding and unbinding

championswimmer commented 6 years ago

This is a good and mature implementation https://github.com/lightningkite/kotlin-anko-observable