SwiftUI: Animate resizing of .sheet (macOS)

Viewed 18

Is it possible to animate a size change of a sheet? If I animate a size change of the sheet's contents, the sheet itself will immediately assume the new size without animation. See video (white background of sheet should never be visible):

enter image description here

Code:

struct ContentView: View {
    @State var isPresented = false
    @State var sheetContentHeight = 100.0

    var body: some View {
        VStack {
            Button("Show Sheet") {
                isPresented = true
            }
        }
        .frame(width: 500, height: 300)
        .sheet(isPresented: $isPresented) {
            sheetContent
        }
    }

    var sheetContent: some View {
        ZStack {
            Rectangle()
                .frame(width: 300, height: sheetContentHeight)
                .foregroundColor(Color.gray)
            Button("Change Content Height") {
                sheetContentHeight = 200
            }
        }
        .animation(.easeOut(duration: 1), value: sheetContentHeight)
    }
}
0 Answers
Related