mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 08:17:04 +05:30
android: use navigation destination to signal selected state
This commit is contained in:
parent
2bfdab7a1a
commit
f8e7043a42
1 changed files with 2 additions and 9 deletions
|
@ -11,10 +11,6 @@ import androidx.compose.material3.NavigationBar
|
|||
import androidx.compose.material3.NavigationBarItem
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.navigation.NavController
|
||||
|
@ -28,8 +24,6 @@ fun ClawNavigationBar(
|
|||
isVisible: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
var selectedIndex by remember { mutableStateOf(0) }
|
||||
|
||||
AnimatedVisibility(
|
||||
visible = isVisible,
|
||||
enter =
|
||||
|
@ -47,13 +41,12 @@ fun ClawNavigationBar(
|
|||
modifier = Modifier,
|
||||
) {
|
||||
NavigationBar(modifier = modifier) {
|
||||
items.forEachIndexed { index, navItem ->
|
||||
items.forEach { navItem ->
|
||||
NavigationBarItem(
|
||||
icon = { Icon(painter = navItem.icon, contentDescription = navItem.label) },
|
||||
label = { Text(text = navItem.label) },
|
||||
selected = selectedIndex == index,
|
||||
selected = navController.currentDestination?.route == navItem.route,
|
||||
onClick = {
|
||||
selectedIndex = index
|
||||
if (navController.currentDestination?.route == navItem.route) return@NavigationBarItem
|
||||
navController.popBackStack(navController.graph.startDestinationRoute!!, false)
|
||||
if (navItem.route != Destinations.startDestination.getRoute()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue