Show Jetpack Compose snackbars from Composables or ViewModels without passing SnackbarHostState through your application. SnapNotify provides a shared message queue, semantic styling, action callbacks, and optional top notifications.
Ensure Maven Central is available in your project's dependency repositories:
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}Add the library to your application module:
// app/build.gradle.kts
dependencies {
implementation("io.github.ivamsi:snapnotify:1.2.0")
}Add a provider around your Compose content, then call SnapNotify.show. The provider is required; a show call alone does not install a host. The following example uses Material 3 components inside your existing application theme:
@Composable
fun NotificationExample() {
SnapNotifyProvider {
Button(onClick = { SnapNotify.show("Saved") }) {
Text("Show snackbar")
}
}
}For application-wide notifications, put the provider around your application content in setContent instead. Hilt is optional.
| Your situation | Suggested approach |
|---|---|
| One screen with a simple snackbar | Compose's built-in SnackbarHostState may be enough; no additional dependency is necessary. |
| Notifications triggered from several Composables or ViewModels | SnapNotify offers a shared API and queue without passing host state to each caller. |
| Success, error, warning, or information messages | Use the semantic styling helpers. |
| Strictly isolated notification channels per feature | Review the shared singleton architecture before adopting; provider placement alone should not be treated as an independent message channel. |
Keep notification calls in your presentation layer rather than adding a UI-library dependency to domain or data code.
SnapNotify.showSuccess("Profile saved")
SnapNotify.showError("Upload failed")
SnapNotify.showWarning("Unsaved changes")
SnapNotify.showInfo("Update available")SnapNotify.show(
message = "Message deleted",
actionLabel = "Undo",
onAction = { undoDelete() }
)undoDelete() is application code that you provide.
SnapNotify.show("Processing complete", durationMillis = 5000L)SnapNotify.showUndoable(
message = "Item moved to trash",
onAction = { restoreItem() },
durationMillis = 5000L,
onTimeout = { permanentlyDelete() }
)restoreItem() and permanentlyDelete() are application callbacks. Pressing the snackbar pauses the countdown. The action and close control do not run onTimeout. Do not use a UI timeout as your only mechanism for durable background work.
SnapNotifyProvider(placement = NotificationPlacement.TopPill()) {
AppContent()
}AppContent() represents your application's Compose content. TopBanner and BottomSnackbar are also available.
SnapNotify.configure(
SnapNotifyConfig(
maxQueueSize = 50,
onMessageDropped = { message ->
// Handle a dropped message if your application needs to.
}
)
)
// Clear queued and current notification state when appropriate for your UX.
SnapNotify.clearAll()The queue is bounded. When full, the lowest-priority oldest message is dropped; do not treat it as guaranteed delivery.
- Android minimum SDK: API 24.
- This is a Jetpack Compose library, not a replacement for Android system notifications.
- Keep a provider in the composition wherever notifications must be displayed.
- Notifications use shared singleton state. Review placement and queue-clearing behavior when integrating multiple providers or navigation destinations.
- Custom host rendering is available through
hostContent; when supplied, the normalplacementrendering is not applied. - Validate the published artifact against your application's Kotlin and Compose versions before rollout. The repository build configuration does not establish compatibility with every consumer toolchain.
Clone the repository and run the demo on an attached Android device or emulator:
./gradlew :SnapNotifyDemo:installDebugThe sample uses project(":snapnotify"). It exercises local source, not the Maven Central artifact.
See CHANGELOG.md for release history. Pin an explicit dependency version and review release notes before upgrading.
Open an issue with your library, Kotlin, Compose, and Android versions, a minimal reproducer, and expected versus actual behavior. For provider or queue problems, include where the provider is installed and how messages are triggered. Do not include secrets or private application data.
./gradlew :snapnotify:test
./gradlew :snapnotify:check
./gradlew checkTests cover the queue, deduplication, countdown behavior, placement, and public show methods. Run the tasks to obtain current test results.
To validate a locally published artifact, run ./gradlew :snapnotify:publishToMavenLocal and configure a separate consumer module with mavenLocal() and io.github.ivamsi:snapnotify:1.2.0. This does not verify the artifact hosted on Maven Central.
- Update coordinates in
snapnotify/build.gradle.kts, demo versionCode/versionName, CHANGELOG.md, and README dependency snippets. - Run
./gradlew check. - Commit, create an annotated
vX.Y.Ztag, and push the branch and tag. - Run
./gradlew :snapnotify:publishAndReleaseToMavenCentralwith the required Central Portal credentials and signing configuration. See publishing setup and comments in gradle.properties. - Create a GitHub Release from the tag with the release notes.
Copyright 2025 Vamsi Vaddavalli
Licensed under the Apache License, Version 2.0. The software is provided on an AS IS basis, without warranties or conditions of any kind. See the repository's license terms for details.
