Skip to content

Instantly share code, notes, and snippets.

@muhammedesadcomert
Created January 3, 2024 08:56
Show Gist options
  • Save muhammedesadcomert/b93ca552a0b84293a40aa609bbe0a1cd to your computer and use it in GitHub Desktop.
Save muhammedesadcomert/b93ca552a0b84293a40aa609bbe0a1cd to your computer and use it in GitHub Desktop.
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