This is an automated archive made by the Lemmit Bot.

The original was posted on /r/androiddev by /u/callmeeismann on 2024-11-06 19:07:35+00:00.


Specifically speaking about animating screen changes. I’ve found little to no discussion on this and Google’s sample apps offer no guidance. I am extremely curious to hear what people here think.

So let’s say we have the following, simple setup:

From Screen A I can navigate towards a Screen B and a Screen C.

Screen B is supposed to slide in from the right as Screen A slides out to the left and vice versa when the backstack is popped.

Screen C should slide in from the bottom while Screen A is not animated at all during the transition.

When navigating from Screen A to one of the other screens, the enter transition is used based on my destination declaration of B/C so they slide in from the right/bottom as expected. But instead of using the exit transition declared in B/C, it uses the exit transition declared in A! So now I’d have to check whether I’m transitioning to B or C in my setup for Screen A when determining the exit transition, which is doable in this simple setup but very quickly becomes unreasonably difficult to manage in a more complex app. It seems incredibly counter-intuitive to me that the exit transition isn’t taken from the destination that I’m navigating towards, similar to how it works in XML when executing a fragment transaction.

I had implemented a generic solution, passing in my desired transition as a navigation argument to each screen and retrieving it from the target state in the enter/exit and from the initial state in the popEnter/popExit transition lambdas. That worked totally fine and was very easy to use after the initial setup but refactoring an app of mine to use type-safe destinations has opened this question for me again. How do other folks here deal with this? I’m kind of baffled that I haven’t managed to find discussion or any helpful samples on this as it seems like an extremely common issue to me?