I have a bunch of cells in a vertical scroll view, but am seeing some weird behavior from the onTapGesture and fullScreenCover for those cells. When I click on a cell, it registers the correct cell in onTapGesture but presents the wrong object, in the fullScreenCover it looks like it's being executed many times, and presenting the wrong object. Not sure why this is happening, anyone have any insight on what the issue could be?
Here are the print statements from clicking 1 cell:
TAP HERE: 1935
FULL SCREEN: 1942
FULL SCREEN: 1940
FULL SCREEN: 1935
FULL SCREEN: 1934
struct TakesList: View {
@ObservedObject var viewModel: TakesListViewModel
@State private var isPresented = false
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
LazyVStack {
ForEach(viewModel.takes, id: \.self) { take in
ListTakeCell(presenter: TakeCellViewModel(take: take))
.padding(.horizontal, 10)
.padding(.vertical, 6)
.onTapGesture {
let _ = print("TAP HERE: \(take.id)")
UIImpactFeedbackGenerator(style: .light).impactOccurred()
isPresented = true
}
.fullScreenCover(isPresented: $isPresented, onDismiss: nil, content: {
let _ = print("FULL SCREEN: \(take.id)")
SingleTakeView(take: take)
.edgesIgnoringSafeArea(.bottom)
})
}
}
}
}
}
Maybe you can try this:
Added the
selectedTakeproperty. This is kind of a workaround for not being able to usefullScreenCover(item. When the cell is tapped, you set theselectedTakeproperty with thetakethat was tapped. Then adidSetgets triggered which checks to make sureselectedTakeisn'tnil. If it isn't, then it setsisPresentedtotrue. ThefullScreenCover(isPresentedmodifier is moved out of the list onto theLazyVStackwhich still gets triggered ifisPresentedbecomestrue. I haven't tested this, but it's an idea that could work.Curious if this works for you. Cheers!