How to customise or remove separators from List in SwiftUI

I have a List in my SwiftUI view in order to present a presumably long list of cells. My designers want table separators to have custom length and colour.

Previously I’ve had a dirty hack to hide default separators completely (modified UITableView.appearance() separator-related values) which does not seem to work on iOS 14.

I’ve thought of using .listStyle(...) with custom ListStyle but the protocol stubs for this protocol look really scary. Is there some normal way to modify separators in List? Or is the preferable way on iOS 14 for this kind of layout would be one-column LazyVGrid inside a ScrollView?

Replies

Found a radar about this: http://www.openradar.me/FB7802824
Posted one in Feedback Assistant: FB7808596
Meanwhile here's all you need to trick SwiftUI into removing separators from List (at least as of Xcode 12 beta 1 and iOS 14.0 beta 1) 👌

Code Block Swift
extension List {
    @ViewBuilder func noSeparators() -> some View {
        #if swift(>=5.3) // Xcode 12
        if #available(iOS 14.0, *) { // iOS 14
            self
            .accentColor(Color.secondary)
            .listStyle(SidebarListStyle())
            .onAppear {
                UITableView.appearance().backgroundColor = UIColor.systemBackground
            }
        } else { // iOS 13
            self
.listStyle(PlainListStyle())
            .onAppear {
                UITableView.appearance().separatorStyle = .none
            }
        }
        #else // Xcode 11.5
        self
.listStyle(PlainListStyle())
        .onAppear {
            UITableView.appearance().separatorStyle = .none
        }
        #endif
    }
}

Any suggestions how to do this for macOS?