SwiftUI – Wrap ListStyle in an enum and translate it back to ListStyle

You can return an opaque type (some View) instead:

extension List {
    @ViewBuilder
    func listStyle(for customListStyle: SupportOptions.CustomListStyle) -> some View {
        switch customListStyle {
        case .defaultListStyle:
            listStyle(DefaultListStyle())
        case .plainListStyle:
            listStyle(PlainListStyle())
        case .groupedListStyle:
            listStyle(GroupedListStyle())
        case .insetGroupedListStyle:
            listStyle(InsetGroupedListStyle())
        case .insetListStyle:
            listStyle(InsetListStyle())
        case .sidebarListStyle:
            listStyle(SidebarListStyle())
        }
    }
}
List {
    // ...
}
.listStyle(for: options.listStyle)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top