var drawGravity: Int by InvalidateDelegate(Gravity.LEFT)
private inner class InvalidateDelegate<T>(t: T) : SetActionDelegate<T>(t, {
invalidate()
})
Last active
January 20, 2022 03:26
-
-
Save tiiime/8979ee70f828247c6d0d3920572b4238 to your computer and use it in GitHub Desktop.
delegate set operate, run specify action
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
open class SetActionDelegate<T>( | |
var t: T, | |
inline val action: () -> Unit | |
) { | |
operator fun getValue(any: Any, property: KProperty<*>): T = t | |
operator fun setValue(any: Any, property: KProperty<*>, i: T) { | |
if (t != i) { | |
t = i | |
action() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment