danielsaidi / SystemNotification

SystemNotification is a Swift SDK that helps you mimic the native iOS system notification in SwiftUI.
MIT License
428 stars 14 forks source link

MacOS notification sticking to the top of screen #11

Closed ZhichGaming closed 1 year ago

ZhichGaming commented 1 year ago

In MacOS, the notification shows up stuck to the top, without any spacing from the border when open in another window than the main window. SystemNotificationMessage in the demo project works, but the error one from the bottom sticks to the border too.

image

Potential solutions:

Reproduce this issue:

struct ContentView: View {
    @StateObject var context = SystemNotificationContext()

    var body: some View {
        Button("Open in new window") {
            Button("Hello") {
                context.present { Text("Hello").padding() }
            }
            .padding()
            .systemNotification(context)
            .openNewWindow()
        }
    }
}

extension View {
    private func newWindowInternal(with title: String) -> NSWindow {
        let window = NSWindow(
            contentRect: NSRect(x: 20, y: 20, width: 1000, height: 625),
            styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
            backing: .buffered,
            defer: false)
        window.center()
        window.isReleasedWhenClosed = false
        window.title = title
        window.makeKeyAndOrderFront(nil)
        return window
    }

    func openNewWindow(with title: String = "new Window") {
        self.newWindowInternal(with: title).contentView = NSHostingView(rootView: self)
    }
}
danielsaidi commented 1 year ago

Hi @ZhichGaming

I have fixed this and released it in a new 0.6 release. You can now customize the padding as well.

ZhichGaming commented 1 year ago

Thank you very much!