I have created a status bar item that shows a popover view when it is clicked
import SwiftUI
@main
class AppDelegate: NSObject, NSApplicationDelegate {
var popover: NSPopover!
let statusItem = NSStatusBar.system.statusItem(withLength: 125)
@IBOutlet weak var menu: NSMenu!
override internal func awakeFromNib() {
statusItem.button?.action = #selector(togglePopover(_:))
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
let popover = NSPopover()
self.popover = popover
popover.contentViewController = NSHostingController(rootView: NavigatorView() )
}
@objc func togglePopover(_ sender: AnyObject?) {
if let button = statusItem.button {
if self.popover.isShown {
self.popover.performClose(sender) } else {
self.popover.behavior = NSPopover.Behavior.transient
self.popover.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)
} } } }
Within this popover I would like to use a navigation stack:
import SwiftUI
struct NavigatorView: View { var body: some View {
NavigationStack { List {
NavigationLink("Test", destination: EmptyView() )
} } } }
This seems to work.
However, if there is a navigation to a new view, there is no button to return to the original navigation stack.
From all the tutorials I have seen, there should be text in the top left corner that brings me back to the navigation stack. However, I am unsure if I have failed follow the tutorial in the correct manner or whether there is an issue when navigation stacks are used with popovers.
In either case, I would like the Empty View that is clicked from the navigation stack to include some link to go back to the navigation stack like in this example from https://www.swiftyplace.com/blog/better-navigation-in-swiftui-with-navigation-stack.