-
-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
B.Cem edited this page Jul 28, 2026
·
1 revision
PeekDialog adds a peekDialog modifier to any view. Bind some state, describe the content, and it handles presentation and dismissal.
There are two ways to drive a single dialog. For a queue of notifications, see Stacking (iOS).
Same idea as .sheet(isPresented:):
struct ContentView: View {
@State private var showDialog = false
var body: some View {
Button("Show") { showDialog = true }
.peekDialog(isPresented: $showDialog, dismissDelay: .medium) {
HStack {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.green)
Text("Done")
Spacer()
}
.padding()
}
}
}The dialog appears when the optional becomes non-nil, and the value is passed into the content closure:
struct ContentView: View {
@State private var errorMessage: String?
var body: some View {
Button("Fail") { errorMessage = "Network request failed" }
.peekDialog(with: $errorMessage, dismissDelay: .long) { message in
HStack {
Image(systemName: "exclamationmark.triangle.fill")
.foregroundColor(.red)
Text(message)
Spacer()
}
.padding()
}
}
}A dialog goes away when:
- its
dismissDelayelapses → Duration and Placement - the user swipes it away → Swipe to Dismiss
- the binding is cleared (
false/nil)
Optional onDismiss callback:
.peekDialog(with: $errorMessage, onDismiss: {
print("dismissed")
}) { message in
Text(message).padding()
}| Topic | Guide |
|---|---|
| Delays & position | Duration and Placement |
| Lock swipe | Swipe to Dismiss |
| Multiple notifications | Stacking |
| Look & feel | Styling · Custom Styles |
| Silent failures | Common Mistakes |