Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Last active December 22, 2023 02:07
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 KatieBarnett/69f8e04e299aa63d9b29dd363d0bb25a to your computer and use it in GitHub Desktop.
Save KatieBarnett/69f8e04e299aa63d9b29dd363d0bb25a to your computer and use it in GitHub Desktop.
Confirm dialog
val coroutineScope = rememberCoroutineScope()
var showConfirmChanges by rememberSaveable { mutableStateOf(false) }
...
if (showConfirmChanges) {
AlertDialog(
onDismissRequest = { showConfirmChanges = false },
title = { Text(stringResource(R.string.confirm_changes_title)) },
text = { Text(stringResource(R.string.confirm_changes_text)) },
confirmButton = {
TextButton(onClick = {
// Close the ModalBottomSheet
coroutineScope.launch {
addSheetState.hide()
}.invokeOnCompletion {
if (!addSheetState.isVisible) {
showAddSheet = false
}
}
// Close the confirm changes AlertDialog
showConfirmChanges = false
}) {
Text(stringResource(R.string.confirm_changes_confirm))
}
},
dismissButton = {
TextButton(onClick = {
showConfirmChanges = false
}) {
Text(stringResource(R.string.confirm_changes_dismiss))
}
},
properties = DialogProperties(
dismissOnBackPress = false,
dismissOnClickOutside = false
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment