Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images disappear while in return transition #650

Closed
jventrib opened this issue Feb 1, 2021 · 10 comments
Closed

Images disappear while in return transition #650

jventrib opened this issue Feb 1, 2021 · 10 comments
Labels
bug Something isn't working

Comments

@jventrib
Copy link

jventrib commented Feb 1, 2021

Hello,

Describe the bug
I'm using Jetpack Navigation with shared elements transition between fragments. When my detail fragment is returning to home fragment, images in detail fragment disappear as soon as the transition (MaterialContainerTransform) is initiated. It seems that ViewTargetRequestDelegate.dispose() is called at the beginning of the transition, causing the image to be cleared.

Expected behavior
I expect the images to be displayed (and fade) during the transition. This is working correctly when Glide is used instead of Coil.

To Reproduce
The simpliest I found to reproduce is to take the Reply app from Material-components-android-examples and replace the glide image loading in BindingAdapter.kt with Coil. I see the same behaviour with my own app.

Logs/Screenshots

With Coil
coil

With Glide
glide

Version
Coil 1.1.1

Thank you in advance !

@jventrib jventrib added the bug Something isn't working label Feb 1, 2021
@kroegerama
Copy link

kroegerama commented Feb 6, 2021

I'm so glad I found this bug report. At first I thought it was a bug in the material design library. They have a bug open, too. But it's seems to be the fault of the image loading frameworks.

Keywords for anyone with the same problem: Coil preserve image during return transition ImageView ShapeableImageView

@colinrtwhite
Copy link
Member

I haven't tested myself, but if you set lifecycle(activity) on your ImageRequest does it work around the issue?

@kroegerama
Copy link

Just tested lifecycle(requireActivity()) but sadly didn't help.

@colinrtwhite
Copy link
Member

colinrtwhite commented Feb 7, 2021

Setting a custom target should hopefully work around the issue:

val request = ImageRequest.Builder(context)
    .data(url)
    .target { imageView.setImageDrawable(it) }
    .build()
imageLoader.enqueue(request)

@jventrib
Copy link
Author

jventrib commented Feb 8, 2021

I can confirm that setting a custom target fix the issue !
Thank you.

@kroegerama
Copy link

So is this the intended way? Don't really want to put any hacks in production code :)

@kahakai
Copy link

kahakai commented Feb 17, 2021

So is this the intended way? Don't really want to put any hacks in production code :)

I don't think this is the intended way, but it might be the only way to workaround the problem as it was found out here after the research: facebook/fresco#1445 (comment)
Maybe this can be fixed on the library side.

@ardyfeb
Copy link

ardyfeb commented Mar 18, 2021

Setting a custom target should hopefully work around the issue:

val request = ImageRequest.Builder(context)
    .data(url)
    .target { imageView.drawable = it }
    .build()
imageLoader.enqueue(request)

val cannot be reassigned

I use imageView.setImageDrawable(it) instead

@ianhanniballake
Copy link
Contributor

Note that it is expected behavior from the Android framework side that any Transition will detach the views from their window (thus triggering any disposal associated with onDetachedFromWindow()).

To fix this, you'd need to disable that behavior and only rely on the LifecycleOwner reaching DESTROYED (e.g., for Fragments, the viewLifecycleOwner only reaches DESTROYED once the Transition fully completes). Is that possible to do right now with Coil?

@colinrtwhite
Copy link
Member

colinrtwhite commented Jul 20, 2021

@ianhanniballake Yep, we could probably add an option disable the detach behaviour (like how using a non-ViewTarget disables it) though this would require enabling it manually. I'm planning to address this bug in 2.0 by removing the automatic ImageView clearing behaviour since it's mostly needed for bitmap pooling which is also going away.

EDIT: This issue is fixed in the 2.0.0-alpha01 and newer releases of Coil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants