calimarkus / JDStatusBarNotification

Highly customizable & feature rich notifications. Interactive dismiss. Custom Views. SwiftUI. Tap-to-hold. Progress. Written in Swift, compatible for ObjC!
http://calimarkus.github.io/JDStatusBarNotification/documentation/jdstatusbarnotification
MIT License
4.19k stars 555 forks source link

Add a SwiftUI modifier similar to Alert/Sheet for a more Swifty presentation #143

Open CleverLemming1337 opened 1 month ago

CleverLemming1337 commented 1 month ago

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.

CleverLemming1337 commented 1 month ago

Or this (functionally equal to the previous):

var body: some View {
    Button("Tap me!") {
        Notification(color:spinner:progressBar:...) {
            Text("Hello")
        }.present(duration:)
    }
}
CleverLemming1337 commented 1 month ago

Oh, excuse me, I didn't see NotificationPresenter.presentSwiftView(styleName:viewBuilder:completion:).

calimarkus commented 1 month ago

Yep that allows you to present SwiftUI views. I thought about adding the Alert pattern also. I renamed the issue accordingly.