Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent reverse shared element transition

I have a litle problem.

I have a fragment A with a list and an activity B with also a list. Now A and B have an image in common, so I set up an shared element transition and it works on the way from A to B.

But I don't want to have the reverse transition if I press the back button. So I don't call in B supportFinishAfterTransition instead of finish. But now there is some ugly animation:

B disappears normally except the image. The image stays in foreground until A is visible in the background and then disappears.

How can I prevent this? I want the normal behavior like if I would call finish or onBackPressed.

Greets

like image 310
lampenlampen Avatar asked Apr 28 '17 14:04

lampenlampen


2 Answers

I found a solution.

I have played around a bit and if you override onBackPressed() and call finish() instead of super.onBackPressed(), It works.

like image 96
lampenlampen Avatar answered Oct 15 '22 08:10

lampenlampen


just stumbled upon this problem and there's a cleaner solution..

Just override finishAfterTransition(). You should have a boolean in your base class maybe, so it will look like this:

final override fun finishAfterTransition() {
    if (myShouldAllowReverseTransitionsBoolean) {
        super.finishAfterTransition()
    } else {
        super.finish()
    }
}
like image 22
guy_m Avatar answered Oct 15 '22 07:10

guy_m