Use nested navigation for Account settings (#133)

This commit is contained in:
Andrew Haisting 2023-10-18 16:40:33 -05:00 committed by Álison Fernandes
parent a55d6a519a
commit 95b13882dd
5 changed files with 27 additions and 41 deletions

View file

@ -4,23 +4,33 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions import androidx.navigation.NavOptions
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.navigation
const val SETTINGS_ROUTE: String = "settings" const val SETTINGS_GRAPH_ROUTE: String = "settings_graph"
private const val SETTINGS_ROUTE: String = "settings"
/** /**
* Add settings destinations to the nav graph. * Add settings destinations to the nav graph.
*/ */
fun NavGraphBuilder.settingsDestinations( fun NavGraphBuilder.settingsGraph(
onNavigateToAccountSecurity: () -> Unit, navController: NavController,
) { ) {
composable(SETTINGS_ROUTE) { navigation(
SettingsScreen(onNavigateToAccountSecurity = onNavigateToAccountSecurity) startDestination = SETTINGS_ROUTE,
route = SETTINGS_GRAPH_ROUTE,
) {
composable(SETTINGS_ROUTE) {
SettingsScreen(
onNavigateToAccountSecurity = { navController.navigateToAccountSecurity() },
)
}
accountSecurityDestination(onNavigateBack = { navController.popBackStack() })
} }
} }
/** /**
* Navigate to the settings screen screen. * Navigate to the settings screen screen.
*/ */
fun NavController.navigateToSettings(navOptions: NavOptions? = null) { fun NavController.navigateToSettingsGraph(navOptions: NavOptions? = null) {
navigate(SETTINGS_ROUTE, navOptions) navigate(SETTINGS_GRAPH_ROUTE, navOptions)
} }

View file

@ -5,8 +5,6 @@ import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import androidx.navigation.NavOptions import androidx.navigation.NavOptions
import androidx.navigation.navigation import androidx.navigation.navigation
import com.x8bit.bitwarden.ui.platform.feature.settings.accountSecurityDestination
import com.x8bit.bitwarden.ui.platform.feature.settings.navigateToAccountSecurity
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
@ -27,11 +25,6 @@ fun NavGraphBuilder.vaultUnlockedDestinations(navController: NavHostController)
startDestination = VAULT_UNLOCKED_NAV_BAR_ROUTE, startDestination = VAULT_UNLOCKED_NAV_BAR_ROUTE,
route = VAULT_UNLOCKED_ROUTE, route = VAULT_UNLOCKED_ROUTE,
) { ) {
vaultUnlockedNavBarDestination( vaultUnlockedNavBarDestination()
onNavigateToAccountSecurity = { navController.navigateToAccountSecurity() },
)
accountSecurityDestination(
onNavigateBack = { navController.popBackStack() },
)
} }
} }

View file

@ -20,12 +20,8 @@ fun NavController.navigateToVaultUnlockedNavBar(navOptions: NavOptions? = null)
/** /**
* Add vault unlocked destination to the root nav graph. * Add vault unlocked destination to the root nav graph.
*/ */
fun NavGraphBuilder.vaultUnlockedNavBarDestination( fun NavGraphBuilder.vaultUnlockedNavBarDestination() {
onNavigateToAccountSecurity: () -> Unit,
) {
composable(VAULT_UNLOCKED_NAV_BAR_ROUTE) { composable(VAULT_UNLOCKED_NAV_BAR_ROUTE) {
VaultUnlockedNavBarScreen( VaultUnlockedNavBarScreen()
onNavigateToAccountSecurity = onNavigateToAccountSecurity,
)
} }
} }

View file

@ -28,9 +28,9 @@ import androidx.navigation.navOptions
import com.x8bit.bitwarden.R import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect
import com.x8bit.bitwarden.ui.platform.components.PlaceholderComposable import com.x8bit.bitwarden.ui.platform.components.PlaceholderComposable
import com.x8bit.bitwarden.ui.platform.feature.settings.SETTINGS_ROUTE import com.x8bit.bitwarden.ui.platform.feature.settings.SETTINGS_GRAPH_ROUTE
import com.x8bit.bitwarden.ui.platform.feature.settings.navigateToSettings import com.x8bit.bitwarden.ui.platform.feature.settings.navigateToSettingsGraph
import com.x8bit.bitwarden.ui.platform.feature.settings.settingsDestinations import com.x8bit.bitwarden.ui.platform.feature.settings.settingsGraph
import com.x8bit.bitwarden.ui.tools.feature.generator.GENERATOR_ROUTE import com.x8bit.bitwarden.ui.tools.feature.generator.GENERATOR_ROUTE
import com.x8bit.bitwarden.ui.tools.feature.generator.generatorDestination import com.x8bit.bitwarden.ui.tools.feature.generator.generatorDestination
import com.x8bit.bitwarden.ui.tools.feature.generator.navigateToGenerator import com.x8bit.bitwarden.ui.tools.feature.generator.navigateToGenerator
@ -44,7 +44,6 @@ import kotlinx.parcelize.Parcelize
*/ */
@Composable @Composable
fun VaultUnlockedNavBarScreen( fun VaultUnlockedNavBarScreen(
onNavigateToAccountSecurity: () -> Unit,
viewModel: VaultUnlockedNavBarViewModel = hiltViewModel(), viewModel: VaultUnlockedNavBarViewModel = hiltViewModel(),
navController: NavHostController = rememberNavController(), navController: NavHostController = rememberNavController(),
) { ) {
@ -65,14 +64,13 @@ fun VaultUnlockedNavBarScreen(
} }
VaultUnlockedNavBarEvent.NavigateToSettingsScreen -> { VaultUnlockedNavBarEvent.NavigateToSettingsScreen -> {
navigateToSettings(navOptions) navigateToSettingsGraph(navOptions)
} }
} }
} }
} }
VaultUnlockedNavBarScaffold( VaultUnlockedNavBarScaffold(
navController = navController, navController = navController,
onNavigateToAccountSecurity = onNavigateToAccountSecurity,
generatorTabClickedAction = { generatorTabClickedAction = {
viewModel.trySendAction(VaultUnlockedNavBarAction.GeneratorTabClick) viewModel.trySendAction(VaultUnlockedNavBarAction.GeneratorTabClick)
}, },
@ -94,7 +92,6 @@ fun VaultUnlockedNavBarScreen(
@Composable @Composable
@Suppress("LongMethod") @Suppress("LongMethod")
private fun VaultUnlockedNavBarScaffold( private fun VaultUnlockedNavBarScaffold(
onNavigateToAccountSecurity: () -> Unit,
navController: NavHostController, navController: NavHostController,
vaultTabClickedAction: () -> Unit, vaultTabClickedAction: () -> Unit,
sendTabClickedAction: () -> Unit, sendTabClickedAction: () -> Unit,
@ -168,9 +165,7 @@ private fun VaultUnlockedNavBarScaffold(
vaultDestination() vaultDestination()
sendDestination() sendDestination()
generatorDestination() generatorDestination()
settingsDestinations( settingsGraph(navController)
onNavigateToAccountSecurity = onNavigateToAccountSecurity,
)
} }
} }
} }
@ -259,7 +254,7 @@ private sealed class VaultUnlockedNavBarTab : Parcelable {
override val iconRes get() = R.drawable.ic_settings override val iconRes get() = R.drawable.ic_settings
override val labelRes get() = R.string.settings override val labelRes get() = R.string.settings
override val contentDescriptionRes get() = R.string.settings override val contentDescriptionRes get() = R.string.settings
override val route get() = SETTINGS_ROUTE override val route get() = SETTINGS_GRAPH_ROUTE
} }
} }

