I have a ScrollView which has inside a LazyVStack and multiple rows. On the appearing of the ScrollView, I scroll to row 250. When having the VoiceOver running, after opening the app, the focus is on the navigation title as it should be, than, after swiping right to enter the ScrollView, one would expect the focus to be placed on the first visible row, but this is not the case, it scrolls back to some row and focus on that, than reads it.
Here is the code to reproduce it, and if you ask me, this is pretty standard stuff I don't do anything special.
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
ScrollViewReader { scrollProxy in
ScrollView {
LazyVStack {
ForEach(1...500, id: \.self) { index in
NavigationLink(destination: DetailView(row: index)) {
Text("Row \(index)")
.padding()
.frame(maxWidth: .infinity)
.background(Color.gray.opacity(0.2))
.cornerRadius(8)
.padding(.horizontal)
}
}
}
}
.onAppear {
// Scroll to row 250 when the view appears
withAnimation {
scrollProxy.scrollTo(250, anchor: .center)
}
}
}
.navigationTitle("Rows")
}
}
}
struct DetailView: View {
let row: Int
var body: some View {
VStack {
Text("Detail for Row \(row)")
.font(.largeTitle)
.padding()
Spacer()
}
.navigationTitle("Row \(row) Details")
}
}
@main
struct ScrollViewExampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}