1
votes

I am trying to load image from network using Coil accompanist library. I am getting frame drops due to the same.

I/Choreographer: Skipped 34 frames!  The application may be doing too much work on its main thread.

Is there a way to load images in background thread? Here is my code :

 val painter = rememberCoilPainter(request = url)

    Card(modifier = modifier) {
      when (painter.loadState) {
        is ImageLoadState.Success ->
          Image(
            painter = painter,
            contentDescription = title,
            contentScale = ContentScale.FillBounds
          )
        else ->
          Image(
            painter = rememberCoilPainter(request = R.drawable.placeholder),
            contentDescription = title,
            contentScale = ContentScale.FillBounds
          )
      }
    }

This code is the content part of LazyRow and there are around 20-25 items in the list.

Please suggest a way to perform the image loading in background thread to avoid frame drops.

1

1 Answers

1
votes

I am not sure if it is enough to improve your performance.

You can start improving the use of the placeholder drawables which can set be on the request.
Something like:

    Image(
        painter = rememberCoilPainter(
            request = "url",
            requestBuilder = {
                placeholder(R.drawable.placeholder)
            }
        ),
        contentDescription = null)