I have a bunch of Text views that i get through ForEach. Now, I need to each of them to be hidden (like spoiler text) and only show when i tap. For this, i wrapped the text in a ZStack with a rounded rectangle. I have set a @State var showText = false that i toggle inside the onTapGesture modifier of the rounded rectangle. I set the opacity on the basis of showText to hide and show the text.
Now the problem is, since i have multiple text views through ForEach and only one showText, all of the text views hide and show together when i tap one of them. What can i do to fix that?
Here's the code
ZStack(alignment: .leading) {
if rev.spoiler {
RoundedRectangle(cornerRadius: 3)
.foregroundColor(showSpoiler ? .gray : .black)
.opacity(showSpoiler ? 0.3 : 1.0)
.onTapGesture{
showSpoiler.toggle()
}
.animation(.easeInOut)
}
Text(rev.review ?? "No review.")
.padding(.top, 2)
}```