2

I've stumbled across what looks like a bug caused by a NavigationView.

For the reproducible code here we have two circles that pulsate . It works fine, until we add the NavigationView ! What is going on? I'm pretty sure this is a bug, but is it well known, any workarounds?

GLIMPSE OF GLITCHING ANIMATION

Pulsating circle that glitches with addition of NavigationBar

REPRODUCIBLE CODE :

  import SwiftUI

struct ContentView: View {
    @State private var animationAmount: CGFloat = 1
    var body: some View {
        NavigationView {
            HStack {
                Circle()
                    .frame(width: 100, height: 100)
                    .overlay (
                        Circle()
                            .stroke()
                            .scaleEffect(animationAmount)
                            .opacity(Double(2 - animationAmount))
                            .animation(
                                Animation.easeInOut(duration: 1).repeatForever(autoreverses: false)
                            )
                        
                        
                    ).onAppear {
                        self.animationAmount = 2
                }
                Circle()
                    .frame(width: 100, height: 100)
                    .overlay (
                        Circle()
                            .stroke()
                            .scaleEffect(animationAmount)
                            .opacity(Double(2 - animationAmount))
                            .animation(
                                Animation.easeInOut(duration: 1).repeatForever(autoreverses: false)
                            ))
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Sergio Bost
  • 2,591
  • 2
  • 11
  • 29
  • 1
    [SwiftUI: Broken explicit animations in NavigationView?](https://stackoverflow.com/questions/64566492/swiftui-broken-explicit-animations-in-navigationview/64566746#64566746) is probably what's happening here. – aheze Apr 04 '21 at 03:05
  • 1
    That worked. Thanks – Sergio Bost Apr 04 '21 at 03:58

0 Answers0