组合 BottomSheetScaffold 与工作表上边距

Sim*_*ays 6 android bottom-sheet android-jetpack android-jetpack-compose

我正在尝试BottomSheetScaffold,但无法弄清楚如何设置纸张的上边距/最小偏移/锚点。

像这样设置工作表:

val scaffoldState = rememberBottomSheetScaffoldState()
BottomSheetScaffold(
    sheetContent = {
        LazyColumn(modifier = Modifier
            .fillMaxSize()
            .padding(10.dp)
        ) {
            items(100) {
                Text(text = "Sheet item $it")
                Spacer(modifier = Modifier.height(10.dp))
            }
        }
    },
    scaffoldState = scaffoldState,
    sheetPeekHeight = 100.dp,
    sheetShape = RoundedCornerShape(10.dp),
    sheetBackgroundColor = Color.Gray
) { innerPadding ->
    Box(
        modifier = Modifier
            .fillMaxSize()
            .padding(innerPadding)
            .background(Color.Green),
        contentAlignment = Alignment.Center
    ) { Text(text = "Content") }
}
Run Code Online (Sandbox Code Playgroud)

结果在应用程序的底部工作表中:

折叠:

扩展:

我正在寻找的是为工作表添加上边距,以便它不会扩展超过此状态。

我知道我可以为工作表内容添加高度,但随后我必须计算height = windowHeight - bottomNavHeight - sheetTopMargin,这感觉比它应该的更复杂。

有没有更简单的方法来设置顶页边距?

小智 9

我们使用ModalBottomSheetLayout并提供最大高度作为可组合项的屏幕空间modifier因素sheetContent

sheetContent = {
    DatesFilterSheet(
        modifier = Modifier.fillMaxHeight(0.9f)
    )
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


hel*_*and 0

目前没有更简单的方法来做到这一点,您可以尝试在惰性列周围设置一个列,并在之前使用间隔符,该间隔仅在sheetState展开时显示。如果你在它折叠时离开它,那么底部会出现一个白色的间隙。

此外,您需要将sheetBackgroundColor设置为透明并在LazyColumn上使用Color.grey