There is a list in which there are sections and each section contains items, put inside a horizontal scrollview, when trying to navigate to detail page using NavigationLink all the items get selected, I want to select individual item to navigate to detail page. Here is my code. When i tap on the list it opens multiple times. I want the only selected item to be opened
let menu = Bundle.main.decode([ItemSection].self, from: "abc.json")
var body: some View {
List(menu) { sections in
VStack(alignment: .leading){
Text(sections.name)
HStack{
ScrollView(.horizontal, showsIndicators: false) {
Section {
HStack{
ForEach(sections.items){ allItems in
NavigationLink(destination: DetailView()){
ItemsTab(item: allItems)
}
}
}
}
}
}
}
}
}
struct ItemTab: View {
var items: Items
var body: some View {
VStack{
Image("name")
.resizable()
.cornerRadius(3)
.frame(width: 180, height: 180)
Text(items.name)
.foregroundColor( Color(red: 0 / 255, green: 38 / 255, blue: 107 / 255))
.font(.headline)
}
.padding(.top)
.padding(.bottom)
.padding(.leading, 5)
.padding(.trailing,5)
}