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?
Post
Replies
Boosts
Views
Activity
Example code:
struct ContentView: View {
@State var isSelected = false
var body: some View {
VStack {
Button("Button1") {
}
Button(action: {
}, label: {
Image(systemName: "checkmark.square")
})
.accessibilityRepresentation {
Toggle("", isOn: $isSelected)
}
Button("Button3") {
}
}
.padding()
}
}
There are three buttons in the view, the middle button I want to custom Toggle and using accessibilityRepresentation replace accessibility elements.
But using keyboard navigation (System settings -> Keyboard -> Keyboard navigation) VocieOver can't read the middle button. (VoiceOver key can read it)
If not use accessibilityRepresentation, the keyboard navigation works
How to make keyboard navigation read the accessibilityRepresentation elements?