I used BottomSheet view in the jetpack compose but I want to lock the screen with bottomSheet until we click on the bottomShets's button and disable outside touching in the bottomSheet. How can I do it?
My bottomSheet:
@ExperimentalMaterialApi
@Composable
fun BottomSheet(
modifier: Modifier = Modifier,
composable: @Composable () -> Unit,
scope: CoroutineScope
) {
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = BottomSheetState(BottomSheetValue.Expanded)
)
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetContent = {
Column(
Modifier
.fillMaxWidth()
.height(200.dp)
.padding(8.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(colors = ButtonDefaults.buttonColors(
backgroundColor = AppColor.brandColor.BLUE_DE_FRANCE,
contentColor = AppColor.neutralColor.DOCTOR
),
shape = RoundedCornerShape(
small
),
onClick = {
scope.launch {
bottomSheetScaffoldState.bottomSheetState.collapse()
}
}) {
}
}
},
sheetPeekHeight = 0.dp,
sheetShape = RoundedCornerShape(topEnd = medium, topStart = medium)
) {
composable()
}
}
The composable function is a google map screen
CodePudding user response:
You can use sheetGesturesEnabled = false
property of BottomSheetScaffold
to disable gestures. And if you set it with a var sheetGesturesEnabled by remember {mutableStateOf(true)}
you can toggle it as you wish.
var sheetGesturesEnabled by remember {mutableStateOf(true)}
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetGesturesEnabled = sheetGesturesEnabled,
sheetContent = {
},
drawerContent= {
}
)
CodePudding user response:
You can use sheetGesturesEnabled: Boolean = true/false
attribute, if you want to change the bottom sheet cancelable or not cancelable from outside.
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetGesturesEnabled = false,
sheetContent = {
...
},
sheetPeekHeight = 0.dp,
sheetShape = RoundedCornerShape(topEnd = medium, topStart = medium)
) {
composable()
}
for proper documentation use this link: BottomSheetScaffold