fix: resolve keyboard dismissal issues on Samsung devices by tracking back-press state in MaintenanceDashboardScreen
This commit is contained in:
@@ -1084,37 +1084,43 @@ fun EditActivityBottomSheet(
|
||||
val focusManager = LocalFocusManager.current
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
// Read WindowInsets.ime in Composable scope and wrap in rememberUpdatedState
|
||||
val isKeyboardOpen = WindowInsets.ime.getBottom(density) > 0
|
||||
val isKeyboardOpenState = rememberUpdatedState(isKeyboardOpen)
|
||||
|
||||
// State flag to track if keyboard was already dismissed by a back press.
|
||||
// This solves Samsung OneUI inset update delay issues after keyboardController.hide().
|
||||
var keyboardDismissedByBack by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(isKeyboardOpen) {
|
||||
if (isKeyboardOpen) {
|
||||
keyboardDismissedByBack = false
|
||||
}
|
||||
}
|
||||
|
||||
// Handle system Back button:
|
||||
// 1. If keyboard is open -> clear focus and hide keyboard (sheet stays open)
|
||||
// 2. If keyboard is closed -> animate sheet hiding and call onDismiss()
|
||||
// 1st back press (keyboard open): clear focus and hide keyboard.
|
||||
// 2nd back press (or keyboard closed): animate sheet hiding and call onDismiss().
|
||||
BackHandler(enabled = true) {
|
||||
if (isKeyboardOpenState.value) {
|
||||
focusManager.clearFocus()
|
||||
if (isKeyboardOpen && !keyboardDismissedByBack) {
|
||||
keyboardDismissedByBack = true
|
||||
focusManager.clearFocus(force = true)
|
||||
keyboardController?.hide()
|
||||
} else {
|
||||
keyboardDismissedByBack = false
|
||||
coroutineScope.launch {
|
||||
sheetState.hide()
|
||||
}.invokeOnCompletion {
|
||||
if (!sheetState.isVisible) {
|
||||
onDismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = {
|
||||
coroutineScope.launch {
|
||||
sheetState.hide()
|
||||
}.invokeOnCompletion {
|
||||
if (!sheetState.isVisible) {
|
||||
onDismiss()
|
||||
}
|
||||
}
|
||||
},
|
||||
sheetState = sheetState,
|
||||
containerColor = Color.White,
|
||||
|
||||
Reference in New Issue
Block a user