drawer: open focused on the current destination

Opening the menu landed focus on Home regardless of where the user was;
the sensible start is the item that already carries the selected state.
From there all other destinations are a D-pad step or two away.
This commit is contained in:
Jeena 2026-10-14 00:02:40 +00:00
parent 6d1cc8986a
commit 44a39b83e9

View file

@ -382,6 +382,8 @@ private fun MenuDrawer(
onDismiss: () -> Unit, onDismiss: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
// Focus the destination we are on (issue #16); its item carries the red
// selected background. The first drawer item (Home) was the wrong target.
val drawerFocus = remember { FocusRequester() } val drawerFocus = remember { FocusRequester() }
LaunchedEffect(Unit) { runCatching { drawerFocus.requestFocus() } } LaunchedEffect(Unit) { runCatching { drawerFocus.requestFocus() } }
val signOutContext = androidx.compose.ui.platform.LocalContext.current val signOutContext = androidx.compose.ui.platform.LocalContext.current
@ -405,13 +407,13 @@ private fun MenuDrawer(
} else false } else false
}, },
) { ) {
Destination.entries.forEachIndexed { index, dest -> Destination.entries.forEach { dest ->
MenuDrawerItem( MenuDrawerItem(
icon = dest.icon(), icon = dest.icon(),
label = dest.title, label = dest.title,
selected = dest == selected, selected = dest == selected,
onClick = { onSelect(dest) }, onClick = { onSelect(dest) },
modifier = if (index == 0) Modifier.focusRequester(drawerFocus) else Modifier, modifier = if (dest == selected) Modifier.focusRequester(drawerFocus) else Modifier,
) )
} }
Spacer(modifier = Modifier.weight(1f)) Spacer(modifier = Modifier.weight(1f))