Skip to content

Commit 52dae12

Browse files
committed
added multi-touch support
1 parent 4f5685c commit 52dae12

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/draggable.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ var dragEventFor = eventsFor.mouse;
8181
* get {clientX, clientY} positions of control
8282
* */
8383
function getControlPosition(e) {
84-
var position = (e.touches && e.touches[0]) || e;
84+
var position = (e.targetTouches && e.targetTouches[0]) || e;
8585
return {
8686
clientX: position.clientX,
8787
clientY: position.clientY
@@ -514,6 +514,11 @@ module.exports = React.createClass({
514514
},
515515

516516
handleDragStart: function (e) {
517+
// Set touch identifier in component state if this is a touch event
518+
if(e.targetTouches){
519+
this.setState({identifier: e.targetTouches[0].identifier});
520+
}
521+
517522
// Make it possible to attach event handlers on top of this one
518523
this.props.onMouseDown(e);
519524

@@ -574,6 +579,10 @@ module.exports = React.createClass({
574579
},
575580

576581
handleDrag: function (e) {
582+
// Return if this is a touch event, but not the correct one for thiss element
583+
if(e.targetTouches && (e.targetTouches[0].identifier != this.state.identifier)){
584+
return;
585+
}
577586
var dragPoint = getControlPosition(e);
578587

579588
// Calculate X and Y

0 commit comments

Comments
 (0)