Fix menu not working properly
This commit is contained in:
parent
8391997848
commit
3c2cc8cb48
@ -11,7 +11,7 @@ import AppKit
|
||||
public struct MenuWrapper: MacWidget {
|
||||
|
||||
/// Whether the menu is visible.
|
||||
var present: Signal
|
||||
@Binding var present: Signal
|
||||
/// The content.
|
||||
var content: Body
|
||||
/// The menu.
|
||||
@ -22,8 +22,8 @@ public struct MenuWrapper: MacWidget {
|
||||
/// - content: The view content.
|
||||
/// - present: The signal for presenting the menu.
|
||||
/// - menu: The menu.
|
||||
public init(@ViewBuilder content: () -> Body, present: Signal, @ViewBuilder menu: () -> Body) {
|
||||
self.present = present
|
||||
public init(@ViewBuilder content: () -> Body, present: Binding<Signal>, @ViewBuilder menu: () -> Body) {
|
||||
self._present = present
|
||||
self.content = content()
|
||||
self.menu = menu()
|
||||
}
|
||||
@ -69,6 +69,9 @@ public struct MenuWrapper: MacWidget {
|
||||
let menu = storage.fields["menu"] as? NSMenu,
|
||||
let content = storage.content[.mainContent]?.first?.pointer as? NSView,
|
||||
let currentEvent = NSApp.currentEvent {
|
||||
StateManager.blockUpdates = true
|
||||
present.signal()
|
||||
StateManager.blockUpdates = false
|
||||
NSMenu.popUpContextMenu(menu, with: currentEvent, for: content)
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ extension AnyView {
|
||||
/// - isPresented: Whether the menu is currently visible.
|
||||
/// - menu: The menu.
|
||||
/// - Returns: The view.
|
||||
public func menu(present: Signal, @ViewBuilder menu: @escaping () -> Body) -> AnyView {
|
||||
public func menu(present: Binding<Signal>, @ViewBuilder menu: @escaping () -> Body) -> AnyView {
|
||||
MenuWrapper(content: { self }, present: present, menu: menu)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user