我在我的应用中使用了 Modal Bottom Sheet。如何防止它在向下滑动时关闭?我在表单上有一个延迟列。我希望它只在我单击关闭图标时关闭。
fun Preview(
list: List<String>,
onBottomSheetDismiss: (Boolean) -> Unit,
) {
val scope = rememberCoroutineScope()
val previewSheetState = rememberModalBottomSheetState(
skipPartiallyExpanded = false,
)
ModalBottomSheet(
onDismissRequest = { onBottomSheetDismiss(false) },
sheetState = previewSheetState,
modifier = Modifier.height(700.dp),
dragHandle = {
Column {
Row(
Modifier
.fillMaxWidth()
.background(Color.White)
.padding(start = 15.dp, top = 10.dp, bottom = 5.dp, end = 10.dp),
Arrangement.SpaceBetween,
Alignment.CenterVertically
) {
Text(text= "Preview")
CloseIcon(onClick = {
scope.launch {
previewSheetState.hide()
onBottomSheetDismiss(false)
}
})
}
HorizontalDivider(thickness = 1.dp)
}
}
) {
LazyColumn(){
items(list){
Text(text= "it")
}
}
添加一个布尔变量
isClosable
来控制何时可以关闭底部表单。然后确认状态更改为Hidden
仅当isClosable
为真时。任何状态更改都会重置isClosable
为假。isClosable
在通过关闭图标隐藏底部工作表之前设置为 true: