In the following code, click/touch anywhere on any row of the list deletes that row. This is not expected. Only the click/touch on the "xmark" button should delete that row.
import SwiftUI
struct MainView: View {
private let arr: [String] = ["one", "two", "three"]
var body: some View {
List(arr, id: \.self) {item in
SecView(name: item)
}
}
}
struct SecView: View {
var name: String
@State private var show = true
var body: some View {
if show {
HStack {
Text(name)
Button(action: {
show = false
}, label: {
Image(systemName: "xmark")
})
.border(.yellow)
}
}
}
}
@main
struct XApp: App {
var body: some Scene {
WindowGroup {
MainView()
}
}
}
Please check. I ran the above code for iPAD air (5th generation).