0

I need to display a WebView, and get the interactions from the user, the touches, and the scrolls. For now, I am able to display the Website and print the tap coordinate:

struct TapGesture: View {
    var body: some View {
        let getCoordinates = DragGesture(minimumDistance: 0, coordinateSpace: .global).onEnded({ dragGesture in
            print("X: \(dragGesture.location.x)")
            print("Y: \(dragGesture.location.y)")
        })
        WebView(url: "https://www.google.com").gesture(getCoordinates)
    }
}

The WebView is:

struct WebView : UIViewRepresentable {
    var url: String
    
    func makeUIView(context: Context) -> WKWebView  {
        return WKWebView()
    }
    
    func updateUIView(_ uiView: WKWebView, context: Context) {
        let request = URLRequest(url: URL(string: url)!)
        uiView.load(request)
    }
}

The problem is, that even I can get the coordinates of the tap of the user, it does block the interaction with the website, and make it unusable, since the touch of the website gets kind of "overridden" by the gesture. How can I allow the gesture to go through and still get the coordinates of the touch? How can I also detect scroll instead of touch and his coordinates?

kike
  • 499
  • 6
  • 17

0 Answers0