Issue #768
Use custom NSWindow
, set level
in becomeKey
and call NSApp.runModal
to show modal
final class ModalWindow: NSWindow {
override func becomeKey() {
super.becomeKey()
level = .statusBar
}
override func close() {
super.close()
NSApp.stopModal()
}
}
let window = ModalWindow(
contentRect: .zero,
styleMask: [.titled, .closable],
backing: .buffered,
defer: false
)
window.titlebarAppearsTransparent = true
window.title = "Manage collections"
window.center()
window.isReleasedWhenClosed = false
self.window = window
let view = CollectionSettingsView(store: Store.shared)
.padding()
.frame(
width: Constants.settingsViewWidth,
height: 350,
alignment: .topLeading
)
let hosting = NSHostingView(rootView: view)
window.contentView = hosting
hosting.autoresizingMask = [.width, .height]
NSApp.runModal(for: window)
Another way is to use NSPanel
let panel = NSPanel(contentViewController: NSHostingController(rootView: view))
panel.makeKeyAndOrderFront(nil)