admin管理员组文章数量:1287556
I'm developing an app with React Native which has to respond to tap gestures as soon as possible because more than one tap event can be fired in a second. No need for double tap or move gestures, but need to take care of simultaneous taps. I've been testing with both onTouchStart
and PanResponder | onPanResponderGrant
and seen that:
onTouchStart
is fired twice when two taps are simultaneous, whileonPanResponderGrant
is called just once.onPanResponderMove
is fired even when I haveonMoveShouldSetPanResponder
tofalse
, and it's fired many times when two taps are simultaneous, or when there are several taps in a second.- When several taps are done in a second,
onTouchStart
works fine, butonPanResponderGrant
is fired less times.
Based on above reasons, I think that I'd better use onTouchStart
.
Now the question is: Should I use onTouchStart
even when React Native docs suggest to use the PanResponder
for multi-touch gestures?
PanResponder reconciles several touches into a single gesture. It makes single-touch gestures resilient to extra touches, and can be used to recognize simple multi-touch gestures.
Or am I missing something of PanResponder
?
Edit:
Also, gestureState.numberActiveTouches
is always 1, event when two taps are simultaneous. I thought that this could do the trick.
I'm developing an app with React Native which has to respond to tap gestures as soon as possible because more than one tap event can be fired in a second. No need for double tap or move gestures, but need to take care of simultaneous taps. I've been testing with both onTouchStart
and PanResponder | onPanResponderGrant
and seen that:
onTouchStart
is fired twice when two taps are simultaneous, whileonPanResponderGrant
is called just once.onPanResponderMove
is fired even when I haveonMoveShouldSetPanResponder
tofalse
, and it's fired many times when two taps are simultaneous, or when there are several taps in a second.- When several taps are done in a second,
onTouchStart
works fine, butonPanResponderGrant
is fired less times.
Based on above reasons, I think that I'd better use onTouchStart
.
Now the question is: Should I use onTouchStart
even when React Native docs suggest to use the PanResponder
for multi-touch gestures?
PanResponder reconciles several touches into a single gesture. It makes single-touch gestures resilient to extra touches, and can be used to recognize simple multi-touch gestures.
Or am I missing something of PanResponder
?
Edit:
Also, gestureState.numberActiveTouches
is always 1, event when two taps are simultaneous. I thought that this could do the trick.
- Is this for a scroll view? – sooper Commented Aug 3, 2017 at 23:23
- 1 @sooper - No, it's for some drums. – Manolo Commented Aug 4, 2017 at 8:52
- Hi @Manolo , is my answer satisfying? please accept it if so, otherwise let us know what's missing :). (edit: ah my bad, the bounty is replacing the check icon I suppose) – Jeremie Commented Aug 16, 2017 at 13:00
-
@Jeremie - Well, your answer is based on mon sense and makes sense, but what about multi-touch gestures? They won't be fired simultaneously. And why does not work with
PanResponder
? Is it just a not documented behaviour? – Manolo Commented Aug 16, 2017 at 18:27 - to detect multitouch, I suppose we must tolerate that user is not going to press 3 fingers at the exact same time, so the API leaves some delay for the user to make it happen. this explains why it get triggered a few times per second and not more. I'm not sure I understand your ment "multi touch gestures won't be fired simultaneously". sounds plicated to me, you expect the user pressing at the same time 2 different drums with multiple fingers? – Jeremie Commented Aug 17, 2017 at 19:24
1 Answer
Reset to default 11 +50From the definition of PanResponder, I understand that it's used to interpret a multi-touch gesture and render 1 action. Like I tap with 2 fingers on an image and I could get the image copied to the clipboard.
While it seems you want a different behaviour: I you tap with 2 fingers on 1 drum cymbal, you want to get 2 sounds. It's as if you were dividing your drum cymbals into an infinity of buttons, and whatever you do, for every tap, you'll get one separate sound.
Then you don't want to use PanResponder, because it's going to try to interpret a bunch of movements into a single sound, while you want every movement to generate a separate sound. And onTouchStart simply gets the job done. So you are probably doing the right thing with it!
本文标签: javascriptReact NativeonTouchStart vs PanResponder for multiple touches per secondStack Overflow
版权声明:本文标题:javascript - React Native - onTouchStart vs PanResponder for multiple touches per second - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741309611a2371574.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论