|
1 | 1 | # TopToast |
2 | | -Simple toast library for Jetpack Compose |
3 | | -- ⚠️ 0.0.11 and higher use Material 3 |
4 | | -- 👀 You can try TopToast by downloading demo application from [releases](https://github.com/aliernfrog/top-toast-compose/releases) |
| 2 | +[](https://github.com/aliernfrog/top-toast-compose/packages) |
| 3 | +[](https://jitpack.io/#aliernfrog/top-toast-compose) |
5 | 4 |
|
6 | | -## [📁 JitPack](https://jitpack.io/#aliernfrog/top-toast-compose) |
7 | | -[](https://jitpack.io/#aliernfrog/top-toast-compose) |
| 5 | +Toast library for Jetpack Compose |
| 6 | + |
| 7 | +## 👀 Try it out |
| 8 | +You can try TopToast by downloading demo application from [releases](https://github.com/aliernfrog/top-toast-compose/releases) |
| 9 | + |
| 10 | +## 📥 Installation |
| 11 | +You can get the library from GitHub Packages or JitPack |
| 12 | +### GitHub Packages |
| 13 | +- Create a GitHub PAT with `read:packages` scope |
| 14 | +- Put the PAT and your GitHub username in global/project `gradle.properties`: |
| 15 | + ``` |
| 16 | + gpr.user=MyUserName |
| 17 | + gpr.key=MyPAT |
| 18 | + ``` |
| 19 | + or supply `GITHUB_ACTOR` (username) and `GITHUB_TOKEN` (PAT) in environment variables |
| 20 | +- Add maven repository: (Kotlin) |
| 21 | + ```kts |
| 22 | + maven(url = "https://maven.pkg.github.com/aliernfrog/top-toast-compose") { |
| 23 | + credentials { |
| 24 | + username = providers.gradleProperty("gpr.user").orNull ?: System.getenv("GITHUB_ACTOR") |
| 25 | + password = providers.gradleProperty("gpr.key").orNull ?: System.getenv("GITHUB_TOKEN") |
| 26 | + } |
| 27 | + } |
| 28 | + ``` |
| 29 | +- Add dependency: (Kotlin) |
| 30 | + ```kts |
| 31 | + implementation("aliernfrog:top-toast-compose:<VERSION>") |
| 32 | + ``` |
| 33 | + |
| 34 | +### JitPack |
| 35 | +> [!WARNING] |
| 36 | +> As JitPack now fails to build with no reason, latest versions available on JitPack are `1.3.4` and `1.3.5-alpha01`. |
| 37 | +> It may or may not be updated in the future. |
| 38 | +- Add maven repository: (Kotlin) |
| 39 | + ```kts |
| 40 | + maven(url = "https://jitpack.io") |
| 41 | + ``` |
| 42 | +- Add dependency: (Kotlin) |
| 43 | + ```kts |
| 44 | + implementation("com.github.aliernfrog:top-toast-compose:<VERSION>") |
| 45 | + ``` |
8 | 46 |
|
9 | 47 | ## 🍞 Example usage |
10 | 48 | ```kotlin |
11 | 49 | val topToastState = remember { |
12 | | - TopToastState(window.decorView) |
| 50 | + TopToastState( |
| 51 | + // Required for Android type toasts, you can set it to null and set it later using `setComposeView()` |
| 52 | + composeView = window.decorView, |
| 53 | + // Used in Android type toasts, you can set it to null and set it later using `setAppTheme()` |
| 54 | + appTheme = { toastContent -> |
| 55 | + MyAppTheme(toastContent) |
| 56 | + } |
| 57 | + ) |
13 | 58 | } |
14 | 59 |
|
15 | 60 | Box( |
16 | 61 | modifier = Modifier.background(MaterialTheme.colorScheme.surface) |
17 | 62 | ) { |
18 | | - Button( |
19 | | - content = { |
20 | | - Text("Click me") |
21 | | - }, |
22 | | - onClick = { |
23 | | - topToastState.showToast("This is a toast") |
24 | | - } |
25 | | - ) |
| 63 | + Column { |
| 64 | + Button( |
| 65 | + content = { |
| 66 | + Text("Click me") |
| 67 | + }, |
| 68 | + onClick = { |
| 69 | + // Shows an interactive toast in TopToastHost |
| 70 | + topToastState.showToast("This is a toast") |
| 71 | + } |
| 72 | + ) |
| 73 | + Button( |
| 74 | + content = { |
| 75 | + Text("Android toast") |
| 76 | + }, |
| 77 | + onClick = { |
| 78 | + // Shows a toast using Android Toast APIs, visible on top of modals and dialogs |
| 79 | + // Cannot be interacted with |
| 80 | + topToastState.showToast("This is a toast") |
| 81 | + } |
| 82 | + ) |
| 83 | + } |
26 | 84 | TopToastHost(topToastState) |
27 | 85 | } |
28 | 86 | ``` |
|
0 commit comments