Created
April 21, 2022 19:25
-
-
Save safaorhan/70216fa8edd47c3b7106dabcc7803293 to your computer and use it in GitHub Desktop.
Log the fragment back stack status with each change for debugging purposes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from: https://stackoverflow.com/a/67267584/3539594 | |
private fun listenNavigationChanges() { | |
val navHost = supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment | |
val navController = navHost.navController | |
navController.addOnDestinationChangedListener { _, destination, _ -> | |
val breadcrumb = navController | |
.backQueue | |
.map { | |
it.destination | |
} | |
.filterNot { | |
it is NavGraph | |
} | |
.joinToString(" > ") { | |
it.displayName.split('/')[1] | |
} | |
println(breadcrumb) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment