jetpack组成 - 无法使modalbottomsheet用户不相互作用

问题描述 投票:0回答:1

我想通过编程方式使模量器完全可以交互,并防止用户打开和关闭它。看来我必须以某种方式创建SheetState,但是我找不到方法。

到目前为止,我做到了:

val bottomSheetState = rememberModalBottomSheetState(confirmValueChange = { sheetValue -> sheetValue != SheetValue.PartiallyExpanded }, skipPartiallyExpanded = true) val showBottomSheet = remember { mutableStateOf(false) } Box(modifier = modifier.fillMaxSize().background(color = Color.Green)) { Button(modifier = Modifier.align(Alignment.Center), onClick = { showBottomSheet.value = !showBottomSheet.value }) { Text("CLICK ME") } if (showBottomSheet.value) { ModalBottomSheet(onDismissRequest = { }, sheetState = bottomState, shape = RoundedCornerShape(size = 12.dp), sheetGesturesEnabled = false, dragHandle = null, modifier = Modifier.fillMaxWidth(), properties = ModalBottomSheetProperties(shouldDismissOnBackPress = false, isAppearanceLightStatusBars = true ), containerColor = Color.Red ) { BackHandler(true) {} Box(modifier = Modifier .fillMaxWidth() ) { Text(text = "BOTTOM SHEET CONTENT", textAlign = TextAlign.Center, modifier = Modifier.align(Alignment.Center).height(100.dp)) } } } }
使用此代码,我可以通过编程方式打开/关闭Modalbottomsheet,但是当它打开时,用户可以通过单击后台将其关闭。
我有这个问题,因为版本

material31.4.0-alpha08

android-jetpack-compose android-jetpack android-jetpack-compose-material3
1个回答
0
投票
您可以通过

Remebermodalbottomsheetstate禁用用户互动或背景按下,并比较新值与hiddend

rememberModalBottomSheetState(skipPartiallyExpanded = true, confirmValueChange = {
    it != SheetValue.Hidden
})

您的模态将继续按用户进行滑动动画,但无法关闭,始终将模态表在“expanded”状态上。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.