Reload image after a failed load in Jetpack Compose
See original GitHub issueIs your feature request related to a problem? Please describe.
val painter = rememberImagePainter(url)
Image(
modifier = Modifier.fillMaxSize(),
painter = painter,
contentDescription = null,
contentScale = ContentScale.Fit
)
when (val state = painter.state) {
is ImagePainter.State.Error -> {
TextButton(onClick = { }) { Text("retry") }
}
}
After a failed load, the user should be able to reload the image via the retry button.
Describe the solution you’d like
It is better to provide reload
method, but it seems that setting request
in ImagePainter
to public would also work.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Jetpack compose - how do I refresh a screen when app ...
I came up with this: @Composable fun OnLifecycleEvent(onEvent: (owner: LifecycleOwner, event: Lifecycle.Event) -> Unit) { val eventHandler ...
Read more >Loading images for Jetpack Compose using Glide, Coil, and ...
Landscapist is an image loading library for Jetpack Compose. There are three options; Glide, Coil, and Fresco. So you can choose by your...
Read more >Asynchronously Load Images with Jetpack Compose - YouTube
The BEST android courses in the world: https://codingwithmitch.com/How to asynchronously load images using Jetpack Compose.
Read more >Loading images | Jetpack Compose - Android Developers
Use the Image composable to display a graphic on screen. To load an image (for example: PNG, JPEG, WEBP) or vector resource from...
Read more >Loading Image in Android Jetpack Compose Made Easy
It can be easily setup to handle Loading, Error and Success state. It can have fade in effect provided too, as shown below....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Still figuring out a good public API for this, but if you need this today you can force retry by changing a parameter:
Currently, I’m thinking the public API should be something like this, but let me know what you think!
Thanks! I’ll try it later.
The api is indeed a problem. Your example is very similar to
focusRequester
. I’m ok with it. But since there must be an ImagePainter object here, I think it would be simpler to have an ImagePainter with a retry method.