A repo to track unexpected behavior with gestures when mixing SwiftUI and UIKit

Gesture Collision with SwiftUI + UIKit

This project demonstrates a bug – or at least unexpected behavior – that occurs when combining UIKit with SwiftUI.

Given the following view structure:

— UIWindow — UIHostingController — A SwiftUI View as UIHostingController.view — A SwiftUI Button — A UIView with a gesture recogznier, added as a subview to UIHostingController.view

If the SwiftUI Button and the UIView are overlaid, a tap on the UIView will be recognized, but also pass through to the SwiftUI Button, triggering a tap on it as well.

Expected behavior is that the UIView, being on top, would absorb the touch and the SwiftUI Button would have no knowledge of the interaction.

Try enabling usesTouchAbsorbingView in ContentView to see a workaround in use.

GitHub

View Github