SwiftUI ForEach Text padding adds additional spacing below the elements

Viewed 546

Adding a padding to the Text(name) element results in some additional spacing below the each name (John-spacing-Chris-spacing-Mary-spacing-Thomas) while iterating using ForEach. Is this a bug in SwiftUI ? How to remove this spacing ?

import SwiftUI

struct ContentView: View {
    
    var names = ["John", "Chris", "Mary", "Thomas"]
    
    var body: some View {
        ForEach(names, id: \.self) { (name) in
            ///adds weird padding between the entries
            Text(name).padding(16).background(Color.green)
        }
        ForEach(names, id: \.self) { (name) in
            ///this is fine
            Text(name).padding(0).background(Color.yellow)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

enter image description here

0 Answers
Related