https://github.com/andykale/toastkit
Minimal, customizable toast system for SwiftUI apps.
https://github.com/andykale/toastkit
haptics ios notifications swift-package swiftui toast
Last synced: 3 months ago
JSON representation
Minimal, customizable toast system for SwiftUI apps.
- Host: GitHub
- URL: https://github.com/andykale/toastkit
- Owner: andykale
- Created: 2025-05-11T01:35:11.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-12T01:36:17.000Z (about 1 year ago)
- Last Synced: 2025-05-12T02:28:38.847Z (about 1 year ago)
- Topics: haptics, ios, notifications, swift-package, swiftui, toast
- Language: Swift
- Homepage:
- Size: 65.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ToastKit




A lightweight SwiftUI toast notification system with configurable types, animations, and optional haptics. Easily show unobtrusive alerts like success, error, or info messages.
## ⨠Features
- Clean, customizable toast overlay
- Four toast types: success, warning, error, info
- Built-in support for haptic feedback
- Smooth transition animations
- Easy integration with `.environmentObject`

## đĻ Installation
### Swift Package Manager
1. In Xcode, open your project.
2. Go to `File > Add Packages...`
3. Enter the URL to this repository:
```
https://github.com/andykale/ToastKit.git
```
4. Choose the latest version and click **Add Package**.
---
## đ Usage
### 1. Import ToastKit
```swift
import ToastKit
```
### 2. Add the ToastManager to your environment
```swift
@StateObject var toastManager = ToastManager()
var body: some View {
ContentView()
.environmentObject(toastManager)
}
```
### 3. Show a toast
```swift
toastManager.show("Saved successfully!", type: .success)
```
### 4. Add the overlay to your UI
```swift
ToastOverlay()
```
This can be placed globally in your `ZStack` or root view.
---
## đĄ Toast Types
```swift
enum ToastType {
case success // â
green
case warning // â ī¸ orange
case error // â red
case info // âšī¸ black
}
```
All toasts use Apple SF Symbols and automatically apply a light haptic.
---
## đ Customization
- Change colors or icons in `ToastType.swift`
- Modify transitions or timing in `ToastOverlay.swift`
---
## âšī¸ Advanced Usage (ViewModel integration)
If you're calling `toastManager.show(...)` from a view model or external object:
- Inject your `ToastManager` into the view model via its initializer:
```swift
let toastManager = ToastManager()
let viewModel = YourViewModelName(toastManager: toastManager)
```
- Ensure your view includes `.environmentObject(toastManager)` for `ToastOverlay` to respond.
- ToastManager already uses `withAnimation` internally, so transitions will work correctly. If manually assigning `message`, wrap it in:
```swift
withAnimation {
toastManager.message = "Something happened"
}
```
---
## đĨ Demo Preview
Here's a quick example to see ToastKit in action:
```swift
struct ToastDemoView: View {
@StateObject var toastManager = ToastManager()
var body: some View {
ZStack {
VStack(spacing: 20) {
Button("Show Success") {
toastManager.show("Upload complete!", type: .success)
}
Button("Show Warning") {
toastManager.show("Low battery warning!", type: .warning)
}
Button("Show Error") {
toastManager.show("Failed to save data.", type: .error)
}
Button("Show Info") {
toastManager.show("You're viewing a demo.", type: .info)
}
}
}
.environmentObject(toastManager)
.overlay(ToastOverlay())
}
}
```
This view allows you to test all toast styles interactively.
### đ˛ Try the Demo App
A fully working iOS demo project is included in the `ToastKitDemo/` folder. Open `ToastKitDemo.xcodeproj` and run on simulator or device.
---
## đą Platform Support
- â
iOS 14+
- â Not designed for macOS or watchOS yet
---
## đ License
MIT License â free to use, modify, and distribute.
---
## đ Contribute
Feel free to open a PR to improve visuals, add styling, or extend support!
---
## đ Related
Check out [AnimatedVisibility](https://github.com/andykale/animated-visibility-swiftui) for clean SwiftUI transition helpers.