Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove default transitions in Jetpack Compose Navigation

I'm using the following sippet of code to navigate from a composable to another one, but it has a default fade animation. How can I remove it? I tried using an empty anim resource but it doesn't work.

navHostController.navigate(
    "destination_route",
    navOptions {
        popUpTo("this_route") {
            inclusive = true
        }
        anim {
            enter = R.anim.empty_animation
            exit = R.anim.empty_animation
            popEnter = R.anim.empty_animation
            popExit = R.anim.empty_animation
        }
    }
)

R.anim.empty_animation:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <!--Empty to disable animation-->
</set>
like image 746
Soroush Lotfi Avatar asked Nov 16 '25 03:11

Soroush Lotfi


1 Answers

if you use version navigation-compose:2.7.5 or above, you need to add enterTransition and exitTransition in NavHost.

NavHost(navController = rememberNavigationBarController,
        startDestination = "home",
        modifier = Modifier.padding(it),
        enterTransition = {
            // you can change whatever you want transition
            EnterTransition.None 
        },
        exitTransition = {
            // you can change whatever you want transition
            ExitTransition.None
        }) {
        composable("home") {}
        composable("cinema") {}
        composable("ticket") { }
    }
like image 83
Dafi Avatar answered Nov 18 '25 17:11

Dafi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!