NSViewRepresentable, NSScrollView and missing mouse events

Because the SwiftUI native Scrollview is so lacking (you can't scroll it to precise coordinates and no zoom), against my better judgement I ported it to AppKit by going the NSViewRepresentable route. (I also did this on iOS and have no problems there).

Long story short: everything works. If I put a SwiftUI button in the scrollview I can click on it. Ditto sliders.

But when you try click on a toggle switch, nothing.
And all gesture manipulation fails.

Clearly, certain mouse events (but not all) are failing to be detected/routed to SwiftUI. But there's no rhyme or reason. Why does an embedded button work but not a toggle? Why not gestures?

I've tried every forwarding mechnaism in my AppKit code to route detected mouse events back to the NSHostingView view that is SwiftUI, but nothing helps.

Anybody got a brilliant idea?

Still not sure how to solve it, but I was barking up the wrong tree. It's not event forwarding directly, rather, it's the coordinate system: if I simply scroll (i.e. offset) it works properly, but as soon as I change the zoom (magnification) gesture recognizers, and certain elements, like toggle switches, break.


Hey @davidbaraff, I see this is a bit old topic, but have you found a solution? I'm having the same problem and thinking of somehow converting coordinates, but not sure if that is possible/sufficient.


Terms of Service

Privacy Policy

Cookie Policy