From 88be33c182a1d500278845f620379a44bed62fc4 Mon Sep 17 00:00:00 2001 From: Colin White Date: Mon, 18 Nov 2024 01:34:00 -0800 Subject: [PATCH 01/22] Fix FakeImage constructor parameter ordering. # Conflicts: # coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt # coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt --- coil-test/api/android/coil-test.api | 4 +++- coil-test/api/coil-test.klib.api | 1 + coil-test/api/jvm/coil-test.api | 4 +++- .../kotlin/coil3/test/FakeImage.android.kt | 12 +++++++++++- .../src/commonMain/kotlin/coil3/test/FakeImage.kt | 15 +++++++++++++-- .../kotlin/coil3/test/FakeImage.nonAndroid.kt | 12 +++++++++++- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/coil-test/api/android/coil-test.api b/coil-test/api/android/coil-test.api index 420123ce51..13d5dac6da 100644 --- a/coil-test/api/android/coil-test.api +++ b/coil-test/api/android/coil-test.api @@ -1,6 +1,8 @@ public final class coil3/test/FakeImage : coil3/Image { public fun ()V - public fun (IIJZI)V + public fun (IIIJZ)V + public synthetic fun (IIIJZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (IIJZI)V public synthetic fun (IIJZIILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun draw (Landroid/graphics/Canvas;)V public fun equals (Ljava/lang/Object;)Z diff --git a/coil-test/api/coil-test.klib.api b/coil-test/api/coil-test.klib.api index 4846c3f64a..3f98b70fab 100644 --- a/coil-test/api/coil-test.klib.api +++ b/coil-test/api/coil-test.klib.api @@ -7,6 +7,7 @@ // Library unique name: final class coil3.test/FakeImage : coil3/Image { // coil3.test/FakeImage|null[0] + constructor (kotlin/Int = ..., kotlin/Int = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin/Boolean = ...) // coil3.test/FakeImage.|(kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Boolean){}[0] constructor (kotlin/Int = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin/Boolean = ..., kotlin/Int = ...) // coil3.test/FakeImage.|(kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Boolean;kotlin.Int){}[0] final val color // coil3.test/FakeImage.color|{}color[0] diff --git a/coil-test/api/jvm/coil-test.api b/coil-test/api/jvm/coil-test.api index 3a32b023ca..056f99a7ff 100644 --- a/coil-test/api/jvm/coil-test.api +++ b/coil-test/api/jvm/coil-test.api @@ -1,6 +1,8 @@ public final class coil3/test/FakeImage : coil3/Image { public fun ()V - public fun (IIJZI)V + public fun (IIIJZ)V + public synthetic fun (IIIJZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (IIJZI)V public synthetic fun (IIJZIILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun draw (Lorg/jetbrains/skia/Canvas;)V public fun equals (Ljava/lang/Object;)Z diff --git a/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt b/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt index e8bda40fa3..c6955c58da 100644 --- a/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt +++ b/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt @@ -7,12 +7,22 @@ import coil3.annotation.Poko @Poko actual class FakeImage actual constructor( + actual val color: Int, actual override val width: Int, actual override val height: Int, actual override val size: Long, actual override val shareable: Boolean, - actual val color: Int, ) : Image { + + @Deprecated("Kept for binary compatibility.", level = DeprecationLevel.HIDDEN) + actual constructor( + width: Int, + height: Int, + size: Long, + shareable: Boolean, + color: Int, + ) : this(color, width, height, size, shareable) + private var lazyPaint: Paint? = null actual override fun draw(canvas: Canvas) { diff --git a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt index 24956a809e..caf9d9fd9a 100644 --- a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt +++ b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt @@ -8,16 +8,27 @@ import coil3.test.internal.Black * A simple [Image] that draws a 100x100 black square by default. */ expect class FakeImage( + color: Int = Black, width: Int = 100, height: Int = 100, size: Long = 4L * width * height, shareable: Boolean = true, - color: Int = Black, ) : Image { + + @Deprecated("Kept for binary compatibility.", level = DeprecationLevel.HIDDEN) + constructor( + width: Int = 100, + height: Int = 100, + size: Long = 4L * width * height, + shareable: Boolean = true, + color: Int = Black, + ) + + val color: Int override val width: Int override val height: Int override val size: Long override val shareable: Boolean - val color: Int + override fun draw(canvas: Canvas) } diff --git a/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt b/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt index cbe1539c10..a0c230c54c 100644 --- a/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt +++ b/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt @@ -8,12 +8,22 @@ import org.jetbrains.skia.Rect @Poko actual class FakeImage actual constructor( + actual val color: Int, actual override val width: Int, actual override val height: Int, actual override val size: Long, actual override val shareable: Boolean, - actual val color: Int, ) : Image { + + @Deprecated("Kept for binary compatibility.", level = DeprecationLevel.HIDDEN) + actual constructor( + width: Int, + height: Int, + size: Long, + shareable: Boolean, + color: Int, + ) : this(color, width, height, size, shareable) + private var lazyPaint: Paint? = null private var lazyRect: Rect? = null From fe6f2949adb785e0675b3e423bb074dba1a19f7a Mon Sep 17 00:00:00 2001 From: Colin White Date: Mon, 18 Nov 2024 01:43:35 -0800 Subject: [PATCH 02/22] Fix constructor resolution. --- coil-test/api/coil-test.klib.api | 2 +- coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/coil-test/api/coil-test.klib.api b/coil-test/api/coil-test.klib.api index 3f98b70fab..8fbe61240a 100644 --- a/coil-test/api/coil-test.klib.api +++ b/coil-test/api/coil-test.klib.api @@ -8,7 +8,7 @@ // Library unique name: final class coil3.test/FakeImage : coil3/Image { // coil3.test/FakeImage|null[0] constructor (kotlin/Int = ..., kotlin/Int = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin/Boolean = ...) // coil3.test/FakeImage.|(kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Boolean){}[0] - constructor (kotlin/Int = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin/Boolean = ..., kotlin/Int = ...) // coil3.test/FakeImage.|(kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Boolean;kotlin.Int){}[0] + constructor (kotlin/Int, kotlin/Int, kotlin/Long, kotlin/Boolean, kotlin/Int = ...) // coil3.test/FakeImage.|(kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Boolean;kotlin.Int){}[0] final val color // coil3.test/FakeImage.color|{}color[0] final fun (): kotlin/Int // coil3.test/FakeImage.color.|(){}[0] diff --git a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt index caf9d9fd9a..9daad1ecd2 100644 --- a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt +++ b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt @@ -17,10 +17,10 @@ expect class FakeImage( @Deprecated("Kept for binary compatibility.", level = DeprecationLevel.HIDDEN) constructor( - width: Int = 100, - height: Int = 100, - size: Long = 4L * width * height, - shareable: Boolean = true, + width: Int, + height: Int, + size: Long, + shareable: Boolean, color: Int = Black, ) From e98e2c1e08e6b90cf33987d34a6cba1f3b668ad9 Mon Sep 17 00:00:00 2001 From: Colin White Date: Mon, 18 Nov 2024 18:00:35 -0800 Subject: [PATCH 03/22] Revert. --- coil-test/api/android/coil-test.api | 4 +--- coil-test/api/coil-test.klib.api | 3 +-- coil-test/api/jvm/coil-test.api | 4 +--- .../kotlin/coil3/test/FakeImage.android.kt | 12 +----------- .../src/commonMain/kotlin/coil3/test/FakeImage.kt | 14 ++------------ .../kotlin/coil3/test/FakeImage.nonAndroid.kt | 12 +----------- 6 files changed, 7 insertions(+), 42 deletions(-) diff --git a/coil-test/api/android/coil-test.api b/coil-test/api/android/coil-test.api index 13d5dac6da..420123ce51 100644 --- a/coil-test/api/android/coil-test.api +++ b/coil-test/api/android/coil-test.api @@ -1,8 +1,6 @@ public final class coil3/test/FakeImage : coil3/Image { public fun ()V - public fun (IIIJZ)V - public synthetic fun (IIIJZILkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun (IIJZI)V + public fun (IIJZI)V public synthetic fun (IIJZIILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun draw (Landroid/graphics/Canvas;)V public fun equals (Ljava/lang/Object;)Z diff --git a/coil-test/api/coil-test.klib.api b/coil-test/api/coil-test.klib.api index 8fbe61240a..4846c3f64a 100644 --- a/coil-test/api/coil-test.klib.api +++ b/coil-test/api/coil-test.klib.api @@ -7,8 +7,7 @@ // Library unique name: final class coil3.test/FakeImage : coil3/Image { // coil3.test/FakeImage|null[0] - constructor (kotlin/Int = ..., kotlin/Int = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin/Boolean = ...) // coil3.test/FakeImage.|(kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Boolean){}[0] - constructor (kotlin/Int, kotlin/Int, kotlin/Long, kotlin/Boolean, kotlin/Int = ...) // coil3.test/FakeImage.|(kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Boolean;kotlin.Int){}[0] + constructor (kotlin/Int = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin/Boolean = ..., kotlin/Int = ...) // coil3.test/FakeImage.|(kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Boolean;kotlin.Int){}[0] final val color // coil3.test/FakeImage.color|{}color[0] final fun (): kotlin/Int // coil3.test/FakeImage.color.|(){}[0] diff --git a/coil-test/api/jvm/coil-test.api b/coil-test/api/jvm/coil-test.api index 056f99a7ff..3a32b023ca 100644 --- a/coil-test/api/jvm/coil-test.api +++ b/coil-test/api/jvm/coil-test.api @@ -1,8 +1,6 @@ public final class coil3/test/FakeImage : coil3/Image { public fun ()V - public fun (IIIJZ)V - public synthetic fun (IIIJZILkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun (IIJZI)V + public fun (IIJZI)V public synthetic fun (IIJZIILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun draw (Lorg/jetbrains/skia/Canvas;)V public fun equals (Ljava/lang/Object;)Z diff --git a/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt b/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt index c6955c58da..e8bda40fa3 100644 --- a/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt +++ b/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt @@ -7,22 +7,12 @@ import coil3.annotation.Poko @Poko actual class FakeImage actual constructor( - actual val color: Int, actual override val width: Int, actual override val height: Int, actual override val size: Long, actual override val shareable: Boolean, + actual val color: Int, ) : Image { - - @Deprecated("Kept for binary compatibility.", level = DeprecationLevel.HIDDEN) - actual constructor( - width: Int, - height: Int, - size: Long, - shareable: Boolean, - color: Int, - ) : this(color, width, height, size, shareable) - private var lazyPaint: Paint? = null actual override fun draw(canvas: Canvas) { diff --git a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt index 9daad1ecd2..309e937bc5 100644 --- a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt +++ b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt @@ -8,27 +8,17 @@ import coil3.test.internal.Black * A simple [Image] that draws a 100x100 black square by default. */ expect class FakeImage( - color: Int = Black, width: Int = 100, height: Int = 100, size: Long = 4L * width * height, shareable: Boolean = true, + color: Int = Black, ) : Image { - - @Deprecated("Kept for binary compatibility.", level = DeprecationLevel.HIDDEN) - constructor( - width: Int, - height: Int, - size: Long, - shareable: Boolean, - color: Int = Black, - ) - - val color: Int override val width: Int override val height: Int override val size: Long override val shareable: Boolean + val color: Int override fun draw(canvas: Canvas) } diff --git a/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt b/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt index a0c230c54c..cbe1539c10 100644 --- a/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt +++ b/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt @@ -8,22 +8,12 @@ import org.jetbrains.skia.Rect @Poko actual class FakeImage actual constructor( - actual val color: Int, actual override val width: Int, actual override val height: Int, actual override val size: Long, actual override val shareable: Boolean, + actual val color: Int, ) : Image { - - @Deprecated("Kept for binary compatibility.", level = DeprecationLevel.HIDDEN) - actual constructor( - width: Int, - height: Int, - size: Long, - shareable: Boolean, - color: Int, - ) : this(color, width, height, size, shareable) - private var lazyPaint: Paint? = null private var lazyRect: Rect? = null From a832d742135d6c39c05a7865fc64ca2be86b6488 Mon Sep 17 00:00:00 2001 From: Colin White Date: Mon, 18 Nov 2024 18:54:28 -0800 Subject: [PATCH 04/22] Replace FakeImage with ColorImage. # Conflicts: # internal/test-compose-screenshot/src/screenshotTest/java/coil3/composescreenshot/PreviewScreenshots.kt --- coil-test/api/android/coil-test.api | 25 +++++++++++ coil-test/api/coil-test.klib.api | 35 +++++++++++++++ coil-test/api/jvm/coil-test.api | 25 +++++++++++ .../kotlin/coil3/test/ColorImage.android.kt | 39 ++++++++++++++++ .../kotlin/coil3/test/FakeImage.android.kt | 6 ++- .../kotlin/coil3/test/ColorImage.kt | 34 ++++++++++++++ .../commonMain/kotlin/coil3/test/FakeImage.kt | 8 +++- .../kotlin/coil3/test/internal/utils.kt | 3 -- .../coil3/test/ColorImage.nonAndroid.kt | 45 +++++++++++++++++++ .../kotlin/coil3/test/FakeImage.nonAndroid.kt | 5 +++ .../composescreenshot/PreviewScreenshots.kt | 6 +-- .../java/coil3/paparazzi/PaparazziTest.kt | 10 ++--- .../roborazzi/RoborazziComposeTestAndroid.kt | 8 ++-- .../coil3/roborazzi/RoborazziViewTest.kt | 6 +-- .../roborazzi/RoborazziComposeTestJvm.kt | 15 ++----- 15 files changed, 238 insertions(+), 32 deletions(-) create mode 100644 coil-test/src/androidMain/kotlin/coil3/test/ColorImage.android.kt create mode 100644 coil-test/src/commonMain/kotlin/coil3/test/ColorImage.kt create mode 100644 coil-test/src/nonAndroidMain/kotlin/coil3/test/ColorImage.nonAndroid.kt diff --git a/coil-test/api/android/coil-test.api b/coil-test/api/android/coil-test.api index 420123ce51..bf4d09ae6a 100644 --- a/coil-test/api/android/coil-test.api +++ b/coil-test/api/android/coil-test.api @@ -1,3 +1,28 @@ +public final class coil3/test/ColorImage : coil3/Image { + public static final field Black I + public static final field Blue I + public static final field Companion Lcoil3/test/ColorImage$Companion; + public static final field Green I + public static final field Red I + public static final field Transparent I + public static final field White I + public fun ()V + public fun (IIIJZ)V + public synthetic fun (IIIJZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun draw (Landroid/graphics/Canvas;)V + public fun equals (Ljava/lang/Object;)Z + public final fun getColor ()I + public fun getHeight ()I + public fun getShareable ()Z + public fun getSize ()J + public fun getWidth ()I + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class coil3/test/ColorImage$Companion { +} + public final class coil3/test/FakeImage : coil3/Image { public fun ()V public fun (IIJZI)V diff --git a/coil-test/api/coil-test.klib.api b/coil-test/api/coil-test.klib.api index 4846c3f64a..c45a4de053 100644 --- a/coil-test/api/coil-test.klib.api +++ b/coil-test/api/coil-test.klib.api @@ -6,6 +6,41 @@ // - Show declarations: true // Library unique name: +final class coil3.test/ColorImage : coil3/Image { // coil3.test/ColorImage|null[0] + constructor (kotlin/Int = ..., kotlin/Int = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin/Boolean = ...) // coil3.test/ColorImage.|(kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Boolean){}[0] + + final val color // coil3.test/ColorImage.color|{}color[0] + final fun (): kotlin/Int // coil3.test/ColorImage.color.|(){}[0] + final val height // coil3.test/ColorImage.height|{}height[0] + final fun (): kotlin/Int // coil3.test/ColorImage.height.|(){}[0] + final val shareable // coil3.test/ColorImage.shareable|{}shareable[0] + final fun (): kotlin/Boolean // coil3.test/ColorImage.shareable.|(){}[0] + final val size // coil3.test/ColorImage.size|{}size[0] + final fun (): kotlin/Long // coil3.test/ColorImage.size.|(){}[0] + final val width // coil3.test/ColorImage.width|{}width[0] + final fun (): kotlin/Int // coil3.test/ColorImage.width.|(){}[0] + + final fun draw(org.jetbrains.skia/Canvas) // coil3.test/ColorImage.draw|draw(org.jetbrains.skia.Canvas){}[0] + final fun equals(kotlin/Any?): kotlin/Boolean // coil3.test/ColorImage.equals|equals(kotlin.Any?){}[0] + final fun hashCode(): kotlin/Int // coil3.test/ColorImage.hashCode|hashCode(){}[0] + final fun toString(): kotlin/String // coil3.test/ColorImage.toString|toString(){}[0] + + final object Companion { // coil3.test/ColorImage.Companion|null[0] + final const val Black // coil3.test/ColorImage.Companion.Black|{}Black[0] + final fun (): kotlin/Int // coil3.test/ColorImage.Companion.Black.|(){}[0] + final const val Blue // coil3.test/ColorImage.Companion.Blue|{}Blue[0] + final fun (): kotlin/Int // coil3.test/ColorImage.Companion.Blue.|(){}[0] + final const val Green // coil3.test/ColorImage.Companion.Green|{}Green[0] + final fun (): kotlin/Int // coil3.test/ColorImage.Companion.Green.|(){}[0] + final const val Red // coil3.test/ColorImage.Companion.Red|{}Red[0] + final fun (): kotlin/Int // coil3.test/ColorImage.Companion.Red.|(){}[0] + final const val Transparent // coil3.test/ColorImage.Companion.Transparent|{}Transparent[0] + final fun (): kotlin/Int // coil3.test/ColorImage.Companion.Transparent.|(){}[0] + final const val White // coil3.test/ColorImage.Companion.White|{}White[0] + final fun (): kotlin/Int // coil3.test/ColorImage.Companion.White.|(){}[0] + } +} + final class coil3.test/FakeImage : coil3/Image { // coil3.test/FakeImage|null[0] constructor (kotlin/Int = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin/Boolean = ..., kotlin/Int = ...) // coil3.test/FakeImage.|(kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Boolean;kotlin.Int){}[0] diff --git a/coil-test/api/jvm/coil-test.api b/coil-test/api/jvm/coil-test.api index 3a32b023ca..3073d10e7d 100644 --- a/coil-test/api/jvm/coil-test.api +++ b/coil-test/api/jvm/coil-test.api @@ -1,3 +1,28 @@ +public final class coil3/test/ColorImage : coil3/Image { + public static final field Black I + public static final field Blue I + public static final field Companion Lcoil3/test/ColorImage$Companion; + public static final field Green I + public static final field Red I + public static final field Transparent I + public static final field White I + public fun ()V + public fun (IIIJZ)V + public synthetic fun (IIIJZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun draw (Lorg/jetbrains/skia/Canvas;)V + public fun equals (Ljava/lang/Object;)Z + public final fun getColor ()I + public fun getHeight ()I + public fun getShareable ()Z + public fun getSize ()J + public fun getWidth ()I + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class coil3/test/ColorImage$Companion { +} + public final class coil3/test/FakeImage : coil3/Image { public fun ()V public fun (IIJZI)V diff --git a/coil-test/src/androidMain/kotlin/coil3/test/ColorImage.android.kt b/coil-test/src/androidMain/kotlin/coil3/test/ColorImage.android.kt new file mode 100644 index 0000000000..7b8b7b274b --- /dev/null +++ b/coil-test/src/androidMain/kotlin/coil3/test/ColorImage.android.kt @@ -0,0 +1,39 @@ +package coil3.test + +import android.graphics.Paint +import coil3.Canvas +import coil3.Image +import coil3.annotation.Poko + +@Poko +actual class ColorImage actual constructor( + actual val color: Int, + actual override val width: Int, + actual override val height: Int, + actual override val size: Long, + actual override val shareable: Boolean, +) : Image { + private var lazyPaint: Paint? = null + + actual override fun draw(canvas: Canvas) { + val paint = lazyPaint ?: run { + Paint() + .apply { color = this@ColorImage.color } + .also { lazyPaint = it } + } + if (width >= 0 && height >= 0) { + canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), paint) + } else { + canvas.drawPaint(paint) + } + } + + actual companion object { + actual const val Black = 0xFF000000.toInt() + actual const val White = 0xFFFFFFFF.toInt() + actual const val Transparent = 0x00000000.toInt() + actual const val Red = 0xFFFF0000.toInt() + actual const val Green = 0xFF00FF00.toInt() + actual const val Blue = 0xFF0000FF.toInt() + } +} diff --git a/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt b/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt index e8bda40fa3..106b893f4c 100644 --- a/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt +++ b/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt @@ -5,6 +5,11 @@ import coil3.Canvas import coil3.Image import coil3.annotation.Poko +@Deprecated( + message = "This use case is better fulfilled by ColorImage.", + replaceWith = ReplaceWith("ColorImage", ["coil3.test.ColorImage"]), + level = DeprecationLevel.WARNING, +) @Poko actual class FakeImage actual constructor( actual override val width: Int, @@ -21,7 +26,6 @@ actual class FakeImage actual constructor( .apply { color = this@FakeImage.color } .also { lazyPaint = it } } - canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), paint) } } diff --git a/coil-test/src/commonMain/kotlin/coil3/test/ColorImage.kt b/coil-test/src/commonMain/kotlin/coil3/test/ColorImage.kt new file mode 100644 index 0000000000..201dfb4d6d --- /dev/null +++ b/coil-test/src/commonMain/kotlin/coil3/test/ColorImage.kt @@ -0,0 +1,34 @@ +package coil3.test + +import coil3.Canvas +import coil3.Image + +/** + * An image that draws a [color]. + * + * By default the image has no intrinsic size and will fill its canvas. Set [width] and [height] + * to a positive value to draw a square with those dimensions. + */ +expect class ColorImage( + color: Int = Black, + width: Int = -1, + height: Int = -1, + size: Long = 0, + shareable: Boolean = true, +) : Image { + val color: Int + override val size: Long + override val width: Int + override val height: Int + override val shareable: Boolean + override fun draw(canvas: Canvas) + + companion object { + val Black: Int + val White: Int + val Transparent: Int + val Red: Int + val Green: Int + val Blue: Int + } +} diff --git a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt index 309e937bc5..4a3ccbc667 100644 --- a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt +++ b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt @@ -2,11 +2,16 @@ package coil3.test import coil3.Canvas import coil3.Image -import coil3.test.internal.Black +import coil3.test.ColorImage.Companion.Black /** * A simple [Image] that draws a 100x100 black square by default. */ +@Deprecated( + message = "This use case is better fulfilled by ColorImage.", + replaceWith = ReplaceWith("ColorImage(color, width, height, size, shareable)", ["coil3.test.ColorImage"]), + level = DeprecationLevel.WARNING, +) expect class FakeImage( width: Int = 100, height: Int = 100, @@ -19,6 +24,5 @@ expect class FakeImage( override val size: Long override val shareable: Boolean val color: Int - override fun draw(canvas: Canvas) } diff --git a/coil-test/src/commonMain/kotlin/coil3/test/internal/utils.kt b/coil-test/src/commonMain/kotlin/coil3/test/internal/utils.kt index f2f2b993b2..3a67c25e5d 100644 --- a/coil-test/src/commonMain/kotlin/coil3/test/internal/utils.kt +++ b/coil-test/src/commonMain/kotlin/coil3/test/internal/utils.kt @@ -13,6 +13,3 @@ internal fun imageResultOf( request = request, dataSource = DataSource.MEMORY, ) - -// Format: 0xALPHA_RED_GREEN_BLUE -internal const val Black = 0xFF_00_00_00.toInt() diff --git a/coil-test/src/nonAndroidMain/kotlin/coil3/test/ColorImage.nonAndroid.kt b/coil-test/src/nonAndroidMain/kotlin/coil3/test/ColorImage.nonAndroid.kt new file mode 100644 index 0000000000..d580027851 --- /dev/null +++ b/coil-test/src/nonAndroidMain/kotlin/coil3/test/ColorImage.nonAndroid.kt @@ -0,0 +1,45 @@ +package coil3.test + +import coil3.Canvas +import coil3.Image +import coil3.annotation.Poko +import org.jetbrains.skia.Paint +import org.jetbrains.skia.Rect + +@Poko +actual class ColorImage actual constructor( + actual val color: Int, + actual override val width: Int, + actual override val height: Int, + actual override val size: Long, + actual override val shareable: Boolean, +) : Image { + private var lazyPaint: Paint? = null + private var lazyRect: Rect? = null + + actual override fun draw(canvas: Canvas) { + val paint = lazyPaint ?: run { + Paint() + .apply { color = this@ColorImage.color } + .also { lazyPaint = it } + } + if (width >= 0 && height >= 0) { + val rect = lazyRect ?: run { + Rect.makeWH(width.toFloat(), height.toFloat()) + .also { lazyRect = it } + } + canvas.drawRect(rect, paint) + } else { + canvas.drawPaint(paint) + } + } + + actual companion object { + actual const val Black = 0xFF000000.toInt() + actual const val White = 0xFFFFFFFF.toInt() + actual const val Transparent = 0x00000000.toInt() + actual const val Red = 0xFFFF0000.toInt() + actual const val Green = 0xFF00FF00.toInt() + actual const val Blue = 0xFF0000FF.toInt() + } +} diff --git a/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt b/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt index cbe1539c10..5247935f58 100644 --- a/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt +++ b/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt @@ -6,6 +6,11 @@ import coil3.annotation.Poko import org.jetbrains.skia.Paint import org.jetbrains.skia.Rect +@Deprecated( + message = "This use case is better fulfilled by ColorImage.", + replaceWith = ReplaceWith("ColorImage(color, width, height, size, shareable)", ["coil3.test.ColorImage"]), + level = DeprecationLevel.WARNING, +) @Poko actual class FakeImage actual constructor( actual override val width: Int, diff --git a/internal/test-compose-screenshot/src/screenshotTest/java/coil3/composescreenshot/PreviewScreenshots.kt b/internal/test-compose-screenshot/src/screenshotTest/java/coil3/composescreenshot/PreviewScreenshots.kt index 7091b78c62..cfa55358fd 100644 --- a/internal/test-compose-screenshot/src/screenshotTest/java/coil3/composescreenshot/PreviewScreenshots.kt +++ b/internal/test-compose-screenshot/src/screenshotTest/java/coil3/composescreenshot/PreviewScreenshots.kt @@ -1,6 +1,5 @@ package coil3.composescreenshot -import android.graphics.Color import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize @@ -19,13 +18,14 @@ import coil3.compose.AsyncImage import coil3.compose.AsyncImagePreviewHandler import coil3.compose.LocalAsyncImagePreviewHandler import coil3.compose.rememberAsyncImagePainter -import coil3.test.FakeImage +import coil3.test.ColorImage +import coil3.test.ColorImage.Companion.Red import coil3.test.composescreenshot.R @OptIn(ExperimentalCoilApi::class) class PreviewScreenshots { private val previewHandler = AsyncImagePreviewHandler { - FakeImage(color = Color.RED) + ColorImage(Red, width = 100, height = 100) } @Preview( diff --git a/internal/test-paparazzi/src/test/java/coil3/paparazzi/PaparazziTest.kt b/internal/test-paparazzi/src/test/java/coil3/paparazzi/PaparazziTest.kt index edd5320cf5..21965950f1 100644 --- a/internal/test-paparazzi/src/test/java/coil3/paparazzi/PaparazziTest.kt +++ b/internal/test-paparazzi/src/test/java/coil3/paparazzi/PaparazziTest.kt @@ -1,6 +1,5 @@ package coil3.paparazzi -import android.graphics.Color import android.widget.ImageView import androidx.compose.foundation.Image import androidx.compose.foundation.layout.fillMaxSize @@ -14,7 +13,8 @@ import coil3.compose.rememberAsyncImagePainter import coil3.decode.ImageSource import coil3.request.ImageRequest import coil3.request.target -import coil3.test.FakeImage +import coil3.test.ColorImage +import coil3.test.ColorImage.Companion.Red import coil3.test.FakeImageLoaderEngine import kotlin.test.assertTrue import okio.Buffer @@ -38,7 +38,7 @@ class PaparazziTest { fun imageView() { val url = "https://www.example.com/image.jpg" val engine = FakeImageLoaderEngine.Builder() - .intercept(url, FakeImage(color = Color.RED)) + .intercept(url, ColorImage(Red, width = 100, height = 100)) .build() val imageLoader = ImageLoader.Builder(paparazzi.context) .components { add(engine) } @@ -60,7 +60,7 @@ class PaparazziTest { fun asyncImage() { val url = "https://www.example.com/image.jpg" val engine = FakeImageLoaderEngine.Builder() - .intercept(url, FakeImage(color = Color.RED)) + .intercept(url, ColorImage(Red, width = 100, height = 100)) .build() val imageLoader = ImageLoader.Builder(paparazzi.context) .components { add(engine) } @@ -81,7 +81,7 @@ class PaparazziTest { fun rememberAsyncImagePainter() { val url = "https://www.example.com/image.jpg" val engine = FakeImageLoaderEngine.Builder() - .intercept(url, FakeImage(color = Color.RED)) + .intercept(url, ColorImage(Red, width = 100, height = 100)) .build() val imageLoader = ImageLoader.Builder(paparazzi.context) .components { add(engine) } diff --git a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt index 26dbead0c0..bf08e8924d 100644 --- a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt +++ b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt @@ -1,6 +1,5 @@ package coil3.roborazzi -import android.graphics.Color import androidx.compose.foundation.Image import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.ui.Modifier @@ -10,7 +9,8 @@ import androidx.compose.ui.test.onRoot import coil3.ImageLoader import coil3.compose.AsyncImage import coil3.compose.rememberAsyncImagePainter -import coil3.test.FakeImage +import coil3.test.ColorImage +import coil3.test.ColorImage.Companion.Red import coil3.test.FakeImageLoaderEngine import coil3.test.utils.ComposeTestActivity import coil3.test.utils.RobolectricTest @@ -39,7 +39,7 @@ class RoborazziComposeTestAndroid : RobolectricTest() { fun asyncImage() { val url = "https://www.example.com/image.jpg" val engine = FakeImageLoaderEngine.Builder() - .intercept(url, FakeImage(color = Color.RED)) + .intercept(url, ColorImage(Red, width = 100, height = 100)) .build() val imageLoader = ImageLoader.Builder(composeTestRule.activity) .components { add(engine) } @@ -60,7 +60,7 @@ class RoborazziComposeTestAndroid : RobolectricTest() { fun rememberAsyncImagePainter() { val url = "https://www.example.com/image.jpg" val engine = FakeImageLoaderEngine.Builder() - .intercept(url, FakeImage(color = Color.RED)) + .intercept(url, ColorImage(Red, width = 100, height = 100)) .build() val imageLoader = ImageLoader.Builder(composeTestRule.activity) .components { add(engine) } diff --git a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt index 9487e9cfcb..59f1e19c12 100644 --- a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt +++ b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt @@ -1,6 +1,5 @@ package coil3.roborazzi -import android.graphics.Color import android.widget.ImageView import androidx.test.espresso.Espresso.onView import androidx.test.espresso.matcher.ViewMatchers.isRoot @@ -8,7 +7,8 @@ import androidx.test.ext.junit.rules.activityScenarioRule import coil3.ImageLoader import coil3.request.ImageRequest import coil3.request.target -import coil3.test.FakeImage +import coil3.test.ColorImage +import coil3.test.ColorImage.Companion.Red import coil3.test.FakeImageLoaderEngine import coil3.test.utils.RobolectricTest import coil3.test.utils.ViewTestActivity @@ -37,7 +37,7 @@ class RoborazziViewTest : RobolectricTest() { fun imageView() { val url = "https://www.example.com/image.jpg" val engine = FakeImageLoaderEngine.Builder() - .intercept(url, FakeImage(color = Color.RED)) + .intercept(url, ColorImage(Red, width = 100, height = 100)) .build() val activity = activityRule.scenario.activity val imageLoader = ImageLoader.Builder(activity) diff --git a/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt b/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt index 6353ef2384..1f9130d0a0 100644 --- a/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt +++ b/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt @@ -14,7 +14,8 @@ import coil3.PlatformContext import coil3.asImage import coil3.compose.AsyncImage import coil3.compose.rememberAsyncImagePainter -import coil3.test.FakeImage +import coil3.test.ColorImage +import coil3.test.ColorImage.Companion.Red import coil3.test.FakeImageLoaderEngine import coil3.toBitmap import io.github.takahirom.roborazzi.captureRoboImage @@ -26,11 +27,7 @@ class RoborazziComposeTestJvm { @Test fun asyncImage() { val url = "https://www.example.com/image.jpg" - val image = FakeImage( - width = 100, - height = 100, - color = org.jetbrains.skia.Color.RED, - ) + val image = ColorImage(Red, width = 100, height = 100) val engine = FakeImageLoaderEngine.Builder() .intercept(url, image) @@ -60,11 +57,7 @@ class RoborazziComposeTestJvm { @Test fun rememberAsyncImagePainter() { val url = "https://www.example.com/image.jpg" - val image = FakeImage( - width = 100, - height = 100, - color = org.jetbrains.skia.Color.RED, - ) + val image = ColorImage(Red, width = 100, height = 100) val engine = FakeImageLoaderEngine.Builder() .intercept(url, image.toBitmap().asImage()) .build() From 11a341c38c3c057085be8a96993924b316495cd1 Mon Sep 17 00:00:00 2001 From: Colin White Date: Mon, 18 Nov 2024 20:45:07 -0800 Subject: [PATCH 05/22] Replace usages. --- .../kotlin/coil3/test/FakeImageLoaderEngineTest.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/coil-test/src/commonTest/kotlin/coil3/test/FakeImageLoaderEngineTest.kt b/coil-test/src/commonTest/kotlin/coil3/test/FakeImageLoaderEngineTest.kt index 4d7c97b558..86a17305ff 100644 --- a/coil-test/src/commonTest/kotlin/coil3/test/FakeImageLoaderEngineTest.kt +++ b/coil-test/src/commonTest/kotlin/coil3/test/FakeImageLoaderEngineTest.kt @@ -18,7 +18,7 @@ class FakeImageLoaderEngineTest : RobolectricTest() { @Test fun extraData() = runTest { val url = "https://www.example.com/image.jpg" - val image = FakeImage() + val image = ColorImage() val engine = FakeImageLoaderEngine.Builder() .intercept(url, image) .build() @@ -39,9 +39,9 @@ class FakeImageLoaderEngineTest : RobolectricTest() { @Test fun predicateData() = runTest { val url = "https://www.example.com/image.jpg" - val image = FakeImage() + val image = ColorImage() val engine = FakeImageLoaderEngine.Builder() - .intercept("different_string", FakeImage()) + .intercept("different_string", ColorImage()) .intercept({ it is String && it == url }, image) .build() val imageLoader = ImageLoader.Builder(context) @@ -61,9 +61,9 @@ class FakeImageLoaderEngineTest : RobolectricTest() { @Test fun defaultDrawable() = runTest { val url = "https://www.example.com/image.jpg" - val image = FakeImage() + val image = ColorImage() val engine = FakeImageLoaderEngine.Builder() - .intercept("different_string", FakeImage()) + .intercept("different_string", ColorImage()) .default(image) .build() val imageLoader = ImageLoader.Builder(context) @@ -84,7 +84,7 @@ class FakeImageLoaderEngineTest : RobolectricTest() { fun optionalInterceptor() = runTest { var currentIndex = -1 val url = "https://www.example.com/image.jpg" - val images = listOf(FakeImage(), FakeImage(), FakeImage()) + val images = listOf(ColorImage(), ColorImage(), ColorImage()) fun testInterceptor(index: Int) = OptionalInterceptor { chain -> if (currentIndex == index) { SuccessResult(images[index], chain.request, DataSource.MEMORY) @@ -119,7 +119,7 @@ class FakeImageLoaderEngineTest : RobolectricTest() { fun requestTransformerEnforcesInvariants() = runTest { val url = "https://www.example.com/image.jpg" val engine = FakeImageLoaderEngine.Builder() - .intercept(url, FakeImage()) + .intercept(url, ColorImage()) .requestTransformer { request -> request.newBuilder() .data(null) From f62c5038f93130dcafff5e7afe50780c2a08c3cd Mon Sep 17 00:00:00 2001 From: Colin White Date: Thu, 28 Nov 2024 18:55:44 -0800 Subject: [PATCH 06/22] Fix build. --- .../src/androidMain/kotlin/coil3/test/FakeImage.android.kt | 2 +- coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt | 2 +- .../nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt b/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt index 106b893f4c..6084f20080 100644 --- a/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt +++ b/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt @@ -7,7 +7,7 @@ import coil3.annotation.Poko @Deprecated( message = "This use case is better fulfilled by ColorImage.", - replaceWith = ReplaceWith("ColorImage", ["coil3.test.ColorImage"]), + replaceWith = ReplaceWith("ColorImage", "coil3.test.ColorImage"), level = DeprecationLevel.WARNING, ) @Poko diff --git a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt index 4a3ccbc667..99e516f101 100644 --- a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt +++ b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt @@ -9,7 +9,7 @@ import coil3.test.ColorImage.Companion.Black */ @Deprecated( message = "This use case is better fulfilled by ColorImage.", - replaceWith = ReplaceWith("ColorImage(color, width, height, size, shareable)", ["coil3.test.ColorImage"]), + replaceWith = ReplaceWith("ColorImage(color, width, height, size, shareable)", "coil3.test.ColorImage"), level = DeprecationLevel.WARNING, ) expect class FakeImage( diff --git a/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt b/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt index 5247935f58..e6b91297a2 100644 --- a/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt +++ b/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt @@ -8,7 +8,7 @@ import org.jetbrains.skia.Rect @Deprecated( message = "This use case is better fulfilled by ColorImage.", - replaceWith = ReplaceWith("ColorImage(color, width, height, size, shareable)", ["coil3.test.ColorImage"]), + replaceWith = ReplaceWith("ColorImage(color, width, height, size, shareable)", "coil3.test.ColorImage"), level = DeprecationLevel.WARNING, ) @Poko From 7e72b08fcd69f9834b9400aebdbb4f8aff34f764 Mon Sep 17 00:00:00 2001 From: Colin White Date: Sun, 22 Dec 2024 16:29:32 -0500 Subject: [PATCH 07/22] Add ColorImage to coil-core. --- .../kotlin/coil3/compose/AsyncImagePainter.kt | 3 ++ coil-compose/README.md | 2 +- coil-core/api/android/coil-core.api | 15 ++++++++ coil-core/api/coil-core.klib.api | 20 +++++++++++ coil-core/api/jvm/coil-core.api | 15 ++++++++ .../androidMain/kotlin/coil3/ColorImage.kt | 13 +------ .../commonMain/kotlin/coil3}/ColorImage.kt | 22 +++++------- .../nonAndroidMain/kotlin/coil3/ColorImage.kt | 13 +------ coil-test/README.md | 12 +++---- coil-test/api/android/coil-test.api | 25 ------------- coil-test/api/coil-test.klib.api | 35 ------------------- coil-test/api/jvm/coil-test.api | 25 ------------- .../commonMain/kotlin/coil3/test/FakeImage.kt | 3 +- .../coil3/test/FakeImageLoaderEngine.kt | 6 ++-- .../coil3/test/FakeImageLoaderEngineTest.kt | 1 + .../composescreenshot/PreviewScreenshots.kt | 7 ++-- .../java/coil3/paparazzi/PaparazziTest.kt | 11 +++--- .../roborazzi/RoborazziComposeTestAndroid.kt | 10 +++--- .../coil3/roborazzi/RoborazziViewTest.kt | 8 +++-- .../roborazzi/RoborazziComposeTestJvm.kt | 9 ++--- 20 files changed, 102 insertions(+), 153 deletions(-) rename coil-test/src/androidMain/kotlin/coil3/test/ColorImage.android.kt => coil-core/src/androidMain/kotlin/coil3/ColorImage.kt (64%) rename {coil-test/src/commonMain/kotlin/coil3/test => coil-core/src/commonMain/kotlin/coil3}/ColorImage.kt (60%) rename coil-test/src/nonAndroidMain/kotlin/coil3/test/ColorImage.nonAndroid.kt => coil-core/src/nonAndroidMain/kotlin/coil3/ColorImage.kt (69%) diff --git a/coil-compose-core/src/commonMain/kotlin/coil3/compose/AsyncImagePainter.kt b/coil-compose-core/src/commonMain/kotlin/coil3/compose/AsyncImagePainter.kt index 823c680f04..050e7de698 100644 --- a/coil-compose-core/src/commonMain/kotlin/coil3/compose/AsyncImagePainter.kt +++ b/coil-compose-core/src/commonMain/kotlin/coil3/compose/AsyncImagePainter.kt @@ -13,6 +13,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.DefaultAlpha import androidx.compose.ui.graphics.FilterQuality @@ -20,6 +21,7 @@ import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.drawscope.DrawScope import androidx.compose.ui.graphics.drawscope.DrawScope.Companion.DefaultFilterQuality import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalInspectionMode @@ -242,6 +244,7 @@ class AsyncImagePainter internal constructor( } override fun onAbandoned() { + Color.Black.toArgb() rememberJob = null (painter as? RememberObserver)?.onAbandoned() } diff --git a/coil-compose/README.md b/coil-compose/README.md index 40308a71aa..6b341eaa1b 100644 --- a/coil-compose/README.md +++ b/coil-compose/README.md @@ -175,7 +175,7 @@ You can override the preview behaviour like so: ```kotlin val previewHandler = AsyncImagePreviewHandler { - FakeImage(color = 0xFFFF0000) // Available in `io.coil-kt.coil3:coil-test`. + ColorImage(Color.Red.toArgb()) } CompositionLocalProvider(LocalAsyncImagePreviewHandler provides previewHandler) { diff --git a/coil-core/api/android/coil-core.api b/coil-core/api/android/coil-core.api index 382e2b3013..b3959b3d8f 100644 --- a/coil-core/api/android/coil-core.api +++ b/coil-core/api/android/coil-core.api @@ -10,6 +10,21 @@ public final class coil3/BitmapImage : coil3/Image { public fun toString ()Ljava/lang/String; } +public final class coil3/ColorImage : coil3/Image { + public fun ()V + public fun (IIIJZ)V + public synthetic fun (IIIJZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun draw (Landroid/graphics/Canvas;)V + public fun equals (Ljava/lang/Object;)Z + public final fun getColor ()I + public fun getHeight ()I + public fun getShareable ()Z + public fun getSize ()J + public fun getWidth ()I + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + public final class coil3/ComponentRegistry { public fun ()V public synthetic fun (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V diff --git a/coil-core/api/coil-core.klib.api b/coil-core/api/coil-core.klib.api index 317d9ca436..460e2fc98b 100644 --- a/coil-core/api/coil-core.klib.api +++ b/coil-core/api/coil-core.klib.api @@ -828,6 +828,26 @@ final class coil3/BitmapImage : coil3/Image { // coil3/BitmapImage|null[0] final fun toString(): kotlin/String // coil3/BitmapImage.toString|toString(){}[0] } +final class coil3/ColorImage : coil3/Image { // coil3/ColorImage|null[0] + constructor (kotlin/Int = ..., kotlin/Int = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin/Boolean = ...) // coil3/ColorImage.|(kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Boolean){}[0] + + final val color // coil3/ColorImage.color|{}color[0] + final fun (): kotlin/Int // coil3/ColorImage.color.|(){}[0] + final val height // coil3/ColorImage.height|{}height[0] + final fun (): kotlin/Int // coil3/ColorImage.height.|(){}[0] + final val shareable // coil3/ColorImage.shareable|{}shareable[0] + final fun (): kotlin/Boolean // coil3/ColorImage.shareable.|(){}[0] + final val size // coil3/ColorImage.size|{}size[0] + final fun (): kotlin/Long // coil3/ColorImage.size.|(){}[0] + final val width // coil3/ColorImage.width|{}width[0] + final fun (): kotlin/Int // coil3/ColorImage.width.|(){}[0] + + final fun draw(org.jetbrains.skia/Canvas) // coil3/ColorImage.draw|draw(org.jetbrains.skia.Canvas){}[0] + final fun equals(kotlin/Any?): kotlin/Boolean // coil3/ColorImage.equals|equals(kotlin.Any?){}[0] + final fun hashCode(): kotlin/Int // coil3/ColorImage.hashCode|hashCode(){}[0] + final fun toString(): kotlin/String // coil3/ColorImage.toString|toString(){}[0] +} + final class coil3/ComponentRegistry { // coil3/ComponentRegistry|null[0] constructor () // coil3/ComponentRegistry.|(){}[0] diff --git a/coil-core/api/jvm/coil-core.api b/coil-core/api/jvm/coil-core.api index 332721729f..3368c2cd33 100644 --- a/coil-core/api/jvm/coil-core.api +++ b/coil-core/api/jvm/coil-core.api @@ -10,6 +10,21 @@ public final class coil3/BitmapImage : coil3/Image { public fun toString ()Ljava/lang/String; } +public final class coil3/ColorImage : coil3/Image { + public fun ()V + public fun (IIIJZ)V + public synthetic fun (IIIJZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun draw (Lorg/jetbrains/skia/Canvas;)V + public fun equals (Ljava/lang/Object;)Z + public final fun getColor ()I + public fun getHeight ()I + public fun getShareable ()Z + public fun getSize ()J + public fun getWidth ()I + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + public final class coil3/ComponentRegistry { public fun ()V public synthetic fun (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V diff --git a/coil-test/src/androidMain/kotlin/coil3/test/ColorImage.android.kt b/coil-core/src/androidMain/kotlin/coil3/ColorImage.kt similarity index 64% rename from coil-test/src/androidMain/kotlin/coil3/test/ColorImage.android.kt rename to coil-core/src/androidMain/kotlin/coil3/ColorImage.kt index 7b8b7b274b..0415b7ebba 100644 --- a/coil-test/src/androidMain/kotlin/coil3/test/ColorImage.android.kt +++ b/coil-core/src/androidMain/kotlin/coil3/ColorImage.kt @@ -1,8 +1,6 @@ -package coil3.test +package coil3 import android.graphics.Paint -import coil3.Canvas -import coil3.Image import coil3.annotation.Poko @Poko @@ -27,13 +25,4 @@ actual class ColorImage actual constructor( canvas.drawPaint(paint) } } - - actual companion object { - actual const val Black = 0xFF000000.toInt() - actual const val White = 0xFFFFFFFF.toInt() - actual const val Transparent = 0x00000000.toInt() - actual const val Red = 0xFFFF0000.toInt() - actual const val Green = 0xFF00FF00.toInt() - actual const val Blue = 0xFF0000FF.toInt() - } } diff --git a/coil-test/src/commonMain/kotlin/coil3/test/ColorImage.kt b/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt similarity index 60% rename from coil-test/src/commonMain/kotlin/coil3/test/ColorImage.kt rename to coil-core/src/commonMain/kotlin/coil3/ColorImage.kt index 201dfb4d6d..ae51603572 100644 --- a/coil-test/src/commonMain/kotlin/coil3/test/ColorImage.kt +++ b/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt @@ -1,16 +1,21 @@ -package coil3.test +package coil3 -import coil3.Canvas -import coil3.Image +import coil3.annotation.ExperimentalCoilApi /** * An image that draws a [color]. * * By default the image has no intrinsic size and will fill its canvas. Set [width] and [height] * to a positive value to draw a square with those dimensions. + * + * [color] can be set either: + * + * - with a custom hex value following the `0xAARRGGBB.toInt()` format (alpha is required) + * - or it can be set with `androidx.compose.ui.graphics.Color`: `ColorImage(Color.Black.toArgb())`. */ +@ExperimentalCoilApi expect class ColorImage( - color: Int = Black, + color: Int = 0xFF000000.toInt(), width: Int = -1, height: Int = -1, size: Long = 0, @@ -22,13 +27,4 @@ expect class ColorImage( override val height: Int override val shareable: Boolean override fun draw(canvas: Canvas) - - companion object { - val Black: Int - val White: Int - val Transparent: Int - val Red: Int - val Green: Int - val Blue: Int - } } diff --git a/coil-test/src/nonAndroidMain/kotlin/coil3/test/ColorImage.nonAndroid.kt b/coil-core/src/nonAndroidMain/kotlin/coil3/ColorImage.kt similarity index 69% rename from coil-test/src/nonAndroidMain/kotlin/coil3/test/ColorImage.nonAndroid.kt rename to coil-core/src/nonAndroidMain/kotlin/coil3/ColorImage.kt index d580027851..11148bcbc4 100644 --- a/coil-test/src/nonAndroidMain/kotlin/coil3/test/ColorImage.nonAndroid.kt +++ b/coil-core/src/nonAndroidMain/kotlin/coil3/ColorImage.kt @@ -1,7 +1,5 @@ -package coil3.test +package coil3 -import coil3.Canvas -import coil3.Image import coil3.annotation.Poko import org.jetbrains.skia.Paint import org.jetbrains.skia.Rect @@ -33,13 +31,4 @@ actual class ColorImage actual constructor( canvas.drawPaint(paint) } } - - actual companion object { - actual const val Black = 0xFF000000.toInt() - actual const val White = 0xFFFFFFFF.toInt() - actual const val Transparent = 0x00000000.toInt() - actual const val Red = 0xFFFF0000.toInt() - actual const val Green = 0xFF00FF00.toInt() - actual const val Blue = 0xFF0000FF.toInt() - } } diff --git a/coil-test/README.md b/coil-test/README.md index 8b6fd7ee0f..1e8bbaaea2 100644 --- a/coil-test/README.md +++ b/coil-test/README.md @@ -10,9 +10,9 @@ testImplementation("io.coil-kt.coil3:coil-test:3.0.4") ```kotlin val engine = FakeImageLoaderEngine.Builder() - .intercept("https://example.com/image.jpg", FakeImage(color = 0xF00)) // Red - .intercept({ it is String && it.endsWith("test.png") }, FakeImage(color = 0x0F0)) // Green - .default(FakeImage(color = 0x00F)) // Blue + .intercept("https://example.com/image.jpg", ColorImage(Color.Red.toArgb())) + .intercept({ it is String && it.endsWith("test.png") }, ColorImage(Color.Green.toArgb())) + .default(ColorImage(Color.Blue.toArgb())) .build() val imageLoader = ImageLoader.Builder(context) .components { add(engine) } @@ -31,9 +31,9 @@ class PaparazziTest { @Before fun before() { val engine = FakeImageLoaderEngine.Builder() - .intercept("https://example.com/image.jpg", FakeImage(color = 0xF00)) // Red - .intercept({ it is String && it.endsWith("test.png") }, FakeImage(color = 0x0F0)) // Green - .default(FakeImage(color = 0x00F)) // Blue + .intercept("https://example.com/image.jpg", ColorImage(Color.Red.toArgb())) + .intercept({ it is String && it.endsWith("test.png") }, ColorImage(Color.Green.toArgb())) + .default(ColorImage(Color.Blue.toArgb())) .build() val imageLoader = ImageLoader.Builder(paparazzi.context) .components { add(engine) } diff --git a/coil-test/api/android/coil-test.api b/coil-test/api/android/coil-test.api index bf4d09ae6a..420123ce51 100644 --- a/coil-test/api/android/coil-test.api +++ b/coil-test/api/android/coil-test.api @@ -1,28 +1,3 @@ -public final class coil3/test/ColorImage : coil3/Image { - public static final field Black I - public static final field Blue I - public static final field Companion Lcoil3/test/ColorImage$Companion; - public static final field Green I - public static final field Red I - public static final field Transparent I - public static final field White I - public fun ()V - public fun (IIIJZ)V - public synthetic fun (IIIJZILkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun draw (Landroid/graphics/Canvas;)V - public fun equals (Ljava/lang/Object;)Z - public final fun getColor ()I - public fun getHeight ()I - public fun getShareable ()Z - public fun getSize ()J - public fun getWidth ()I - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class coil3/test/ColorImage$Companion { -} - public final class coil3/test/FakeImage : coil3/Image { public fun ()V public fun (IIJZI)V diff --git a/coil-test/api/coil-test.klib.api b/coil-test/api/coil-test.klib.api index c45a4de053..4846c3f64a 100644 --- a/coil-test/api/coil-test.klib.api +++ b/coil-test/api/coil-test.klib.api @@ -6,41 +6,6 @@ // - Show declarations: true // Library unique name: -final class coil3.test/ColorImage : coil3/Image { // coil3.test/ColorImage|null[0] - constructor (kotlin/Int = ..., kotlin/Int = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin/Boolean = ...) // coil3.test/ColorImage.|(kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Boolean){}[0] - - final val color // coil3.test/ColorImage.color|{}color[0] - final fun (): kotlin/Int // coil3.test/ColorImage.color.|(){}[0] - final val height // coil3.test/ColorImage.height|{}height[0] - final fun (): kotlin/Int // coil3.test/ColorImage.height.|(){}[0] - final val shareable // coil3.test/ColorImage.shareable|{}shareable[0] - final fun (): kotlin/Boolean // coil3.test/ColorImage.shareable.|(){}[0] - final val size // coil3.test/ColorImage.size|{}size[0] - final fun (): kotlin/Long // coil3.test/ColorImage.size.|(){}[0] - final val width // coil3.test/ColorImage.width|{}width[0] - final fun (): kotlin/Int // coil3.test/ColorImage.width.|(){}[0] - - final fun draw(org.jetbrains.skia/Canvas) // coil3.test/ColorImage.draw|draw(org.jetbrains.skia.Canvas){}[0] - final fun equals(kotlin/Any?): kotlin/Boolean // coil3.test/ColorImage.equals|equals(kotlin.Any?){}[0] - final fun hashCode(): kotlin/Int // coil3.test/ColorImage.hashCode|hashCode(){}[0] - final fun toString(): kotlin/String // coil3.test/ColorImage.toString|toString(){}[0] - - final object Companion { // coil3.test/ColorImage.Companion|null[0] - final const val Black // coil3.test/ColorImage.Companion.Black|{}Black[0] - final fun (): kotlin/Int // coil3.test/ColorImage.Companion.Black.|(){}[0] - final const val Blue // coil3.test/ColorImage.Companion.Blue|{}Blue[0] - final fun (): kotlin/Int // coil3.test/ColorImage.Companion.Blue.|(){}[0] - final const val Green // coil3.test/ColorImage.Companion.Green|{}Green[0] - final fun (): kotlin/Int // coil3.test/ColorImage.Companion.Green.|(){}[0] - final const val Red // coil3.test/ColorImage.Companion.Red|{}Red[0] - final fun (): kotlin/Int // coil3.test/ColorImage.Companion.Red.|(){}[0] - final const val Transparent // coil3.test/ColorImage.Companion.Transparent|{}Transparent[0] - final fun (): kotlin/Int // coil3.test/ColorImage.Companion.Transparent.|(){}[0] - final const val White // coil3.test/ColorImage.Companion.White|{}White[0] - final fun (): kotlin/Int // coil3.test/ColorImage.Companion.White.|(){}[0] - } -} - final class coil3.test/FakeImage : coil3/Image { // coil3.test/FakeImage|null[0] constructor (kotlin/Int = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin/Boolean = ..., kotlin/Int = ...) // coil3.test/FakeImage.|(kotlin.Int;kotlin.Int;kotlin.Long;kotlin.Boolean;kotlin.Int){}[0] diff --git a/coil-test/api/jvm/coil-test.api b/coil-test/api/jvm/coil-test.api index 3073d10e7d..3a32b023ca 100644 --- a/coil-test/api/jvm/coil-test.api +++ b/coil-test/api/jvm/coil-test.api @@ -1,28 +1,3 @@ -public final class coil3/test/ColorImage : coil3/Image { - public static final field Black I - public static final field Blue I - public static final field Companion Lcoil3/test/ColorImage$Companion; - public static final field Green I - public static final field Red I - public static final field Transparent I - public static final field White I - public fun ()V - public fun (IIIJZ)V - public synthetic fun (IIIJZILkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun draw (Lorg/jetbrains/skia/Canvas;)V - public fun equals (Ljava/lang/Object;)Z - public final fun getColor ()I - public fun getHeight ()I - public fun getShareable ()Z - public fun getSize ()J - public fun getWidth ()I - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class coil3/test/ColorImage$Companion { -} - public final class coil3/test/FakeImage : coil3/Image { public fun ()V public fun (IIJZI)V diff --git a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt index 99e516f101..447252bde1 100644 --- a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt +++ b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt @@ -2,7 +2,6 @@ package coil3.test import coil3.Canvas import coil3.Image -import coil3.test.ColorImage.Companion.Black /** * A simple [Image] that draws a 100x100 black square by default. @@ -17,7 +16,7 @@ expect class FakeImage( height: Int = 100, size: Long = 4L * width * height, shareable: Boolean = true, - color: Int = Black, + color: Int = 0xFF000000.toInt(), ) : Image { override val width: Int override val height: Int diff --git a/coil-test/src/commonMain/kotlin/coil3/test/FakeImageLoaderEngine.kt b/coil-test/src/commonMain/kotlin/coil3/test/FakeImageLoaderEngine.kt index 53eb4acb6b..37928ff469 100644 --- a/coil-test/src/commonMain/kotlin/coil3/test/FakeImageLoaderEngine.kt +++ b/coil-test/src/commonMain/kotlin/coil3/test/FakeImageLoaderEngine.kt @@ -29,9 +29,9 @@ fun FakeImageLoaderEngine(image: Image): FakeImageLoaderEngine { * * ``` * val engine = FakeImageLoaderEngine.Builder() - * .intercept("https://www.example.com/image.jpg", FakeImage()) - * .intercept({ it is String && it.endsWith("test.png") }, FakeImage()) - * .default(FakeImage(color = 0x0000FF)) + * .intercept("https://www.example.com/image.jpg", ColorImage(Color.Red)) + * .intercept({ it is String && it.endsWith("test.png") }, ColorImage(Color.Green)) + * .default(ColorImage(Color.Blue)) * .build() * val imageLoader = ImageLoader.Builder(context) * .components { add(engine) } diff --git a/coil-test/src/commonTest/kotlin/coil3/test/FakeImageLoaderEngineTest.kt b/coil-test/src/commonTest/kotlin/coil3/test/FakeImageLoaderEngineTest.kt index 86a17305ff..26d63d2f3c 100644 --- a/coil-test/src/commonTest/kotlin/coil3/test/FakeImageLoaderEngineTest.kt +++ b/coil-test/src/commonTest/kotlin/coil3/test/FakeImageLoaderEngineTest.kt @@ -1,5 +1,6 @@ package coil3.test +import coil3.ColorImage import coil3.ImageLoader import coil3.decode.DataSource import coil3.request.ErrorResult diff --git a/internal/test-compose-screenshot/src/screenshotTest/java/coil3/composescreenshot/PreviewScreenshots.kt b/internal/test-compose-screenshot/src/screenshotTest/java/coil3/composescreenshot/PreviewScreenshots.kt index cfa55358fd..f574f09337 100644 --- a/internal/test-compose-screenshot/src/screenshotTest/java/coil3/composescreenshot/PreviewScreenshots.kt +++ b/internal/test-compose-screenshot/src/screenshotTest/java/coil3/composescreenshot/PreviewScreenshots.kt @@ -8,24 +8,25 @@ import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Devices import androidx.compose.ui.tooling.preview.Preview +import coil3.ColorImage import coil3.ImageLoader import coil3.annotation.ExperimentalCoilApi import coil3.compose.AsyncImage import coil3.compose.AsyncImagePreviewHandler import coil3.compose.LocalAsyncImagePreviewHandler import coil3.compose.rememberAsyncImagePainter -import coil3.test.ColorImage -import coil3.test.ColorImage.Companion.Red import coil3.test.composescreenshot.R @OptIn(ExperimentalCoilApi::class) class PreviewScreenshots { private val previewHandler = AsyncImagePreviewHandler { - ColorImage(Red, width = 100, height = 100) + ColorImage(Color.Red.toArgb(), width = 100, height = 100) } @Preview( diff --git a/internal/test-paparazzi/src/test/java/coil3/paparazzi/PaparazziTest.kt b/internal/test-paparazzi/src/test/java/coil3/paparazzi/PaparazziTest.kt index 21965950f1..1e663dddce 100644 --- a/internal/test-paparazzi/src/test/java/coil3/paparazzi/PaparazziTest.kt +++ b/internal/test-paparazzi/src/test/java/coil3/paparazzi/PaparazziTest.kt @@ -4,17 +4,18 @@ import android.widget.ImageView import androidx.compose.foundation.Image import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.layout.ContentScale import app.cash.paparazzi.DeviceConfig import app.cash.paparazzi.Paparazzi +import coil3.ColorImage import coil3.ImageLoader import coil3.compose.AsyncImage import coil3.compose.rememberAsyncImagePainter import coil3.decode.ImageSource import coil3.request.ImageRequest import coil3.request.target -import coil3.test.ColorImage -import coil3.test.ColorImage.Companion.Red import coil3.test.FakeImageLoaderEngine import kotlin.test.assertTrue import okio.Buffer @@ -38,7 +39,7 @@ class PaparazziTest { fun imageView() { val url = "https://www.example.com/image.jpg" val engine = FakeImageLoaderEngine.Builder() - .intercept(url, ColorImage(Red, width = 100, height = 100)) + .intercept(url, ColorImage(Color.Red.toArgb(), width = 100, height = 100)) .build() val imageLoader = ImageLoader.Builder(paparazzi.context) .components { add(engine) } @@ -60,7 +61,7 @@ class PaparazziTest { fun asyncImage() { val url = "https://www.example.com/image.jpg" val engine = FakeImageLoaderEngine.Builder() - .intercept(url, ColorImage(Red, width = 100, height = 100)) + .intercept(url, ColorImage(Color.Red.toArgb(), width = 100, height = 100)) .build() val imageLoader = ImageLoader.Builder(paparazzi.context) .components { add(engine) } @@ -81,7 +82,7 @@ class PaparazziTest { fun rememberAsyncImagePainter() { val url = "https://www.example.com/image.jpg" val engine = FakeImageLoaderEngine.Builder() - .intercept(url, ColorImage(Red, width = 100, height = 100)) + .intercept(url, ColorImage(Color.Red.toArgb(), width = 100, height = 100)) .build() val imageLoader = ImageLoader.Builder(paparazzi.context) .components { add(engine) } diff --git a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt index bf08e8924d..ab068dd70b 100644 --- a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt +++ b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt @@ -3,14 +3,16 @@ package coil3.roborazzi import androidx.compose.foundation.Image import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onRoot +import coil3.ColorImage +import coil3.ColorImage.Companion.Red import coil3.ImageLoader import coil3.compose.AsyncImage import coil3.compose.rememberAsyncImagePainter -import coil3.test.ColorImage -import coil3.test.ColorImage.Companion.Red import coil3.test.FakeImageLoaderEngine import coil3.test.utils.ComposeTestActivity import coil3.test.utils.RobolectricTest @@ -39,7 +41,7 @@ class RoborazziComposeTestAndroid : RobolectricTest() { fun asyncImage() { val url = "https://www.example.com/image.jpg" val engine = FakeImageLoaderEngine.Builder() - .intercept(url, ColorImage(Red, width = 100, height = 100)) + .intercept(url, ColorImage(Color.Red.toArgb(), width = 100, height = 100)) .build() val imageLoader = ImageLoader.Builder(composeTestRule.activity) .components { add(engine) } @@ -60,7 +62,7 @@ class RoborazziComposeTestAndroid : RobolectricTest() { fun rememberAsyncImagePainter() { val url = "https://www.example.com/image.jpg" val engine = FakeImageLoaderEngine.Builder() - .intercept(url, ColorImage(Red, width = 100, height = 100)) + .intercept(url, ColorImage(Color.Red.toArgb(), width = 100, height = 100)) .build() val imageLoader = ImageLoader.Builder(composeTestRule.activity) .components { add(engine) } diff --git a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt index 59f1e19c12..5adca77c9a 100644 --- a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt +++ b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt @@ -1,14 +1,16 @@ package coil3.roborazzi import android.widget.ImageView +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toArgb import androidx.test.espresso.Espresso.onView import androidx.test.espresso.matcher.ViewMatchers.isRoot import androidx.test.ext.junit.rules.activityScenarioRule +import coil3.ColorImage +import coil3.ColorImage.Companion.Red import coil3.ImageLoader import coil3.request.ImageRequest import coil3.request.target -import coil3.test.ColorImage -import coil3.test.ColorImage.Companion.Red import coil3.test.FakeImageLoaderEngine import coil3.test.utils.RobolectricTest import coil3.test.utils.ViewTestActivity @@ -37,7 +39,7 @@ class RoborazziViewTest : RobolectricTest() { fun imageView() { val url = "https://www.example.com/image.jpg" val engine = FakeImageLoaderEngine.Builder() - .intercept(url, ColorImage(Red, width = 100, height = 100)) + .intercept(url, ColorImage(Color.Red.toArgb(), width = 100, height = 100)) .build() val activity = activityRule.scenario.activity val imageLoader = ImageLoader.Builder(activity) diff --git a/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt b/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt index 1f9130d0a0..5e3a230beb 100644 --- a/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt +++ b/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt @@ -5,17 +5,18 @@ import androidx.compose.foundation.background import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.test.ExperimentalTestApi import androidx.compose.ui.test.onRoot import androidx.compose.ui.test.runDesktopComposeUiTest +import coil3.ColorImage +import coil3.ColorImage.Companion.Red import coil3.ImageLoader import coil3.PlatformContext import coil3.asImage import coil3.compose.AsyncImage import coil3.compose.rememberAsyncImagePainter -import coil3.test.ColorImage -import coil3.test.ColorImage.Companion.Red import coil3.test.FakeImageLoaderEngine import coil3.toBitmap import io.github.takahirom.roborazzi.captureRoboImage @@ -27,7 +28,7 @@ class RoborazziComposeTestJvm { @Test fun asyncImage() { val url = "https://www.example.com/image.jpg" - val image = ColorImage(Red, width = 100, height = 100) + val image = ColorImage(Color.Red.toArgb(), width = 100, height = 100) val engine = FakeImageLoaderEngine.Builder() .intercept(url, image) @@ -57,7 +58,7 @@ class RoborazziComposeTestJvm { @Test fun rememberAsyncImagePainter() { val url = "https://www.example.com/image.jpg" - val image = ColorImage(Red, width = 100, height = 100) + val image = ColorImage(Color.Red.toArgb(), width = 100, height = 100) val engine = FakeImageLoaderEngine.Builder() .intercept(url, image.toBitmap().asImage()) .build() From c39bd4e672553899a7eb5df2f406a2ff1b89bb85 Mon Sep 17 00:00:00 2001 From: Colin White Date: Sun, 22 Dec 2024 16:45:00 -0500 Subject: [PATCH 08/22] Fix import. --- .../jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt b/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt index 5e3a230beb..22a25413fb 100644 --- a/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt +++ b/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt @@ -11,7 +11,6 @@ import androidx.compose.ui.test.ExperimentalTestApi import androidx.compose.ui.test.onRoot import androidx.compose.ui.test.runDesktopComposeUiTest import coil3.ColorImage -import coil3.ColorImage.Companion.Red import coil3.ImageLoader import coil3.PlatformContext import coil3.asImage From d2f115b4a25a0cb7af1103b4e0a97f3c465be989 Mon Sep 17 00:00:00 2001 From: Colin White Date: Sun, 22 Dec 2024 16:58:52 -0500 Subject: [PATCH 09/22] Fix imports. --- .../kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt | 1 - .../androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt | 1 - 2 files changed, 2 deletions(-) diff --git a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt index ab068dd70b..50c9ad1b4f 100644 --- a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt +++ b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt @@ -9,7 +9,6 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onRoot import coil3.ColorImage -import coil3.ColorImage.Companion.Red import coil3.ImageLoader import coil3.compose.AsyncImage import coil3.compose.rememberAsyncImagePainter diff --git a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt index 5adca77c9a..4a097ded9c 100644 --- a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt +++ b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt @@ -7,7 +7,6 @@ import androidx.test.espresso.Espresso.onView import androidx.test.espresso.matcher.ViewMatchers.isRoot import androidx.test.ext.junit.rules.activityScenarioRule import coil3.ColorImage -import coil3.ColorImage.Companion.Red import coil3.ImageLoader import coil3.request.ImageRequest import coil3.request.target From be2562f7258c27f5d0689006ac9a6023043d830f Mon Sep 17 00:00:00 2001 From: Colin White Date: Sun, 22 Dec 2024 17:09:22 -0500 Subject: [PATCH 10/22] Docs. --- coil-core/src/commonMain/kotlin/coil3/ColorImage.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt b/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt index ae51603572..74192ca8e3 100644 --- a/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt +++ b/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt @@ -10,8 +10,8 @@ import coil3.annotation.ExperimentalCoilApi * * [color] can be set either: * - * - with a custom hex value following the `0xAARRGGBB.toInt()` format (alpha is required) - * - or it can be set with `androidx.compose.ui.graphics.Color`: `ColorImage(Color.Black.toArgb())`. + * - with a custom hex value (alpha is required): `0xAARRGGBB.toInt()` + * - or with `androidx.compose.ui.graphics.Color`: `ColorImage(Color.Black.toArgb())` */ @ExperimentalCoilApi expect class ColorImage( From 4e768e2c8a80cd2cb437b56fa9f5c8887ccfdbb7 Mon Sep 17 00:00:00 2001 From: Colin White Date: Sun, 22 Dec 2024 17:13:22 -0500 Subject: [PATCH 11/22] Remove debug code. --- .../src/commonMain/kotlin/coil3/compose/AsyncImagePainter.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/coil-compose-core/src/commonMain/kotlin/coil3/compose/AsyncImagePainter.kt b/coil-compose-core/src/commonMain/kotlin/coil3/compose/AsyncImagePainter.kt index 050e7de698..823c680f04 100644 --- a/coil-compose-core/src/commonMain/kotlin/coil3/compose/AsyncImagePainter.kt +++ b/coil-compose-core/src/commonMain/kotlin/coil3/compose/AsyncImagePainter.kt @@ -13,7 +13,6 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.geometry.Size -import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.DefaultAlpha import androidx.compose.ui.graphics.FilterQuality @@ -21,7 +20,6 @@ import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.drawscope.DrawScope import androidx.compose.ui.graphics.drawscope.DrawScope.Companion.DefaultFilterQuality import androidx.compose.ui.graphics.painter.Painter -import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalInspectionMode @@ -244,7 +242,6 @@ class AsyncImagePainter internal constructor( } override fun onAbandoned() { - Color.Black.toArgb() rememberJob = null (painter as? RememberObserver)?.onAbandoned() } From fc29c85db36b99e052057098289b4610f4dbc14f Mon Sep 17 00:00:00 2001 From: Colin White Date: Sun, 22 Dec 2024 17:15:03 -0500 Subject: [PATCH 12/22] Fix imports. --- .../src/androidMain/kotlin/coil3/test/FakeImage.android.kt | 2 +- coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt | 2 +- .../nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt b/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt index 6084f20080..39f6715bfe 100644 --- a/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt +++ b/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt @@ -7,7 +7,7 @@ import coil3.annotation.Poko @Deprecated( message = "This use case is better fulfilled by ColorImage.", - replaceWith = ReplaceWith("ColorImage", "coil3.test.ColorImage"), + replaceWith = ReplaceWith("ColorImage", "coil3.ColorImage"), level = DeprecationLevel.WARNING, ) @Poko diff --git a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt index 447252bde1..2c24d9f10f 100644 --- a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt +++ b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt @@ -8,7 +8,7 @@ import coil3.Image */ @Deprecated( message = "This use case is better fulfilled by ColorImage.", - replaceWith = ReplaceWith("ColorImage(color, width, height, size, shareable)", "coil3.test.ColorImage"), + replaceWith = ReplaceWith("ColorImage", "coil3.ColorImage"), level = DeprecationLevel.WARNING, ) expect class FakeImage( diff --git a/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt b/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt index e6b91297a2..e5687c075c 100644 --- a/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt +++ b/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt @@ -8,7 +8,7 @@ import org.jetbrains.skia.Rect @Deprecated( message = "This use case is better fulfilled by ColorImage.", - replaceWith = ReplaceWith("ColorImage(color, width, height, size, shareable)", "coil3.test.ColorImage"), + replaceWith = ReplaceWith("ColorImage", "coil3.ColorImage"), level = DeprecationLevel.WARNING, ) @Poko From 3ee1d9be1f79f366ff313a491b79721370dc3a7e Mon Sep 17 00:00:00 2001 From: Colin White Date: Sun, 22 Dec 2024 17:26:04 -0500 Subject: [PATCH 13/22] Annotation. --- coil-core/src/androidMain/kotlin/coil3/ColorImage.kt | 2 ++ coil-core/src/nonAndroidMain/kotlin/coil3/ColorImage.kt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/coil-core/src/androidMain/kotlin/coil3/ColorImage.kt b/coil-core/src/androidMain/kotlin/coil3/ColorImage.kt index 0415b7ebba..e5bd595667 100644 --- a/coil-core/src/androidMain/kotlin/coil3/ColorImage.kt +++ b/coil-core/src/androidMain/kotlin/coil3/ColorImage.kt @@ -1,8 +1,10 @@ package coil3 import android.graphics.Paint +import coil3.annotation.ExperimentalCoilApi import coil3.annotation.Poko +@ExperimentalCoilApi @Poko actual class ColorImage actual constructor( actual val color: Int, diff --git a/coil-core/src/nonAndroidMain/kotlin/coil3/ColorImage.kt b/coil-core/src/nonAndroidMain/kotlin/coil3/ColorImage.kt index 11148bcbc4..9b65d1efe8 100644 --- a/coil-core/src/nonAndroidMain/kotlin/coil3/ColorImage.kt +++ b/coil-core/src/nonAndroidMain/kotlin/coil3/ColorImage.kt @@ -1,9 +1,11 @@ package coil3 +import coil3.annotation.ExperimentalCoilApi import coil3.annotation.Poko import org.jetbrains.skia.Paint import org.jetbrains.skia.Rect +@ExperimentalCoilApi @Poko actual class ColorImage actual constructor( actual val color: Int, From 9c63ec6f635f88afdf11c38f5c47795998c64c8a Mon Sep 17 00:00:00 2001 From: Colin White Date: Sun, 22 Dec 2024 19:26:26 -0500 Subject: [PATCH 14/22] Docs. --- coil-core/src/commonMain/kotlin/coil3/ColorImage.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt b/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt index 74192ca8e3..4ab7a200ce 100644 --- a/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt +++ b/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt @@ -8,10 +8,12 @@ import coil3.annotation.ExperimentalCoilApi * By default the image has no intrinsic size and will fill its canvas. Set [width] and [height] * to a positive value to draw a square with those dimensions. * - * [color] can be set either: - * - * - with a custom hex value (alpha is required): `0xAARRGGBB.toInt()` - * - or with `androidx.compose.ui.graphics.Color`: `ColorImage(Color.Black.toArgb())` + * @param color The ARGB hex color to draw with the format `0xAARRGGBB.toInt()`. + * Tip: Use Compose's color class, e.g. `ColorImage(Color.Black.toArgb())`. + * @param width See [Image.width]. + * @param height See [Image.height]. + * @param size See [Image.size]. + * @param shareable See [Image.shareable]. */ @ExperimentalCoilApi expect class ColorImage( From 81f1c367cf0d4cac8f335e194b9c22ba1e7ed103 Mon Sep 17 00:00:00 2001 From: Colin White Date: Wed, 25 Dec 2024 22:06:30 -0500 Subject: [PATCH 15/22] Remove custom image. --- .../commonMain/kotlin/coil3/decode/BlackholeDecoder.kt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/coil-core/src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt b/coil-core/src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt index c49fbecf7c..60d4292a60 100644 --- a/coil-core/src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt +++ b/coil-core/src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt @@ -1,6 +1,6 @@ package coil3.decode -import coil3.Canvas +import coil3.ColorImage import coil3.Image import coil3.ImageLoader import coil3.annotation.ExperimentalCoilApi @@ -38,13 +38,7 @@ class BlackholeDecoder( ) = BlackholeDecoder(imageFactory) companion object { - @JvmField val EMPTY_IMAGE = object : Image { - override val size get() = 0L - override val width get() = -1 - override val height get() = -1 - override val shareable get() = true - override fun draw(canvas: Canvas) { /* Draw nothing. */ } - } + @JvmField val EMPTY_IMAGE: Image = ColorImage() } } } From b5fcd96524327497a24fb9deed3bdf9c845dcf01 Mon Sep 17 00:00:00 2001 From: Colin White Date: Wed, 25 Dec 2024 22:07:35 -0500 Subject: [PATCH 16/22] Use transparent color. --- .../src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coil-core/src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt b/coil-core/src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt index 60d4292a60..b613d810c3 100644 --- a/coil-core/src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt +++ b/coil-core/src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt @@ -38,7 +38,7 @@ class BlackholeDecoder( ) = BlackholeDecoder(imageFactory) companion object { - @JvmField val EMPTY_IMAGE: Image = ColorImage() + @JvmField val EMPTY_IMAGE: Image = ColorImage(color = 0x00000000) } } } From bf545fcc1e191190c7dec91b7962bacf972973e2 Mon Sep 17 00:00:00 2001 From: Colin White Date: Wed, 25 Dec 2024 22:08:54 -0500 Subject: [PATCH 17/22] Formatting. --- .../src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coil-core/src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt b/coil-core/src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt index b613d810c3..b47aad65b6 100644 --- a/coil-core/src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt +++ b/coil-core/src/commonMain/kotlin/coil3/decode/BlackholeDecoder.kt @@ -38,7 +38,7 @@ class BlackholeDecoder( ) = BlackholeDecoder(imageFactory) companion object { - @JvmField val EMPTY_IMAGE: Image = ColorImage(color = 0x00000000) + @JvmField val EMPTY_IMAGE: Image = ColorImage(0x00000000) } } } From 48ff05c8c0cf6508ffe504e6acac87abfa53f6ce Mon Sep 17 00:00:00 2001 From: Colin White Date: Sun, 5 Jan 2025 01:51:10 -0500 Subject: [PATCH 18/22] Docs. --- coil-core/src/androidMain/kotlin/coil3/Image.android.kt | 3 --- coil-core/src/commonMain/kotlin/coil3/Image.kt | 2 +- coil-core/src/nonAndroidMain/kotlin/coil3/Image.nonAndroid.kt | 3 --- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/coil-core/src/androidMain/kotlin/coil3/Image.android.kt b/coil-core/src/androidMain/kotlin/coil3/Image.android.kt index d751f3767f..0f6fb18e08 100644 --- a/coil-core/src/androidMain/kotlin/coil3/Image.android.kt +++ b/coil-core/src/androidMain/kotlin/coil3/Image.android.kt @@ -53,9 +53,6 @@ fun Image.toBitmap( return createBitmap(width, height, config).applyCanvas(::draw) } -/** - * An [Image] backed by an Android [Bitmap]. - */ @Poko actual class BitmapImage internal constructor( actual val bitmap: Bitmap, diff --git a/coil-core/src/commonMain/kotlin/coil3/Image.kt b/coil-core/src/commonMain/kotlin/coil3/Image.kt index b423ce0ce1..8af83857f3 100644 --- a/coil-core/src/commonMain/kotlin/coil3/Image.kt +++ b/coil-core/src/commonMain/kotlin/coil3/Image.kt @@ -38,7 +38,7 @@ interface Image { } /** - * A special implementation of [Image] that's backed by a [Bitmap]. + * An [Image] that's backed by a [Bitmap]. */ expect class BitmapImage : Image { val bitmap: Bitmap diff --git a/coil-core/src/nonAndroidMain/kotlin/coil3/Image.nonAndroid.kt b/coil-core/src/nonAndroidMain/kotlin/coil3/Image.nonAndroid.kt index cfbfe913cc..55b51cedcc 100644 --- a/coil-core/src/nonAndroidMain/kotlin/coil3/Image.nonAndroid.kt +++ b/coil-core/src/nonAndroidMain/kotlin/coil3/Image.nonAndroid.kt @@ -64,9 +64,6 @@ fun Image.toBitmap( return bitmap } -/** - * An [Image] backed by a Skia [Bitmap]. - */ @Poko actual class BitmapImage internal constructor( actual val bitmap: Bitmap, From 1d534b487e4f72f30198a5515a9a1f6882458b33 Mon Sep 17 00:00:00 2001 From: Colin White Date: Sun, 5 Jan 2025 01:53:57 -0500 Subject: [PATCH 19/22] Docs. --- coil-core/src/commonMain/kotlin/coil3/ColorImage.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt b/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt index 4ab7a200ce..ff1ae69a31 100644 --- a/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt +++ b/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt @@ -9,7 +9,7 @@ import coil3.annotation.ExperimentalCoilApi * to a positive value to draw a square with those dimensions. * * @param color The ARGB hex color to draw with the format `0xAARRGGBB.toInt()`. - * Tip: Use Compose's color class, e.g. `ColorImage(Color.Black.toArgb())`. + * Tip: Use Compose's color class: `ColorImage(Color.Black.toArgb())`. * @param width See [Image.width]. * @param height See [Image.height]. * @param size See [Image.size]. From 448aaf8f1daaf92687eb36a8b92715cc9a46dab2 Mon Sep 17 00:00:00 2001 From: Colin White Date: Tue, 14 Jan 2025 21:24:39 -0800 Subject: [PATCH 20/22] Improve deprecation warning. --- .../src/androidMain/kotlin/coil3/test/FakeImage.android.kt | 3 ++- coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt | 3 ++- .../nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt b/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt index 39f6715bfe..7e59a26ffd 100644 --- a/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt +++ b/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt @@ -6,7 +6,8 @@ import coil3.Image import coil3.annotation.Poko @Deprecated( - message = "This use case is better fulfilled by ColorImage.", + message = "ColorImage supports the same functionality, has `color` as the first argument, " + + "and is more easily accessible in coil-core instead of coil-test.", replaceWith = ReplaceWith("ColorImage", "coil3.ColorImage"), level = DeprecationLevel.WARNING, ) diff --git a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt index 2c24d9f10f..3cd5394074 100644 --- a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt +++ b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt @@ -7,7 +7,8 @@ import coil3.Image * A simple [Image] that draws a 100x100 black square by default. */ @Deprecated( - message = "This use case is better fulfilled by ColorImage.", + message = "ColorImage supports the same functionality, has `color` as the first argument, " + + "and is more easily accessible in coil-core instead of coil-test.", replaceWith = ReplaceWith("ColorImage", "coil3.ColorImage"), level = DeprecationLevel.WARNING, ) diff --git a/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt b/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt index e5687c075c..37898c128f 100644 --- a/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt +++ b/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt @@ -7,7 +7,8 @@ import org.jetbrains.skia.Paint import org.jetbrains.skia.Rect @Deprecated( - message = "This use case is better fulfilled by ColorImage.", + message = "ColorImage supports the same functionality, has `color` as the first argument, " + + "and is more easily accessible in coil-core instead of coil-test.", replaceWith = ReplaceWith("ColorImage", "coil3.ColorImage"), level = DeprecationLevel.WARNING, ) From 466b31415b9a6f6159d9ab5789078dbaabb2896f Mon Sep 17 00:00:00 2001 From: Colin White Date: Tue, 14 Jan 2025 21:26:41 -0800 Subject: [PATCH 21/22] Remove unnecessary docs. --- coil-core/src/commonMain/kotlin/coil3/ColorImage.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt b/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt index ff1ae69a31..7f5311dfdc 100644 --- a/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt +++ b/coil-core/src/commonMain/kotlin/coil3/ColorImage.kt @@ -10,10 +10,6 @@ import coil3.annotation.ExperimentalCoilApi * * @param color The ARGB hex color to draw with the format `0xAARRGGBB.toInt()`. * Tip: Use Compose's color class: `ColorImage(Color.Black.toArgb())`. - * @param width See [Image.width]. - * @param height See [Image.height]. - * @param size See [Image.size]. - * @param shareable See [Image.shareable]. */ @ExperimentalCoilApi expect class ColorImage( From fec6b4899b143e14f972b7409ece6c4f5a3c7bc7 Mon Sep 17 00:00:00 2001 From: Colin White Date: Tue, 14 Jan 2025 21:36:33 -0800 Subject: [PATCH 22/22] Fix docs. --- .../commonMain/kotlin/coil3/test/FakeImageLoaderEngine.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/coil-test/src/commonMain/kotlin/coil3/test/FakeImageLoaderEngine.kt b/coil-test/src/commonMain/kotlin/coil3/test/FakeImageLoaderEngine.kt index 37928ff469..73ffb4ae7d 100644 --- a/coil-test/src/commonMain/kotlin/coil3/test/FakeImageLoaderEngine.kt +++ b/coil-test/src/commonMain/kotlin/coil3/test/FakeImageLoaderEngine.kt @@ -29,9 +29,9 @@ fun FakeImageLoaderEngine(image: Image): FakeImageLoaderEngine { * * ``` * val engine = FakeImageLoaderEngine.Builder() - * .intercept("https://www.example.com/image.jpg", ColorImage(Color.Red)) - * .intercept({ it is String && it.endsWith("test.png") }, ColorImage(Color.Green)) - * .default(ColorImage(Color.Blue)) + * .intercept("https://www.example.com/image.jpg", ColorImage(Color.Red.toArgb())) + * .intercept({ it is String && it.endsWith("test.png") }, ColorImage(Color.Green.toArgb())) + * .default(ColorImage(Color.Blue.toArgb())) * .build() * val imageLoader = ImageLoader.Builder(context) * .components { add(engine) }