title: Animate NSWindow's size change based on SwiftUI changes
body: <p>By default, an <code>NSWindow</code> that hosts a SwiftUI view will automatically resize to fit the size of the view if/when it changes. However, if the changes are animated, the window jumps to the final size without animating. Is there a way to animate the window size along with the content?</p>
  <p>I've tried this with and without SwiftUI's lifecycle. I'v also tried calling the <code>toggle</code> method with <code>NSAnimationContext.runAnimationGroup</code></p>
  <p><a href="https://i.stack.imgur.com/Qw7jr.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qw7jr.gif" alt="Gif showing SwiftUI view animating but window jumping to final position without animating" /></a></p>
  <pre class="lang-swift prettyprint-override"><code>struct ContentView: View {
      @State var isExpanded = false
      
      var body: some View {
          VStack {
              Button(isExpanded ? &quot;Close&quot; : &quot;Open&quot;, action: toggleExpand)
              
              if isExpanded {
                  ForEach(0..&lt;5) { count in
                      Text(&quot;\(count). Some Item&quot;)
                  }
              }
          }
          .padding()
          .fixedSize()
      }
      
      func toggleExpand() {
          withAnimation(.easeInOut(duration: 1)) { isExpanded.toggle() }
      }
  }
  </code></pre>