1

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 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

I tried using ImageRequest but still there are frame drops :( Here is my code : val imageRequest = ImageRequest.Builder(context) .data(url) .placeholder(R.drawable.placeholder) .error(R.drawable.error) .build() Image( painter = rememberCoilPainter(request = imageRequest), contentDescription = title, contentScale = ContentScale.FillBounds )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.