Embed SwiftUI views inside UIAlertController alerts and action sheets with simple alertContent and confirmationDialogContent modifiers.
- Custom SwiftUI content inside
UIAlertController. - Drop-in modifiers – no need to rework existing alerts or confirmation dialogs.
| Alert content | Confirmation dialog content |
|
|
import SwiftUI
import AlertAdvance
struct ContentView: View {
@State private var showAlert = false
@State private var showSheet = false
var body: some View {
VStack(spacing: 16) {
Button("Show alert") { showAlert = true }
.alert("Title", isPresented: $showAlert) {
Button("OK") {}
}
.alertContent(isPresented: $showAlert) {
VStack {
Text("Custom alert content")
ProgressView()
}
.padding()
}
Button("Show confirmation") { showSheet = true }
.confirmationDialog("Title", isPresented: $showSheet) {
Button("Action") {}
}
.confirmationDialogContent(isPresented: $showSheet) {
VStack {
Text("Custom sheet content")
Image(systemName: "hand.thumbsup.fill")
}
.padding()
}
}
.padding()
}
}Add via Swift Package Manager:
dependencies: [
.package(url: "https://github.com/inekipelov/swiftui-alert-advance.git", from: "0.1.0")
],
targets: [
.target(
name: "YourTarget",
dependencies: [
.product(name: "AlertAdvance", package: "swiftui-alert-advance")
]
)
]
