title: SwiftUI .onAppear withAnimation speeds up each time the view appears. Why?
body: <p>I have on-going animations in my app that are triggered on <code>onAppear</code> and configured using <code>withAnimation</code>, updating a <code>@State</code> property.</p>
  <p>Each time the view appears, the animation runs a little faster than before, so if the view is displayed, then covered by a modal display or hidden in navigation and later reappears, the animation starts to go really, really fast – maybe 10 or 20 times faster than it should.</p>
  <p>Here's the code...</p>
  <pre><code>struct HueRotationAnimation: ViewModifier {
      @State var hueRotationValue: Double
      func body(content: Content) -&gt; some View {
          content
              .hueRotation(Angle(degrees: hueRotationValue))
              .onAppear() {
                  DispatchQueue.main.async {
                      withAnimation(.linear(duration: 20).repeatForever(autoreverses: false)) {
                          hueRotationValue += 360
                      }
                  }
              }
      }
  }
  
  struct GradientCircle: View {
      var gradient: Gradient
      @State var hueRotationValue: Double = Double.random(in: 0..&lt;360)
      
      var body: some View {
          GeometryReader { geometry in
              Circle()
                  .fill(
                      radialGradient(geometry: geometry, gradient: gradient)
                  )
                  .modifier(HueRotationAnimation(hueRotationValue: hueRotationValue))
          }
      }
  }
  
  func radialGradient(geometry: GeometryProxy, gradient: Gradient) -&gt; RadialGradient {
      RadialGradient(gradient: gradient,
                     center: .init(x: 0.82, y: 0.85),
                     startRadius: 0.0,
                     endRadius: max(geometry.size.width, geometry.size.height) * 0.8)
  }
  </code></pre>
  <p>Any idea what's causing that speed up each time the view re-appears? Any suggestions to solve this problem?</p>
  <p>(Note: this is running Xcode 13.0 beta 4)</p>