9

I have list with items. How can i scroll to list 12. I can use geometry reader to calculate offset. But how to scroll to this offset?

List {
      ForEach(0..<12) { index in
          Text("...")          
      }  
}
1

1 Answer 1

6

Form Xcode 12, You can turn in to a ScrollView and then you can do it by .scrollTo(id):

var body: some View {
    ScrollViewReader { scrollProxy in
        ScrollView {
            ForEach((1...100), id: \.self) { Text("\($0)") }
        }
        Button("Go!") {
            withAnimation { scrollProxy.scrollTo(50) }
        }
    }
}

Note that ScrollViewReader should support all scrollable content, but now it only supports ScrollView

Sign up to request clarification or add additional context in comments.

1 Comment

I just tried in XCode 13 on macOS 12 and ScrollViewReader now works with List.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.