Closed topnax closed 4 years ago
Hey hey!
While it's not the theoretically best design choice, it's a "less intrusive" solution in Java than it would have been in Kotlin - so you can extends DefaultFragmentStateChanger
and override the following 3 methods:
protected void onForwardNavigation(@Nonnull FragmentTransaction fragmentTransaction, @Nonnull StateChange stateChange) {
fragmentTransaction.setCustomAnimations(R.anim.slide_in_from_right, R.anim.slide_out_to_left, R.anim.slide_in_from_right, R.anim.slide_out_to_left);
}
protected void onBackwardNavigation(@Nonnull FragmentTransaction fragmentTransaction, @Nonnull StateChange stateChange) {
fragmentTransaction.setCustomAnimations(R.anim.slide_in_from_left, R.anim.slide_out_to_right, R.anim.slide_in_from_left, R.anim.slide_out_to_right);
}
protected void onReplaceNavigation(@Nonnull FragmentTransaction fragmentTransaction, @Nonnull StateChange stateChange) {
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
}
If it's overridden as empty, or maybe things like val topNewKey = stateChange.topNewKey<MyFragmentKey>(); if(topNewKey.isAnimationEnabled()) { super.
then you can control whether animation happens or not.
Ultimate last resort can always be pasting the handleStateChange
and customize it as needed, but that shouldn't be needed as just overriding the methods should be sufficient, and is already possible.
Any luck?
Technically this is already possible so I will close the issue.
What would be the way to disable animation for just one transition? Is that possible?
@uberchilly heyo, by default, fragment animations can be customized by extending from DefaultFragmentStateChanger, and override either onReplaceNavigation, onForwardNavigation, or onBackwardNavigation.
If you don't call super.___ there it will not execute the default transition.
You can customize when you want to or don't want to keep it based on the stateChange
parameter, which contains the new keys and the previous keys.
It would be amazing if the default fragment state changer allowed us to disable fragment transaction animations.