I came across this crash I can't explain, even after I boiling it down to the minimal components which would still cause the crash: Repeatedly tapping the screen quickly (use two fingers) to hide/show an overlayed button with an explicit animation will crash the app under this VERY specific layout:
import SwiftUI
struct ContentView: View {
@State var showControls: Bool = true
var body: some View {
ZStack {
Rectangle().foregroundColor(Color.gray) // Removing this would fix it
VStack {
Text("someText")
Text("anotherText") // Removing this would also fix it
}
if showControls {
Text("Button")
.zIndex(1) // Removing this would also fix it
}
}
.onTapGesture {
withAnimation(.easeInOut(duration: 1)) { // Removing this would also fix it
showControls.toggle()
}
}
}
}
As mentioned in the code comments, any of these changes prevent the crash:
- Remove the Rectangle from the bottom of the ZStack
- Remove one of the two views from the VStack
- Remove the zIndex (this will break the fade-out animation)
- Remove the explicit animation call
I would like to know what's happening here, what's causing the crash ?
