Open thibseisel opened 4 years ago
Hey @thibseisel,
Thanks so much for taking the time to file an issue! Couple of questions to help us debug:
ImageView
s and not ShapableImageView
s?Hi @hunterstich ,
This also happens with regular ImageView
s, not only ShapeableImageView
s.
But it seems that ShapeableImageView
s have an additional issue that's visible when using MaterialContainerTransform
.
I created a sample project that's very similar in structure in so that you could easily reproduce. Here is the link: material-motion-bug
Hi @hunterstich , Any progress on this issue? Did you manage to reproduce the bug from the linked sample project?
Thanks in advance.
This is because you are using Glide to load images and Glide automatically clears the loaded images when the fragment is destroyed, as stated in #1734.
@thibseisel - thanks for the sample project.
I looked into this. The only workaround I was able to find is to use Glide's with
builder that accepts a Context
instead of a Fragment
to keep Glide from registering with the Fragment's lifecycle and clearing images when the Fragment is destroyed.
So in the case of your sample, you would change AlbumDetailFragment
s Glide call to:
Glide.with(requireContext()).asBitmap()
.load(it.artworkUrl)
.into(album_art_view)
This works in my testing. Let me know how it goes for you.
Thanks @mxalbert1996 and @hunterstich for your answers!
I just managed to make the return transition work for my use case. I've had to change the Fragment
passed to Glide to its associated Activity
(fragment.requireActivity()
) so that images are not cleared before being captured.
There's still a problem with ShapeableImageView
's corners, though.
With a ShapeAppereance having 8dp rounded corners, black corners artifacts are visible during return transition. You can see those on the GIF I posted in the original post. This is less noticeable but still there.
Tying the image to the activity's lifecycle can prevent the problem but that's essentially memory leak and isn't something that can be recommended IMHO. Is there anything that can be done on the MDC side? Since this problem doesn't happen when using regular androidx transitions and capturing the view after the fragment is destroyed or after the view is detached sounds problematic.
Same issue with Coil image loading framework. Anything new regarding this bug?
Thanks @mxalbert1996 and @hunterstich for your answers!
I just managed to make the return transition work for my use case. I've had to change the
Fragment
passed to Glide to its associatedActivity
(fragment.requireActivity()
) so that images are not cleared before being captured.There's still a problem with
ShapeableImageView
's corners, though. With a ShapeAppereance having 8dp rounded corners, black corners artifacts are visible during return transition. You can see those on the GIF I posted in the original post. This is less noticeable but still there.
i have a problem with the shapeableimageview with a corner radius having a back artifacts too. is there any solution or workaround for this?
@kenshin171 Using standard ImageView
and wrapping it with a MaterialCardView
should work I believe.
@mxalbert1996 thanks for the suggestion, black artifacts are gone BUT there is another issue where during transition all cardview corner radii are gone. It should be the same as this issue #1542
I have the same problem. But in my case I also have the same problem with MaterialCardView
I am also having this same issue. I also tested with coil but that doesn't help.
Description: I'm using
MaterialContainerTransform
to transition from Fragment A, to a Fragment B that contains aRecyclerView
whose items haveShapeableImageView
s. Note: Fragment A is part of aViewPager2
, hosted by Fragment Z.Transitionning from A to B works fine: transition is postponed until B's
RecyclerView
display is ready. But when returning from B, we notice that images (that are loaded with Glide) are reset and blank.Expected behavior: Images loaded into
ImageView
s should not be reset ; those should be preserved in the return transition. Also, why isSheapeableImageView
showing black rounded corners ? This strange behavior ofShapeableImageView
is also noticeable on Android Studio's layout preview (corners are then light grey).Source code:
In Fragment Z:
In Fragment A:
In Fragment B:
Android API version: 29 (Q)
Material Library version: 1.2.1
Device: Nokia 7.1, but also encountered on emulator.