JDStatusBarNotification icon indicating copy to clipboard operation
JDStatusBarNotification copied to clipboard

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

Open CleverLemming1337 opened this issue 1 year ago • 3 comments

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 avatar Jul 18 '24 10:07 CleverLemming1337

Or this (functionally equal to the previous):

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

CleverLemming1337 avatar Jul 18 '24 10:07 CleverLemming1337

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

CleverLemming1337 avatar Jul 18 '24 15:07 CleverLemming1337

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

calimarkus avatar Jul 18 '24 20:07 calimarkus

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!")
}

calimarkus avatar Dec 08 '24 17:12 calimarkus