react-juce icon indicating copy to clipboard operation
react-juce copied to clipboard

Investigate/Improve TouchEvent support

Open JoshMarler opened this issue 5 years ago • 1 comments

We are currently doing some work to improve blueprint's SyntheticEvent implementation. MouseEvent is gaining adoption of properties like target, relatedTarget, shitKey etc. It could be very useful to provide a TouchEvent for some applications.

This should match the spec here as close as possible: https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent

Ideally we would provide the following set of events: onTouchCancel onTouchEnd onTouchMove onTouchStart. See: https://reactjs.org/docs/events.html

As per this forum post JUCE has a MultiTouch example we could leverage:

https://forum.juce.com/t/how-to-do-ios-style-multitouch-handling/23936

It may be that we need to provide some mechanism to opt into this behaviour as the C++ side of generating TouchEvents is sure to incur some level of overhead.

JoshMarler avatar Nov 06 '20 17:11 JoshMarler

Hey @JoshMarler @nick-thompson ! First of all let me tell you how nice this project looks ! It's amazing what you have achieved already and I'm looking forward for the first release.

@JoshMarler concerning this feature, I gave it a shot and got pretty nice results on a real iPad (so multi touch surface) with 3 fingers and on the iPad Simulator in XCode where you are bound to 2 fingers. I managed to pull out an example mimicking the behavior of the example in the spec of the TouchEvent, by drawing on a CanvasView with multitouch. Here is a shot of the results: https://www.youtube.com/watch?v=V62-N2PH4eY

I have added also a "click" event on the Slider through Touch Event (for usage on an iPad) for example.

With the way JUCE handles the clicks/touches (not simultaneously but one after another even on the iPad simulator where the double touch occurs at the exact same moment), I didn't find a proper way to "bufferize" the juce mouse events to be able to generate multiple Touch object inside the changedTouches property of the TouchEvent. That's the closest I could get to the the spec you sent.

For now, I have handled onTouchStart, onTouchMove and onTouchEnd.

I'm really not familiar with C++ (I'm a Python dev) and JUCE var types (Array, Variant etc...) as I'm still discovering the project so feel free to comment and don't hesitate to tell me I've wrote some horrible code (I know that's probably the case)! Would you mind having a look at the PR please (here) ?

rafou avatar Nov 25 '20 23:11 rafou