SwiftUI List with InsetGroupedListStyle only updates correct row height after scrolling

Viewed 209

I have a list in SwiftUI with InsetGroupedListStyle. Generally it works well but occasionally the text height in a section will not be correct until scrolling. Seems to depend on the length of the text. I have added .fixedSize(horizontal: false, vertical: true) which helps in some cases but not all.

Is there anything else I can do to force the view to layout correctly or is it a bug? It is not working in iOS 15 as well.

The example below shows a url as text but I have seen this in other scenarios with just plain text.

import SwiftUI

struct ContentView: View {
    var body: some View {
        List {
            Section(header: Text("Header Title")) {
                VStack {
                    Spacer()
                        .frame(height: 8)
                    Text("https://example.govt.nz/notice/id/2021-go1593")
                        .fixedSize(horizontal: false, vertical: true)
                }
            }
        }
        .listStyle(InsetGroupedListStyle())
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Initially looks like this:

enter image description here

After Scroll looks like this:

enter image description here

If I remove VStack and spacer the problem still exists although not as noticeable but still there:

List {
    Section(header: Text("Header Title")) {
        Text("https://example.govt.nz/notice/id/2021-go1593")
            .fixedSize(horizontal: false, vertical: true)
    }
}
.listStyle(InsetGroupedListStyle())

This time before scroll:

enter image description here

And after Scroll:

enter image description here

0 Answers
Related