Skip to content

Commit 302a500

Browse files
committed
Merge pull request #68 from YottaSecond/master
Add multitouch support
2 parents 4f5685c + c36dbcd commit 302a500

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/draggable.js

Lines changed: 15 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({touchIdentifier: 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

@@ -557,6 +562,11 @@ module.exports = React.createClass({
557562
return;
558563
}
559564

565+
// Short circuit if this is not the correct touch event
566+
if(e.changedTouches && (e.changedTouches[0].identifier != this.state.touchIdentifier)){
567+
return;
568+
}
569+
560570
removeUserSelectStyles(this);
561571

562572
// Turn off dragging
@@ -574,6 +584,10 @@ module.exports = React.createClass({
574584
},
575585

576586
handleDrag: function (e) {
587+
// Return if this is a touch event, but not the correct one for this element
588+
if(e.targetTouches && (e.targetTouches[0].identifier != this.state.touchIdentifier)){
589+
return;
590+
}
577591
var dragPoint = getControlPosition(e);
578592

579593
// Calculate X and Y

0 commit comments

Comments
 (0)