kotlin-delegate

Kotlin delegate property causes a preview rendering error in Android Studio

半世苍凉 提交于 2021-02-20 19:08:01
问题 I have created a custom property dedicated to holding properties of the view that require invalidate() call for one of my projects: class InvalidatingProperty<T>(private var _value: T) { operator fun getValue(thisRef: View, property: KProperty<*>): T { return _value } operator fun setValue(thisRef: View, property: KProperty<*>, value: T) { _value = value thisRef.invalidate() } } In another project, I wanted to reuse some of my previous work, so i copied the views and their dependencies,

Kotlin delegate property causes a preview rendering error in Android Studio

旧时模样 提交于 2021-02-20 19:07:59
问题 I have created a custom property dedicated to holding properties of the view that require invalidate() call for one of my projects: class InvalidatingProperty<T>(private var _value: T) { operator fun getValue(thisRef: View, property: KProperty<*>): T { return _value } operator fun setValue(thisRef: View, property: KProperty<*>, value: T) { _value = value thisRef.invalidate() } } In another project, I wanted to reuse some of my previous work, so i copied the views and their dependencies,

How to combine kotlin delegated property: observable, vetoable, and “by map”?

我只是一个虾纸丫 提交于 2020-05-13 05:05:26
问题 I'm trying to combine delegates/observable with vetoable (which isn't a problem after looking at the source kotlin.properties.Delegates.kt), but things got hairy when trying to also store the properties in a map. Or in other words, how to combine these three: var k1: Int by Delegates.observable(0) { property, oldValue, newValue -> println("Hi from k1 observer") } var k2:Int by Delegates.vetoable(0) {property, oldValue, newValue -> println("Hi from k2 more-than check") oldValue > newValue }

How to combine kotlin delegated property: observable, vetoable, and “by map”?

淺唱寂寞╮ 提交于 2020-05-13 05:05:16
问题 I'm trying to combine delegates/observable with vetoable (which isn't a problem after looking at the source kotlin.properties.Delegates.kt), but things got hairy when trying to also store the properties in a map. Or in other words, how to combine these three: var k1: Int by Delegates.observable(0) { property, oldValue, newValue -> println("Hi from k1 observer") } var k2:Int by Delegates.vetoable(0) {property, oldValue, newValue -> println("Hi from k2 more-than check") oldValue > newValue }