Updated Fragments to v1.7 and switched from Animations to Animators as per the Android guide. This brings predictive back gesture support to the FragmentManager back stack. Because the previous scene is now peekable on Android as well as iOS, removed the platform checks from the peekable logic. For example, rendering a fluently skipped scene in the background is necessary on Android, too.
The FragmentManager only supports predictive back on primary Fragments. A Fragment is only primary if it and all its ancestor Fragments are primary. The simplest way to do this was to create all stack Fragments as children of the Activity’s FragmentManager. Then don’t have to worry about the ancestors because they have none. But a FragmentManager can only have one primary Fragment at a time and switching the primary Fragment around, depending on which one was at the top, is difficult. Can’t just use onAttached/Detached to/from the window to move it around.
For example, consider a stack within a stack (not inside a modal - just one of the scenes in a stack renders a new stack). What happens after gesturing back to the beginning of the child stack? The child stack is still in the window but the gesture back should go to the parent instead.
So created the stack Fragments inside each other’s childFragmentManagers. In the Twitter sample, the top level stack is in the Activity’s FragmentManager and the child nested tab stacks are created in the top level stack’s childFragmentManager. That way both the parent stack and (one of) the nested stacks can both be primary Fragments at the same time. Now only have to shift the primary around between the sibling stacks, not between parent and child, and can use onAttached/Detached for that.
There’s some weirdness around the predictive back that couldn’t get to the bottom of.
Couldn’t get Transitions to work. Not just shared elements but material transitions, too. Even with the predictive back turned off transitions still wouldn’t work. Some of it is the switch to Animators. The fragment library doesn’t like Animators and Transitions configured together. But even after skipping setCutomAnimations, when there’s a Transition, there were still problems. Kept getting a blank screen when the gesture back was cancelled (cancelling Transactions was added for predictive back). Also OnTransitionEnd fired when Transition was cancelled so it’s hard to tell cancel apart from success. Even if all this worked the ChangeTransform returned false from isSeekingSupported so predictive back wouldn’t work for shared elements?! Worked around it by forcing in all four transitions (enter, return, exit, reenter) if there was at least one and making sure they had isSeekingSupported set to false.
Predictive back listeners don’t always fire in reverse order as promised. The modal back listener in the medley sample always received the gesture back even if there was a back stack in the modal. So the modal closed instead of going back through the stack first. Think it must be that different OnBackPressedDispatchers have different precedence?! Writing a custom gesture back for a modal that uses the Activity’s dispatcher should fix it.
Updated Fragments to v1.7 and switched from Animations to Animators as per the Android guide. This brings predictive back gesture support to the
FragmentManager
back stack. Because the previous scene is now peekable on Android as well as iOS, removed the platform checks from the peekable logic. For example, rendering a fluently skipped scene in the background is necessary on Android, too.The
FragmentManager
only supports predictive back on primary Fragments. A Fragment is only primary if it and all its ancestor Fragments are primary. The simplest way to do this was to create all stack Fragments as children of the Activity’sFragmentManager
. Then don’t have to worry about the ancestors because they have none. But aFragmentManager
can only have one primary Fragment at a time and switching the primary Fragment around, depending on which one was at the top, is difficult. Can’t just useonAttached/Detached
to/from the window to move it around.For example, consider a stack within a stack (not inside a modal - just one of the scenes in a stack renders a new stack). What happens after gesturing back to the beginning of the child stack? The child stack is still in the window but the gesture back should go to the parent instead.
So created the stack Fragments inside each other’s
childFragmentManagers
. In the Twitter sample, the top level stack is in the Activity’sFragmentManager
and the child nested tab stacks are created in the top level stack’schildFragmentManager
. That way both the parent stack and (one of) the nested stacks can both be primary Fragments at the same time. Now only have to shift the primary around between the sibling stacks, not between parent and child, and can useonAttached/Detached
for that.There’s some weirdness around the predictive back that couldn’t get to the bottom of.
setCutomAnimations
, when there’s a Transition, there were still problems. Kept getting a blank screen when the gesture back was cancelled (cancelling Transactions was added for predictive back). AlsoOnTransitionEnd
fired when Transition was cancelled so it’s hard to tell cancel apart from success. Even if all this worked theChangeTransform
returned false fromisSeekingSupported
so predictive back wouldn’t work for shared elements?! Worked around it by forcing in all four transitions (enter, return, exit, reenter) if there was at least one and making sure they hadisSeekingSupported
set to false.OnBackPressedDispatchers
have different precedence?! Writing a custom gesture back for a modal that uses the Activity’s dispatcher should fix it.