Animating popover size changes

According to the HIG, changes in popover size should be animated:

Animate changes in size to avoid giving the impression that a new popover replaced the old one.

How can this be done in SwiftUI? No matter where I put .animate() annotations, I can't get the actual popover frame to transition smoothly. Best I can get is that the popover frame changes immediately, and then the controls awkwardly animate over to the right location.
Post not yet marked as solved Up vote post of fractal Down vote post of fractal
1.2k views
  • Did you ever find an answer? I have the same question. I have a popover that changes width and height and I'd like them to animate.

  • Same issue here, ever found anything?

Add a Comment

Replies

Can you show some code to reproduce your issue?
Sorry, here is an example. Paste this into a new macOS swiftUI project and do a live preview to see what I mean.

Code Block swift
import SwiftUI
struct ContentView: View {
    @State var isPopped = false
    var body: some View {
        Button("Popover") {
            isPopped = true
        }
        .popover(isPresented: $isPopped, content: {
            MyPopover()
        })
        .padding()
    }
}
struct MyPopover: View {
    @State var moreControls = false
    var body: some View {
        Form {
            Text("Text")
            Button("Toggle") {
                withAnimation {
                    moreControls.toggle()
                }
            }
            if moreControls {
                Text("More Controls")
            }
        }
        .padding()
    }
}