How to link the forEach index and photos index in the new view? Trying to open a new view by button. This new View has a carouselList, which is created by this structure. When opening the view by NavigationLink, all photos in carouselList are displayed correctly, depending on the index, but it doesn't work with button, the first index is always opened.
struct Catalog: View {
@State private var isOpen = false
var shop: Shop = shops[0]
var picture: Picture = pictures[0]
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
VStack(spacing: 0) {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(0..<shops.count, id: \.self) { index in
Button(action: {
self.isOpen.toggle()
}) {
ShopItem(shop: shops[index])
} .sheet(isPresented: $isOpen) {
PictureItem(picture: pictures[index])
}
}
}
.padding(.top, 10)
}
}
}