Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModalBottomSheetLayout and back pressed

Currently I am using Jetpack compose and use ModalBottomSheetLayout to display the bottom sheet.

How to hide sheetState when back pressed?

like image 601
LinggaMG Avatar asked Jun 09 '26 06:06

LinggaMG


1 Answers

You can use BackHandler .. Something like this .

 val modalBottomSheetState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)
ModalBottomSheetLayout() {
    Scaffold() { innerPadding ->
        // Content goes here
        BackHandler(enabled = modalBottomSheetState.isVisible) {
            coroutineScope.launch {
                modalBottomSheetState.hide()
            }
        }
    }
}
like image 170
ADM Avatar answered Jun 10 '26 18:06

ADM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!