coil-kt / coil

Image loading for Android and Compose Multiplatform.
https://coil-kt.github.io/coil/
Apache License 2.0
10.46k stars 639 forks source link

Execute image request on spot from compose resources #2310

Closed nilufer32 closed 1 week ago

nilufer32 commented 2 weeks ago

Describe the bug A clear and concise description of what the bug is. I want to be able to execute an image request from compose resources in a blocking way. I should be able to call execute blocking on the main thread. Currently if I attempt to do this my app will crash

To Reproduce

var imageRequest: ImageRequest? = null

fun initializeResource(
    context: PlatformContext,
    imageLoader: ImageLoader,
    byteArray: ByteArray,
) {
    imageRequest =
        ImageRequest.Builder(context)
            .decoderFactory { result, options, _ ->
                SvgDecoder(result.source, options)
            }
            .data(byteArray)
            .crossfade(0)
            .build()

    runOnMainDispatcher {
        imageLoader.execute(imageRequest!!)
    }
}

Version Coil 3.0.0-alpha06

colinrtwhite commented 2 weeks ago

What's the exception?

colinrtwhite commented 1 week ago

There's not enough info here to reproduce the issue. This should be supported, but it's recommended to not load resources on the main thread as it will block the main thread and drop frames.