Bottom sheets
Use these Jetpack Compose Bottom Sheets to display some information on the lower part of the screen. Bottom sheets are part of the current screen layout and can either in a fixed position or visible when needed.
Simple Bottom Sheet
/** * Add the following dependency to your build.gradle.kts: * * dependencies { * implementation("com.composables:core:1.11.2") * } */ BoxWithConstraints(modifier = Modifier.fillMaxSize()) { val isCompact = maxWidth < 600.dp val sheetState = rememberBottomSheetState( initialDetent = FullyExpanded, detents = listOf(Hidden, FullyExpanded) ) LaunchedEffect(sheetState.isIdle) { if (sheetState.isIdle && sheetState.currentDetent == Hidden) { delay(500) sheetState.currentDetent = FullyExpanded } } BottomSheet( state = sheetState, modifier = Modifier .padding(top = 12.dp) .let { if (isCompact) it else it.padding(horizontal = 56.dp) } .statusBarsPadding() .padding(WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal).asPaddingValues()) .shadow(4.dp, RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp)) .clip(RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp)) .background(Color.White) .widthIn(max = 640.dp) .fillMaxWidth() .imePadding(), ) { Box(Modifier.fillMaxWidth().height(600.dp), contentAlignment = Alignment.TopCenter) { DragIndication( modifier = Modifier.padding(top = 22.dp) .background(Color.Black.copy(0.4f), RoundedCornerShape(100)) .width(32.dp) .height(4.dp) ) } } }
Bottom Sheet with custom detent
/** * Add the following dependency to your build.gradle.kts: * * dependencies { * implementation("com.composables:core:1.11.2") * } */ val Peek = remember { SheetDetent("peek") { containerHeight, sheetHeight -> containerHeight * 0.6f } } BoxWithConstraints(modifier = Modifier.fillMaxSize()) { val isCompact = maxWidth < 600.dp val sheetState = rememberBottomSheetState( initialDetent = Peek, detents = listOf(Hidden, Peek, FullyExpanded) ) LaunchedEffect(sheetState.isIdle) { if (sheetState.isIdle && sheetState.currentDetent == Hidden) { delay(500) sheetState.currentDetent = Peek } } BottomSheet( state = sheetState, modifier = Modifier .padding(top = 12.dp) .let { if (isCompact) it else it.padding(horizontal = 56.dp) } .statusBarsPadding() .padding(WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal).asPaddingValues()) .shadow(4.dp, RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp)) .clip(RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp)) .background(Color.White) .widthIn(max = 640.dp) .fillMaxWidth() .imePadding(), ) { Box(Modifier.fillMaxWidth().height(600.dp), contentAlignment = Alignment.TopCenter) { DragIndication( modifier = Modifier.padding(top = 22.dp) .background(Color.Black.copy(0.4f), RoundedCornerShape(100)) .width(32.dp) .height(4.dp) ) } } }
@Composable
fun NiceTry(){
Column {
BasicText("Nice try. Use code COMPOSE10 for a 10% discount on checkout ;)")
}
}
Phone
Sit tight. We are loading your preview
Simple Bottom Sheet