简体   繁体   中英

How to create rounded corner BottomDrawer (aka Modal Bottom Sheet) in Jetpack compose

How to create rounded corner BottomDrawer (aka Modal Bottom Sheet) in new android jetpack compose.

eg image

在此处输入图像描述

You can use the sheetShape parameter in the BottomSheetScaffold or ModalBottomSheetLayout .

Something like:

BottomSheetScaffold(
        sheetShape = RoundedCornerShape(16.dp),
        /* ... */
){}

在此处输入图像描述

We can easily create in jetpack compose by using ButtomDrawer and Surface .


@Composable
fun RoundedBottomDrawer(){

    val scope = rememberCoroutineScope()
    val drawerState = rememberBottomDrawerState(initialValue = BottomDrawerValue.Closed)

    BottomDrawer(
        gesturesEnabled = true, // making scrollable to fit screen
        drawerState = drawerState,
        drawerBackgroundColor = Color.Transparent, // transparent background
        drawerContent = {

            Button(onClick = { scope.launch { drawerState.close() } }) {
                    Text("Close")
            }
            
            Spacer(modifier = Modifier.height(16.dp)) // some padding

            BottomDrawerSurface()

        },
        content = {
            // outside content
            Button(onClick = { scope.launch { drawerState.open() } }) {
                    Text("Open BottomDrawer")
            }
        }
    )
}

@Composable
fun BottomDrawerSurface() {
    Surface(
        color = Color.White,
        shape = RoundedCornerShape(16.dp, 16.dp, 0.dp, 0.dp)
    ) {
        // your design..
    }
}

In your case you need top start and top end corners rounded for that add this attribute:

sheetShape = RoundedCornerShape(topEnd = 16.dp, topStart = 16.dp)

In your BottomSheetScaffold .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM