简体   繁体   中英

SwiftUI ScrollView inside List disappears when scrolling

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

录屏

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM