Last active
January 9, 2016 17:20
-
-
Save tsuharesu/195ffa4c4d48aef8852e to your computer and use it in GitHub Desktop.
Kotlin ViewBinder for Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* View binder with nullable types support | |
*/ | |
class ViewBinder<M>(val function: (M) -> Unit) : ReadWriteProperty<Any, M> { | |
private var mValue: M? = null | |
override fun getValue(thisRef: Any, property: KProperty<*>): M { | |
return mValue as M | |
} | |
override fun setValue(thisRef: Any, property: KProperty<*>, value: M) { | |
mValue = value | |
function(value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment