Skip to content

Instantly share code, notes, and snippets.

@MrNtlu
Created December 6, 2022 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrNtlu/31c9b0aae5de70321bc719b1b62f7732 to your computer and use it in GitHub Desktop.
Save MrNtlu/31c9b0aae5de70321bc719b1b62f7732 to your computer and use it in GitHub Desktop.
Bottom Sheet Activity Skeleton
@Composable
fun BottomSheetLayout() {
val coroutineScope = rememberCoroutineScope()
val modalSheetState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden,
confirmStateChange = { it != ModalBottomSheetValue.HalfExpanded },
skipHalfExpanded = true
)
ModalBottomSheetLayout(
sheetState = modalSheetState,
sheetContent = {
Column(
//...
) {
Button(
onClick = {
coroutineScope.launch { modalSheetState.hide() }
}
) {
Text(text = "Hide Sheet")
}
}
}
) {
Scaffold {
Box(
modifier = Modifier
.fillMaxSize(),
contentAlignment = Alignment.Center,
) {
Button(
onClick = {
coroutineScope.launch {
if (modalSheetState.isVisible)
modalSheetState.hide()
else
modalSheetState.animateTo(ModalBottomSheetValue.Expanded)
}
},
) {
Text(text = "Open Sheet")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment