Created
January 3, 2024 08:56
-
-
Save muhammedesadcomert/b93ca552a0b84293a40aa609bbe0a1cd to your computer and use it in GitHub Desktop.
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
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.getValue | |
import androidx.navigation.NavDestination | |
import androidx.navigation.NavDestination.Companion.hierarchy | |
import androidx.navigation.NavHostController | |
import androidx.navigation.compose.currentBackStackEntryAsState | |
@Composable | |
fun NavHostController.currentDestination(): NavDestination? { | |
val navBackStackEntry by currentBackStackEntryAsState() | |
return navBackStackEntry?.destination | |
} | |
@Composable | |
fun NavHostController.isRouteSelected(route: String): Boolean { | |
return currentDestination()?.hierarchy?.any { it.route == route } == true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment