EasyToast is a lightweight and customizable SwiftUI package that provides easy-to-use toast notifications. Display brief messages to your users with minimal effort.
- Simple Text Toasts: Display a quick message to the user with just a few lines of code.
- Flexible Positioning: Position the toast at the top, center, or bottom of the screen.
- Configurable Duration: Control how long the toast remains visible.
- Customizable appearance: Control background color, text color, corner radius, font, padding, shadow, and text alignment
- Predefined toast types: Use built-in styles like .success, .error, .warning, and .info.
- Interactive toasts: User can create an
onTap
closure to add custom behavior when the toast is tapped. - Custom Toast Views: Create and display fully custom-designed toast notifications.
- Improved animations: Additional animations and transitions to enhance the toast appearance and disappearance.
- Toast queueing: Working in progress 🔨
- Accessibility support: Working in progress 🔨
- Unit tests: Working in progress 🔨
- iOS >= 15.0
- Swift >= 5.9
You can add EasyToast to your project using Swift Package Manager.
- Open your project in Xcode.
- Go to
File > Add Packages Dependencies...
- Enter the package URL: https://github.com/banghuazhao/EasyToast
- Choose the latest release
Alternatively, add the following to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/banghuazhao/EasyToast.git", from: "0.4.0")
]
To display a simple toast with a message, use the easyToast
modifier:
import EasyToast
struct ContentView: View {
@State private var showToast = false
var body: some View {
content
.easyToast(isPresented: $showToast, message: "Hello, EasyToast!")
}
}
To display a simple toast with a message, use the easyToast
modifier:
var body: some View {
content
.easyToast(isPresented: $showToast, message: "This is a toast message on top", position: .top)
}
Customize the appearance and behavior:
let customStyle = ToastStyle(
backgroundColor: .blue,
textColor: .white,
font: .headline,
cornerRadius: 12,
shadow: .gray,
padding: EdgeInsets(top: 16, leading: 16, bottom: 16, trailing: 16)
)
Text("Custom Toast")
.easyToast(
isPresented: $showToast,
message: "This is a custom toast message.",
position: .bottom,
duration: 3
style: customStyle
)
To display a custom-designed toast view, use the easyToast
modifier with a custom view:
var body: some View {
content
.customToast(isPresented: $showToast, duration: 3, position: .bottom) {
HStack {
Image(systemName: "checkmark.circle")
.foregroundColor(.white)
Text("Show Custom Toast Success")
.foregroundColor(.white)
}
.padding()
.background(Color.green)
.cornerRadius(20)
}
}
@State private var showToast = false
var body: some View {
VStack {
Button("Show Toast") {
showToast = true
}
}
.easyToast(
isPresented: $showToast,
message: "Tap to dismiss",
onTap: {
print("Toast tapped, dismissing")
showToast = false
}
)
}
The toast is implemented by overlaying a custom view on top of the view that applies the .easyToast
modifier, ensuring it seamlessly appears over the current content without disrupting the underlying layout
EasyToast is released under the MIT License. See LICENSE for details.