Search code examples
androidandroid-architecture-componentsnavigationcontroller

How to use shared element transitions in Navigation Controller


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 documentations there is nothing about it. Can someone help me?


Solution

  • I took reference from this github sample https://github.com/serbelga/android_navigation_shared_elements

    cardView.setOnClickListener{
      val extras = FragmentNavigatorExtras(
        imageView to "imageView"
      )
      findNavController().navigate(R.id.detailAction, null, null, extras)
    }
    
    override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      sharedElementEnterTransition = TransitionInflater.from(context).inflateTransition(android.R.transition.move)
    

    It is working properly.