Confirmation

Functions summary

Unit
@Composable
Confirmation(
    onTimeout: () -> Unit,
    modifier: Modifier,
    icon: (@Composable ColumnScope.() -> Unit)?,
    scrollState: ScalingLazyListState,
    durationMillis: Long,
    backgroundColor: Color,
    contentColor: Color,
    iconColor: Color,
    verticalArrangement: Arrangement.Vertical,
    contentPadding: PaddingValues,
    content: @Composable ColumnScope.() -> Unit
)

Confirmation lays out the content for an opinionated confirmation screen that displays a message to the user for durationMillis.

Functions

@Composable
fun Confirmation(
    onTimeout: () -> Unit,
    modifier: Modifier = Modifier,
    icon: (@Composable ColumnScope.() -> Unit)? = null,
    scrollState: ScalingLazyListState = rememberScalingLazyListState(),
    durationMillis: Long = DialogDefaults.ShortDurationMillis,
    backgroundColor: Color = MaterialTheme.colors.background,
    contentColor: Color = contentColorFor(backgroundColor),
    iconColor: Color = contentColor,
    verticalArrangement: Arrangement.Vertical = DialogDefaults.ConfirmationVerticalArrangement,
    contentPadding: PaddingValues = DialogDefaults.ContentPadding,
    content: @Composable ColumnScope.() -> Unit
): Unit

Confirmation lays out the content for an opinionated confirmation screen that displays a message to the user for durationMillis. It has a slot for an icon or image (which could be animated).

Confirmation can be used as a destination in a navigation graph e.g. using SwipeDismissableNavHost. However, for a conventional fullscreen dialog, displayed on top of other content, use Dialog.

Example of a Confirmation with animation:

import androidx.compose.animation.graphics.res.animatedVectorResource
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
import androidx.compose.animation.graphics.vector.AnimatedImageVector
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.dialog.Confirmation

val animation = AnimatedImageVector.animatedVectorResource(R.drawable.open_on_phone_animation)
Confirmation(
    onTimeout = {
        /* Do something e.g. navController.popBackStack() */
    },
    icon = {
        // Initially, animation is static and shown at the start position (atEnd = false).
        // Then, we use the EffectAPI to trigger a state change to atEnd = true,
        // which plays the animation from start to end.
        var atEnd by remember { mutableStateOf(false) }
        DisposableEffect(Unit) {
            atEnd = true
            onDispose {}
        }
        Image(
            painter = rememberAnimatedVectorPainter(animation, atEnd),
            contentDescription = "Open on phone",
            modifier = Modifier.size(48.dp),
        )
    },
    durationMillis = animation.totalDuration * 2L,
) {
    Text(
        text = "Body text displayed here " + "(swipe right to dismiss)",
        textAlign = TextAlign.Center,
    )
}
Parameters
onTimeout: () -> Unit

Event invoked when the dialog has been shown for durationMillis.

modifier: Modifier = Modifier

Modifier to be applied to the dialog.

icon: (@Composable ColumnScope.() -> Unit)? = null

An optional slot for displaying an icon or image.

scrollState: ScalingLazyListState = rememberScalingLazyListState()

The scroll state for the dialog so that the scroll position can be displayed e.g. by the PositionIndicator passed to Scaffold.

durationMillis: Long = DialogDefaults.ShortDurationMillis

The number of milliseconds for which the dialog is displayed, must be positive. Suggested values are DialogDefaults.ShortDurationMillis, DialogDefaults.LongDurationMillis or DialogDefaults.IndefiniteDurationMillis.

backgroundColor: Color = MaterialTheme.colors.background

Color representing the background color for this dialog.

contentColor: Color = contentColorFor(backgroundColor)

Color representing the color for content.

iconColor: Color = contentColor

Icon Color that defaults to the contentColor, unless specifically overridden.

verticalArrangement: Arrangement.Vertical = DialogDefaults.ConfirmationVerticalArrangement

The vertical arrangement of the dialog's children. This allows us to add spacing between items and specify the arrangement of the items when we have not enough of them to fill the whole minimum size.

contentPadding: PaddingValues = DialogDefaults.ContentPadding

The padding to apply around the whole of the dialog's contents.

content: @Composable ColumnScope.() -> Unit

A slot for the dialog title, expected to be one line of text.