0

I am using a package that hides the list view separator for iOS 14. https://github.com/SchmidtyApps/SwiftUIListSeparator

Whenever I add another view on top of the List, like a simple Divider(), the list row separator will appear again for no reason.

var body: some View {
    
    VStack{
        
        Divider() //if I remove this divider, everything works fine
        
        List{
            ForEach(1...3, id: \.self){_ in
                
                Text("item")
                
            } .listSeparatorStyle(.none) ///the method to hide the row separator
            
        }
    }
}

You can try on your preview by yourself. I have tried multiple way to hide the separator but just this one worked for me, so please do not duplicate it.

Why whenever I add another view, the separator line appear again?

Also, how I can add the if #available(iOS 15, *)?

   var body: some View {
    
    VStack{
        Divider()
        
        List{
            ForEach(1...3, id: \.self){_ in
                
                Text("fdasf")
                
            }
            
            if #available(iOS 15, *) {
                .listRowSeparator(.hidden)
            }
            else{
                .listSeparatorStyle(.none)
            }
            
        }
    }
}
dhaval123
  • 107
  • 11
  • use `.listRowSeparator(.hidden)` instead of listSeparatorStyle() – YodagamaHeshan Feb 20 '23 at 09:41
  • I am trying to use if #available(iOS 15, *) but it gives me an error. How do you use the if #available(iOS 15, *) {.listRowSeparator(.hidden)} ? – dhaval123 Feb 20 '23 at 11:25
  • Use ` .listRowSeparator(.hidden)` which is available in #available(iOS 15.0, *). Its fixed issues at me end in SwiftUI\ – Kudos Feb 20 '23 at 11:31
  • How I can use that on my code? I tried and it does not work for me.. how do you use the #available(iOS 15.0, *) – dhaval123 Feb 20 '23 at 11:40

1 Answers1

0

Per @Yodagama's comment, use .listRowSeparator(.hidden)

To use different modifiers for OS versions, pull your List out into a function (or its own View), and then apply the relevant modifier…

struct ContentView: View {
    
    var body: some View {
        if #available(iOS 15, *) {
            list()
                .listRowSeparator(.hidden)
        } else{
            list()
                .listRowSeparator(.hidden)
        }
    }
    
    func list() -> some View {
        List {
            ForEach(1...3, id: \.self){_ in
                Text("fdasf")
            }
        }
    }
}
Ashley Mills
  • 50,474
  • 16
  • 129
  • 160