Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CleverLemming1337 opened this issue Jul 18, 2024 · 3 comments

Comments

@CleverLemming1337
Copy link

CleverLemming1337 commented Jul 18, 2024

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
Copy link
Author

CleverLemming1337 commented Jul 18, 2024

Or this (functionally equal to the previous):

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

@CleverLemming1337
Copy link
Author

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

@calimarkus calimarkus changed the title SwiftUI Code style Consider adding SwiftUI modifier similar to Alert/Sheet Jul 18, 2024
@calimarkus calimarkus changed the title Consider adding SwiftUI modifier similar to Alert/Sheet Add a SwiftUI modifier similar to Alert/Sheet Jul 18, 2024
@calimarkus calimarkus reopened this Jul 18, 2024
@calimarkus
Copy link
Owner

calimarkus commented Jul 18, 2024

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

@calimarkus calimarkus changed the title Add a SwiftUI modifier similar to Alert/Sheet Add a SwiftUI modifier similar to Alert/Sheet for a more Swifty presentation Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants