Add a SwiftUI modifier similar to Alert/Sheet for a more Swifty presentation
It's a bit confusing to me that you don't give SwiftUI views to the function. Maybe implement something like this (similar to Alert and Sheet):
@State private var presentNotification = false
var body: some View {
Button("Tap me!") {
presentNotification = true
}
.notification(color:dismissable:spinner:progressBar:…) {
HStack {
Text("Hello!")
Text("Swipe up to dismiss")
.font(.subheadline)
}
}
}
Or:
var notification: Notification {
Text("Hello!")
}
var body: some View {
Button("Tap me!") {
notification.present(duration: 5.0)
}
}
Maybe it's just me but I would prefer one of these solutions.
Or this (functionally equal to the previous):
var body: some View {
Button("Tap me!") {
Notification(color:spinner:progressBar:...) {
Text("Hello")
}.present(duration:)
}
}
Oh, excuse me, I didn't see NotificationPresenter.presentSwiftView(styleName:viewBuilder:completion:).
Yep that allows you to present SwiftUI views. I thought about adding the Alert pattern also. I renamed the issue accordingly.
The above commit adds this functionalty. You can now present like so:
.notification(isPresented: $shouldPresent) {
Text("✨ So simple!")
}
and/or:
.notification(isPresented: $shouldPresent, style: {
$0.xx = xx
}) {
Text("✨ So simple!")
}