androidbroadcast / ViewBindingPropertyDelegate

Make work with Android View Binding simpler
https://proandroiddev.com/make-android-view-binding-great-with-kotlin-b71dd9c87719
Apache License 2.0
1.43k stars 102 forks source link

checkIsMainThread #18

Closed InsaneDoggo closed 4 years ago

InsaneDoggo commented 4 years ago

Hi, nice lib. Isn't checkIsMainThread redundant? Android framework already has a lot of checks. You will got an exception if trying to touch views from another thread.

Consider next snippet:

binding.textView1.text = "blabla"
binding.textView3.text = "blabla"
binding.textView2.text = "blabla"

Looper.getMainLooper() contains synchronized block, seems like overhead for mentioned above case.

kirich1409 commented 4 years ago

Hi. It was maid to guarantee proper initialization and clearing of the property. It can be replaced with own synchronization inside ViewBindingPropertyDelegate. I’ll think about that

kirich1409 commented 4 years ago

Instead of your case I prefer to do next


with(binding) {
    textView1.text = "blabla"
    textView3.text = "blabla"
    textView2.text = "blabla"
}
InsaneDoggo commented 4 years ago

Instead of your case I prefer to do next

with(binding) {
    textView1.text = "blabla"
    textView3.text = "blabla"
    textView2.text = "blabla"
}

iirc compiler will unwrap it into my example (three independent calls)

kirich1409 commented 4 years ago

Will be changed in 1.2.3