How to show a progress bar while fetching image from URL in Coil.?
Use ImageRequest.Listener
Example:
val imageRequest = ImageRequest.Builder(context)
.data(url)
.listener(
onStart = {
// set your progressbar visible here
},
onSuccess = { request, metadata ->
// set your progressbar invisible here
}
)
.build()
imageLoader.enqueue(request)
If you are creating app with jetpack compose then you don't need to do manual stuff,
you can use the builtin SubcomposeAsyncImage provided by the library from version 2.0.0-rc01
SubcomposeAsyncImage(
model = image,
contentDescription = "",
loading = {
CircularProgressIndicator(color = Color.Black)
},
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With