Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI macOS List Row removing padding

I am trying to display a row inside my ListView in SwiftUI for MacOS. However, my issue is that the row contains padding around it. I would like to stretch it to the boundaries of my ListView.

Apple uses .listRowInsets(EdgeInsets()) in their example. However, that is only shown on iOS. For me, it is not working on macOS.

My row got a red border to visualize the issue. I want it to be stretched all the way to the boundaries of the List Row, so fill the whole blue row. Is that possible in macOS?

Thanks in advance.

preview

like image 388
lvollmer Avatar asked Mar 17 '20 14:03

lvollmer


Video Answer


1 Answers

For now I've found only workaround (.listRowInsets should really do this work, so worth submitting feedback to Apple):

demo

struct TestListRow: View {
    var body: some View {
        List {
            ForEach (0..<3) { i in
                HStack {
                    Text("Test row \(i)").font(.largeTitle)
                    Spacer()
                }
            }
            .listRowBackground(Color.green)
            .border(Color.red)
            .padding(.horizontal, -8)   // << workaround !!
        }.environment(\.defaultMinListRowHeight, 40)
        .border(Color.yellow)
    }
}
like image 195
Asperi Avatar answered Oct 07 '22 13:10

Asperi