I had design where bottom sheet is with certain peek height when it is fully collapsed. And fill entire height when it is expanded. How to implement this design using Modal Bottom Sheet (Jetpack Compose M3) ?
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = false)
val scope = rememberCoroutineScope()
Scaffold() {
WeatherView(api = api)
ModalBottomSheet(
modifier = Modifier.fillMaxSize(),
sheetState = sheetState,
onDismissRequest = {scope.launch { sheetState.partialExpand() }.invokeOnCompletion {
if (sheetState.targetValue == SheetValue.Hidden) {
}
}},
shape = RoundedCornerShape(
topStart = 20.dp,
topEnd = 20.dp
),
containerColor = Color.White.copy(0.2f),
dragHandle = {
BottomSheetDefaults.DragHandle(
width = 48.dp,
height = 5.dp,
color = Color.Black.copy(0.3f)
)
}
) {
BottomSheetContent()
}
}
}
If I understand your question correct, you have at least 2 options to set height of ModalBottomSheet:
fillMaxHeight
toModalBottomSheet
with required fraction if height should be based on percentage:height
toModalBottomSheet
with required height inDp
:Full example with height based on fraction:
Result: