简体   繁体   English

React Native - 按时取消

[英]React Native - cancel on press

I'm creating a game with react native that involves multiple users interacting with the screen.我正在创建一个包含多个用户与屏幕交互的本机反应游戏。

Most of the time, it works fine, but there are times where it causes problems eg someone leaving their finger on the phone, then other users presses not being recognised大多数情况下,它工作正常,但有时会导致问题,例如有人将手指放在手机上,然后其他用户按下不被识别

I'm looking for a way to cancel the on press, after the tap has initially registered在水龙头最初注册后,我正在寻找一种取消按下的方法

Going through the docs for tocuhables, I'm not sure it's possible through react native浏览 tocuhables 的文档,我不确定是否可以通过本机反应

Any suggestions welcome欢迎任何建议

If you want to manage complex touches then you'll want to use the PanResponder .如果您想管理复杂的触摸,那么您将需要使用PanResponder "Cancel" isn't really an option, but you can definitely stop responding to a touch if certain conditions are met. “取消”并不是一个真正的选项,但如果满足某些条件,您绝对可以停止响应触摸。

there are times where it causes problems eg someone leaving their finger on the phone, then other users presses not being recognised有时它会导致问题,例如有人将手指放在手机上,然后其他用户按下无法识别

The methods which come into play for this are the *ShouldSetPanResponder methods.为此发挥作用的方法是*ShouldSetPanResponder方法。 These determine whether the current touch should become the active touch.这些决定了当前触摸是否应该成为活动触摸。

onMoveShouldSetPanResponder: (e, gestureState) => {...}
onMoveShouldSetPanResponderCapture: (e, gestureState) => {...}
onStartShouldSetPanResponder: (e, gestureState) => {...}
onStartShouldSetPanResponderCapture: (e, gestureState) => {...}

The react-native-gesture-handler library can make it a lot easier to deal with these low-level APIs. react-native-gesture-handler库可以让处理这些低级 API 变得更加容易。 It includes components like TapGestureHandler with standardized props like maxDurationMs , numberOfTaps , etc.它包括像TapGestureHandler这样的组件,以及像maxDurationMsnumberOfTaps等标准化的道具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM