2

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

JohnSF
  • 3,736
  • 3
  • 36
  • 72

0 Answers0