Peter Mandeljc
07/20/2021, 6:00 PMModalBottomSheetLayout
and I'm having a weird effect, please see video. Sheet layout seems to visually collapse on start. Any ideas? Source code in thread.@Preview
@Composable
fun Screen() {
val scope = rememberCoroutineScope()
var isSheetA by remember { mutableStateOf(true) }
val sheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Expanded)
fun openSheet(isA: Boolean) = scope.launch {
isSheetA = isA
sheetState.expand()
}
ModalBottomSheetLayout(
sheetState = sheetState,
sheetElevation = 0.dp,
sheetContent = {
if (isSheetA) SheetA() else SheetB()
}
) {
Content(
onOpenA = {
openSheet(true)
},
onOpenB = {
openSheet(false)
},
)
}
}
@Composable
private fun SheetA() = Column {
// Just added few composables, to increase complexity, otherwise it works fine
Row(modifier = Modifier.fillMaxWidth()) {
Text(text = "open A")
Text(text = "open A")
}
Row(modifier = Modifier.fillMaxWidth()) {
Text(text = "open A")
Text(text = "open A")
}
Row(modifier = Modifier.fillMaxWidth()) {
Text(text = "open A")
Text(text = "open A")
}
}
@Composable
private fun SheetB() = Sheet(height = 600.dp, color = Color.Green)
@Composable
private fun Sheet(height: Dp, color: Color) = Box(
modifier = Modifier
.fillMaxWidth()
.height(height)
.background(color)
)
@Composable
private fun Content(onOpenA: () -> Unit, onOpenB: () -> Unit) = Column(
modifier = Modifier.fillMaxSize()
) {
Button(onClick = onOpenA) {
Text(text = "open A")
}
Button(onClick = onOpenB) {
Text(text = "open B")
}
}
Ian Lake
07/20/2021, 6:18 PMinitialState
you're passing into rememberModalBottomSheetState
is ModalBottomSheetValue.Expanded
which means the sheet is 'visible at full height' (compared to HalfExpanded
with the 50% of the available height or Hidden
which is not visible by default), but your video seems to show you starting in the 'no bottom sheet visible' kind of state, which seems to imply that Hidden
is more correct?Peter Mandeljc
07/20/2021, 6:21 PMIan Lake
07/20/2021, 6:26 PMPeter Mandeljc
07/20/2021, 6:29 PMsheetState.show()
, but it's not ideal, since would need to have it fully expandedIan Lake
07/20/2021, 6:31 PMHidden
and show()
, it animates up to the fully expanded height of your contentHidden
state - i.e., animating up from the bottom when you next show
your sheetModalBottomSheetLayout
appears to be animating from the Expanded
height of the green sheet to the Expanded
height of the white sheethide()
, swap contents, then show()
- as hide()
and show()
are suspending methods, they'll only resume after they complete (i.e., you won't swap contents until the hide
completes and the anchor is back at the bottom)Peter Mandeljc
07/20/2021, 6:45 PMIan Lake
07/20/2021, 11:16 PMshow()
runs (and sets the anchors based on the old height) for a frame before the new height comes inPeter Mandeljc
07/21/2021, 8:05 AM