I have a ScrollView with a LazyVStack with Sections. I initialize the ScrollView with a scroll position but the ScrollView starts with the first row at the top.
Am I doing something wrong or is this just a bug in ScrollView?
It seems to work fine if I do not use Section.
struct ContentView: View {
@State var scrollPosition: ScrollPosition
init() {
var p = ScrollPosition(idType: Int.self)
p.scrollTo(id: 500, anchor: .top)
scrollPosition = p
}
var body: some View {
ScrollView {
LazyVStack {
ForEach(0..<sectionCount, id: \.self) { j in
Section {
ForEach(0..<rowCount, id: \.self) { i in
RowView(text: "\(j)/\(i) [\(j*rowCount+i)]")
.id(j*rowCount+i)
}
} header: {
HeaderView(title: "\(j)")
}
}
}
.scrollTargetLayout()
}
.scrollPosition($scrollPosition)
}
}