mirror of
https://github.com/bitwarden/android.git
synced 2024-11-24 18:36:32 +03:00
Use nested navigation for Account settings (#133)
This commit is contained in:
parent
a55d6a519a
commit
95b13882dd
5 changed files with 27 additions and 41 deletions
|
@ -4,23 +4,33 @@ import androidx.navigation.NavController
|
|||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.NavOptions
|
||||
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.
|
||||
*/
|
||||
fun NavGraphBuilder.settingsDestinations(
|
||||
onNavigateToAccountSecurity: () -> Unit,
|
||||
fun NavGraphBuilder.settingsGraph(
|
||||
navController: NavController,
|
||||
) {
|
||||
navigation(
|
||||
startDestination = SETTINGS_ROUTE,
|
||||
route = SETTINGS_GRAPH_ROUTE,
|
||||
) {
|
||||
composable(SETTINGS_ROUTE) {
|
||||
SettingsScreen(onNavigateToAccountSecurity = onNavigateToAccountSecurity)
|
||||
SettingsScreen(
|
||||
onNavigateToAccountSecurity = { navController.navigateToAccountSecurity() },
|
||||
)
|
||||
}
|
||||
accountSecurityDestination(onNavigateBack = { navController.popBackStack() })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to the settings screen screen.
|
||||
*/
|
||||
fun NavController.navigateToSettings(navOptions: NavOptions? = null) {
|
||||
navigate(SETTINGS_ROUTE, navOptions)
|
||||
fun NavController.navigateToSettingsGraph(navOptions: NavOptions? = null) {
|
||||
navigate(SETTINGS_GRAPH_ROUTE, navOptions)
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ import androidx.navigation.NavGraphBuilder
|
|||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.NavOptions
|
||||
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.vaultUnlockedNavBarDestination
|
||||
|
||||
|
@ -27,11 +25,6 @@ fun NavGraphBuilder.vaultUnlockedDestinations(navController: NavHostController)
|
|||
startDestination = VAULT_UNLOCKED_NAV_BAR_ROUTE,
|
||||
route = VAULT_UNLOCKED_ROUTE,
|
||||
) {
|
||||
vaultUnlockedNavBarDestination(
|
||||
onNavigateToAccountSecurity = { navController.navigateToAccountSecurity() },
|
||||
)
|
||||
accountSecurityDestination(
|
||||
onNavigateBack = { navController.popBackStack() },
|
||||
)
|
||||
vaultUnlockedNavBarDestination()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,8 @@ fun NavController.navigateToVaultUnlockedNavBar(navOptions: NavOptions? = null)
|
|||
/**
|
||||
* Add vault unlocked destination to the root nav graph.
|
||||
*/
|
||||
fun NavGraphBuilder.vaultUnlockedNavBarDestination(
|
||||
onNavigateToAccountSecurity: () -> Unit,
|
||||
) {
|
||||
fun NavGraphBuilder.vaultUnlockedNavBarDestination() {
|
||||
composable(VAULT_UNLOCKED_NAV_BAR_ROUTE) {
|
||||
VaultUnlockedNavBarScreen(
|
||||
onNavigateToAccountSecurity = onNavigateToAccountSecurity,
|
||||
)
|
||||
VaultUnlockedNavBarScreen()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ import androidx.navigation.navOptions
|
|||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect
|
||||
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.navigateToSettings
|
||||
import com.x8bit.bitwarden.ui.platform.feature.settings.settingsDestinations
|
||||
import com.x8bit.bitwarden.ui.platform.feature.settings.SETTINGS_GRAPH_ROUTE
|
||||
import com.x8bit.bitwarden.ui.platform.feature.settings.navigateToSettingsGraph
|
||||
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.generatorDestination
|
||||
import com.x8bit.bitwarden.ui.tools.feature.generator.navigateToGenerator
|
||||
|
@ -44,7 +44,6 @@ import kotlinx.parcelize.Parcelize
|
|||
*/
|
||||
@Composable
|
||||
fun VaultUnlockedNavBarScreen(
|
||||
onNavigateToAccountSecurity: () -> Unit,
|
||||
viewModel: VaultUnlockedNavBarViewModel = hiltViewModel(),
|
||||
navController: NavHostController = rememberNavController(),
|
||||
) {
|
||||
|
@ -65,14 +64,13 @@ fun VaultUnlockedNavBarScreen(
|
|||
}
|
||||
|
||||
VaultUnlockedNavBarEvent.NavigateToSettingsScreen -> {
|
||||
navigateToSettings(navOptions)
|
||||
navigateToSettingsGraph(navOptions)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
VaultUnlockedNavBarScaffold(
|
||||
navController = navController,
|
||||
onNavigateToAccountSecurity = onNavigateToAccountSecurity,
|
||||
generatorTabClickedAction = {
|
||||
viewModel.trySendAction(VaultUnlockedNavBarAction.GeneratorTabClick)
|
||||
},
|
||||
|
@ -94,7 +92,6 @@ fun VaultUnlockedNavBarScreen(
|
|||
@Composable
|
||||
@Suppress("LongMethod")
|
||||
private fun VaultUnlockedNavBarScaffold(
|
||||
onNavigateToAccountSecurity: () -> Unit,
|
||||
navController: NavHostController,
|
||||
vaultTabClickedAction: () -> Unit,
|
||||
sendTabClickedAction: () -> Unit,
|
||||
|
@ -168,9 +165,7 @@ private fun VaultUnlockedNavBarScaffold(
|
|||
vaultDestination()
|
||||
sendDestination()
|
||||
generatorDestination()
|
||||
settingsDestinations(
|
||||
onNavigateToAccountSecurity = onNavigateToAccountSecurity,
|
||||
)
|
||||
settingsGraph(navController)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -259,7 +254,7 @@ private sealed class VaultUnlockedNavBarTab : Parcelable {
|
|||
override val iconRes get() = R.drawable.ic_settings
|
||||
override val labelRes get() = R.string.settings
|
||||
override val contentDescriptionRes get() = R.string.settings
|
||||
override val route get() = SETTINGS_ROUTE
|
||||
override val route get() = SETTINGS_GRAPH_ROUTE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
|
|||
VaultUnlockedNavBarScreen(
|
||||
viewModel = viewModel,
|
||||
navController = fakeNavHostController,
|
||||
onNavigateToAccountSecurity = {},
|
||||
)
|
||||
}
|
||||
onNodeWithText("My vault").performClick()
|
||||
|
@ -53,7 +52,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
|
|||
VaultUnlockedNavBarScreen(
|
||||
viewModel = viewModel,
|
||||
navController = fakeNavHostController,
|
||||
onNavigateToAccountSecurity = {},
|
||||
)
|
||||
}
|
||||
runOnIdle { fakeNavHostController.assertCurrentRoute("vault") }
|
||||
|
@ -75,7 +73,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
|
|||
VaultUnlockedNavBarScreen(
|
||||
viewModel = viewModel,
|
||||
navController = fakeNavHostController,
|
||||
onNavigateToAccountSecurity = {},
|
||||
)
|
||||
}
|
||||
onNodeWithText("Send").performClick()
|
||||
|
@ -96,7 +93,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
|
|||
VaultUnlockedNavBarScreen(
|
||||
viewModel = viewModel,
|
||||
navController = fakeNavHostController,
|
||||
onNavigateToAccountSecurity = {},
|
||||
)
|
||||
}
|
||||
runOnIdle { fakeNavHostController.assertCurrentRoute("vault") }
|
||||
|
@ -118,7 +114,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
|
|||
VaultUnlockedNavBarScreen(
|
||||
viewModel = viewModel,
|
||||
navController = fakeNavHostController,
|
||||
onNavigateToAccountSecurity = {},
|
||||
)
|
||||
}
|
||||
onNodeWithText("Generator").performClick()
|
||||
|
@ -139,7 +134,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
|
|||
VaultUnlockedNavBarScreen(
|
||||
viewModel = viewModel,
|
||||
navController = fakeNavHostController,
|
||||
onNavigateToAccountSecurity = {},
|
||||
)
|
||||
}
|
||||
runOnIdle { fakeNavHostController.assertCurrentRoute("vault") }
|
||||
|
@ -161,7 +155,6 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
|
|||
VaultUnlockedNavBarScreen(
|
||||
viewModel = viewModel,
|
||||
navController = fakeNavHostController,
|
||||
onNavigateToAccountSecurity = {},
|
||||
)
|
||||
}
|
||||
onNodeWithText("Settings").performClick()
|
||||
|
@ -182,14 +175,13 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
|
|||
VaultUnlockedNavBarScreen(
|
||||
viewModel = viewModel,
|
||||
navController = fakeNavHostController,
|
||||
onNavigateToAccountSecurity = {},
|
||||
)
|
||||
}
|
||||
runOnIdle { fakeNavHostController.assertCurrentRoute("vault") }
|
||||
vaultUnlockedNavBarEventFlow.tryEmit(VaultUnlockedNavBarEvent.NavigateToSettingsScreen)
|
||||
runOnIdle {
|
||||
fakeNavHostController.assertLastNavigation(
|
||||
route = "settings",
|
||||
route = "settings_graph",
|
||||
navOptions = expectedNavOptions,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue