What are the applicable solutions for asynchronous...
# compose
w
What are the applicable solutions for asynchronously loading images from remote URLs in Compose’s scroll view? I try to use onCommit to load asynchronously in Image and recompose the UI to show the image. But this way will cause UI freeze when sliding? Do you have any good suggestions?(These codes run in Compose for desktop platform)
Copy code
@Composable
fun NetworkImage(url: String, modifier: Modifier) {
    var imageBitmap by remember { mutableStateOf<ImageBitmap?>(null) }
    imageBitmap?.let {
        Image(bitmap = imageBitmap!!, modifier = modifier, contentScale = ContentScale.Crop)
    }
    onCommit(url) {
        ImageLoader.instance
            .loadUrl(url)
            .listen {
                if (it.status == Status.success) {
                    imageBitmap = it.content
                }else{
                    println("image load failed.")
                }
            }
            .exec()
    }
}
c
w
Thanks for sharing! But this is the Compose version of the desktop platform that the library is not compatible with. They all depend on the Android platform. https://github.com/chrisbanes/accompanist/issues/136
c
oh ok maybe ask on #compose-desktop desktop then ?
(may be you can get inspiration from the source code tho)
w
yup,I simply implemented one, but there are still some problems in performance. thank you
🙏 2
c
I think it's worth filing a feature request for coil to be KMM. (There might already be a ticket for it)
w
I load the remote image through Accompanist on the Android platform and displayed it through LazyColumn, and the problem of sliding and freezing still occurred. Is it because of performance issues in the alpha version?🙂
c
Most likely but I would file a bug since it sounds like you have a minimal repro project.