I want to transition between fragments with two shared elements. But the problem is: only one gets animated.
The shared elements are taken from a viewHolder from list in the first fragment. The transitions I use are from Material library, exactly these ones https://medium.com/androiddevelopers/material-motion-with-mdc-c1f09bb90bf9
Fragment A:
fragmentManager.commit {
replace([...])
setReorderingAllowed(true)
addSharedElement(viewA, viewA.transitionName)
addSharedElement(viewB, viewB.transitionName)
addToBackStack(fragmentClass.qualifiedName)
}
Fragment B:
sharedElementReturnTransition = MaterialContainerTransform().apply {
scrimColor = Color.TRANSPARENT
duration = 3000L
interpolator = DecelerateInterpolator()
}
binding.headerContainer.header.cover.transitionName = arguments?.getString("firstTrName") ?: return
binding.headerContainer.title.cover.transitionName = arguments?.getString("secondTrName") ?: return
binding.headerContainer.header.setImageResource(arguments?.getString("image") ?: return)
binding.headerContainer.title.text = arguments?.getString("title") ?: return
It seems like only the last element that I added in the commit{} is the one that transitions. I have checked everything, transition names are unique, all data is there in the second fragment, all transition names, it's not an argument problem. Any ideas? Help would be highly appreciated, this is a very important client request.
https://material.io/develop/android/theming/motion
Two shared element doesn't work properly. When selecting start view from the top of the list, imageView becomes a container. When selecting from the bottom, textView becomes a container. (See difference between example1 and example5 from the gif below)
You can use traditional shared element transition instead of Material Motion.
EXAMPLE AND GIF
SOLUTION
You can change transition like this:
Proper way of using MaterialContainerTransform:
Share one element
FragmentEnd Layout:
Set transition name to top layout of fragmentEnd
RESULT