CRAlpha / CRAlpha/react-native-wkwebview
Are tap (gesture) events unsupported?
- Dominant language
- Objective-C
- Stars
- 637
- Forks
- 263
- PR merge metrics
- No merged PRs in 30d
Description
In the iOS native WKWebView, one would approach gesture handling like so:
```Swift
import WebKit
import UIKit
import JavaScriptCore
import Foundation
class ViewController: UIViewController {
var webView: WKWebView?
override func loadView() {
super.loadView()
webView = WKWebView(frame: self.view.frame, configuration: WKWebViewConfiguration())
setUpTapGesture(target: webView!.scrollView, selector: #selector(onTap(gesture:)), delegate: self)
}
func setUpTapGesture(target: UIView, selector: Selector, delegate: UIGestureRecognizerDelegate?){
let gesture = UITapGestureRecognizer(target: self, action: selector)
// gesture.cancelsTouchesInView = false
gesture.delegate = delegate
target.addGestureRecognizer(gesture)
}
}
extension ViewController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
@objc func onTap(gesture:UITapGestureRecognizer) -> Void {
if(gesture.state == .ended){
let touchPoint: CGPoint = gesture.location(in: view)
let scrollPoint: CGPoint = gesture.location(in: webView!.scrollView)
let zoomScale: CGFloat = webView!.scrollView.zoomScale
// Now do something with this gesture information
}
}
}
```
How can we achieve full `onTap` functionality from the JavaScript side? I quickly tested whether `` accepts an `onClick={}` prop, but it seems to not have any effect. If we wrap a `` or `` component around it, I doubt we would get all the desired functionality (i.e. touch location, location in scrollview, and zoom level of scrollView); is this as-yet unimplemented? Has anyone out there made an implementation of it?
Are we also missing `scrollViewDidScroll`?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.