mirror of
https://github.com/bitwarden/android.git
synced 2024-11-22 09:25:58 +03:00
Rename Login navigation components to Auth (#23)
This commit is contained in:
parent
c048d36f0e
commit
915e9d5fd6
4 changed files with 17 additions and 17 deletions
|
@ -1,4 +1,4 @@
|
||||||
package com.x8bit.bitwarden.ui.feature.login
|
package com.x8bit.bitwarden.ui.feature.auth
|
||||||
|
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
|
@ -10,15 +10,15 @@ import com.x8bit.bitwarden.ui.feature.createaccount.navigateToCreateAccount
|
||||||
import com.x8bit.bitwarden.ui.feature.landing.LANDING_ROUTE
|
import com.x8bit.bitwarden.ui.feature.landing.LANDING_ROUTE
|
||||||
import com.x8bit.bitwarden.ui.feature.landing.landingDestination
|
import com.x8bit.bitwarden.ui.feature.landing.landingDestination
|
||||||
|
|
||||||
const val LOGIN_ROUTE: String = "login"
|
const val AUTH_ROUTE: String = "auth"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add login destinations to the nav graph.
|
* Add auth destinations to the nav graph.
|
||||||
*/
|
*/
|
||||||
fun NavGraphBuilder.loginDestinations(navController: NavHostController) {
|
fun NavGraphBuilder.authDestinations(navController: NavHostController) {
|
||||||
navigation(
|
navigation(
|
||||||
startDestination = LANDING_ROUTE,
|
startDestination = LANDING_ROUTE,
|
||||||
route = LOGIN_ROUTE,
|
route = AUTH_ROUTE,
|
||||||
) {
|
) {
|
||||||
createAccountDestinations()
|
createAccountDestinations()
|
||||||
landingDestination(
|
landingDestination(
|
||||||
|
@ -28,10 +28,10 @@ fun NavGraphBuilder.loginDestinations(navController: NavHostController) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigate to the login screen. Note this will only work if login destination was added
|
* Navigate to the auth screen. Note this will only work if auth destination was added
|
||||||
* via [loginDestinations].
|
* via [authDestinations].
|
||||||
*/
|
*/
|
||||||
fun NavController.navigateToLogin(
|
fun NavController.navigateToAuth(
|
||||||
navOptions: NavOptions? = null,
|
navOptions: NavOptions? = null,
|
||||||
) {
|
) {
|
||||||
navigate(LANDING_ROUTE, navOptions)
|
navigate(LANDING_ROUTE, navOptions)
|
|
@ -12,8 +12,8 @@ import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import androidx.navigation.navOptions
|
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.auth.authDestinations
|
||||||
import com.x8bit.bitwarden.ui.feature.login.navigateToLogin
|
import com.x8bit.bitwarden.ui.feature.auth.navigateToAuth
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls root level [NavHost] for the app.
|
* Controls root level [NavHost] for the app.
|
||||||
|
@ -30,7 +30,7 @@ fun RootNavScreen(
|
||||||
startDestination = SplashRoute,
|
startDestination = SplashRoute,
|
||||||
) {
|
) {
|
||||||
splashDestinations()
|
splashDestinations()
|
||||||
loginDestinations(navController)
|
authDestinations(navController)
|
||||||
}
|
}
|
||||||
|
|
||||||
// When state changes, navigate to different root navigation state
|
// When state changes, navigate to different root navigation state
|
||||||
|
@ -41,7 +41,7 @@ fun RootNavScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
when (state) {
|
when (state) {
|
||||||
RootNavState.Login -> navController.navigateToLogin(rootNavOptions)
|
RootNavState.Auth -> navController.navigateToAuth(rootNavOptions)
|
||||||
RootNavState.Splash -> navController.navigateToSplash(rootNavOptions)
|
RootNavState.Splash -> navController.navigateToSplash(rootNavOptions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ class RootNavViewModel @Inject constructor() :
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
@Suppress("MagicNumber")
|
@Suppress("MagicNumber")
|
||||||
delay(1000)
|
delay(1000)
|
||||||
mutableStateFlow.value = RootNavState.Login
|
mutableStateFlow.value = RootNavState.Auth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,9 +32,9 @@ class RootNavViewModel @Inject constructor() :
|
||||||
*/
|
*/
|
||||||
sealed class RootNavState {
|
sealed class RootNavState {
|
||||||
/**
|
/**
|
||||||
* Show the login screen.
|
* Show the auth screens.
|
||||||
*/
|
*/
|
||||||
data object Login : RootNavState()
|
data object Auth : RootNavState()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the splash screen.
|
* Show the splash screen.
|
||||||
|
|
|
@ -16,11 +16,11 @@ class RootNavViewModelTests : BaseViewModelTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `state should move from splash to login`() = runTest {
|
fun `state should move from splash to auth`() = runTest {
|
||||||
val viewModel = RootNavViewModel()
|
val viewModel = RootNavViewModel()
|
||||||
viewModel.stateFlow.test {
|
viewModel.stateFlow.test {
|
||||||
assert(awaitItem() is RootNavState.Splash)
|
assert(awaitItem() is RootNavState.Splash)
|
||||||
assert(awaitItem() is RootNavState.Login)
|
assert(awaitItem() is RootNavState.Auth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue