0

I have a scrollview which does not contain a list of items with ID's:


ScrollView {

    Text(...)

    TextField(...)

    MyView()

    ...

    Button(...)

}

How can I scroll this programmatically to the bottom?

I have found several examples of how to scroll a scrollview programmatically, but all of them involve using a ScrollViewReader to scroll to an ID, for example in the answers to this question

How can I achieve this if no id is defined?

sak
  • 2,612
  • 24
  • 55
  • 1
    I don't understand that restriction, `id` is not only for List, you can add `id` to the latest view in scroll view and jump to it when needed. – Asperi Apr 20 '22 at 11:52
  • But like for instance in the example I gave, what will be the ID of the last button? I don't understand where the id of a view comes from if it's not coming from a list/ForEach block – sak Apr 20 '22 at 11:53
  • 1
    Anything, like `Button(...).id("end")` and then `scrollView.scrollTo("end", anchor: .bottom)`. It can be done even having only one view inside, like in https://stackoverflow.com/a/69955679/12299030. – Asperi Apr 20 '22 at 11:56
  • 1
    You can also add and empty view with 0 size frame at the end of scroll view with a specific id. – Ptit Xav Apr 20 '22 at 13:53

0 Answers0