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

1

5

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

Enchiridion answered 2/10, 2020 at 17:1 Comment(0)
E
12

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()
  }
}
Enchiridion answered 11/10, 2020 at 15:0 Comment(2)
Is this documented anywhere? As of 23 Nov 2020 Apple Dev's own SwiftUI tutorial omits this part, making it confusing for newcomersBurnie
Great answer man, I was banging my headExpeller

© 2022 - 2024 — McMap. All rights reserved.