PresentationKit is a SwiftUI library that makes it easy to present alerts, sheets, full screen covers, and toasts for any model, using an observable Presentation class.
PresentationKit can be installed with the Swift Package Manager:
https://github.com/danielsaidi/PresentationKit.git
PresentationKit supports iOS 17, tvOS 17, macOS 14, watchOS 10, and visionOS 1.
PresentationKit has features for value-based navigation and presentation, and lets you present alerts, covers, popovers, sheets, and toasts in the same way. See the documentation for more information.
The Navigation class can be used to perform value-based navigation.
struct MyView: View {
@State var navigation = Navigation()
var body: some View {
NavigationStack(path: $navigation.path) {
Button("Push view") {
navigation.push("detail")
}
.navigationDestination(for: String.self) { value in
Text(value)
}
}
}
}Types that implement the NavigationDestination protocol can be used to create a NavigationStack for that specific type.
See the Navigation article for more information.
The Presentation class can be used to perform value-based presentation of alerts, modals, sheets, popovers, and toasts.
struct MyView: View {
// In this example, consider there are enums for the various content types.
@State var alert = Presentation<MyAlert>()
@State var cover = Presentation<MyModal>()
@State var popover = Presentation<MyPopover>()
@State var sheet = Presentation<MyModal>()
@State var toast = Presentation<MyToast>()
var body: some View {
Button("Perform presentation") {
alert.present(.someAlert) // or
cover.present(.someModal) // or
popover.present(.somePopover) // or
sheet.present(.someModal) // or
sheet.present(.someToast)
}
.alert(for: $alert) { alert in
// Present an AlertMessage for the alert
}
#if !os(macOS)
.fullScreenCover(for: $cover) { cover in
// Present a view for the full screen cover
}
#endif
.popover(for: $popover) { popover in
// Present a view for the popover
}
.sheet(for: $sheet) { sheet in
// Present a view for the sheet
}
.toast(for: $toast) { toast in
// Present a view for the toast
}
}
}Each modifier supports the same customizations as the native modifiers. For instance, sheets can define a dismiss action, popovers can define an arrow direction, toasts can define an edge, etc.
PresentationKit also adds additional support to each content type. For instance, alerts can be used to automatically alert async errors, a sheets can be resized with animations, etc.
See the Presentation article and the separate content type articles for more information.
The online documentation has more information, articles, code examples, etc.
The Demo folder has a demo app that lets you explore the library.
You can become a sponsor to help me dedicate more time on my various open-source tools. Every contribution, no matter the size, makes a real difference in keeping these tools free and actively developed.
Feel free to reach out if you have questions, or want to contribute in any way:
- Website: danielsaidi.com
- E-mail: daniel.saidi@gmail.com
- Bluesky: @danielsaidi@bsky.social
- Mastodon: @danielsaidi@mastodon.social
PresentationKit is available under the MIT license. See the LICENSE file for more info.
