SwiftUI MultiviewResponder mystery crash

Viewed 190

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:

  1. Remove the Rectangle from the bottom of the ZStack
  2. Remove one of the two views from the VStack
  3. Remove the zIndex (this will break the fade-out animation)
  4. Remove the explicit animation call

Here is my console output: XCode debugging output

I would like to know what's happening here, what's causing the crash ?

0 Answers
Related