Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Last active December 22, 2023 02:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save KatieBarnett/3ef2d4a913696050de687d8ab8e12c6c to your computer and use it in GitHub Desktop.
Basic ModalBottomSheet
val coroutineScope = rememberCoroutineScope()
var items by rememberSaveable { mutableStateOf(listOf<String>()) }
var showAddSheet by rememberSaveable { mutableStateOf(false) }
val addSheetState = rememberModalBottomSheetState()
Scaffold(...) { innerPadding ->
// Screen content
ShoppingList(
items = items,
onAddItemClick = { showAddSheet = true },
modifier = Modifier.fillMaxSize().padding(innerPadding)
)
// Bottom sheet
if (showAddSheet) {
ModalBottomSheet(
onDismissRequest = { showAddSheet = false },
sheetState = addSheetState,
modifier = Modifier
) {
BottomSheetContent(
onSaveClick = {
// Save the value
items = items.plus(it)
// Close the sheet, allowing the animation to run
coroutineScope.launch {
addSheetState.hide()
}.invokeOnCompletion {
if (!addSheetState.isVisible) {
showAddSheet = false
}
}
}
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment