Create a empty AppKit project and replace the ViewController.swift
import Cocoa
import SwiftUI
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let hostingView = NSHostingView(rootView: ButtonView())
view.addSubview(hostingView)
hostingView.frame = NSRect(x: 50, y: 100, width: 100, height: 40)
}
override func viewDidAppear() {
super.viewDidAppear()
view.window?.acceptsMouseMovedEvents = true
}
}
struct ButtonView: View {
@State var isPresented = false
var body: some View {
Button("Click me") {
isPresented = true
}
.popover(isPresented: $isPresented, arrowEdge: .trailing) {
Button("Hello world", action: {
})
.padding()
.onHover { hover in
print(hover)
}
}
}
}
If set the window.acceptsMouseMovedEvents
to true, the onHover of button in popover is broken.
How to resolve it?