Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onTouchStart, onTouchMove and onTouchEnd aren't true multi-touch #10068

Closed
robclouth opened this issue Sep 23, 2016 · 9 comments
Closed

onTouchStart, onTouchMove and onTouchEnd aren't true multi-touch #10068

robclouth opened this issue Sep 23, 2016 · 9 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@robclouth
Copy link
Contributor

I'm using RN 0.33.
The onTouchStart, onTouchMove and onTouchEnd props of View aren't multi-touch. You can't control two at the same time which heavily restricts their usefulness!
For example, it's impossible to create two sliders that can be controlled independently.

@hey99xx
Copy link

hey99xx commented Sep 23, 2016

They certainly are multi touch, they give you entire touch history on the screen. See https://facebook.github.io/react-native/docs/gesture-responder-system.html for more detailed information on touches including

changedTouches - Array of all touch events that have changed since the last event

touches - Array of all current touches on the screen

Now creating two touchable sliders might a bit more difficult since if they are separate views, they would likely cancel each other. That's why React gives you ability to create your own native view subclasses and add your gesture events. The MapView example at https://facebook.github.io/react-native/docs/native-components-ios.html can certainly accept multi touch gestures.

@robclouth
Copy link
Contributor Author

This is what I'm talking about sorry, multi-touch over separate views. The fact that you have to create a native view to be able to press two buttons at the same time seems like a fundamental limitation, and unnecessarily restricts the utility. So you're saying there's no pure RN way of reacting simultaneously to gestures on different view simultaneously?

@robclouth
Copy link
Contributor Author

Sorry @hey99xx could you just confirm that there's no way to control two views at the same time with pure RN? It's not possible to bypass all the responder stuff and hook straight into touch events coming from the native views?

@hey99xx
Copy link

hey99xx commented Sep 27, 2016

Hey Rob. I'm not a FB employee or a contributor, so don't take my word :) you might prefer to choose from from a more authoritative person.

With <Touchable> components, I'm pretty sure there is no way. They hook themselves into the global responder system and receive rejections / grants, so only one <Touchable> component will be receiving an event at all times.

Hooking straight into touch events might work. I've investigated a little into it earlier, but my problem was different (I was trying to find how to terminate responders from native side similar to how scroll view drag gesture works).

If there is a way, you will likely need an extensive look at https://github.com/facebook/react/tree/15-dev/src/renderers/shared/stack/event and especially https://github.com/facebook/react/blob/15-dev/src/renderers/shared/stack/event/eventPlugins/ResponderEventPlugin.js where all responder rejections / grants etc happen.


Edit
Btw if you prefer to write a little bit native code, you can surely bypass reading all this JS code. For my specific problem, I managed to use gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: which allowed me to have a custom gesture recognizer running together with JS touchable components.

@robclouth
Copy link
Contributor Author

Yeah I know it's impossible with Touchables, but I've had some success with hooking into the onTouchX methods directly on Views. But this doesn't work on android.
Thanks for your help!

@aleclarson
Copy link
Contributor

aleclarson commented Nov 29, 2016

@robclouth Did you ever resolve your issue? Or could you confirm that multi-gesture support is not currently implemented?

Once @kmagiera finishes his work on react-native-gesture-handler, that might be the solution (which is to not use React's JS responder system at all).

It would be nice if a FB employee could chime in here. 😄

@robclouth
Copy link
Contributor Author

Hey. Basically multiple touches on separate views works on iOS, using the onTouchMove View prop. But it doesn't work on android. I've had to make a native wrapper component.

@aleclarson
Copy link
Contributor

aleclarson commented Nov 29, 2016

That's not ideal, considering you don't get separate on{Start,Move}ShouldSetResponder{Capture} or onResponder{Grant,End} or terminate events.

I whipped up some commits to support multiple views handling gestures simultaneously:

72242ff - BUGFIX: Ensures onResponderTerminate is handled by the old responder before onResponderGrant is handled by the new responder

113f2c6 - Implements multi-gesture support for facebook/react

0116996 - Allows multiple JS responders in RCTUIManager


  • Nothing for Android yet
  • Not tested with PanResponder or Touchable since I use aleclarson/gesture

@aleclarson
Copy link
Contributor

Alright, I finished all the necessary work (no test suite yet) and updated the commit SHAs in the above comment. If you get the chance, let me know if PanResponder and/or Touchable work with the changes.

Cheers 🍻

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants