compose-destinations icon indicating copy to clipboard operation
compose-destinations copied to clipboard

[Question] How to enable / disable animation based on destination value

Open UKMIITB opened this issue 6 months ago • 4 comments

In DestinationsNavHost I am using rememberAnimatedNavHostEngine & provide rootDefaultAnimations as follows

engine = rememberAnimatedNavHostEngine(rootDefaultAnimations = RootNavGraphDefaultAnimations(
                        enterTransition = {
                            slideIntoContainer(
                                towards = AnimatedContentTransitionScope.SlideDirection.Companion.Left,
                                animationSpec = tween(400)
                            )
                        },
                        exitTransition = {
                            slideOutOfContainer(
                                towards = AnimatedContentTransitionScope.SlideDirection.Companion.Left,
                                animationSpec = tween(400)
                            )
                        },
                        popEnterTransition = {
                            slideIntoContainer(
                                towards = AnimatedContentTransitionScope.SlideDirection.Companion.Right,
                                animationSpec = tween(400)
                            )
                        },
                        popExitTransition = {
                            slideOutOfContainer(
                                towards = AnimatedContentTransitionScope.SlideDirection.Companion.Right,
                                animationSpec = tween(400)
                            )
                        }
                    ))

Is there a way to make this conditional ? I want to disable this if I am navigating to some specific destination or coming back from specific destination

UKMIITB avatar Jan 03 '24 09:01 UKMIITB

@raamcosta Did you get a chance to look at this ?

UKMIITB avatar Jan 16 '24 10:01 UKMIITB

You can just use DestinationStyle.Animated.None in the annotation of the destination that you want to disable. (This is from memory, but it should be something like this 😅).

Please try it and let me know

raamcosta avatar Jan 16 '24 10:01 raamcosta

Although that may only remove animation from that destination 🤔 If you are navigating to it and your current destination has some exit animation that exit would still be performed I believe.. so that may not be enough to achieve what you want..

But try it please 🙏

raamcosta avatar Jan 16 '24 10:01 raamcosta

@raamcosta Sure. Will try this & share the results here

UKMIITB avatar Jan 16 '24 18:01 UKMIITB

@UKMIITB : Did you manage to get your transition animations to work with Compose Destinations? Do you mind sharing the final code that worked for you?

arunabhdas avatar Feb 29 '24 21:02 arunabhdas

@arunabhdas For getting the animations for transition between destinations, this is the code that I used

engine =
                        rememberAnimatedNavHostEngine(
                            rootDefaultAnimations =
                                RootNavGraphDefaultAnimations(
                                    enterTransition = {
                                        slideIntoContainer(
                                            towards =
                                                AnimatedContentTransitionScope.SlideDirection
                                                    .Companion
                                                    .Left,
                                            animationSpec = tween(400)
                                        )
                                    },
                                    exitTransition = {
                                        slideOutOfContainer(
                                            towards =
                                                AnimatedContentTransitionScope.SlideDirection
                                                    .Companion
                                                    .Left,
                                            animationSpec = tween(400)
                                        )
                                    },
                                    popEnterTransition = {
                                        slideIntoContainer(
                                            towards =
                                                AnimatedContentTransitionScope.SlideDirection
                                                    .Companion
                                                    .Right,
                                            animationSpec = tween(400)
                                        )
                                    },
                                    popExitTransition = {
                                        slideOutOfContainer(
                                            towards =
                                                AnimatedContentTransitionScope.SlideDirection
                                                    .Companion
                                                    .Right,
                                            animationSpec = tween(400)
                                        )
                                    }
                                )
                        )

UKMIITB avatar Mar 01 '24 18:03 UKMIITB

Closing this. Take a look at v2's runtime animations as soon as that's documented!

raamcosta avatar Mar 12 '24 00:03 raamcosta