Feedback
Feedbackanimated

Toast

A floating toast that drops in from the top with an icon, message and dismiss.

Profile updated

Installation

caveui components are copy-paste Jetpack Compose built entirely on Material 3 — there's no caveui dependency to add. Make sure Material 3 is on your classpath (it ships with the Compose BOM), then copy the Usage snippet below into your project.

kotlin
// build.gradle.kts (module)
dependencies {
    implementation(platform("androidx.compose:compose-bom:2025.06.00"))
    implementation("androidx.compose.material3:material3")
}

Usage

kotlin
@Composable
fun Toast(visible: Boolean, message: String, onDismiss: () -> Unit) {
    AnimatedVisibility(
        visible,
        enter = slideInVertically { -it } + fadeIn(),
        exit = slideOutVertically { -it } + fadeOut(),
    ) {
        Surface(
            shape = MaterialTheme.shapes.large,
            tonalElevation = 3.dp,
            shadowElevation = 6.dp,
            modifier = Modifier.fillMaxWidth(),
        ) {
            Row(
                Modifier.padding(12.dp),
                verticalAlignment = Alignment.CenterVertically,
            ) {
                Icon(Icons.Filled.CheckCircle, null, tint = Color(0xFF16A34A))
                Spacer(Modifier.width(10.dp))
                Text(message, Modifier.weight(1f),
                    style = MaterialTheme.typography.bodyMedium)
                IconButton(onClick = onDismiss) {
                    Icon(Icons.Filled.Close, "Dismiss", Modifier.size(18.dp))
                }
            }
        }
    }
}