imthath
imthath

Reputation: 1678

How to create custom ListStyle in SwiftUI?

I want to make changes to the listItem's background, rowInsets based on multiple conditions. How can I create a struct conforming to the ListStyle protocol?

I tried conforming to it and get the following code blocks. But I've no idea how to proceed from here.


struct CustomListStyle: ListStyle {
    
    static func _makeView<SelectionValue>(value: _GraphValue<_ListValue<CustomListStyle, SelectionValue>>, inputs: _ViewInputs) -> _ViewOutputs where SelectionValue : Hashable {
        
    }
    
    static func _makeViewList<SelectionValue>(value: _GraphValue<_ListValue<CustomListStyle, SelectionValue>>, inputs: _ViewListInputs) -> _ViewListOutputs where SelectionValue : Hashable {
        
    }
}

Upvotes: 5

Views: 1028

Answers (1)

Lingxi Li
Lingxi Li

Reputation: 71

I was also facing this issue in these days. After some investigation, I eventually realized that SwiftUI does not really "allow" us to customize the list style by overriding the ListStyle protocol. And I found out that there is no any documentation related to this.

However, it is actually possible (not perfect, but doable) to customize it by using Introspect. Check here for more information: https://github.com/siteline/SwiftUI-Introspect#list

Upvotes: 1

Related Questions