To use the Android Compose ModalBottomSheetLayout instead of a DialogFragment, you need to follow these steps:
implementation "androidx.compose.material:material:1.0.3"
@Composable
fun MyBottomSheetContent() {
// your content goes here
}
var isBottomSheetOpen by remember { mutableStateOf(false) }
ModalBottomSheetLayout(
sheetState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden
),
sheetContent = { MyBottomSheetContent() }
) {
// your main content goes here
}
Button(
onClick = { isBottomSheetOpen = true },
content = { Text("Open Bottom Sheet") }
)
LaunchedEffect(isBottomSheetOpen) {
if (isBottomSheetOpen) {
sheetState.show()
} else {
sheetState.hide()
}
}
With these steps, you can use the Android Compose ModalBottomSheetLayout to display your content in a bottom sheet instead of a DialogFragment.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-03 08:58:34 +0000
Seen: 13 times
Last updated: Jun 03 '23