LazyVGrid Navigation link not using the correct GridItem

119 views Asked by At

So I'm trying to use the LazyVGrid and I can get it to load my items well. The challenge is that I want the user to be able to click on an item in the grid and go to it's details. But right now, it's randomly picking other items in the grid as the detail item.

`struct CamerasView: View {

@ObservedObject var model: HomeStore
@ObservedObject var theRow: cameraAccessoryClass

var body: some View {
    
    let columns : [GridItem] = Array(repeating: GridItem(), count: 3)
    let homeId : UUID = model.homes.first!.uniqueIdentifier
    
    List {
        Section(header: HStack {
            Text("Cameras")
        }) {
            LazyVGrid(columns: columns, spacing: 40) {
                ForEach(model.cameraAccessories, id: \.id) { myaccessory in CameraRow(theRow: myaccessory)
                }
            }
            
        }.onAppear {
            model.findAccessories(homeId: homeId)
            model.StartVideos()
            print ("Cameras:" + String(model.cameraAccessories.count))
        }
        
    }
    
}

}

struct CameraRow: View { @ObservedObject var theRow : cameraAccessoryClass

var body: some View {
 //   NavigationStack {
        VStack {
            GetNextCameraView()
                .frame(width: 100, height: 100)
            NavigationLink {
                CameraViewDetail(theRow: theRow)
            } label: {
                Text(theRow.accessory.name)
            }
            Spacer()
            Spacer()
        }
    }`
0

There are 0 answers