SwiftUI ignores UIView.isUserInteractionEnabled and other UIKit hit-testing methods

Number:rdar://FB9818366 Date Originated:12/22/2021
Status:Open Resolved:
Product:SwiftUI Product Version:15.4
Classification: Reproducible:

SwiftUI doesn't respect the hit-testing preferences of the UIViews inside UIViewRepresentables.

Twitter thread of me complaining about this problem: https://twitter.com/mattxcurtis/status/1473543903232118787

UIViews have several ways they can react to hit-testing, primarily:

- UIView.isUserInteractionEnabled
- UIView.point(inside:event:)
- UIView.hitTest(_:event:)

While UIViewRepresentable will let you embed a UIView in SwiftUI content, SwiftUI completely ignores the inner UIView's hit-testing preferences, and instead treats the entire region of space the UIViewRepresentable takes up as a fully hit-testable area, which means the UIViewRepresentable blocks all touches to any SwiftUI content below it.

Steps to reproduce:

The attached project demonstrates this issue with a UIViewRepresentable that creates a UIView that has isUserInteractionEnabled set to false. The UIViewRepresentable still blocks touches to the SwiftUI content below it.

Link to the project attached to the original radar on Github: https://github.com/matt-curtis/UIViewRepresentable-hitTest-bug-demonstration

Expected behavior:

SwiftUI should be take into account and respect the hit-testing preferences of the UIView content it lets you embed. Not taking this hit-testing into account makes it much harder to integrate UIKit content with SwiftUI content.


Using SwiftUI's contentShape, or allowsHitTesting, can give you some ability to mitigate this problem, but they are no substitute for the flexibility of UIKit's built-in methods.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!