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 focusManager = LocalFocusManager.current
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
// Read WindowInsets.ime in Composable scope and wrap in rememberUpdatedState
|
|
||||||
val isKeyboardOpen = WindowInsets.ime.getBottom(density) > 0
|
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:
|
// Handle system Back button:
|
||||||
// 1. If keyboard is open -> clear focus and hide keyboard (sheet stays open)
|
// 1st back press (keyboard open): clear focus and hide keyboard.
|
||||||
// 2. If keyboard is closed -> animate sheet hiding and call onDismiss()
|
// 2nd back press (or keyboard closed): animate sheet hiding and call onDismiss().
|
||||||
BackHandler(enabled = true) {
|
BackHandler(enabled = true) {
|
||||||
if (isKeyboardOpenState.value) {
|
if (isKeyboardOpen && !keyboardDismissedByBack) {
|
||||||
focusManager.clearFocus()
|
keyboardDismissedByBack = true
|
||||||
|
focusManager.clearFocus(force = true)
|
||||||
keyboardController?.hide()
|
keyboardController?.hide()
|
||||||
} else {
|
} else {
|
||||||
|
keyboardDismissedByBack = false
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
sheetState.hide()
|
sheetState.hide()
|
||||||
}.invokeOnCompletion {
|
}.invokeOnCompletion {
|
||||||
if (!sheetState.isVisible) {
|
|
||||||
onDismiss()
|
onDismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ModalBottomSheet(
|
ModalBottomSheet(
|
||||||
onDismissRequest = {
|
onDismissRequest = {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
sheetState.hide()
|
sheetState.hide()
|
||||||
}.invokeOnCompletion {
|
}.invokeOnCompletion {
|
||||||
if (!sheetState.isVisible) {
|
|
||||||
onDismiss()
|
onDismiss()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
sheetState = sheetState,
|
sheetState = sheetState,
|
||||||
containerColor = Color.White,
|
containerColor = Color.White,
|
||||||
|
|||||||
Reference in New Issue
Block a user