PeekDialog is a lightweight and customizable SwiftUI component for displaying temporary, non-intrusive dialogs (or "peek dialogs") in your iOS apps. It supports automatic dismissal after a specified delay or manual dismissal via a drag gesture. Perfect for showing notifications, alerts, or other transient messages.
- ⏳ Customizable Duration: Choose from predefined durations (short, medium, long) or specify a custom duration.
- 👆 Drag-to-Dismiss: Users can swipe the dialog away to dismiss it.
- 🖌️ Flexible Content: Use any SwiftUI view as the dialog's content.
You can install the PeekDialog via Swift Package Manager.
- In Xcode, add the PeekDialog by navigating to File > Add Package Dependencies
- And enter the GitHub link:
https://github.com/cembaykara/PeekDialog.git
Add PeekDialog to your Package.swift
:
dependencies: [
.package(url: "https://github.com/cembaykara/PeekDialog.git", from: "1.0.0")
]
You can present a dialog just like you would do with .sheet(isPresented: )
import SwiftUI
import PeekDialog
struct ContentView: View {
@State private var showDialog = false
var body: some View {
VStack {
Button("Show Peek Dialog") {
showDialog = true
}
}
.peekDialog(isPresented: $showDialog) {
Text("This is a peek dialog!")
.padding()
.background(Color.white)
.cornerRadius(8)
.shadow(radius: 10)
}
}
}
You can also bind the dialog to an optional item. The dialog will automatically show when the item is non-nil and dismiss when it becomes nil.
struct ContentView: View {
@State private var activeItem: String? = nil
var body: some View {
VStack {
Button("Show Dialog with Item") {
activeItem = "Example Item"
}
}
.peekDialog(with: $activeItem, dismissDelay: .long) {
if let item = activeItem {
Text("Dialog for item: \(item)")
.padding()
.background(Color.white)
.cornerRadius(8)
.shadow(radius: 10)
}
}
}
}
You can define a duration by using PeekDialogDelay.custom(seconds: Double)
.
.peekDialog(with: $activeItem, dismissDelay: .custom(seconds: 1.25)) {
/* ... */
}
Contributions are welcome! If you find a bug or have a feature request, please open an issue. If you'd like to contribute code, fork the repository and submit a pull request.
SwiftyEndpoint is released under the Apache License 2.0.
See the LICENSE file for full details.