UIHostingController interaction breaks if view.layer.zPosition is greater than 50 or less than -49

Originator:kellerbryan19
Number:rdar://FB13731297 Date Originated:04/15/2024
Status:Open Resolved:No
Product:SwiftUI Product Version:visionOS 1.0 and 1.1
Classification:Bug Reproducible:Yes
 
A `UIHostingController`’s root view fails to receive any touches (including from trackpad pointer) on VisionOS 1.0 and 1.1 if the hosting controller’s `view.layer.zPosition` is set to a value greater than +50 or less than -49. Values from -49…50 don’t cause any issues. See example project for a minimal repro.

This is causing major issues for the Airbnb iPad app (which is available on visionOS via the iPad app). Core UI components, like the search bar and the listing card shown on the map, cannot receive “touches” on visionOS.

============

final class ViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    let hostingController = UIHostingController(rootView: TestView())

    hostingController.willMove(toParent: parent)
    addChild(hostingController)
    view.addSubview(hostingController.view)
    hostingController.view.translatesAutoresizingMaskIntoConstraints = false
    NSLayoutConstraint.activate([
      hostingController.view.centerXAnchor.constraint(equalTo: view.centerXAnchor),
      hostingController.view.centerYAnchor.constraint(equalTo: view.centerYAnchor),
    ])
    hostingController.didMove(toParent: parent)

    // Breaks touch handling if zPosition is outside of the range -49...50
    hostingController.view.layer.zPosition = 51
  }

}

private struct TestView: View {

  @State private var state = false

  var body: some View {
    Rectangle()
      .fill(state ? Color.red : Color.blue)
      .frame(width: 100, height: 100)
      .onTapGesture {
        state.toggle()
      }
  }

}

Comments


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!