Reputation: 146
So I have the following ContentView
shows as a popover in the menu bar.
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Create the SwiftUI view that provides the window contents.
let contentView = ContentView()
// Create the popover
let popover = NSPopover()
popover.contentSize = NSSize(width: 500, height: 700)
popover.behavior = .transient
popover.contentViewController = NSHostingController(rootView: contentView)
self.popover = popover
// Create the status item
self.statusBarItem = NSStatusBar.system.statusItem(withLength: CGFloat(NSStatusItem.variableLength))
if let button = self.statusBarItem.button {
button.image = NSImage(named:NSImage.Name("Icon"))
button.action = #selector(togglePopover(_:))
}
(NSApp.delegate as! AppDelegate).statusBarItem.button?.image = NSImage(named:NSImage.Name("Icon"))
NSApp.activate(ignoringOtherApps: true)
}
@objc func togglePopover(_ sender: AnyObject?) {
if let button = self.statusBarItem.button {
if self.popover.isShown {
self.popover.performClose(sender)
} else {
self.popover.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)
}
self.popover.contentViewController?.view.window?.becomeKey()
}
self.popover.contentViewController?.view.window?.becomeKey()
}
And my content view has a .searchable()
tag. I see it when loading it under normal window but not when loading it under a popover. Does anyone know how can I adapt the searchable to the pop over?
Upvotes: 0
Views: 55