I experienced rendering problems when using animations inside a NavigationView. The same animations work fine when no NavigationView is present.
See my example code below. There are two previews, one working, the other one not. Unfortunately, this behavior is not limited to previews but also happens when the app runs in simulator or on a real device.
Am I doing something wrong? Any help would be appreciated. Thanks!
import SwiftUI
struct MyView: View {
@State private var isAnimating = false
var body: some View {
let animation = Animation
.linear
.repeatForever(autoreverses: false)
return Image(systemName: "iphone")
.rotationEffect(.degrees(isAnimating ? 360 : 0))
.animation(animation)
.onAppear { isAnimating = true }
}
}
struct MyView_Previews: PreviewProvider {
static var previews: some View {
Group {
MyView()
.previewDisplayName("Working")
NavigationView {
MyView()
}
.previewDisplayName("Not Working")
}
}
}
(Xcode12.5, iOS14.5)
2
3
6.1k