refactor: lift sheet state management to parent and implement custom back press handling for EditActivityBottomSheet
This commit is contained in:
@@ -12,6 +12,7 @@ import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.focusable
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import com.google.android.gms.auth.api.signin.GoogleSignIn
|
||||
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
|
||||
import com.google.android.gms.common.api.ApiException
|
||||
@@ -575,11 +576,14 @@ fun MaintenanceDashboardScreen(
|
||||
|
||||
// Details & Edit bottom sheet
|
||||
if (showEditSheet && selectedActivity != null) {
|
||||
val editSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||
|
||||
EditActivityBottomSheet(
|
||||
activity = selectedActivity!!,
|
||||
history = selectedActivityHistory,
|
||||
currentUser = currentUser,
|
||||
userAccessLevel = userAccessLevel,
|
||||
sheetState = editSheetState,
|
||||
onDismiss = {
|
||||
showEditSheet = false
|
||||
viewModel.selectActivity(null)
|
||||
@@ -1070,6 +1074,7 @@ fun EditActivityBottomSheet(
|
||||
history: List<OSUpdateHistory>,
|
||||
currentUser: com.example.data.model.GoogleUser?,
|
||||
userAccessLevel: String?,
|
||||
sheetState: SheetState,
|
||||
onDismiss: () -> Unit,
|
||||
onUpdateProgress: (Int, String, String?) -> Unit,
|
||||
onGoogleLoginClick: () -> Unit
|
||||
@@ -1077,28 +1082,25 @@ fun EditActivityBottomSheet(
|
||||
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
|
||||
}
|
||||
// Handle system Back button: if keyboard is open, close keyboard; otherwise close sheet
|
||||
BackHandler(enabled = true) {
|
||||
if (isKeyboardOpen) {
|
||||
focusManager.clearFocus()
|
||||
keyboardController?.hide()
|
||||
} else {
|
||||
onDismiss()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = onDismiss,
|
||||
sheetState = sheetState,
|
||||
containerColor = Color.White
|
||||
containerColor = Color.White,
|
||||
properties = ModalBottomSheetDefaults.properties(
|
||||
shouldDismissOnBackPress = false
|
||||
)
|
||||
) {
|
||||
|
||||
var progressValue by remember(activity) { mutableStateOf(activity.percentualExecucao.toFloat()) }
|
||||
|
||||
Reference in New Issue
Block a user