From ce00eabcbf70071a0869e753bdf4316045a6f7f7 Mon Sep 17 00:00:00 2001 From: Colin White Date: Mon, 18 Nov 2024 23:10:46 -0800 Subject: [PATCH] Fix ScaleDrawable and CrossfadeDrawable not respecting tint states. (#2704) * Fix ScaleDrawable and CrossfadeDrawable not respecting tint states. * Remove debug invalidateSelf. * Update API. --- coil-core/api/android/coil-core.api | 2 ++ .../androidMain/kotlin/coil3/size/ScaleDrawable.kt | 4 +++- .../kotlin/coil3/transition/CrossfadeDrawable.kt | 12 ++++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/coil-core/api/android/coil-core.api b/coil-core/api/android/coil-core.api index ba35b52612..e769c944ed 100644 --- a/coil-core/api/android/coil-core.api +++ b/coil-core/api/android/coil-core.api @@ -904,6 +904,7 @@ public final class coil3/size/ScaleDrawable : android/graphics/drawable/Drawable public final fun getScale ()Lcoil3/size/Scale; public fun invalidateDrawable (Landroid/graphics/drawable/Drawable;)V public fun isRunning ()Z + public fun isStateful ()Z public fun scheduleDrawable (Landroid/graphics/drawable/Drawable;Ljava/lang/Runnable;J)V public fun setAlpha (I)V public fun setColorFilter (Landroid/graphics/ColorFilter;)V @@ -1049,6 +1050,7 @@ public final class coil3/transition/CrossfadeDrawable : android/graphics/drawabl public final fun getStart ()Landroid/graphics/drawable/Drawable; public fun invalidateDrawable (Landroid/graphics/drawable/Drawable;)V public fun isRunning ()Z + public fun isStateful ()Z public fun registerAnimationCallback (Landroidx/vectordrawable/graphics/drawable/Animatable2Compat$AnimationCallback;)V public fun scheduleDrawable (Landroid/graphics/drawable/Drawable;Ljava/lang/Runnable;J)V public fun setAlpha (I)V diff --git a/coil-core/src/androidMain/kotlin/coil3/size/ScaleDrawable.kt b/coil-core/src/androidMain/kotlin/coil3/size/ScaleDrawable.kt index 93185a23fc..12b1acf9a8 100644 --- a/coil-core/src/androidMain/kotlin/coil3/size/ScaleDrawable.kt +++ b/coil-core/src/androidMain/kotlin/coil3/size/ScaleDrawable.kt @@ -81,10 +81,12 @@ class ScaleDrawable @JvmOverloads constructor( childScale = multiplier.toFloat() } - override fun onLevelChange(level: Int) = child.setLevel(level) + override fun isStateful() = child.isStateful override fun onStateChange(state: IntArray) = child.setState(state) + override fun onLevelChange(level: Int) = child.setLevel(level) + override fun getIntrinsicWidth() = child.intrinsicWidth override fun getIntrinsicHeight() = child.intrinsicHeight diff --git a/coil-core/src/androidMain/kotlin/coil3/transition/CrossfadeDrawable.kt b/coil-core/src/androidMain/kotlin/coil3/transition/CrossfadeDrawable.kt index 1a494d51dd..18d2bc360d 100644 --- a/coil-core/src/androidMain/kotlin/coil3/transition/CrossfadeDrawable.kt +++ b/coil-core/src/androidMain/kotlin/coil3/transition/CrossfadeDrawable.kt @@ -154,10 +154,8 @@ class CrossfadeDrawable @JvmOverloads constructor( end?.let { updateBounds(it, bounds) } } - override fun onLevelChange(level: Int): Boolean { - val startChanged = start?.setLevel(level) ?: false - val endChanged = end?.setLevel(level) ?: false - return startChanged || endChanged + override fun isStateful(): Boolean { + return (start?.isStateful ?: false) || (end?.isStateful ?: false) } override fun onStateChange(state: IntArray): Boolean { @@ -166,6 +164,12 @@ class CrossfadeDrawable @JvmOverloads constructor( return startChanged || endChanged } + override fun onLevelChange(level: Int): Boolean { + val startChanged = start?.setLevel(level) ?: false + val endChanged = end?.setLevel(level) ?: false + return startChanged || endChanged + } + override fun getIntrinsicWidth() = intrinsicWidth override fun getIntrinsicHeight() = intrinsicHeight