最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

kotlin - ModalBottomSheet in Jetpack Compose with Sticky Button at the Bottom - Stack Overflow

programmeradmin0浏览0评论

I am trying to achieve similar effect like the one on the image below:

The screen contains header at the top, LazyColumn inside and a button that is sticky. I've tried to modify the already existing ModalBottomSheet from Material3, so that I can have customisable PartialExpanded percentage instead of the default 50%, but I cannot figure out how to achieve the same effect as on the image.

        Box(modifier = Modifier.fillMaxSize().imePadding().semantics { isTraversalGroup = true }) {
        Scrim(
            color = scrimColor,
            onDismissRequest = animateToDismiss,
            visible = sheetState.targetValue != Hidden,
        )
        ModalBottomSheetContent(
            predictiveBackProgress,
            scope,
            animateToDismiss,
            settleToDismiss,
            modifier,
            sheetState,
            sheetMaxWidth,
            shape,
            containerColor,
            contentColor,
            tonalElevation,
            dragHandle,
            contentWindowInsets,
            content
        )
        StickyContent() // Something like this
    }

Does anyone have some tips on how to achieve this?

I am trying to achieve similar effect like the one on the image below:

The screen contains header at the top, LazyColumn inside and a button that is sticky. I've tried to modify the already existing ModalBottomSheet from Material3, so that I can have customisable PartialExpanded percentage instead of the default 50%, but I cannot figure out how to achieve the same effect as on the image.

        Box(modifier = Modifier.fillMaxSize().imePadding().semantics { isTraversalGroup = true }) {
        Scrim(
            color = scrimColor,
            onDismissRequest = animateToDismiss,
            visible = sheetState.targetValue != Hidden,
        )
        ModalBottomSheetContent(
            predictiveBackProgress,
            scope,
            animateToDismiss,
            settleToDismiss,
            modifier,
            sheetState,
            sheetMaxWidth,
            shape,
            containerColor,
            contentColor,
            tonalElevation,
            dragHandle,
            contentWindowInsets,
            content
        )
        StickyContent() // Something like this
    }

Does anyone have some tips on how to achieve this?

Share Improve this question asked Jan 20 at 0:40 David TrpcevskiDavid Trpcevski 1458 bronze badges 1
  • Do you want to achieve initially it should be 50% when user scrolls up list it should be expanded to top? – Santhosh Kumar Commented Jan 20 at 3:09
Add a comment  | 

1 Answer 1

Reset to default 0

Maybe you should adjust the screen with LocalConfiguration.current.screenHeightDp? You can try something like this:

val sheetState = rememberModalBottomSheetState(
    skipPartiallyExpanded = true
)
val screenHeight = LocalConfiguration.current.screenHeightDp.dp

ModalBottomSheet(
    onDismissRequest = { /*your action*/ },
    sheetState = sheetState,
    tonalElevation = 72.dp,
    dragHandle = {}
) {
    Column(
        modifier = Modifier
            .heightIn(max = screenHeight * 0.93f)
            .fillMaxWidth()
    ) {
      /* your modal content */
    }
}

0.93f - this is the maximum height to which the modal will expand. You can customize it according to your needs

发布评论

评论列表(0)

  1. 暂无评论