ScrollViewReader scrollTo ignores withAnimation-Duration

I tried animating the scrollTo() like so, as described in the docs.

Code Block swift
withAnimation {
scrollProxy.scrollTo(index, anchor: .center)
}


the result is the same as if I do

Code Block swift
withAnimation(Animation.easeIn(duration: 20)) {
    scrollProxy.scrollTo(progress.currentIndex, anchor: .center)
}


I tried this using the example from the ScrollViewReader docs.
With the result that up and down scrolling has exactly the same animation.

Code Block
struct ScrollingView: View {
    @Namespace var topID
    @Namespace var bottomID
    var body: some View {
        ScrollViewReader { proxy in
            ScrollView {
                Button("Scroll to Bottom") {
                    withAnimation {
                        proxy.scrollTo(bottomID)
                    }
                }
                .id(topID)
                VStack(spacing: 0) {
                    ForEach(0..<100) { i in
                        color(fraction: Double(i) / 100)
                            .frame(height: 32)
                    }
                }
                Button("Top") {
                    withAnimation(Animation.linear(duration: 20)) {
                        proxy.scrollTo(topID)
                    }
                }
                .id(bottomID)
            }
        }
    }
    func color(fraction: Double) -> Color {
        Color(red: fraction, green: 1 - fraction, blue: 0.5)
    }
}
struct ScrollingView_Previews: PreviewProvider {
    static var previews: some View {
        ScrollingView()
    }
}


Post not yet marked as solved Up vote post of Bersaelor Down vote post of Bersaelor
2.8k views

Replies

i have the same issue, the duration did not work

I have the same issue too.... Please help.

I have same issue as well!

Same issue, couldn’t find a solution on macOS - scrolling has no animation when using scrollTo

Same issue

I also have the same issue, the duration did not work in iOS 15.7.8 - iPhone 7