在 safari mobile 中,触摸可以使用以下方式分类为 Apple Pencil 与其他(手指/鼠标):
event.touches[0].touchType === 'stylus' //pencil
event.touches[0].touchType !== 'stylus' //other
然而,在 React Native WebView 中收到的所有事件(Apple Pencil 和使用手指)都在接收:
touchType === 'direct' //inside webview, both pencil and other
如何在 Web 视图中检测 Apple Pencil 的触摸?
显然event.touches[0] > 0
是另一种可能性,但这也被设置为0
对于 webview 中的两种类型。
(不确定这是 React Native 的问题还是 WebView 的内置限制)。
Related:
- UIView 对 Apple Pencil 没有反应 https://stackoverflow.com/questions/35941898/uiview-do-not-react-on-apple-pencil
- Javascript 触摸事件:区分手指与 Apple Pencil https://stackoverflow.com/questions/34986373/javascript-touch-event-distinguishing-finger-vs-apple-pencil
我通过将 React Native WebView 组件替换为 WKWebView 组件解决了这个问题https://github.com/CRAlpha/react-native-wkwebview https://github.com/CRAlpha/react-native-wkwebview
即替换import { WebView } from 'react-native'
with import WKWebView from 'react-native-wkwebview-reborn'
这需要各种修改和解决方法,但最终成功了,事件现在包括额外的参数,例如:
看来较旧的 WebView 可能不支持与 Pencil/Stylus 相关的附加事件参数(但也有可能我使用了错误/旧版本,或者 React Native 没有从本机 WebView 组件传递这些参数。我会如果有人可以澄清的话,很乐意更新更多细节)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)