Skip to content

๐Ÿž Custom toast library for Jetpack Compose

License

Notifications You must be signed in to change notification settings

aliernfrog/top-toast-compose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

TopToast

JitPack GitHub Packages

Toast library for Jetpack Compose

๐Ÿ‘€ Try it out

You can try TopToast by downloading demo application from releases

๐Ÿ“ฅ Installation

JitPack
  • Add maven repository: (Kotlin)
    maven(url = "https://jitpack.io")
  • Add dependency: (Kotlin)
    implementation("com.github.aliernfrog:top-toast-compose:<VERSION>")
GitHub Packages
  • Create a GitHub PAT with read:packages scope
  • Put the PAT and your GitHub username in global/project gradle.properties:
    gpr.user=MyUserName
    gpr.key=MyPAT
    
    or supply GITHUB_ACTOR (username) and GITHUB_TOKEN (PAT) in environment variables
  • Add maven repository: (Kotlin)
    maven(url = "https://maven.pkg.github.com/aliernfrog/top-toast-compose") {
        credentials {
          username = providers.gradleProperty("gpr.user").orNull ?: System.getenv("GITHUB_ACTOR")
          password = providers.gradleProperty("gpr.key").orNull ?: System.getenv("GITHUB_TOKEN")
        }
    }
  • Add dependency: (Kotlin)
    implementation("aliernfrog:top-toast-compose:<VERSION>")

๐Ÿž Example usage

val topToastState = remember {
    TopToastState(
        // Required for Android type toasts, you can set it to null and set it later using `setComposeView()`
        composeView = window.decorView,
        // Used in Android type toasts, you can set it to null and set it later using `setAppTheme()`
        appTheme = { toastContent ->
            MyAppTheme(toastContent)
        }
    )
}

Box(
    modifier = Modifier.background(MaterialTheme.colorScheme.surface)
) {
    Column {
        Button(
            content = {
                Text("Click me")
            },
            onClick = {
                // Shows an interactive toast in TopToastHost
                topToastState.showToast("This is a toast")
            }
        )
        Button(
            content = {
                Text("Android toast")
            },
            onClick = {
                // Shows a toast using Android Toast APIs, visible on top of modals and dialogs
                // Cannot be interacted with
                topToastState.showAndroidToast("This is a toast")
            }
        )
    }
    TopToastHost(topToastState)
}

Check demo application for more examples