When a NSViewRepresentable
is embedded in a SwiftUI ScrollView
AND the "show scroll bar" system setting is set to "When scrolling", it is impossible to drag or click the scrollbar.
I am trying to solve this for a while now, but I am running out of ideas. The only thing that worked is to use an AppKit NSScrollView
and embed the SwiftUI views in that. But that opens up another can of worms.
- Has anyone seen this before?
- Any ideas how to fix this? Seems like a bug to me. But I wonder if anyone can think of a valid workaround?
Please check my minimal example: https://github.com/paxos/NSViewRepresentableScrollBug
I've encountered this too. It does seem to be a bug.
My workaround is to set an overlay with a very low (but non-zero) opacity on the NSViewRepresentable. Apparently this prevents mouse input from falling through the scrollbars, but still allows the expected interactions while being visually imperceptible. For example:
This isn't perfect - in my case, I have a crosshair cursor set on the underlying NSView. It remains a crosshair instead of a pointer while using the scrollbars, but at least it grabs and moves them just fine.