Material-Animations icon indicating copy to clipboard operation
Material-Animations copied to clipboard

addSharedElement not work when using `add`

Open DanteAndroid opened this issue 7 years ago • 5 comments

                Fragment fragment = ViewerFragment.newInstance(diary.getPhotoUrl());
                fragment.setSharedElementEnterTransition(new ChangeBounds());
                getFragmentManager().beginTransaction()
                        .hide(this)//either using hide or not won't work
                        .add(R.id.container, fragment)// it work when using replace 
                        .addToBackStack("")
                        .addSharedElement(attachPicture, attachPicture.getTransitionName())
                        .commit();

Could you tell me why is that? Because I read the document of addSharedElement, it says:

Used with custom Transitions to map a View from a removed or hidden Fragment to a View from a shown or added Fragment.

DanteAndroid avatar Mar 15 '17 05:03 DanteAndroid

I have no idea sorry. Maybe because when you call add you are adding a new fragment instance, so your shared element can be referencing a view in the old one?

lgvalle avatar Mar 15 '17 17:03 lgvalle

I don't get you. When I use replace it works. The view is always referencing in the old one. I think it's a bug. Now I use Activity with sharedElement and works well. I think the document is clear enough, so... Don't you think?

DanteAndroid avatar Mar 16 '17 02:03 DanteAndroid

I have the same problem. It seems like an official bug. It works When I use 'com.android.support:support-v4:25.1.0' and '24.2.1',but ‘25.3.1’ does not . Try to change the support version to 25.1.0 or other can be used.

Lauzy avatar Aug 31 '17 15:08 Lauzy

I don't get you. When I use replace it works. The view is always referencing in the old one. I think it's a bug. Now I use Activity with sharedElement and works well. I think the document is clear enough, so... Don't you think?

Using replace it work fine

KishanViramgama avatar Sep 27 '18 10:09 KishanViramgama

I have exact issues even with androidX. I have open a bug on issuetracker on google. Anyone have found a workaround?

PhantomLord72 avatar Nov 19 '18 06:11 PhantomLord72