mirror of
https://github.com/bitwarden/android.git
synced 2024-11-22 01:16:02 +03:00
Fixed bottom nav bar. (#49)
This commit is contained in:
parent
9d706121ed
commit
8fdfcb1ea2
1 changed files with 8 additions and 9 deletions
|
@ -9,19 +9,18 @@ import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
|
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.NavOptions
|
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.currentBackStackEntryAsState
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import androidx.navigation.navOptions
|
import androidx.navigation.navOptions
|
||||||
import com.x8bit.bitwarden.R
|
import com.x8bit.bitwarden.R
|
||||||
|
@ -71,9 +70,6 @@ private fun VaultUnlockedNavBarScaffold(
|
||||||
generatorTabClickedAction: () -> Unit,
|
generatorTabClickedAction: () -> Unit,
|
||||||
settingsTabClickedAction: () -> Unit,
|
settingsTabClickedAction: () -> Unit,
|
||||||
) {
|
) {
|
||||||
var state by rememberSaveable {
|
|
||||||
mutableStateOf<VaultUnlockedNavBarTab>(VaultUnlockedNavBarTab.Vault)
|
|
||||||
}
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
BottomAppBar {
|
BottomAppBar {
|
||||||
|
@ -83,6 +79,8 @@ private fun VaultUnlockedNavBarScaffold(
|
||||||
VaultUnlockedNavBarTab.Generator,
|
VaultUnlockedNavBarTab.Generator,
|
||||||
VaultUnlockedNavBarTab.Settings,
|
VaultUnlockedNavBarTab.Settings,
|
||||||
)
|
)
|
||||||
|
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||||
|
val currentDestination = navBackStackEntry?.destination
|
||||||
destinations.forEach { destination ->
|
destinations.forEach { destination ->
|
||||||
NavigationBarItem(
|
NavigationBarItem(
|
||||||
icon = {
|
icon = {
|
||||||
|
@ -96,9 +94,10 @@ private fun VaultUnlockedNavBarScaffold(
|
||||||
label = {
|
label = {
|
||||||
Text(text = stringResource(id = destination.labelRes))
|
Text(text = stringResource(id = destination.labelRes))
|
||||||
},
|
},
|
||||||
selected = destination == state,
|
selected = currentDestination?.hierarchy?.any {
|
||||||
|
it.route == destination.route
|
||||||
|
} == true,
|
||||||
onClick = {
|
onClick = {
|
||||||
state = destination
|
|
||||||
when (destination) {
|
when (destination) {
|
||||||
VaultUnlockedNavBarTab.Vault -> vaultTabClickedAction()
|
VaultUnlockedNavBarTab.Vault -> vaultTabClickedAction()
|
||||||
VaultUnlockedNavBarTab.Send -> sendTabClickedAction()
|
VaultUnlockedNavBarTab.Send -> sendTabClickedAction()
|
||||||
|
@ -113,7 +112,7 @@ private fun VaultUnlockedNavBarScaffold(
|
||||||
) { innerPadding ->
|
) { innerPadding ->
|
||||||
NavHost(
|
NavHost(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
startDestination = state.route,
|
startDestination = VAULT_ROUTE,
|
||||||
modifier = Modifier.padding(innerPadding),
|
modifier = Modifier.padding(innerPadding),
|
||||||
) {
|
) {
|
||||||
vaultDestination()
|
vaultDestination()
|
||||||
|
|
Loading…
Reference in a new issue