Description:
When using the ModalBottomSheet from the material3 package in Jetpack Compose, the bottom sheet unexpectedly closes when the back button is pressed while the keyboard is open. This issue should be addressed to ensure that the ModalBottomSheet remains open in such cases.
Steps to Reproduce:
Implement the provided code in a Jetpack Compose Multiplatform project.
Launch the app and navigate to the screen that uses ModalBottomSheet.
Click the "Click Me!" button to open the bottom sheet.
Focus on the OutlinedTextField to open the keyboard.
Press the back button on the device.
Expected Behavior:
The ModalBottomSheet should remain open when the back button is pressed if the keyboard is open. Only the keyboard should be closed.
Actual Behavior:
The ModalBottomSheet closes when the back button is pressed with the keyboard open.
Description: When using the ModalBottomSheet from the material3 package in Jetpack Compose, the bottom sheet unexpectedly closes when the back button is pressed while the keyboard is open. This issue should be addressed to ensure that the ModalBottomSheet remains open in such cases.
Steps to Reproduce:
Expected Behavior: The ModalBottomSheet should remain open when the back button is pressed if the keyboard is open. Only the keyboard should be closed.
Actual Behavior: The ModalBottomSheet closes when the back button is pressed with the keyboard open.
Sample Code
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.displayCutoutPadding import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.statusBarsPadding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Button import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ModalBottomSheet import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text import androidx.compose.material3.TextFieldDefaults import androidx.compose.material3.rememberModalBottomSheetState import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import kotlinx.coroutines.launch
object TestScreen {
} ` Attachment ModalBottomSheetIssue.webm