Reputation: 8899
I am trying to use shared element transition animation with navigation components, but it is not working, may be I am using it wrongly.
when navigation from Fragment A to Fragment B I did like this: Fragment A:
val extras = FragmentNavigatorExtras(v to file.nameInStorage)
val action = FilesFragmentDirections.actionFilesFragmentToImageViewerFragment()
findNavController().navigate(action, extras)
Fragment B:
viewPagerImage.transitionName = filesListViewModel.selectedImage.nameInStorage
But unfortunately, it is not working!!! Can you help me with this?
Upvotes: 0
Views: 46
Reputation:
add these transition lines in your nav_graph.xml action inside your navigation package
<action
app:popEnterAnim="@anim/anim1_enter"
app:popExitAnim="@anim/anim1_exit"
app:enterAnim="@anim/anim2_enter"
app:exitAnim="@anim/anim2_exit"
android:id="@+id/action_homeFragment_to_newsFragment"
app:destination="@id/newsFragment" />
code will look like
<fragment
android:id="@+id/homeFragment"
android:name="com.morchhattisgarh.india.fragments.HomeFragment"
android:label="fragment_home"
tools:layout="@layout/fragment_home" >
<action
app:popEnterAnim="@anim/anim1_enter"
app:popExitAnim="@anim/anim1_exit"
app:enterAnim="@anim/anim2_enter"
app:exitAnim="@anim/anim2_exit"
android:id="@+id/action_homeFragment_to_newsFragment"
app:destination="@id/newsFragment" />
</fragment>
Note - you need to defines anims files inside anim package
Upvotes: 1