furf / jquery-ui-touch-punch

A duck punch for adding touch events to jQuery UI
http://touchpunch.furf.com/
3.51k stars 1.34k forks source link

Issue with Apple Pencil #315

Open andrewkendall opened 5 years ago

andrewkendall commented 5 years ago

There is currently an issue when using an Apple Pencil. Using the Apple Pencil always triggers a touchmove event, meaning the simulated click doesn't work as intended.

// If the touch interaction did not move, it should trigger a click
if (!this._touchMoved) {

  // Simulate the click event
  simulateMouseEvent(event, 'click');
}

A quick fix is to update the code to:

// If the touch interaction did not move, it should trigger a click
if (!this._touchMoved || event.originalEvent.changedTouches[0].touchType === 'stylus') {

  // Simulate the click event
  simulateMouseEvent(event, 'click');
}

Hopefully, that will help someone who is struggling with click events with the Apple Pencil. If anyone has a neater update to the code I'd love to know.

andrewkendall commented 5 years ago

@RWAP you're doing great work folding in fixes, you might want to take a look at this one. It works better with your updated code as you are also watching for the amount of movement before triggering a click.

RWAP commented 5 years ago

@RWAP you're doing great work folding in fixes, you might want to take a look at this one. It works better with your updated code as you are also watching for the amount of movement before triggering a click.

Thanks - I have suggested a change - https://github.com/RWAP/jquery-ui-touch-punch/pull/3 Can you please verify my change - as I do not have an Apple device (let alone a Pencil!)

andrewkendall commented 5 years ago

@RWAP I've just tested on iPad mini 5 and 12.9-inch iPad Pro. That works perfectly.