1

I'm trying to achieve modalBottomSheet by BottomSheetScaffold for some custom implementation.

here is my 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
        )
    }
}

When this scaffold is called by some screen, the sheetContent() will be replaced as screen content. My problem here is when bottomSheet() is empty on that screen and thus there is no height, bottom sheet state think it is expanded while I just not put composable inside bottomSheet() and it just fill based on some condition with no default composable. Because of that the Scrim() function will be visible and when I click on it this exception will throw

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

2 Answers 2

2

It seems while sheetContent is necessary for BottomSheetScaffold there is no way to deal with empty value because BottomSheetState class that handle's swiping need anchor to get height and empty value cause's unexpected result

0

This is a bug introduced in latest release of compose 1.2.x. To stop showing bottom sheet at start, I only add sheetContent if data is not null(this was not possible in previous release1.1.x). Now I have another issue. The click event to expanding bottomSheet won't trigger at first try. I always need to click it twice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.