Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Navigation Animation Complete Listener

I'm trying to get a callback, using the Jetpack Navigation library, when a new navigation event is completed in order to change the status bar color.

So far I've found navController.addOnDestinationChangedListener which notifies me when a new navigation starts but not when it completes, meaning that the enter/exit transitions have completed.

Is there any method to know when all navigation transitions have completed?

like image 619
Alqueraf Avatar asked Jul 18 '19 09:07

Alqueraf


People also ask

What is Navigation animation?

Navigation and motion Navigation transitions use motion to guide users between two screens in your app. They help users orient themselves by expressing your app's hierarchy, using movement to indicate how elements are related to one another.

What is transition animation in Android?

Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.


1 Answers

You can use something like this:

val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment)
navHostFragment?.childFragmentManager?.addOnBackStackChangedListener {
    val currentFragment = navHostFragment.childFragmentManager.fragments.firstOrNull()
    if (currentFragment is YourFragment) {
        // your code here  
    } 
}
like image 114
dmytro19 Avatar answered Jan 11 '23 22:01

dmytro19