snetz
(Snetz)
1
Hi there,
In the following example I expect the red circle to slide in on insertion. But it doesn't. It just instantaneously appears on screen. Removal of the circle slides it out though. If i uncomment the .animation(.default), insertion works as expected. Tested with Xcode 12.3 beta (12C5020f). Is this a bug?
import SwiftUI
struct ContentView: View {
@State var flag = false
var body: some View {
VStack(spacing: 0) {
Circle().fill(Color.orange)
if flag {
Circle()
.fill(Color.red)
.transition(.slide)
// .animation(.default)
}
}
.background(Color.black.ignoresSafeArea())
.onTapGesture {
withAnimation {
flag.toggle()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Update: The example code works as expected on physical devices (tested on iOS 14.3 beta and iOS 14.2). Seems to be a bug in Xcode previews only.
1 Like
Thanks for the update explanation. This helped to save time even in 2023.