Component used: Navigation
Version used: 1.0.0-alpha06
Devices/Android versions reproduced on: All
Fragment one: RecyclerView (GridLayoutManager). Transition name to ImageView is assigned in Adapter from model's name (unique)
Fragment two: Detail Fragment with ImageView and some text data. Transition name retrieved from argument's bundle.
Forward shared transition works excellent, but when I press "back" button there is no transition at all.
In NavHostActivity: override fun onSupportNavigateUp() = findNavController(R.id.nav_host_fragment).navigateUp()
In old paradigm
.beginTransaction()
.addSharedElement(sharedImageView, transitionName)
all worked fine.
I'm also experiencing a lot of issues using shared element transitions. See this commit, the reenter transition causes weird issues: https://github.com/tsuijten/android-architecture-components/commit/3562ed4f31b42c74ae0665f0c8c6d5a82a03ac94
The GithubBrowserSample contains a working shared element transition, added in #546. Feel free to use that as an example and use resources such as stackoverflow.com for help with your own implementation.
The GithubBrowserSample contains a shared element transition between an ImageView and another ImageView. When trying to do this between two different element types (such as a list element and the entire detail view, like in gmail when selecting on an email), the return transition does not seem to work. Are there any examples that use shared element transition with navigation component between a list and the list detail view?
For a master fragment with recyclerview and a detail fragment with the item layout as header, the animation works when going to the detail but it doesn't animate on return.
val extras = FragmentNavigatorExtras(view to ViewCompat.getTransitionName(view))
val directions = MasterFragmentDirections.actionToDetail(item.id)
findNavController().navigate(directions, extras)
if I replace the last line (navigate) with
requireFragmentManager().beginTransaction()
.addToBackStack(null)
.replace(R.id.main_content, DetailFragment().apply { arguments = directions.arguments})
.apply {
extras.sharedElements.entries.forEach {
addSharedElement(it.key, it.value)
}
}
.commit()
It is working perfectly ... but navigation is useless.
Regards``
I think I found the reason with debugging.
navigate will create a transaction with
setReorderingAllowed(true)
This seems to cause the issue
I found a workaround
In calling fragment, add the following in onViewCreated (or at the end of onCreateView)
postponeEnterTransition()
view.doOnPreDraw { startPostponedEnterTransition() }
Tried @wrabot 's solution, but no luck. Could you provide a working sample of that?
Okay, I figured it out. The problem that I was making is that I didn't use postPostponeTransition() on the parent fragment(which is the fragment that actually perform the transaction). So when you have a multiple layer of fragments (like having a viewpager with fragments), then you may probably need to use parent.postPostponeTransition()and parent.startPostponedEnterTransition().
Okay, I figured it out. The problem that I was making is that I didn't use postPostponeTransition() on the parent fragment(which is the fragment that actually perform the transaction). So when you have a multiple layer of fragments (like having a viewpager with fragments), then you may probably need to use
parent.postPostponeTransition()andparent.startPostponedEnterTransition().
@kdreamix I'm in the same situation with:
Parent Fragment A containing a ViewPager2 with Fragment B, C, D. Fragment D has a button to open Fragment E. The enter transition between D and E works but not the exit transition.
Transition from parent Fragment A to E works in both way.
How did you solve the issue exactly?
Thanks
I think I found the reason with debugging.
navigate will create a transaction withsetReorderingAllowed(true)This seems to cause the issue
I found a workaround
In calling fragment, add the following in onViewCreated (or at the end of onCreateView)postponeEnterTransition() view.doOnPreDraw { startPostponedEnterTransition() }
I'm using this but with doOnLayout and the transition seems to be working fine. Although is making some weird things with the Navigation, for example: every time I click on any of the Items of the BottomNavigationView causes the startDestination Fragment to be shown for some milliseconds (on Fragments that had the fix).
Did you find a solution to the startDestination glitch @kevinvillalobosGL?
@kroegerama I had the same issue, and upgrading to androidx.fragment:fragment:1.3.0-beta01 (from 1.2.5) seems to have solved the issue.
You still need the workaround though.
Most helpful comment
I think I found the reason with debugging.
navigate will create a transaction with
This seems to cause the issue
I found a workaround
In calling fragment, add the following in onViewCreated (or at the end of onCreateView)