Hello all :wave: Quick question does the navigati...
# navigation-architecture-component
g
Hello all 👋 Quick question does the navigation component support shared element transitions from fragment to a second activity?
b
It's not as easy as I'd like to be, but yes. I'm doing it here: https://github.com/brady-aiello/Avengers-Android-App/blob/cfdcd9887c34b14fec2b69cfc5138419a6fb84d4/app/src/main/java/com/avengers/employeedirectory/ui/EmployeeListFragment.kt#L149 Like any SharedElementTransition, the transitionName of each pair of shared elements must be the same, and the transition needs to be set. Then you need to pass the shared elements as FragmentNavigatorExtras to the navigate method. Then you need to postpone the enter animation to the new Fragment until it's been drawn, and then resume the postponed enter animation. Dnd you have to do the same thing when going back, if it's an item in a recycler view. And all this info must be set at the right time. Data binding helped a lot with that. I've had a lot of trouble getting this right. I mean, it works, but it's a pain. I wish Nav Comp SharedElementTransition just worked right out of the box, but there were a lot of hoops to jump through.
And sorry, it's not even exactly the same, because it's Fragment to Fragment, not Fragment to Activity, but the same approach generally applies.