BIT-201 Update nav library version and remove workarounds (#63)

This commit is contained in:
Andrew Haisting
2023-09-21 17:00:49 -05:00
committed by Álison Fernandes
parent 90cc9dd270
commit 0e51e76391
4 changed files with 3 additions and 46 deletions

View File

@@ -13,7 +13,7 @@ import com.x8bit.bitwarden.ui.auth.feature.landing.navigateToLanding
import com.x8bit.bitwarden.ui.auth.feature.login.loginDestinations
import com.x8bit.bitwarden.ui.auth.feature.login.navigateToLogin
const val AUTH_ROUTE: String = "auth"
private const val AUTH_ROUTE: String = "auth"
/**
* Add auth destinations to the nav graph.

View File

@@ -4,18 +4,15 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavDestination
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navOptions
import com.x8bit.bitwarden.ui.auth.feature.auth.AUTH_ROUTE
import com.x8bit.bitwarden.ui.auth.feature.auth.authDestinations
import com.x8bit.bitwarden.ui.auth.feature.auth.navigateToAuth
import com.x8bit.bitwarden.ui.platform.feature.splash.SPLASH_ROUTE
import com.x8bit.bitwarden.ui.platform.feature.splash.navigateToSplash
import com.x8bit.bitwarden.ui.platform.feature.splash.splashDestinations
import com.x8bit.bitwarden.ui.platform.feature.vaultunlocked.VAULT_UNLOCKED_ROUTE
import com.x8bit.bitwarden.ui.platform.feature.vaultunlocked.navigateToVaultUnlocked
import com.x8bit.bitwarden.ui.platform.feature.vaultunlocked.vaultUnlockedDestinations
@@ -49,45 +46,9 @@ fun RootNavScreen(
restoreState = true
}
// This workaround is for an issue where "launchSingleTop" flag does not work correctly
// and we "re-navigate" after rotation or process death. To prevent this, we are currently
// checking the root level route and no-opping the navigation, because we are already there.
// When upgrading to the latest compose nav version (which we currently aren't doing for
// other reasons), we can test that this workaround is no longer needed and remove it.
// To test, remove the (currentRoute == targetRoute) and test that state is saved
// on process death and rotation (BIT-201).
val targetRoute = when (state) {
RootNavState.Auth -> AUTH_ROUTE
RootNavState.Splash -> SPLASH_ROUTE
RootNavState.VaultUnlocked -> VAULT_UNLOCKED_ROUTE
}
val currentRoute = navController.currentDestination?.routeLevelRoute()
// Don't navigate if we are already at the correct root:
if (currentRoute == targetRoute) {
return
}
when (state) {
RootNavState.Auth -> navController.navigateToAuth(rootNavOptions)
RootNavState.Splash -> navController.navigateToSplash(rootNavOptions)
RootNavState.VaultUnlocked -> navController.navigateToVaultUnlocked(rootNavOptions)
}
}
/**
* Helper method that returns the highest level route for the given [NavDestination].
*
* As noted above, this can be removed after upgrading to latest compose navigation, since
* the nav args can prevent us from having to do this check.
*/
@Suppress("ReturnCount")
private fun NavDestination?.routeLevelRoute(): String? {
if (this == null) {
return null
}
if (parent?.route == null) {
return route
}
return parent.routeLevelRoute()
}

View File

@@ -7,7 +7,7 @@ import androidx.navigation.navigation
import com.x8bit.bitwarden.ui.platform.feature.vaultunlockednavbar.VAULT_UNLOCKED_NAV_BAR_ROUTE
import com.x8bit.bitwarden.ui.platform.feature.vaultunlockednavbar.vaultUnlockedNavBarDestination
const val VAULT_UNLOCKED_ROUTE: String = "VaultUnlocked"
private const val VAULT_UNLOCKED_ROUTE: String = "VaultUnlocked"
/**
* Navigate to the vault unlocked screen.