Placeholder issue with reloading same images on recyclerView when the images are not in memory
See original GitHub issueHello - I’m running into some reload/flicker issues with gif/video frame support in RecyclerView. I think it might be related to https://github.com/coil-kt/coil/issues/280
We have RecyclerView
s where notifyDataSetChanged()
is called under certain conditions (when clicking on the item and etc.). I’m noticing some flicker when the same images should be re-bind but they aren’t loaded from memory.
For example, when the same image (I’m mostly seeing gif or video frame) is loaded after notifyDataSetChanged()
from DISK, I’m noticing the issue from step 4 & 5 below.
- Coil image request starts and does fresh load for
Image A
notifyDataSetChanged()
is called- Coil image request starts again for
Image A
- onStart() called on the view target to load placeholder
- Takes some time until onSuccess() to load from DISK
When I load with a custom ViewTarget and disable setting the placeholder, the step 4 doesn’t happen so the same image stays between the reload. This isn’t a solution because I do need to clear out the image when a new load starts, but I cannot differentiate if the view is binding from notifyDataSetChanged()
or if it is a fresh load. I’m hoping there is a way not to call onStart()
if we’re requesting the same image.
While I’m looking into why I’m not seeing the issue on Glide, I was wondering if you could advise if this can be handled from Coil. Thank you 🙇♂️
The resulting experience looks like this
Code
From RecyclerView.Adapter
override fun onBindViewHolder(holder: SomeViewHolder, position: Int) {
val request = ImageRequest.Builder(imageView.context)
.data(uri)
.target(imageView)
.placeholder(R.color.some_placeholder)
.build()
myImageLoader.enqueue(request)
}
override fun onViewRecycled(holder: SomeViewHolder) {
CoilUtils.clear(holder.thumbnail)
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (2 by maintainers)
Top GitHub Comments
Closing with updates. Thanks again for your suggestions and clarifications.
ViewTarget
and some tagging logic to skip duplicate requests. This resolved the flicker issue on re-bind which is good enough for now.Movie
to support downsampling before draw time.@colinrtwhite I was trying to skip
onStart()
based on the result drawable fromonSuccess()
. I read it again and it does sound confusing 😃 Anyways, your suggestion makes sense for bothonStart
andonSuccess
.2 & 3 make a lot of sense. Thank you for all the clarifications. It does look like a lot of work and extra complexity. I’ll see if I can solve the issue with a custom
ViewTarget
first before trying to implement the other parts.I’m hoping the tag or some other approach to skip the new request based on the previous request works out. My actual code from
RecyclerView.Adapter
s are more tricky than what I posted in the description so I’ll try out few more things based on your response.Thanks again for your response! I’ll either close this issue or come back with new questions in the next couple of days.