5

If I put multiple horizontal ScrollViews inside a List they disappear when scrolling. Here is an example:

screenrecording

Here is the code to reproduce the issue:

struct ContentView: View {

    var body: some View {
        List {
            ForEach(0...100, id: \.self) { _ in
                ScrollView(.horizontal) {
                    HStack {
                        Rectangle().frame(width: 100, height: 100)
                        Rectangle().frame(width: 100, height: 100)
                        Rectangle().frame(width: 100, height: 100)
                    }
                }
            }
        }
    }
}

I am using iOS 13.3. Adding frames to the ScrollView or HStack did not help, unfortunately. Does anyone know a way to fix this?

5
  • I recommend to use vertical ScrollView instead of List - no this issue (and other known List-based issue) Commented Dec 22, 2019 at 16:59
  • @Asperi A List is much better for performance if it has many items. Furthermore, I cannot style a ScrollView like a List (GroupedListStyle()). So just using a ScrollView is not a real solution for me. Commented Dec 22, 2019 at 17:11
  • Did you ever manage to fix this? Commented Jan 30, 2020 at 0:26
  • @ryansle no, I did not find a fix yet. Commented Jan 30, 2020 at 20:48
  • @ThomasVos it was this link that ended up fixing the issue for me: stackoverflow.com/questions/59810913/… Commented Jan 30, 2020 at 21:04

1 Answer 1

5

This seems to be a bug related to items reuse. You can try to fix setting the id in Lists and ScrollViews.

List(array, id: \.self) { item in
    Text("\(item)")
}.id(UUID().uuidString)

More about this fix in here and here.

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

1 Comment

In my case just setting id to the scroll view worked perfectly. Thanks for your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.