I run into the same problem and it looks like you can not achive this with list or section.
When you put cornerRadius modifier onto a section or list it is just applied to whatever the internals are making cells rounded while section itself being unchanged.
My solution was to avoid lists and sections entirely and build custom ones.
Something like
SectionView: View {
body: some View = {
VStack {
ForEach {
CellView()
}
}
.background(Color.white)
.cornerRadius(10)
.padding()
}
}
And put those sections over a Color
view in some ZStack
to have a gray background.
Take in account that the huge downside is that a ForEach
will render all the cells right away, like if you have a thousand of cells then onAppear()
will be called for each cell and strangely enough they will be called in backward order.
Hope it helps.