-
-
Save KatieBarnett/3ef2d4a913696050de687d8ab8e12c6c to your computer and use it in GitHub Desktop.
Basic ModalBottomSheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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