This solution works with N amount of bottom sheets, and even works if you want to stack them, here is the implementation:
typealias BottomSheetControl = Pair<ModalBottomSheetState, @Composable ColumnScope.() -> Unit>
@Composable
fun HeaderContentMultipleBottomSheetsTemplate(
finalContent: @Composable () -> Unit,
sheetsShape: Shape = ServyUIShapesDefaults.RoundedRectangle,
vararg sheets: BottomSheetControl
) {
HeaderContentBottomSheetsTemplateImpl(
finalContent = finalContent,
sheetsShape = sheetsShape,
sheets = sheets,
)
}
@Composable
private fun HeaderContentBottomSheetsTemplateImpl(
modifier: Modifier = Modifier,
finalContent: @Composable () -> Unit,
scrimColor: Color = ModalBottomSheetDefaults.scrimColor,
sheetsShape: Shape = ServyUIShapesDefaults.RoundedRectangle,
vararg sheets: BottomSheetControl
) {
if (sheets.isNotEmpty()) {
ModalBottomSheetLayout(
modifier = modifier,
sheetState = sheets[0].first,
sheetContent = sheets[0].second,
sheetShape = sheetsShape,
scrimColor = scrimColor
) {
HeaderContentBottomSheetsTemplateImpl(
finalContent = finalContent,
sheets = sheets.sliceArray(1 until sheets.size)
)
}
} else {
finalContent() // Here is your Screen Content
}
}
For the implementation you need to have this :
// The sheet state, you can manipulate it whatever you want.
val testSheetState= rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden,
animationSpec = tween(durationMillis = 100),
confirmValueChange = { it != ModalBottomSheetValue.HalfExpanded },
skipHalfExpanded = true,
)
// The sheet content.
@Composable
fun TestSheet(): @Composable ColumnScope.() -> Unit = {
Text(text = "LOLLL")
}
// The Pair of state and content
val test: BottomSheetControl = Pair(testSheetState, TestSheet())
And finally you can just:
HeaderContentMultipleBottomSheetsTemplate(
finalContent = {
// Here the content of your screen (in ColumnScope)
},
sheets = arrayOf(test)
)
Pd: The order of the items in the vararg argument "sheets" define the level of each one, if you want to stack them, please write in nested order.