Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

visionOS 26.0 beta does not call .onTapGesture

Prior to visionOS 2.5, .onTapGesture was called with the following structure, but in visionOS 26.0 beta, it is no longer called. Is .onTapGesture deprecated in visionOS 26.0 and above? Or is it a bug?

TabView(selection: $selectedTab) {
            WebViewView(selectedTab: $selectedTab)
                    .onTapGesture {
                        viewModel.userDidInteract = true 
		     }
}

Hi @t.nemoto ,

I tested the below code in visionOS 26 and was able to see the on tap gestures being called. I think the issue here is the lack of Tab. Try putting WebViewView inside of a Tab.

struct ContentView: View {
    @State private var selection: Int = 0
    var body: some View {
        TabView(selection: $selection) {
            Tab(value: 0) {
                Rectangle()
                    .fill(.red)
                    .onTapGesture {
                        print("red")
                    }
            }
            Tab(value: 1){
                Rectangle()
                    .fill(.green)
                    .onTapGesture {
                        print("green")
                    }
            }

        }
    }
}

Thanks for the reply.

I tried putting the WebViewView inside the Tab, but it still did not work. The essential problem was that I was using a WebViewView wrapped in a UIViewRepresentable inside a WebViewView.

As a solution, I added the following UITapGestureRecognizer in the makeUIView of the WebView wrapped in UIViewRepresentable.

let tap = UITapGestureRecognizer(
target: context.coordinator,
        action: #selector(Coordinator.didTap(_:))
)
tap.cancelsTouchesInView = false
tap.delegate = context.coordinator
webView.addGestureRecognizer(tap)

We also added the following methods to class Coordinator: NSObject, WKNavigationDelegate, WKScriptMessageHandler, and UIGestureRecognizerDelegate.

        @objc func didTap(_ sender: UITapGestureRecognizer) {
            parent.viewModel.userDidInteract = true
        }

        @objc func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,.
                               shouldRecognizeSimultaneouslyWith other: UIGestureRecognizer) -> Bool {
            true
        }
visionOS 26.0 beta does not call .onTapGesture
 
 
Q