Search code examples
iosswiftiphoneswiftuiios16

Nested ScrollView in a List + refreshable strange behaviour in iOS 16


In my SwiftUI app I've a List with nested ScrollView, since I've updated my iPhone to iOS 16 the refresh on the main List has a strange behavior. It seems that every ScrollView has their own refresh. The issue is that I've applied the .refreshable modifier on the main list, not on the nested ones.

Before iOS 16 the problem did not exist. So, is a bug or we can fix it is some way?

Here is the code and a short video:

List {
    VStack(alignment: .leading) {
        Text("Line 1")
            .font(.title)
        
        ScrollView(.horizontal, showsIndicators: false) {
            LazyHStack(spacing: 20) {
                Text("Item 1")
                Text("Item 2")
                Text("Item 3")
                Text("Item 4")
                Text("Item 5")
                Text("Item 6")
                Text("Item 7")
                Text("Item 8")
                Text("Item 9")
                Text("Item 10")
            }
            .frame(height: 180)
        }
    }
    .listRowSeparator(.hidden)
    
    VStack(alignment: .leading) {
        Text("Line 2")
            .font(.title)
        
        ScrollView(.horizontal, showsIndicators: false) {
            LazyHStack(spacing: 20) {
                Text("Item 1")
                Text("Item 2")
                Text("Item 3")
                Text("Item 4")
                Text("Item 5")
                Text("Item 6")
                Text("Item 7")
                Text("Item 8")
                Text("Item 9")
                Text("Item 10")
            }
            .frame(height: 180)
        }
    }
    .listRowSeparator(.hidden)
}
.listStyle(.plain)
.refreshable {
    print("refresh!")
}

Video of the issue


Solution

  • If you change your List for a ScrollView, and then change the line .listStyle(.plain) for .padding(.horizontal), it will work the same with no bug.