ScrollViewReader's scrollTo may be broken on iOS 15

ScrollViewReader's scrollTo scrolls too much in iOS 15. I had no problem with iOS 14.

This is the code:

import SwiftUI

struct ContentView: View {
  var body: some View {
    ScrollViewReader { proxy in
      ScrollView {
        VStack {
          Color.yellow
            .frame(height: 800)

          ScrollButton(proxy: proxy)
        }
      }
    }
  }
}

struct ScrollButton: View {
  let proxy: ScrollViewProxy

  @Namespace var bottomId

  var body: some View {
    VStack {
      Button("Scroll") {
        withAnimation {
          proxy.scrollTo(bottomId)
        }
      }
      Color.red
        .frame(height: 500)
        .id(bottomId)
    }
  }
}

struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
    ContentView()
  }
}
Post not yet marked as solved Up vote post of tatstana Down vote post of tatstana
2.2k views
  • I am not sure if this is sort of a bug or not, but you can send a bug report when you find some code once was working does not run in the latest beta.

Add a Comment

Answers

I'm experiencing the same problem. No issues on the iOS14 device, however, scrolls too far on the iOS15 device.

I have the same issue but in horizontal direction

  • here is an example of the same issue but in horizontal direction:

Add a Comment
import SwiftUI



struct ContentView: View {

  var body: some View {
      ScrollViewReader { proxy in
          ScrollView {
              VStack {
                  Color.yellow
                      .frame(height: 900)

                  ScrollButton(proxy: proxy)

                  Color.yellow
                      .frame(height: 900)
              }
              .padding(.horizontal, 40)
          }
      }
  }
}



struct ScrollButton: View {

  let proxy: ScrollViewProxy
  @Namespace var bottomId

    var body: some View {
        VStack {
            Button("Scroll") {
                withAnimation {
                    proxy.scrollTo(bottomId, anchor: .top)                    
                }
            }
        }.id(bottomId)
    }

}



struct ContentView_Previews: PreviewProvider {

  static var previews: some View {
    ContentView()
  }

}

+1

+1

I have the same problem. The code was running perfectly, now it overscrolls. I'll submit a bug report. Hopefully Apple will fix this issue before release.

It seems the issue is related to the .padding(.horizontal, 40) on the VStack within the ScrollView. If that padding is applied instead to the views within the VStack, the issue is resolved (although I definitely still think this is a bug).

+1 on this issue.

The workaround from @brian_bern does work (thank you for this Brian), but can only be used in certain scenarios. For instance, you have to add padding to the enclosed H/VStack when you're trying to prevent the ScrollView from clipping shadows, a spring animation on the scaleEffect when the button isPressed, or anything else that could draw outside the ScrollView (more on ScrollView clipping: https://developer.apple.com/forums/thread/653827).

Does anyone know if there is a place where one can see existing SwiftUI Bug Reports and their status? Or should I just submit my own bug report and follow that? It doesn't look like this was mentioned in the Known Issues of the iOS 15 release notes and I'd love to follow something to confirm if/when Apple acknowledges this as a confirmed issue as well as if/when they plan on a fix.

I sent feedback to Apple by the bug report a month ago, but I haven't received a reply yet. It has also been reproduced in the official release version of iOS 15.

I have the same problem, please let us know if some of you have the answer or solution, cheers

+1

Confirmed this has not been fixed in iOS 15.0.1

+1 as well

In my case, LazyVStack helped to fix the scrollTo issue


struct ContentView: View {
 var body: some View {
  ScrollViewReader { proxy in
   ScrollView {
    VStack {
     Color.yellow
      .frame(height: 800)

     ScrollButton(proxy: proxy)
    }
   }
  }
 }
}

struct ScrollButton: View {
 let proxy: ScrollViewProxy

 @Namespace var bottomId

 var body: some View {
  LazyVStack {
   Button("Scroll") {
    withAnimation {
     proxy.scrollTo(bottomId)
    }
   }
   Color.red
    .frame(height: 500)
    .id(bottomId)
  }
 }
}

struct ContentView_Previews: PreviewProvider {
 static var previews: some View {
  ContentView()
 }
}

+1. We are also having this issue. The above workarounds didn't fix it for us either.