mirror of
https://github.com/bitwarden/android.git
synced 2024-11-22 01:16:02 +03:00
BIT-201 Update nav library version and remove workarounds (#63)
This commit is contained in:
parent
90cc9dd270
commit
0e51e76391
4 changed files with 3 additions and 46 deletions
|
@ -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.loginDestinations
|
||||||
import com.x8bit.bitwarden.ui.auth.feature.login.navigateToLogin
|
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.
|
* Add auth destinations to the nav graph.
|
||||||
|
|
|
@ -4,18 +4,15 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.navigation.NavDestination
|
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import androidx.navigation.navOptions
|
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.authDestinations
|
||||||
import com.x8bit.bitwarden.ui.auth.feature.auth.navigateToAuth
|
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.SPLASH_ROUTE
|
||||||
import com.x8bit.bitwarden.ui.platform.feature.splash.navigateToSplash
|
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.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.navigateToVaultUnlocked
|
||||||
import com.x8bit.bitwarden.ui.platform.feature.vaultunlocked.vaultUnlockedDestinations
|
import com.x8bit.bitwarden.ui.platform.feature.vaultunlocked.vaultUnlockedDestinations
|
||||||
|
|
||||||
|
@ -49,45 +46,9 @@ fun RootNavScreen(
|
||||||
restoreState = true
|
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) {
|
when (state) {
|
||||||
RootNavState.Auth -> navController.navigateToAuth(rootNavOptions)
|
RootNavState.Auth -> navController.navigateToAuth(rootNavOptions)
|
||||||
RootNavState.Splash -> navController.navigateToSplash(rootNavOptions)
|
RootNavState.Splash -> navController.navigateToSplash(rootNavOptions)
|
||||||
RootNavState.VaultUnlocked -> navController.navigateToVaultUnlocked(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()
|
|
||||||
}
|
|
||||||
|
|
|
@ -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.VAULT_UNLOCKED_NAV_BAR_ROUTE
|
||||||
import com.x8bit.bitwarden.ui.platform.feature.vaultunlockednavbar.vaultUnlockedNavBarDestination
|
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.
|
* Navigate to the vault unlocked screen.
|
||||||
|
|
|
@ -14,11 +14,7 @@ androidxComposeBom = "2023.06.01"
|
||||||
androidxCore = "1.10.1"
|
androidxCore = "1.10.1"
|
||||||
androidxHiltNavigationCompose = "1.0.0"
|
androidxHiltNavigationCompose = "1.0.0"
|
||||||
androidxLifecycle = "2.6.1"
|
androidxLifecycle = "2.6.1"
|
||||||
# Currently holding navigation at this version because of this bug:
|
androidxNavigation = "2.7.2"
|
||||||
# https://issuetracker.google.com/issues/298059596
|
|
||||||
# When updating, ensure that rememeberSaveable works correctly through process death in
|
|
||||||
# child navigation destinations (BIT-201).
|
|
||||||
androidxNavigation = "2.5.3"
|
|
||||||
androidxRoom = "2.5.2"
|
androidxRoom = "2.5.2"
|
||||||
# Once the app and SDK reach a critical point of completeness we should begin fixing the version
|
# Once the app and SDK reach a critical point of completeness we should begin fixing the version
|
||||||
# here (BIT-311).
|
# here (BIT-311).
|
||||||
|
|
Loading…
Reference in a new issue