From 13468631d6b41faf369aec9b0e03c511366cea07 Mon Sep 17 00:00:00 2001 From: anhtuannd Date: Wed, 11 Sep 2024 08:41:36 +0200 Subject: [PATCH] Refactor and remove isStartDestinationSameWithNextDestination --- .../samples/apps/nowinandroid/ui/NiaAppState.kt | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt index 1bc6059d5..177fe39d8 100644 --- a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt +++ b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt @@ -143,10 +143,10 @@ class NiaAppState( trace("Navigation: ${topLevelDestination.name}") { val topLevelNavOptions = navOptions { val startDestination = navController.graph.findStartDestination() + // Avoid popUpTo and navigate to same screen. - val shouldNotSavedAndRestored = isStartDestinationSameWithNextDestination( - startDestination, topLevelDestination - ) ?: false + val shouldNotSavedAndRestored = startDestination.hasRoute(topLevelDestination.route) + // Pop up to the start destination of the graph to // avoid building up a large stack of destinations // on the back stack as users select items @@ -168,14 +168,6 @@ class NiaAppState( } } - /** - * Check if next destination is same with start destination of current graph. - */ - private fun isStartDestinationSameWithNextDestination( - startDestination: NavDestination, - nextDestination: TopLevelDestination, - ): Boolean? = startDestination.hasRoute(nextDestination.route) - fun navigateToSearch() = navController.navigateToSearch() }