'SwiftUI in NSHostingView — No Animation When Bounds Change
Context
I am using an NSHostingView to include a SwiftUI view in my AppKit-based Mac app. This works fine and the SwiftUI view correctly redraws itself as I live-resize the window.
The Problem
Suppose I toggle the sidebar of my app on/off and NSSplitView animates the opening/closing of the sidebar with the usual sliding effect. All of my native AppKit views in other panes of the splitView slide (animate) gracefully to their new size and position as the sidebar opens or closes.
The NSHostingView, however, does NOT animate. Instead, it immediately redraws itself in the size/location it will occupy when the sidebar animation completes. This is ugly, jerky, and characteristic of a low-quality Mac app.
The Question
How can I force the SwiftUI view inside the NSHosting view to gracefully redraw/animate as native AppKit NSView objects do, instead of snapping to draw its final state right away, before the splitView animation completes?
Note: the hosting view is configured with appropriate constraints, just as native views are.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
