Fix home selected item.
This commit is contained in:
parent
288a79b9f6
commit
944180882e
1 changed files with 11 additions and 9 deletions
|
|
@ -14,7 +14,7 @@ import androidx.compose.material3.TopAppBar
|
|||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
|
|
@ -53,20 +53,25 @@ fun HomeNavHost(
|
|||
)
|
||||
},
|
||||
bottomBar = {
|
||||
val selectedIndex = remember { mutableStateOf(0) }
|
||||
BottomAppBar(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
tonalElevation = 0.dp,
|
||||
) {
|
||||
bottomBarItems.forEach {
|
||||
bottomBarItems.forEachIndexed { index, item ->
|
||||
val selectedItem = remember { derivedStateOf { selectedIndex.value == index } }
|
||||
NavigationBarItem(
|
||||
selected = it.selected.value,
|
||||
onClick = it.onClick,
|
||||
selected = selectedItem.value,
|
||||
onClick = {
|
||||
selectedIndex.value = index
|
||||
item.onClick.invoke()
|
||||
},
|
||||
label = {
|
||||
Text(text = stringResource(id = it.label))
|
||||
Text(text = stringResource(id = item.label))
|
||||
},
|
||||
icon = {
|
||||
Icon(
|
||||
painter = painterResource(id = it.icon),
|
||||
painter = painterResource(id = item.icon),
|
||||
contentDescription = "",
|
||||
)
|
||||
}
|
||||
|
|
@ -93,7 +98,6 @@ fun HomeNavHost(
|
|||
|
||||
@Stable
|
||||
class BottomBarItem(
|
||||
val selected: State<Boolean>,
|
||||
val icon: Int,
|
||||
val label: Int,
|
||||
val onClick: () -> Unit,
|
||||
|
|
@ -107,13 +111,11 @@ private fun rememberBottomBarItems(
|
|||
return remember(navHostController) {
|
||||
listOf(
|
||||
BottomBarItem(
|
||||
selected = mutableStateOf(false),
|
||||
icon = R.drawable.ic_outline_account_circle_24,
|
||||
label = R.string.home_lexicon,
|
||||
onClick = { navHostController.navigateToLexicon(navHostController.pageOption()) }
|
||||
),
|
||||
BottomBarItem(
|
||||
selected = mutableStateOf(false),
|
||||
icon = R.drawable.ic_outline_map_24,
|
||||
label = R.string.home_quest_log,
|
||||
onClick = { navHostController.navigateToQuestList(navHostController.pageOption()) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue