SwiftUI: adding a View at the top of a dynamic List causes the View to shrink

后端 未结 1 1967
既然无缘
既然无缘 2021-01-23 05:44

I have a simple SwiftUI list that displays numbers asynchronously from a Combine publisher, when I add a View at the top of the list to ac

相关标签:
1条回答
  • 2021-01-23 06:24

    The fix is to use explicit list rows inset, something like as below...

    List {
        VStack {
            Rectangle()
            Text("Some Text")
            Text("Some Other Very Long Text Some Other Some Other Long Text")
        }
        .background(Color.red)
        .listRowInsets(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10)
    
        ForEach(viewModel.items, id: \.self) {  item in
            Text("\(item)")
        }
        .listRowInsets(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10)
    }
    
    0 讨论(0)
提交回复
热议问题