I would like to add a shared elements transition using the navigation architecture components, when navigating to an other fragment. But I have no idea how. Also in the document
With the latest library version you can just write the following:
view.findNavController().navigate(
R.id.action_firstFragment_to_secondFragment,
null,
null,
FragmentNavigator.Extras.Builder().addSharedElements(
mapOf(
firstSharedElementView to "firstSharedElementName",
secondSharedElementView to "secondSharedElementName"
)
).build()
)
For the transition to work you also have to specify the sharedElementEnterTransition
and/or the sharedElementReturnTransition
in the destination Fragments onCreateView method just as Xzin explained in his answer.