Lucas Kivi
04/05/2024, 5:21 PMModalBottomSheetLayout
will be ported to Material3
? The Material3
ModalBottomSheet
has some limitations that make it unusable for me. I either need to hack up the BottomSheetScaffold
or use the Material
ModalBottomSheetLayout
and suppress the UsingMaterialAndMaterial3Libraries
warning.jossiwolf
04/08/2024, 4:12 PMModalBottomSheet
is the API shape we're committed to. The team is currently considering some API changes to enable a broader range of use cases, no details on that yet though.
What are the limitations you're facing?Lucas Kivi
04/08/2024, 4:28 PMModalBottomSheet
, I am glad you asked.
1. I need to be able to disable user dragging. There is already a ticket for this erroneously marked as a duplicate.
2. It seems a little weird that we need to wrap the ModalBottomSheet
in an if statement (due to the fact that when the ModalBottomSheet
enters the composition it animates open if it has an expanded state). I could elaborate on this, but I am not sure that you are curious about it. I feel like this would work best if we just had a way to intercept any attempt to dismiss the sheet so we could hand it off the VM, update our state, and manually animate the sheet closed.Lucas Kivi
04/08/2024, 10:06 PMModalBottomSheetLayout
but I would rather just wait for the updated ModalBottomSheet
API if it is going to be something that sees the light of day. Currently migrating away from a BottomSheetDialogFragment
.jossiwolf
04/15/2024, 9:03 AMLucas Kivi
04/15/2024, 4:01 PMBottomSheetDialogFragment
to get the behavior I want.
2. Ok. I will see what I can do about that. Even when it is hidden it still consumes clicks and stuff which I didn’t even realize before!Lucas Kivi
04/15/2024, 6:26 PMModalBottomSheet
if you want to interact with content behind it and avoid the sheet animating open as soon as it enters the composition.
2. I wish I could override clicks outside of the sheet’s content. This is handled by the animateToDismiss
lambda on the Scrim
in the implementation. This way I can go to the VM, and back to the UI, and animate the sheet away.
Here is a bit of code for reproduction of problem 1.
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxSize()
) {
Button(
onClick = { scope.launch { sheetState.show() } },
) {
Text(text = "Open dialog")
}
}
}
ModalBottomSheet(
containerColor = Color.Cyan,
onDismissRequest = { },
sheetState = sheetState,
) {
Spacer(
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
)
}