I need to show two different bottom sheets in one screen. I change the sheetContent of the ModalBottomSheetLayout dynamically using a dialogType state. I hide the High bottom sheet, change dialogType and show the Short. Short appears from the top of the previous bottom sheet, not from the bottom of the screen,
you can see here:
@Composable
fun BottomSheet() {
val sheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
val scope = rememberCoroutineScope()
var dialogType by remember { mutableStateOf<BottomSheetType>(BottomSheetType.None) }
ModalBottomSheetLayout(
sheetState = sheetState,
sheetContent = {
when (dialogType) {
is BottomSheetType.High -> {
LazyColumn {
items(10) {
Text(text = "Item $it")
}
item {
Button(onClick = {
scope.launch {
sheetState.hide()
dialogType = BottomSheetType.Short
sheetState.animateTo(ModalBottomSheetValue.Expanded)
}
}) {
Text(text = "Short Bottom Sheet")
}
}
}
}
is BottomSheetType.Short -> {
Text(text = "Item 1")
}
is BottomSheetType.None -> Spacer(modifier = Modifier.size(1.dp))
}
}
) {
Box(
modifier = Modifier.fillMaxSize()
) {
Button(
onClick = {
dialogType = BottomSheetType.High
scope.launch {
sheetState.animateTo(ModalBottomSheetValue.Expanded)
}
},
modifier = Modifier.align(Alignment.Center)
) {
Text(text = "High Bottom Sheet")
}
}
}
}
sealed class BottomSheetType {
object None : BottomSheetType()
object High : BottomSheetType()
object Short : BottomSheetType()
}
If add sheetState.performFling(0.1f) before sheetState.animateTo(ModalBottomSheetValue.Expanded), Short bottom sheet appears correct.
Compose version 1.1.0-beta01