Solution for 2023:
@Composable
fun ModalStatusBarBottomSheetLayout(
sheetContent: @Composable ColumnScope.() -> Unit,
modifier: Modifier = Modifier,
sheetState: ModalBottomSheetState =
rememberModalBottomSheetState(ModalBottomSheetValue.Hidden),
sheetShape: Shape = MaterialTheme.shapes.large,
sheetElevation: Dp = ModalBottomSheetDefaults.Elevation,
sheetBackgroundColor: Color = MaterialTheme.colors.surface,
sheetContentColor: Color = contentColorFor(sheetBackgroundColor),
scrimColor: Color = ModalBottomSheetDefaults.scrimColor,
content: @Composable () -> Unit
): Unit = ModalBottomSheetLayout(
sheetContent = sheetContent,
modifier = modifier,
sheetState = sheetState,
sheetShape = sheetShape,
sheetElevation = sheetElevation,
sheetBackgroundColor = sheetBackgroundColor,
sheetContentColor = sheetContentColor,
scrimColor = scrimColor
) {
val context = LocalContext.current
var statusBarColor by remember { mutableStateOf(Color.Transparent) }
val backgroundColor = remember {
val typedValue = TypedValue()
if (context.findActivity().theme
.resolveAttribute(android.R.attr.windowBackground, typedValue, true)
) {
Color(typedValue.data)
} else {
sheetBackgroundColor
}
}
Box(modifier = Modifier
.fillMaxWidth()
.background(statusBarColor)
.statusBarsPadding()) {
Box(modifier = Modifier
.background(backgroundColor)
.fillMaxSize()
.navigationBarsPadding()) {
content()
}
}
DisposableEffect(Unit) {
val window = context.findActivity().window
val originalStatusBarColor = window.statusBarColor
statusBarColor = Color(originalStatusBarColor)
window.statusBarColor = TRANSPARENT
WindowCompat.setDecorFitsSystemWindows(window, false)
onDispose {
window.statusBarColor = originalStatusBarColor
WindowCompat.setDecorFitsSystemWindows(window, true)
}
}
}
Usage:
val state = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
val scope = rememberCoroutineScope()
ModalStatusBarBottomSheetLayout(
sheetState = state,
modifier = Modifier.fillMaxSize(),
sheetContent = {
Text(modifier = Modifier
.fillMaxWidth()
.height(250.dp),
text = "BOTTOM SHEET CONTENT")
}
) {
Button(onClick = {
scope.launch {
state.show()
}
}) {
Text(text = "SHOW BOTTOM SHEET")
}
}
Here is findActivity
implementation.