Skip to content

swatikulkarni123/QuickNotify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Jetpack Compose Toast, Snackbar, Dialog & Custom Alert Library

QuickNotify is a Jetpack Compose library that helps Android developers show Toast messages, Snackbars, Dialogs, and custom alerts using a global overlay system with zero setup.

Works across the entire app without requiring a host Composable in each screen.


πŸš€ Features

  • Global overlay via App Startup
  • Jetpack Compose UI β€” Toast, Snackbar, Dialog
  • Toast with text + icon + custom duration
  • Snackbar with ** icon + custom duration **
  • Dialog with:
    • Header image
    • Title
    • Body text
    • Up to 3 customizable buttons
    • Optional top-right close icon
    • Rounded or square corners
  • Custom Overlay for showing any Composable UI globally:
    • Full control over content, alignment, and appearance.
    • Manual or automatic dismissal.
  • Coroutine-based visibility handling
  • Works across entire application

How to Display Toast in Jetpack Compose

To display a toast in Jetpack Compose, you can use the QuickNotify library.

πŸ“¦ Installation

Step 1: Add JitPack

Add in settings.gradle.kts:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        mavenCentral()
        maven { url = uri("https://jitpack.io") }
    }
}

Step 2: Add dependency

dependencies {
    implementation("com.github.swatikulkarni123:QuickNotify:1.0.0")
}

πŸ›  Usage


βœ… 1. Toast

Simple toast

QuickNotify.showToast("Hello world!")

Toast with duration + icon

QuickNotify.showToast(
    message = "Saved successfully",
    duration = 2500L,
    icon = Icons.Default.Check
)

βœ… 2. Snackbar

Basic Snackbar

QuickNotify.showSnackbar(
    message = "No internet connection"
)

Snackbar with icon

QuickNotify.showSnackbar(
    message = "Message sent",
    icon = Icons.Default.Send
)

βœ… 3. Dialog

Shows a fully customizable dialog with an optional top image,
title, body, and up to 3 buttons.

Example

QuickNotify.showDialog(
    title = "Delete Item?",
    body = "This action cannot be undone.",
    topImage = painterResource(R.drawable.warning),

    btn1Text = "Cancel",
    btn1Color = Color.Gray,
    onBtn1Click = { },

    btn2Text = "Delete",
    btn2Color = Color.Red,
    onBtn2Click = { /* Delete logic */ }
)

Dialog only close button (no action buttons)

QuickNotify.showDialog(
    title = "Info",
    body = "This is message-only dialog."
)

This will show a top-right close icon automatically.

✨ 4. Custom Overlay / Custom View

Use showOverlay to display any Composable UI in a global overlay. This is ideal for custom alerts, banners, or full-screen loaders.

The content lambda provides a dismiss: () -> Unit function, which you must call to manually dismiss the overlay.

Example: Custom Success Alert

QuickNotify.showOverlay(
    overlayAlignment = Alignment.Center, // Position your custom view
    autoCancel = false, // Set to true to dismiss after default duration (2000ms) or 'duration'
    content = { dismiss -> // 'dismiss' function to manually close the overlay
        Card(
            // ... your custom UI for the alert ...
            shape = RoundedCornerShape(20.dp),
            // ...
        ) {
            Row(
                // ... your alert content ...
            ) {
                // ...
                // Example of a dismiss button inside the custom view
                Icon(
                    // ...
                    modifier = Modifier.size(20.dp).clickable {
                        dismiss() // **Crucial: Call dismiss() to close the overlay**
                        // You can also show another QuickNotify message here
                        // QuickNotify.showToast("Clicked") 
                    }
                )
            }
        }
    }
)

βš™οΈ How it works

  • Automatically initializes via QuickNotifyInitializer
  • Uses a hidden global Compose host
  • Renders Toast/Snackbar/Dialog using:
    • QuickNotifyHostInternal
    • QuickNotifyController
  • Auto-dismiss using coroutine delays
  • Manual dismiss:
QuickNotifyController.clear()

πŸ“ Icons / Resources

If using a close icon, place it here:

your-library-module/
 └── src/
      └── main/
           └── res/
                └── drawable/
                     └── ic_close.xml

Use inside dialog:

painterResource(R.drawable.ic_close)

πŸ“œ License

MIT

Keywords

Jetpack Compose Toast
Compose Snackbar
Compose Dialog
Android Compose Alert