I have a SwiftUI project that includes a Text object with a .onTapGesture working that, when triggered, should cause the button's background color to pop to another color then quickly fade back to the original color. In my code, I'm able to trigger the color pop, but it stays that way and won't fade back. I'm kind of at a loss on what to do, any help is appreciated...here is the code I'm using:
@State var buttonFlash = false
var body: some View {
Text("Hello")
.font(.system(size: 20))
.frame(width: 30, height: 30)
.foregroundColor(Color.blue)
.background(buttonFlash ? Color.white : Color.red)
.animation(nil)
.background(Color.red)
.animation((Animation.linear).delay(0.1))
.cornerRadius(30)
.onTapGesture {
print("Tapped!")
self.buttonFlash.toggle()
}
