Fix nav drawer focus when pressing back on home page (#274)

Fixes the nav drawer not being focused on when pressing back to open it
on the home page

Dev notes: I think the bug was introduced in #228 due to the new
`Column` not being focusable, but we don't need it to be since we want
to focus on the selected page.
This commit is contained in:
damontecres 2025-11-20 18:04:45 -05:00 committed by GitHub
parent 45567bf4eb
commit 99e8b69c0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -218,14 +218,14 @@ fun NavDrawer(
val listState = rememberLazyListState() val listState = rememberLazyListState()
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val context = LocalContext.current val context = LocalContext.current
val drawerFocusRequester = remember { FocusRequester() }
val focusRequester = remember { FocusRequester() } val focusRequester = remember { FocusRequester() }
val searchFocusRequester = remember { FocusRequester() } val searchFocusRequester = remember { FocusRequester() }
// If the user presses back while on the home page, open the nav drawer, another back press will quit the app // If the user presses back while on the home page, open the nav drawer, another back press will quit the app
BackHandler(enabled = (drawerState.currentValue == DrawerValue.Closed && destination is Destination.Home)) { BackHandler(enabled = (drawerState.currentValue == DrawerValue.Closed && destination is Destination.Home)) {
drawerState.setValue(DrawerValue.Open) drawerState.setValue(DrawerValue.Open)
drawerFocusRequester.requestFocus() focusRequester.requestFocus()
} }
val moreLibraries by viewModel.moreLibraries.observeAsState(listOf()) val moreLibraries by viewModel.moreLibraries.observeAsState(listOf())
val libraries by viewModel.libraries.observeAsState(listOf()) val libraries by viewModel.libraries.observeAsState(listOf())
@ -305,9 +305,7 @@ fun NavDrawer(
) )
val spacedBy = 4.dp val spacedBy = 4.dp
NavigationDrawer( NavigationDrawer(
modifier = modifier = modifier,
modifier
.focusRequester(drawerFocusRequester),
drawerState = drawerState, drawerState = drawerState,
drawerContent = { drawerContent = {
ProvideTextStyle(MaterialTheme.typography.labelMedium) { ProvideTextStyle(MaterialTheme.typography.labelMedium) {