title: SwiftUI: How to use withAnimation in a ScrollView?
body: <p>I've been trying to animate a ScrollView using ScrollViewReader and withAnimation.</p>
  <p>I can't figure out why these two animations are not working, either from Button or .onAppear?</p>
  <pre><code>import SwiftUI
  
  struct ScrollView2: View {
      
      @State private var scrollText = false
      
      var body: some View {
          ScrollViewReader { scrollView in
              ScrollView {
                  Button(&quot;Scroll to bottom&quot;) {
                      withAnimation(.linear(duration: 30)) {
                          scrollView.scrollTo(99, anchor: .center)
                      }
                  }
                  
                  ForEach(0..&lt;100) { index in
                      Text(String(index))
                          .id(index)
                  }
                  .onAppear(perform: {
                      withAnimation(.linear(duration: 30)) {
                          scrollView.scrollTo(scrollText ? 99 : 1, anchor: .center)
                      }
                      scrollText.toggle()
                  })
              }
          }
      }
  }
  </code></pre>