diff --git a/coil-core/src/commonMain/kotlin/coil3/request/ImageRequest.kt b/coil-core/src/commonMain/kotlin/coil3/request/ImageRequest.kt index bb0a3f5f98..4eab434371 100644 --- a/coil-core/src/commonMain/kotlin/coil3/request/ImageRequest.kt +++ b/coil-core/src/commonMain/kotlin/coil3/request/ImageRequest.kt @@ -262,10 +262,7 @@ class ImageRequest private constructor( extras = extras, ) - @Deprecated( - level = DeprecationLevel.HIDDEN, - message = "Kept for binary compatibility." - ) + @Deprecated("Kept for binary compatibility.", level = DeprecationLevel.HIDDEN) fun copy( fileSystem: FileSystem = this.fileSystem, interceptorCoroutineContext: CoroutineContext = this.interceptorCoroutineContext, 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 6514953f87..e8bda40fa3 100644 --- a/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt +++ b/coil-test/src/androidMain/kotlin/coil3/test/FakeImage.android.kt @@ -1,5 +1,6 @@ package coil3.test +import android.graphics.Paint import coil3.Canvas import coil3.Image import coil3.annotation.Poko @@ -12,7 +13,15 @@ actual class FakeImage actual constructor( actual override val shareable: Boolean, actual val color: Int, ) : Image { + private var lazyPaint: Paint? = null + actual override fun draw(canvas: Canvas) { - canvas.drawColor(color) + val paint = lazyPaint ?: run { + Paint() + .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/FakeImage.kt b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt index f4940a19a2..57bd4a12de 100644 --- a/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt +++ b/coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt @@ -11,7 +11,7 @@ expect class FakeImage( height: Int = 100, size: Long = 4L * width * height, shareable: Boolean = true, - color: Int = 0x000000, + color: Int = 0xFF000000.toInt(), ) : Image { override val width: Int override val height: Int 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 34c8a883b1..cbe1539c10 100644 --- a/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt +++ b/coil-test/src/nonAndroidMain/kotlin/coil3/test/FakeImage.nonAndroid.kt @@ -4,6 +4,7 @@ import coil3.Canvas import coil3.Image import coil3.annotation.Poko import org.jetbrains.skia.Paint +import org.jetbrains.skia.Rect @Poko actual class FakeImage actual constructor( @@ -14,6 +15,7 @@ actual class FakeImage actual constructor( actual val color: Int, ) : Image { private var lazyPaint: Paint? = null + private var lazyRect: Rect? = null actual override fun draw(canvas: Canvas) { val paint = lazyPaint ?: run { @@ -21,6 +23,10 @@ actual class FakeImage actual constructor( .apply { color = this@FakeImage.color } .also { lazyPaint = it } } - canvas.drawPaint(paint) + val rect = lazyRect ?: run { + Rect.makeWH(width.toFloat(), height.toFloat()) + .also { lazyRect = it } + } + canvas.drawRect(rect, paint) } } 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 950e808962..1895b3903b 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,7 +1,6 @@ package coil3.composescreenshot import android.graphics.Color -import android.graphics.drawable.ColorDrawable import androidx.compose.foundation.Image import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable @@ -14,19 +13,16 @@ import androidx.compose.ui.tooling.preview.Devices import androidx.compose.ui.tooling.preview.Preview import coil3.ImageLoader import coil3.annotation.ExperimentalCoilApi -import coil3.asImage import coil3.compose.AsyncImage import coil3.compose.AsyncImagePreviewHandler import coil3.compose.LocalAsyncImagePreviewHandler import coil3.compose.rememberAsyncImagePainter +import coil3.test.FakeImage @OptIn(ExperimentalCoilApi::class) class PreviewScreenshots { private val previewHandler = AsyncImagePreviewHandler { - object : ColorDrawable(Color.RED) { - override fun getIntrinsicWidth() = 100 - override fun getIntrinsicHeight() = 100 - }.asImage() + FakeImage(color = Color.RED) } @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 1d767e9c64..edd5320cf5 100644 --- a/internal/test-paparazzi/src/test/java/coil3/paparazzi/PaparazziTest.kt +++ b/internal/test-paparazzi/src/test/java/coil3/paparazzi/PaparazziTest.kt @@ -1,7 +1,6 @@ package coil3.paparazzi import android.graphics.Color -import android.graphics.drawable.ColorDrawable import android.widget.ImageView import androidx.compose.foundation.Image import androidx.compose.foundation.layout.fillMaxSize @@ -15,8 +14,8 @@ import coil3.compose.rememberAsyncImagePainter import coil3.decode.ImageSource import coil3.request.ImageRequest import coil3.request.target +import coil3.test.FakeImage import coil3.test.FakeImageLoaderEngine -import coil3.test.intercept import kotlin.test.assertTrue import okio.Buffer import okio.FileSystem @@ -38,12 +37,8 @@ class PaparazziTest { @Test fun imageView() { val url = "https://www.example.com/image.jpg" - val drawable = object : ColorDrawable(Color.RED) { - override fun getIntrinsicWidth() = 100 - override fun getIntrinsicHeight() = 100 - } val engine = FakeImageLoaderEngine.Builder() - .intercept(url, drawable) + .intercept(url, FakeImage(color = Color.RED)) .build() val imageLoader = ImageLoader.Builder(paparazzi.context) .components { add(engine) } @@ -64,12 +59,8 @@ class PaparazziTest { @Test fun asyncImage() { val url = "https://www.example.com/image.jpg" - val drawable = object : ColorDrawable(Color.RED) { - override fun getIntrinsicWidth() = 100 - override fun getIntrinsicHeight() = 100 - } val engine = FakeImageLoaderEngine.Builder() - .intercept(url, drawable) + .intercept(url, FakeImage(color = Color.RED)) .build() val imageLoader = ImageLoader.Builder(paparazzi.context) .components { add(engine) } @@ -89,12 +80,8 @@ class PaparazziTest { @Test fun rememberAsyncImagePainter() { val url = "https://www.example.com/image.jpg" - val drawable = object : ColorDrawable(Color.RED) { - override fun getIntrinsicWidth() = 100 - override fun getIntrinsicHeight() = 100 - } val engine = FakeImageLoaderEngine.Builder() - .intercept(url, drawable) + .intercept(url, FakeImage(color = Color.RED)) .build() val imageLoader = ImageLoader.Builder(paparazzi.context) .components { add(engine) } diff --git a/internal/test-paparazzi/src/test/snapshots/images/coil3.paparazzi_PaparazziTest_imageView.png b/internal/test-paparazzi/src/test/snapshots/images/coil3.paparazzi_PaparazziTest_imageView.png index e49f4b3529..9e5527da81 100644 Binary files a/internal/test-paparazzi/src/test/snapshots/images/coil3.paparazzi_PaparazziTest_imageView.png and b/internal/test-paparazzi/src/test/snapshots/images/coil3.paparazzi_PaparazziTest_imageView.png differ 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 48166affe9..26dbead0c0 100644 --- a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt +++ b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziComposeTestAndroid.kt @@ -1,7 +1,6 @@ package coil3.roborazzi import android.graphics.Color -import android.graphics.drawable.ColorDrawable import androidx.compose.foundation.Image import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.ui.Modifier @@ -11,8 +10,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.FakeImageLoaderEngine -import coil3.test.intercept import coil3.test.utils.ComposeTestActivity import coil3.test.utils.RobolectricTest import com.github.takahirom.roborazzi.RoborazziRule @@ -39,12 +38,8 @@ class RoborazziComposeTestAndroid : RobolectricTest() { @Test fun asyncImage() { val url = "https://www.example.com/image.jpg" - val drawable = object : ColorDrawable(Color.RED) { - override fun getIntrinsicWidth() = 100 - override fun getIntrinsicHeight() = 100 - } val engine = FakeImageLoaderEngine.Builder() - .intercept(url, drawable) + .intercept(url, FakeImage(color = Color.RED)) .build() val imageLoader = ImageLoader.Builder(composeTestRule.activity) .components { add(engine) } @@ -64,12 +59,8 @@ class RoborazziComposeTestAndroid : RobolectricTest() { @Test fun rememberAsyncImagePainter() { val url = "https://www.example.com/image.jpg" - val drawable = object : ColorDrawable(Color.RED) { - override fun getIntrinsicWidth() = 100 - override fun getIntrinsicHeight() = 100 - } val engine = FakeImageLoaderEngine.Builder() - .intercept(url, drawable) + .intercept(url, FakeImage(color = Color.RED)) .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 79228f98b0..9487e9cfcb 100644 --- a/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt +++ b/internal/test-roborazzi/src/androidUnitTest/kotlin/coil3/roborazzi/RoborazziViewTest.kt @@ -1,7 +1,6 @@ package coil3.roborazzi import android.graphics.Color -import android.graphics.drawable.ColorDrawable import android.widget.ImageView import androidx.test.espresso.Espresso.onView import androidx.test.espresso.matcher.ViewMatchers.isRoot @@ -9,8 +8,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.FakeImageLoaderEngine -import coil3.test.intercept import coil3.test.utils.RobolectricTest import coil3.test.utils.ViewTestActivity import coil3.test.utils.activity @@ -37,12 +36,8 @@ class RoborazziViewTest : RobolectricTest() { @Test fun imageView() { val url = "https://www.example.com/image.jpg" - val drawable = object : ColorDrawable(Color.RED) { - override fun getIntrinsicWidth() = 100 - override fun getIntrinsicHeight() = 100 - } val engine = FakeImageLoaderEngine.Builder() - .intercept(url, drawable) + .intercept(url, FakeImage(color = Color.RED)) .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 25333b1870..6353ef2384 100644 --- a/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt +++ b/internal/test-roborazzi/src/jvmTest/kotlin/coil3/roborazzi/RoborazziComposeTestJvm.kt @@ -29,11 +29,11 @@ class RoborazziComposeTestJvm { val image = FakeImage( width = 100, height = 100, - color = 0xFFFF0000.toInt() + color = org.jetbrains.skia.Color.RED, ) val engine = FakeImageLoaderEngine.Builder() - .intercept(url, image.toBitmap().asImage()) + .intercept(url, image) .build() val imageLoader = ImageLoader.Builder(PlatformContext.INSTANCE) @@ -63,7 +63,7 @@ class RoborazziComposeTestJvm { val image = FakeImage( width = 100, height = 100, - color = 0xFFFF0000.toInt() + color = org.jetbrains.skia.Color.RED, ) val engine = FakeImageLoaderEngine.Builder() .intercept(url, image.toBitmap().asImage())