Search code examples
androidandroid-jetpack-compose

Android jetpack Compose ModalBottomSheet disable outside touch and drag


I'm using ModalBottomSheet I don't want ModalBottomSheet to close when I touch the outside area.

And I also want to stop it from being dragged. What should I do?


Solution

  • You can achieve the desired behaviour just by setting two parameters.

    Just assign empty lambda to onDismissRequest and assign null to dragHandle like this:

    ModalBottomSheet(
        onDismissRequest = {}, // this will prevent outside touch
        dragHandle = null, // this will not show the drag option
        //... other parameters
    ) {
        //... bottom sheet content here
    }