具有空 sheet 内容的 Jetpack Compose Bottomsheet 始终展开

Jetpack Compose Bottomsheet with empty sheet content is always expnaded

我正在尝试通过 BottomSheetScaffold 实现 modalBottomSheet 一些自定义实现。

这是我的 BottomSheetScaffold

BottomSheetScaffold(
    sheetPeekHeight = 0.dp,
    scaffoldState = bottomSheetState,
    sheetBackgroundColor = Color.Transparent,
    backgroundColor = Color.Transparent,
    sheetElevation = 0.dp,
    sheetShape = RoundedCornerShape(topStart = 36.dp, topEnd = 36.dp),
    snackbarHost = snackBarHost,
    sheetContent = { bottomSheet() }) {
    Box(Modifier.fillMaxSize()) {
        val coroutineScope = rememberCoroutineScope()
        sheetContent()
        Scrim(
            color = Primary,
            alpha = bottomSheetState.currentFraction * 0.5f,
            onDismiss = {
                coroutineScope.launch { bottomSheetState.bottomSheetState.collapse() }
            },
            visible = bottomSheetState.bottomSheetState.targetValue != BottomSheetValue.Collapsed && bottomSheetState.bottomSheetState.currentValue != BottomSheetValue.Collapsed
        )
    }
}

当这个脚手架被某个屏幕调用时,sheetContent() 将被替换为屏幕内容。我的问题是,当 bottomSheet() 在该屏幕上为空时,因此没有高度,底部 sheet 状态认为它已扩展,而我只是没有将可组合项放入 bottomSheet() 中,它只是基于填充在某些情况下没有默认可组合项。因此,Scrim() 函数将可见,当我单击它时,此异常将抛出

java.lang.IllegalArgumentException: The target value must have an associated anchor.

虽然 sheetContent 对于 BottomSheetScaffold 是必需的,但似乎无法处理空值,因为 BottomSheetState class 句柄的滑动需要锚点来获取高度和空值导致意外结果