How to remove highlight on tap of List with SwiftUI?

前端 未结 6 868
悲哀的现实
悲哀的现实 2020-12-30 01:19

How to remove highlight on tap of List with SwiftUI?

List {

}.whatModifierToAddHere?

The selection manager documentation doesnt say anythi

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-30 01:36

    A possible solution is to use a ZStack. And adjust insets to .zero. Change Color.red to your color. Your List:

    ForEach(items) { item in
        ZStack {
            NavigationLink(destination: DetailView()) {
                EmptyView()
            }
            ItemRowWrap(item: item)
                .background(Color.red)
        }
        
    }
    .listStyle(InsetListStyle())
    .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
    

    Your ItemRowView:

    struct ItemRowWrap: View {
        
        let item: ListItem
        
        var body: some View {
            ItemRow(item: item)
                .padding(EdgeInsets(top: 5, leading: 8, bottom: 5, trailing: 8))
        }
        
    }
    

    You can adjust paddings as you need.

提交回复
热议问题