4

In a SwiftUI app with SwiftUI flow for iOS15, I'm trying to slow the animation of the ScrollViewReader scrolling speed. Clearly in the example below, the scrolling does not take 100 seconds. While the animation in this example is visually ok, in the real app I am programmatically calling the scrollTo and it is almost immediate and totally looks jerky. Am I missing something?

Here's an example:

struct ListView: View {

    let colors: [Color] = [.red, .green, .blue]
    @State private var shouldChangeRow: Bool = false
    @State private var number: Int = 100

    var body: some View {
    
        VStack {
            ScrollViewReader { proxy in
                List {
                    ForEach(0..<number) { i in
                        Text("Row \(i)")
                            .font(.title)
                            .frame(minWidth: 0, maxWidth: .infinity)
                            .frame(height: 50)
                            .background(colors[i % colors.count])
                            .id(i)
                    }//for each
                }//list
                .onChange(of: shouldChangeRow) { _ in
                    withAnimation(Animation.easeInOut(duration: 100)) {
                        proxy.scrollTo(Int.random(in: 0..<number), anchor: .top)
                    }
                }//on change
            }//reader
            .frame(height: 500)
        
            Button("Change") {
                withAnimation {
                    shouldChangeRow.toggle()
                }
            }
            .buttonStyle(.borderedProminent)
            .padding()

        }//v
    }
}

Any guidance would be appreciated. Xcode 13.2.1, iOS 15

2
  • 1
    It is known behavior, scroll to uses own internal animation, we have no possibility to affect it now. Commented Jan 9, 2022 at 6:27
  • Bummer. Thanks. Commented Jan 9, 2022 at 20:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.