View file

@ -32,7 +32,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
VaultUnlockedNavBarScreen( VaultUnlockedNavBarScreen(
viewModel = viewModel, viewModel = viewModel,
navController = fakeNavHostController, navController = fakeNavHostController,
onNavigateToAccountSecurity = {},
) )
} }
onNodeWithText("My vault").performClick() onNodeWithText("My vault").performClick()
@ -53,7 +52,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
VaultUnlockedNavBarScreen( VaultUnlockedNavBarScreen(
viewModel = viewModel, viewModel = viewModel,
navController = fakeNavHostController, navController = fakeNavHostController,
onNavigateToAccountSecurity = {},
) )
} }
runOnIdle { fakeNavHostController.assertCurrentRoute("vault") } runOnIdle { fakeNavHostController.assertCurrentRoute("vault") }
@ -75,7 +73,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
VaultUnlockedNavBarScreen( VaultUnlockedNavBarScreen(
viewModel = viewModel, viewModel = viewModel,
navController = fakeNavHostController, navController = fakeNavHostController,
onNavigateToAccountSecurity = {},
) )
} }
onNodeWithText("Send").performClick() onNodeWithText("Send").performClick()
@ -96,7 +93,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
VaultUnlockedNavBarScreen( VaultUnlockedNavBarScreen(
viewModel = viewModel, viewModel = viewModel,
navController = fakeNavHostController, navController = fakeNavHostController,
onNavigateToAccountSecurity = {},
) )
} }
runOnIdle { fakeNavHostController.assertCurrentRoute("vault") } runOnIdle { fakeNavHostController.assertCurrentRoute("vault") }
@ -118,7 +114,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
VaultUnlockedNavBarScreen( VaultUnlockedNavBarScreen(
viewModel = viewModel, viewModel = viewModel,
navController = fakeNavHostController, navController = fakeNavHostController,
onNavigateToAccountSecurity = {},
) )
} }
onNodeWithText("Generator").performClick() onNodeWithText("Generator").performClick()
@ -139,7 +134,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
VaultUnlockedNavBarScreen( VaultUnlockedNavBarScreen(
viewModel = viewModel, viewModel = viewModel,
navController = fakeNavHostController, navController = fakeNavHostController,
onNavigateToAccountSecurity = {},
) )
} }
runOnIdle { fakeNavHostController.assertCurrentRoute("vault") } runOnIdle { fakeNavHostController.assertCurrentRoute("vault") }
@ -161,7 +155,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
VaultUnlockedNavBarScreen( VaultUnlockedNavBarScreen(
viewModel = viewModel, viewModel = viewModel,
navController = fakeNavHostController, navController = fakeNavHostController,
onNavigateToAccountSecurity = {},
) )
} }
onNodeWithText("Settings").performClick() onNodeWithText("Settings").performClick()
@ -182,14 +175,13 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
VaultUnlockedNavBarScreen( VaultUnlockedNavBarScreen(
viewModel = viewModel, viewModel = viewModel,
navController = fakeNavHostController, navController = fakeNavHostController,
onNavigateToAccountSecurity = {},
) )
} }
runOnIdle { fakeNavHostController.assertCurrentRoute("vault") } runOnIdle { fakeNavHostController.assertCurrentRoute("vault") }
vaultUnlockedNavBarEventFlow.tryEmit(VaultUnlockedNavBarEvent.NavigateToSettingsScreen) vaultUnlockedNavBarEventFlow.tryEmit(VaultUnlockedNavBarEvent.NavigateToSettingsScreen)
runOnIdle { runOnIdle {
fakeNavHostController.assertLastNavigation( fakeNavHostController.assertLastNavigation(
route = "settings", route = "settings_graph",
navOptions = expectedNavOptions, navOptions = expectedNavOptions,
) )
} }