m-toast
0.3.0indexedLightweight toast overlay system for showing customizable timed messages with icon support, fully custom composable content, alignment and offset controls, and sensible defaults.
Lightweight toast overlay system for showing customizable timed messages with icon support, fully custom composable content, alignment and offset controls, and sensible defaults.
A lightweight Compose Multiplatform library for displaying toast messages across Android, iOS, Desktop (JVM), and Web (Wasm/JS).
Add the dependency to your commonMain source set:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("it.xabaras:mtoast:0.3.0")
}
}
}
To use the library, wrap your main content with the ToastContainer. This component hosts the toast overlays.
ToastContainer {
// Your app content here
App()
}
On iOS, the toast automatically aligns to the top to avoid overlapping with the notch/dynamic island, while on other platforms it defaults to the bottom.
The library provides several showToast methods to display different types of messages.
Displays a basic text message with a default duration.
showToast("Hello, World!")
You can specify a custom duration in milliseconds, or use constants from ToastDefaults.
showToast(
message = "This is a short toast",
durationMillis = ToastDefaults.DURATION_SHORT
)
You can include an icon alongside your message. The library supports ImageVector, ImageBitmap, and Painter.
showToast(
message = "Success!",
icon = Icons.Default.Check,
iconTint = Color.Green,
durationMillis = ToastDefaults.DURATION_LONG
)
If you need complete control over the toast's appearance, you can pass a custom Composable.
showToast(durationMillis = 5000L) {
Row(verticalAlignment = Alignment.CenterVertically) {
CircularProgressIndicator(modifier = Modifier.size(16.dp))
Spacer(Modifier.width(8.dp))
Text("Loading...")
}
}
You can specify where the toast appears and apply additional offsets using offsetX and offsetY.
showToast(
message = "Top aligned with offset",
alignment = Alignment.TopCenter,
offsetY = 48.dp
)
The library provides default values that you can use:
DURATION_SHORT: 2000msDURATION_DEFAULT: 3000msDURATION_LONG: 5000msDEFAULT_ICON_TINT: Color.Unspecified (defaults to Black/White based on theme)DEFAULT_ALIGNMENT: Alignment.AutoApache-2.0 license.
DEFAULT_OFFSET: 0.dpSurfaced from shared tags and platforms — no rankings paid for.