Move Edge Transition in SwiftUI not executing

I have a simple view with a VStack made of two Rectangles. I have a binding on openView. That binding, a bool, is changed and the body of the view is called and the two Rectangles fade away. They do not transition each in the direction I intend.

What is wrong with this code?


Code Block struct OpeningView: View
{
@Binding var openView: Bool
var body: some View
{
VStack
{
if openView == false
{
Rectangle()
.edgesIgnoringSafeArea(.all)
.foregroundColor(Color.red)
.transition(.move(edge: .top))
Rectangle()
.edgesIgnoringSafeArea(.all)
.foregroundColor(Color.blue)
.padding(.top, -8)
.transition(.move(edge: .bottom))
}
}
}
}


Testing with a simple code, two rectangles move as described with transition.
Code Block
import SwiftUI
struct ContentView: View {
    @State var openView: Bool = false
    var body: some View {
        VStack {
            Button("open") {
                withAnimation {
                    self.openView.toggle()
                }
            }
            Text("Hello, World!")
            MyView(openView: $openView)
        }
    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
struct MyView: View {
    @Binding var openView: Bool
    var body: some View {
        VStack {
            if openView == false {
                Rectangle()
                    .edgesIgnoringSafeArea(.all)
                    .foregroundColor(Color.red)
                    .transition(.move(edge: .top))
                Rectangle()
                    .edgesIgnoringSafeArea(.all)
                    .foregroundColor(Color.blue)
                    .padding(.top, -8)
                    .transition(.move(edge: .bottom))
            }
        }
    }
}


Is the view embedded in some complex view?
Please show enough code to reproduce the issue.
Hi OOPer,

Looking at your code I saw something I didn't have in my code: withAnimation {}

Imagine what happened when I added that bit of code? It worked like magic!

Thank you for your help. Much appreciated.
Move Edge Transition in SwiftUI not executing
 
 
Q