我正在尝试通过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
)
}
}当这个scaffold被某些屏幕调用时,sheetContent()将被替换为屏幕内容。我这里的问题是,当bottomSheet()在屏幕上是空的,因此没有高度,底部的表单状态认为它是扩展的,而我只是没有在bottomSheet()中放入composable,它只是根据一些条件填充,没有默认的composable。因此,Scrim()函数将是可见的,当我单击它时,将抛出此异常
java.lang.IllegalArgumentException: The target value must have an associated anchor.
发布于 2021-09-28 08:34:12
虽然sheetContent对于BottomSheetScaffold是必需的,但似乎无法处理空值,因为处理滑动的BottomSheetState类需要锚点来获取高度和空值,从而导致意外的结果
https://stackoverflow.com/questions/69346646
复制相似问题