I use AsyncImage to load an image from a remote location. Use case is a profile picture which is taken from the cam then uploaded to a remote database and then it shall be refreshed in the UI.
Now it can happen that the image changes but the URI remains the same. I then trigger a recomposition, but the image remains the same.
I see nothing happening in the loading/success/error callbacks. I tried to use an ImageRequest as model instead of the URI and tried to disable all caches there but this resulted in an error.
When i try another URI instead the Image changes.
So question here is how to make the AsyncImage refresh also if the URI does not change
As of Coil V3, there is the AsyncImagePainer.reload() functionality.
You can try to use it as follows:
val sizeResolver = rememberConstraintsSizeResolver()
val painter = rememberAsyncImagePainter(
model = ImageRequest.Builder(LocalPlatformContext.current)
.data("https://example.com/image.jpg")
.size(sizeResolver)
.build(),
)
Button(
onClick = {
painter.restart()
}
) {
Text("Reload Image")
}
Image(
painter = painter,
contentDescription = null,
modifier = Modifier.then(sizeResolver),
)
Make sure you have at least this dependency version in your build.gradle:
implementation("io.coil-kt.coil3:coil-compose:3.2.0")
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