【问题标题】:Disable BottomSheet outside touch in the jetpack compose在jetpack compose中禁用BottomSheet外部触摸
【发布时间】:2021-12-12 10:11:26
【问题描述】:

我在jetpack compose 中使用了BottomSheet 视图,但我想用bottomSheet 锁定屏幕,直到我们单击bottomShets 的按钮并禁用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()
    }

}

可组合功能是谷歌地图屏幕

【问题讨论】:

  • 你能提供底页的代码吗??
  • 当然,我在问题中添加了

标签: android android-jetpack-compose android-jetpack bottom-sheet


【解决方案1】:

您可以使用BottomSheetScaffoldsheetGesturesEnabled = false 属性来禁用手势。如果您使用 var sheetGesturesEnabled by remember {mutableStateOf(true)} 设置它,您可以随意切换它。

var sheetGesturesEnabled by remember {mutableStateOf(true)}
BottomSheetScaffold(
    scaffoldState = bottomSheetScaffoldState,
    sheetGesturesEnabled = sheetGesturesEnabled,
    sheetContent = {
    },
    drawerContent= {
    }
)

【讨论】:

    【解决方案2】:

    你可以使用sheetGesturesEnabled: Boolean = true/false属性,如果你想改变底部表可取消或不可从外部取消。

     BottomSheetScaffold(
            scaffoldState = bottomSheetScaffoldState,
            sheetGesturesEnabled = false,
            sheetContent = {
               ...
            },
            sheetPeekHeight = 0.dp,
            sheetShape = RoundedCornerShape(topEnd = medium, topStart = medium)
        ) {
            composable()
        }
    

    如需正确的文档,请使用此链接:BottomSheetScaffold

    【讨论】:

    • 这个屏幕 (composable() ) 是一个谷歌地图。我希望用户在 BottomSheet 打开时不能移动谷歌地图。我该怎么做?
    • 你能告诉我你使用哪个类来查看谷歌地图吗?如果您使用的是 AndroidView,则使用:stackoverflow.com/a/61146384/10954249 answer on update={},使用 bottomsheetexpanded 或 collapse。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多