Skip to content

Commit

Permalink
chore: Always restoreState in bottom navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisCAD committed Dec 17, 2024
1 parent b316896 commit d223148
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,17 @@ private fun NavHostController.navigateToSelectedItem(destination: MainNavigation
}
// Avoid multiple copies of the same destination when re-selecting the same item
launchSingleTop = true

// Restore state when re-selecting a previously selected item
val currentBackStackEntry = this@navigateToSelectedItem.currentBackStackEntry
val hasDeepLink = currentBackStackEntry?.arguments?.parcelableExtra<Intent>(NavController.KEY_DEEP_LINK_INTENT) != null
val isNavigatingToStartDestination = startDestination.route == destination::class.qualifiedName
restoreState = !hasDeepLink || !isNavigatingToStartDestination
restoreState = true

// The commented code below was supposed to be an improvement on the line above,
// but it doesn't behave the way we'd like. TODO: Find a better solution that works

// val currentBackStackEntry = [email protected]
// val hasDeepLink = currentBackStackEntry?.arguments?.parcelableExtra<Intent>(NavController.KEY_DEEP_LINK_INTENT) != null
// val isNavigatingToStartDestination = startDestination.route == destination::class.qualifiedName
// restoreState = !hasDeepLink || !isNavigatingToStartDestination
}
}

Expand Down

0 comments on commit d223148

Please sign in to comment.