Monday, September 9, 2019

Re: GWT Support for Touch Event

I found this as well.  I think browser implementation of these old single touch events isn't great.  I switched to using the multi touch versions.  Something like this:

private HashMap<Integer, Touch> touches;

private void handleScreenTouches(JsArray<Touch> newTouches, boolean touchDown) {
  // Update the touch collection
  for (int i=0; i<newTouches.length(); i++) {
    Touch touch = newTouches.get(i);
    if (touch != null) {
      if (touchDown) {
        touches.put(touch.getIdentifier(), touch);
      }
      else {
        touches.remove(touch.getIdentifier());
      }
    }
  }

  // Look through the remaining touches
  for (Touch touch : touches.values()) {
    ...
  }
}

drawingPaper
.addDomHandler(event -> {
    handleScreenTouches
(event.getChangedTouches(), true);
}, TouchStartEvent.getType()));


drawingPaper
.addDomHandler(event -> {
    handleScreenTouches
(event.getChangedTouches(), true);
}, TouchMoveEvent.getType()));


drawingPaper
.addDomHandler(event -> {
    handleScreenTouches
(event.getChangedTouches(), false);
}, TouchEndEvent.getType()));

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/a5816a19-68c1-48fe-886c-68f111915121%40googlegroups.com.

No comments:

Post a Comment