I've got some elements that have focus in a bottom sheet. I want to collapse the bottom sheet when the system back button is pressed, which is easy enough:
BackHandler(enabled = bottomSheetState.isExpanded) {
scope.launch {
bottomSheetState.collapse()
}
}
The problem is, if an element is focused in the bottom sheet, the back handler's logic only gets triggered after pressing the back button twice: once to remove focus from the element (outlined text field) and once more to trigger the collapse.
I've tried using the LocalFocusManager.current
to combine clearing focus when back is pressed, but the back logic isn't triggered until the element has already lost focus.
I can clear focus on collapse, so I guess the real problem is having to press back twice when the sheet is 1) visible and 2) has a child element focused.
Is there a way to stop focused elements from superseding my back logic?