Skip to content

Instantly share code, notes, and snippets.

@kasem-sm
Created February 6, 2022 15:49
Show Gist options
  • Save kasem-sm/2801c0c2b2472b6765243ac9b39f7b3b to your computer and use it in GitHub Desktop.
Save kasem-sm/2801c0c2b2472b6765243ac9b39f7b3b to your computer and use it in GitHub Desktop.
Small workaround to show thumbnail before loading actual image with Coil.
var isOriginalImageLoaded = false
// Thumbnail Request
val thumbRequest = ImageRequest.Builder(ctx)
.data(thumbUrl)
.target(
onSuccess = { result ->
// If highRes image is not loaded yet,
// show the thumbnail
if (!isOriginalImageLoaded) {
binding.headerImage.setImageDrawable(result)
}
}
)
.build()
imageLoader.enqueue(thumbRequest)
val highResRequest = ImageRequest.Builder(ctx)
.data(highResUrl)
.target(
onSuccess = { result ->
isOriginalImageLoaded = true
binding.headerImage.setImageDrawable(result)
},
onError = { onFailed() }
)
.build()
imageLoader.enqueue(highResRequest)
@kasem-sm
Copy link
Author

Thanks for checking and improving it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment