compose-destinations
compose-destinations copied to clipboard
[Question] How to enable / disable animation based on destination value
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
@raamcosta Did you get a chance to look at this ?
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
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 Sure. Will try this & share the results here
@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 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)
)
}
)
)
Closing this. Take a look at v2's runtime animations as soon as that's documented!