Skip to content

toast README

github-actions[bot] edited this page Jun 2, 2026 · 1 revision

cmp-toast

Compose Multiplatform toast notification system.

Maven Central


What It Does

A lightweight, composable toast library for Compose Multiplatform. Show short non-blocking messages with optional action buttons — positioned at top, center, or bottom of screen, with 5 visual styles and 3 duration presets.

No platform channels, no native code, no DI, no Supabase. Pure Compose.


Quick Start

// 1. Create state (in composable)
val toastState = rememberToastHostState()
val scope = rememberCoroutineScope()

// 2. Place ToastHost in your root Box / Scaffold
Box(modifier = Modifier.fillMaxSize()) {
    YourScreenContent()
    ToastHost(hostState = toastState)
}

// 3. Show toasts from anywhere that has the scope
scope.launch {
    toastState.showToast("File saved!")
    // with options:
    toastState.showToast(
        message     = "Copied to clipboard",
        actionLabel = "Undo",
        duration    = ToastDuration.LONG,
        position    = ToastPosition.BOTTOM,
        style       = ToastStyle.SUCCESS,
    )
}

API Reference

State

// Create (in composable)
val toastState = rememberToastHostState()

// Show (in coroutine scope)
suspend fun showToast(
    message:     String,
    actionLabel: String?       = null,
    duration:    ToastDuration = ToastDuration.SHORT,
    position:    ToastPosition = ToastPosition.BOTTOM,
    style:       ToastStyle    = ToastStyle.DEFAULT,
): ToastResult

// Dismiss programmatically
fun dismiss()

// Observe
val currentToast: StateFlow<ToastData?>

ToastHost (composable)

@Composable
fun ToastHost(
    hostState: ToastHostState,
    modifier:  Modifier = Modifier,
    toast:     @Composable (ToastData) -> Unit = { DefaultToast(it) },
)

Enums

enum class ToastDuration { SHORT, LONG, INDEFINITE }
// SHORT = 3000ms, LONG = 5000ms, INDEFINITE = stays until dismissed

enum class ToastPosition { TOP, CENTER, BOTTOM }

enum class ToastStyle { DEFAULT, SUCCESS, ERROR, WARNING, INFO }

ToastResult

enum class ToastResult { DISMISSED, ACTION_PERFORMED }

Platform Support

Runs everywhere Compose Multiplatform runs:

Platform Support
Android
iOS
macOS
JVM
JS / Wasm

Docs

Clone this wiki locally