Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix the list strange padding when using navigationbaritems in swiftui since iOS 14? [duplicate]

Since iOS 14 i have a strange behavior where i have a padding around a list in a NavigationView as soon as i add navigationBarItems...

My code :

import SwiftUI

struct TestList: View {
  var body: some View {
    NavigationView{
      List {
        Text("hello world")
        Text("hello world")
        Text("hello world")
      }
      .navigationBarTitle(Text("Test List"), displayMode:.inline)
      .navigationBarItems(leading:
                            Image(systemName: "bell")
      )
    }
  }
}

struct TestList_Previews: PreviewProvider {
  static var previews: some View {
    TestList()
  }
}

How can i fix this?

Thanks

like image 638
Flincorp Avatar asked Oct 02 '20 17:10

Flincorp


1 Answers

Ok i got it...

I need to add a ListStyle to the list :

https://developer.apple.com/documentation/swiftui/liststyle

import SwiftUI

struct TestList: View {
  var body: some View {
    NavigationView{
      List {
        Text("hello world")
        Text("hello world")
        Text("hello world")
      }
      .listStyle(PlainListStyle())
      .navigationBarTitle(Text("Test List"), displayMode:.inline)
      .navigationBarItems(leading:
                            Image(systemName: "bell")
      )
    }
  }
}

struct TestList_Previews: PreviewProvider {
  static var previews: some View {
    TestList()
  }
}
like image 61
Flincorp Avatar answered Oct 06 '22 14:10

Flincorp