fix: handle sheet dismissal conflict with keyboard visibility by clearing focus instead of blocking back button
This commit is contained in:
@@ -1075,29 +1075,30 @@ fun EditActivityBottomSheet(
|
||||
onGoogleLoginClick: () -> Unit
|
||||
) {
|
||||
val density = LocalDensity.current
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
val focusManager = LocalFocusManager.current
|
||||
|
||||
// Track keyboard visibility reactively
|
||||
val isKeyboardOpen = WindowInsets.ime.getBottom(density) > 0
|
||||
|
||||
val sheetState = rememberModalBottomSheetState(
|
||||
skipPartiallyExpanded = true,
|
||||
confirmValueChange = { targetValue ->
|
||||
if (targetValue == SheetValue.Hidden && isKeyboardOpen) {
|
||||
// Keyboard is open: reject sheet dismissal and hide keyboard instead
|
||||
keyboardController?.hide()
|
||||
focusManager.clearFocus()
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = onDismiss,
|
||||
sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true),
|
||||
containerColor = Color.White,
|
||||
properties = ModalBottomSheetDefaults.properties(
|
||||
shouldDismissOnBackPress = false
|
||||
),
|
||||
modifier = Modifier
|
||||
.focusable()
|
||||
.onPreviewKeyEvent { event ->
|
||||
if (event.key == Key.Back && event.type == KeyEventType.KeyUp) {
|
||||
if (isKeyboardOpen) {
|
||||
false
|
||||
} else {
|
||||
onDismiss()
|
||||
true
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
sheetState = sheetState,
|
||||
containerColor = Color.White
|
||||
) {
|
||||
|
||||
var progressValue by remember(activity) { mutableStateOf(activity.percentualExecucao.toFloat()) }
|
||||
|
||||
Reference in New Issue
Block a user