Joe Jensen
03/31/2021, 12:43 AMModalBottomSheetLayout as a root component to the app?
My use case: I have an existing app with bottom navigation implemented as a fragment, and I will slowly migrate each tab (each its own fragment) to jetpack compose. How would I render a bottom sheet on top of all that UI? There doesn't seem to be an equivalent to AlertDialog but for bottom sheetsTim Malseed
03/31/2021, 12:45 AMJoe Jensen
03/31/2021, 12:51 AM@ExperimentalMaterialApi
@ExperimentalAnimationApi
@Composable
fun MainScreen() {
ZumperTheme {
Surface(color = ZColor2.BackgroundLight) {
Column {
Text(text = "Testing 1", modifier = Modifier.padding(16.dp))
Text(text = "Testing 2", modifier = Modifier.padding(16.dp))
val sheetState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)
val scope = rememberCoroutineScope()
ModalBottomSheetLayout(
sheetState = sheetState,
sheetContent = {
Text(text = "Testing 2", modifier = Modifier.padding(16.dp))
}
) {
Button(onClick = {
scope.launch { sheetState.show() }
}) {
Text(text = "Open Sheet", modifier = Modifier.padding(16.dp))
}
}
Text(text = "Testing 3", modifier = Modifier.padding(16.dp))
Text(text = "Testing 4", modifier = Modifier.padding(16.dp))
}
}
}
}Joe Jensen
03/31/2021, 12:54 AMModalBottomSheetLayout requires that you wrap the content - alert dialog doesn't.
The above screen renders this:knthmn
03/31/2021, 12:57 AMDialog() and modifying it to use Android platform's bottom sheet dialog and it worked.Joe Jensen
03/31/2021, 12:58 AMJoe Jensen
03/31/2021, 1:01 AMsheet https://www.hackingwithswift.com/quick-start/swiftui/how-to-present-a-new-view-using-sheetsknthmn
03/31/2021, 1:07 AMDialogWrapper in compose that subclasses Android's Dialog, I copied everything from there, but subclass it to material's BottomSheetDialog. I remember it working, but it was drawing over navigation bar when it came up and I didn't bother to fix it.Tim Malseed
03/31/2021, 1:17 AMknthmn
03/31/2021, 1:31 AMModalBottomSheet everywhere since it only creates the bottom sheet inside the area, unlike AlertDialog which is globally positioned.Tim Malseed
03/31/2021, 1:35 AMIan Lake
03/31/2021, 2:10 AMModalBottomSheetLayout because that's what allows it to draw the scrim and intercept touch events outside of it. In a hybrid world, it sounds like you just be using a BottomSheetDialogFragment like beforeIan Lake
03/31/2021, 2:14 AMJoe Jensen
03/31/2021, 2:25 AM