question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image flickers when url changes for rememberImagePainter

See original GitHub issue

Currently I’m using a library to reorder items in a LazyColumn. The library works and functions as expected. The issue I’m running into is that when an item is reordered in the list, it causes a recomposition because my state has changed since the position of the item has changed. This is fine, but when items in my list recompose, they might have different urls so it tries to load the new image for both items that had their positions change. This causes a flicker as it tries to load new images. I’ve tried to use caching to prevent rememberImagePainter from having to go fetch the image again but I don’t think that’s how that works. I’ve tried to prevent the request from going through by providing an ExecuteCallback that returned false if the state wasn’t empty and that didn’t work either.

I would expect to be able to configure coil to not re-load an image when a url changes but instead use a cached version if it exists.

I’m using version 1.3.2 and it’s not device specific.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
iamutkarshtiwaricommented, Aug 25, 2022

Facing the same issue as mentioned by @Swirastlynn with 2.1.0 even when disk and memory caching is applied. I happen to be using Coil in LazyRow.

1reaction
Swirastlynncommented, May 18, 2022

I can still observe flickering on 2.1.0. It doesn’t always happen, but quite often. I haven’t set any caching, all setup is default.

Code:

 val imageRatio = 9f / 16f

 LazyColumn(
            modifier = Modifier
                    .fillMaxSize()
                    .background(AppTheme.colors.itemBackground)
    ) {
        item {
            val screenWidth = LocalConfiguration.current.screenWidthDp.dp
            AsyncImage(
                    model =  detailsInfo?.landscapeImageUrl ?: "", // this change between recompositions is problematic
                    placeholder = ColorPainter(colorResource(id = R.color.details_header_bg)),
                    contentDescription = detailsInfo?.title ?: "placeholder",
                    modifier = Modifier.size(screenWidth, screenWidth * imageRatio)
            )
        }
   ...
   }
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I avoid flickering when image is changed for another ...
The problem is that the menu and logo flickers when I hover the image. This doesn't always happen but seems to have to...
Read more >
Upgrading from Coil 1.x to 2.x
This is a short guide to highlight the main changes when upgrading from Coil 1.x to 2.x ... In Coil 1.x you would...
Read more >
371733 - background image flickers on image changes
Issue 371733: background image flickers on image changes · 1. create a div block · 2. using js setInterval() change the background image...
Read more >
Jetpack Compose: Image loading using Coil | Geek Culture
Loading images from the Coil library which automatically handling the network request as well as image caching.
Read more >
Image flickering when using State changes - E-Learning Heroes
Hi there, I created some animation using state changes thru the timeline. Although it looks as expected in the SL preview, after exporting ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found