coil-kt / coil

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

Feature Request: Add ImageLoader.executeBlocking Implementation #529

Closed bobziuchkovski closed 4 years ago

bobziuchkovski commented 4 years ago

Is your feature request related to a problem? Please describe. Yes. I have a pure Java android project and I'm using rxjava worker threads for background image retrieval. I would like to fetch images synchronously on these threads with coil.

Describe the solution you'd like Rather than document the (admittedly trivial) solution for performing blocking requests from Java, add this to the core library as ImageLoader.executeBlocking and update the documentation to reflect this.

Additional context For now I've added a kotlin module to my project for implementing this behavior, but it seems kind of silly to add an entire kotlin module for this functionality. If the use case is common enough to call out in the documentation, it seems like it'd make sense to add it to the core library.

In any event, kudos on an amazing library. I've thoroughly evaluated Glide, Fresco, and Coil, and Coil is already a clear winner.

colinrtwhite commented 4 years ago

Thanks! I've been reluctant to add this to the core library for a couple reasons:

That said, you bring up a good point that Java-only users can't use execute without either adding the Kotlin plugin to their current module (and slowing their build) or creating a separate module. Even though Coil is Kotlin-first, I think that the core functionality (e.g. creating an ImageRequest + enqueuing/executing it) should work with Java out of the box.

Going to think about this a bit more, but if it's added I think it makes sense to keep it as an extension function callable from Java: val result = ImageLoaders.executeBlocking(imageLoader, request).

bobziuchkovski commented 4 years ago

An extension function sounds completely reasonable. I totally understand the kotlin-first approach and wouldn't argue for the need to support java for everything, but it did strike me as weird to need to add kotlin on my end for blocking requests.

In any event, thanks for the thoughtful response and for taking the time to consider it.

colinrtwhite commented 4 years ago

Added this - it'll be out in rc3. Thanks again for the feedback!