I’m in Chapter 20 and trying to follow the logic using a very simple example. Here’s the code:
struct ContentView: View {
@State var change = false
var body: some View {
Rectangle()
.foregroundColor(change ? .red : .green)
.frame(maxWidth: .infinity)
.transition(.slide)
.onTapGesture {
withAnimation {
change.toggle()
}
}
}
What I expect to see is, when tapping the screen, the green and the red rectangles replacing each other with a sliding transition. Instead, there is a fade-in/fade-out animation, both on the simulator and the device. Why?