Build apps faster with our new App builder! Check it out →

FailureConfirmationDialog

Android

Component in Wear Material 3 Compose

Shows a [FailureConfirmationDialog] with a failure icon and an optional short curved text. This variation of confirmation dialog indicates an unsuccessful operation or action.

The confirmation dialog will show a message to the user for [durationMillis]. After a specified timeout, the [onDismissRequest] callback will be invoked, where it's up to the caller to handle the dismissal. To hide the confirmation, [visible] parameter should be set to false.

Where user input is required, such as choosing to ok or cancel an action, use [AlertDialog] instead of [FailureConfirmationDialog].

Last updated:

Installation

dependencies {
   implementation("androidx.wear.compose:compose-material3:1.0.0-alpha34")
}

Overloads

@Composable
fun FailureConfirmationDialog(
    visible: Boolean,
    onDismissRequest: () -> Unit,
    curvedText: (CurvedScope.() -> Unit)?,
    modifier: Modifier = Modifier,
    colors: ConfirmationDialogColors = ConfirmationDialogDefaults.failureColors(),
    properties: DialogProperties = DialogProperties(),
    durationMillis: Long = ConfirmationDialogDefaults.DurationMillis,
    content: @Composable () -> Unit = { ConfirmationDialogDefaults.FailureIcon() },
)

Parameters

namedescription
visibleA boolean indicating whether the confirmation dialog should be displayed.
onDismissRequestA lambda function to be called when the dialog is dismissed - either by swiping right or when the [durationMillis] has passed. Implementation of this lambda must remove the dialog from the composition hierarchy e.g. by setting [visible] to false.
curvedTextA slot for displaying curved text content which will be shown along the bottom edge of the dialog. We recommend using [confirmationDialogCurvedText] for this parameter, which will give the default sweep angle and padding.
modifierModifier to be applied to the confirmation content.
colorsA [ConfirmationDialogColors] object for customizing the colors used in this [FailureConfirmationDialog].
propertiesAn optional [DialogProperties] object for configuring the dialog's behavior.
durationMillisThe duration in milliseconds for which the dialog is displayed. This value will be adjusted by the accessibility manager according to the content displayed.
contentA slot for displaying an icon inside the confirmation dialog, which can be animated. Defaults to [ConfirmationDialogDefaults.FailureIcon].

Code Example

FailureConfirmationDialogSample

@Composable
fun FailureConfirmationDialogSample() {
    var showConfirmation by remember { mutableStateOf(false) }

    // Use AppScaffold to improve ConfirmationDialog's Performance
    AppScaffold {
        Box(Modifier.fillMaxSize()) {
            FilledTonalButton(
                modifier = Modifier.align(Alignment.Center),
                onClick = { showConfirmation = true },
                label = { Text("Show Confirmation") }
            )
        }

        val text = "Failure"
        val style = ConfirmationDialogDefaults.curvedTextStyle
        FailureConfirmationDialog(
            visible = showConfirmation,
            onDismissRequest = { showConfirmation = false },
            curvedText = { confirmationDialogCurvedText(text, style) }
        )
    }
}
by @alexstyl