mirror of
https://github.com/bitwarden/android.git
synced 2024-11-25 02:46:00 +03:00
Update all navigateTo helpers to pass NavOptions (#20)
This commit is contained in:
parent
24c7dade1e
commit
880d7ae786
2 changed files with 20 additions and 17 deletions
|
@ -3,6 +3,7 @@ package com.x8bit.bitwarden.ui.feature.login
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
|
import androidx.navigation.NavOptions
|
||||||
import androidx.navigation.navigation
|
import androidx.navigation.navigation
|
||||||
import com.x8bit.bitwarden.ui.feature.createaccount.createAccountDestinations
|
import com.x8bit.bitwarden.ui.feature.createaccount.createAccountDestinations
|
||||||
import com.x8bit.bitwarden.ui.feature.createaccount.navigateToCreateAccount
|
import com.x8bit.bitwarden.ui.feature.createaccount.navigateToCreateAccount
|
||||||
|
@ -30,11 +31,8 @@ fun NavGraphBuilder.loginDestinations(navController: NavHostController) {
|
||||||
* Navigate to the login screen. Note this will only work if login destination was added
|
* Navigate to the login screen. Note this will only work if login destination was added
|
||||||
* via [loginDestinations].
|
* via [loginDestinations].
|
||||||
*/
|
*/
|
||||||
fun NavController.navigateToLoginAsRoot() {
|
fun NavController.navigateToLogin(
|
||||||
navigate(LANDING_ROUTE) {
|
navOptions: NavOptions? = null,
|
||||||
// When changing root navigation state, pop everything else off the back stack:
|
) {
|
||||||
popUpTo(graph.id) {
|
navigate(LANDING_ROUTE, navOptions)
|
||||||
inclusive = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,14 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
|
import androidx.navigation.NavOptions
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
|
import androidx.navigation.navOptions
|
||||||
import com.x8bit.bitwarden.ui.components.PlaceholderComposable
|
import com.x8bit.bitwarden.ui.components.PlaceholderComposable
|
||||||
import com.x8bit.bitwarden.ui.feature.login.loginDestinations
|
import com.x8bit.bitwarden.ui.feature.login.loginDestinations
|
||||||
import com.x8bit.bitwarden.ui.feature.login.navigateToLoginAsRoot
|
import com.x8bit.bitwarden.ui.feature.login.navigateToLogin
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls root level [NavHost] for the app.
|
* Controls root level [NavHost] for the app.
|
||||||
|
@ -32,9 +34,15 @@ fun RootNavScreen(
|
||||||
}
|
}
|
||||||
|
|
||||||
// When state changes, navigate to different root navigation state
|
// When state changes, navigate to different root navigation state
|
||||||
|
val rootNavOptions = navOptions {
|
||||||
|
// When changing root navigation state, pop everything else off the back stack:
|
||||||
|
popUpTo(navController.graph.id) {
|
||||||
|
inclusive = true
|
||||||
|
}
|
||||||
|
}
|
||||||
when (state) {
|
when (state) {
|
||||||
RootNavState.Login -> navController.navigateToLoginAsRoot()
|
RootNavState.Login -> navController.navigateToLogin(rootNavOptions)
|
||||||
RootNavState.Splash -> navController.navigateToSplashAsRoot()
|
RootNavState.Splash -> navController.navigateToSplash(rootNavOptions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,11 +76,8 @@ private fun NavGraphBuilder.splashDestinations() {
|
||||||
* TODO: move to splash package (BIT-147)
|
* TODO: move to splash package (BIT-147)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private fun NavController.navigateToSplashAsRoot() {
|
private fun NavController.navigateToSplash(
|
||||||
navigate(SplashRoute) {
|
navOptions: NavOptions? = null,
|
||||||
// When changing root navigation state, pop everything else off the back stack:
|
) {
|
||||||
popUpTo(graph.id) {
|
navigate(SplashRoute, navOptions)
|
||||||
inclusive = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue