PresentationKit is a SwiftUI library designed to simplify the presentation of alerts and modal content across multiple Apple platforms, including iOS, iPadOS, macOS, tvOS, visionOS, and watchOS. This library provides a straightforward API that helps developers create intuitive user interfaces with minimal effort.
To get started with PresentationKit, you can add it to your project using Swift Package Manager. Open your Xcode project, navigate to the project settings, and add the following URL to your package dependencies:
https://github.com/kalyanijawalekar/PresentationKit
Begin by importing PresentationKit into your SwiftUI view:
import PresentationKit
To present an alert, use the AlertView
provided by the library. Hereโs a simple example:
struct ContentView: View {
@State private var showAlert = false
var body: some View {
Button("Show Alert") {
showAlert = true
}
.alert(isPresented: $showAlert) {
Alert(title: Text("Hello"), message: Text("This is an alert!"), dismissButton: .default(Text("OK")))
}
}
}
For presenting modal content, you can use the FullScreenCover
or Sheet
:
struct ContentView: View {
@State private var showModal = false
var body: some View {
Button("Show Modal") {
showModal = true
}
.fullScreenCover(isPresented: $showModal) {
ModalView()
}
}
}
struct ModalView: View {
var body: some View {
VStack {
Text("This is a full-screen modal!")
Button("Dismiss") {
// Dismiss logic here
}
}
}
}
You can customize alerts by modifying their title, message, and buttons. Hereโs an example of a customized alert:
.alert(isPresented: $showAlert) {
Alert(title: Text("Warning"),
message: Text("Are you sure you want to proceed?"),
primaryButton: .destructive(Text("Delete")) {
// Handle delete action
},
secondaryButton: .cancel())
}
For modals, you can control the presentation style and animations. You can also pass data to the modal view:
.fullScreenCover(isPresented: $showModal) {
ModalView(data: someData)
}
Comprehensive documentation is available in the Wiki. This resource provides detailed information on all features, usage examples, and best practices.
To see PresentationKit in action, check out the example projects in the Examples
folder of this repository. These projects demonstrate various use cases and show how to implement the library effectively.
We welcome contributions to PresentationKit. If you want to help improve the library, please follow these steps:
For larger changes, consider opening an issue first to discuss your ideas.
PresentationKit is released under the MIT License. See the LICENSE file for details.
You can find the latest releases of PresentationKit here. Download the latest version and integrate it into your project.
If you encounter any issues or have questions, please open an issue in the repository. We appreciate your feedback and are here to help.
Thanks to the SwiftUI community for their contributions and support. Your input helps make this library better for everyone.
For further information, visit the Releases section for updates and new features.