Hi all,
I have a bug that I cannot seem to locate. I have extracted from my main app the below minimal reproducible example to illustrate the logic. This code has an expectation that as the user swipes and taps on “Tap to reveal” it will reveal the integer (current index of the ForEach index-based loop) when the isRevealed boolean is false. However, I am running into some unexpected results. It seems when I get to the final ‘card’, it does not show the tap to reveal label and the integer of its preceding card transfers across, which corrects itself when tapped on. To reproduce the problem, please ensure you tap on “Tap to reveal” for every card as you swipe to the end. Any help or pointers will be greatly appreciated
import SwiftUI
struct IntegerCardView: View {
@State var isRevealed = false
@State var intHidden = "Tap to reveal"
var body: some View {
GeometryReader { geo in
TabView {
ForEach (0..<4) { index in
ZStack {
Rectangle()
.foregroundColor(.white)
Button {
self.intHidden = "\(index)"
} label: {
Text(isRevealed ? "\(index)" : intHidden)
}
.buttonStyle(.plain)
.onAppear {
self.intHidden = "Tap to reveal its name"
}
}
.frame(width: geo.size.width * 0.85, height: geo.size.height * 0.5, alignment: .center)
.cornerRadius(10)
.shadow(color: .black, radius: 10, x: -4, y: 4)
}
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .never))
}
}
}
struct IntCardView_Previews: PreviewProvider {
static var previews: some View {
IntegerCardView()
}
}