Support a FakeImageLoader for typical Preview use cases
yschimke opened this issue · comments
The https://coil-kt.github.io/coil/image_loaders/#testing docs suggest implementing a custom ImageLoader.
But there could be some useful defaults, like loading DrawableRes, or mapping a url to a test image.
It would be nice to have a Test or Fake ImageLoader that implemented sensible defaults for situations like Previews.
Would this be accepted as a PR?
I agree, having a coil-fakeimageloader
artifact (or similar) would be useful. I've been a bit cautious to add a 1st party artifact for it since it would require ongoing support vs. providing a recipe that can be copied + modified.
I'm going on holiday until the end of July so let's circle back on this then!
I've ended up with this for testing smaller components that use Coil but won't explicitly see an Image Loader. Is this in scope?
public inline fun ImageLoader.override(function: () -> Unit) {
Coil.setImageLoader(this)
try {
function()
} finally {
Coil::class.java.getDeclaredField("imageLoader").apply {
isAccessible = true
}.set(null, null)
}
}
Or some other way to achieve this?