Skip to content

Commit

Permalink
Merge pull request #543 from pomerantsev/fix/touch-ripple
Browse files Browse the repository at this point in the history
(fix) Make touch-ripple properly react to touch events
  • Loading branch information
mmrtnz committed Apr 24, 2015
2 parents fb775c9 + 236fcf9 commit 23790d6
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/js/ripples/touch-ripple.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var TouchRipple = React.createClass({
key: 0,
started: false,
ending: false
}]
}],
touchInProgress: false
};
},

Expand Down Expand Up @@ -105,22 +106,29 @@ var TouchRipple = React.createClass({

_handleMouseDown: function(e) {
//only listen to left clicks
if (e.button === 0) this.start(e);
if (e.button === 0 && !this.state.touchInProgress) this.start(e);
},

_handleMouseUp: function(e) {
this.end();
if (!this.state.touchInProgress) this.end();
},

_handleMouseOut: function(e) {
this.end();
if (!this.state.touchInProgress) this.end();
},

_handleTouchStart: function(e) {
this.start(e);
},

_handleTouchEnd: function(e) {
this.setState({ touchInProgress: true });
setTimeout(function () {
if (this.isMounted()) {
this.setState({ touchInProgress: false });
}
}.bind(this), 100);

this.end();
},

Expand All @@ -130,8 +138,9 @@ var TouchRipple = React.createClass({
var elHeight = el.offsetHeight;
var elWidth = el.offsetWidth;
var offset = Dom.offset(el);
var pageX = e.pageX == undefined ? e.nativeEvent.pageX : e.pageX;
var pageY = e.pageY == undefined ? e.nativeEvent.pageY : e.pageY;
var isTouchEvent = e.touches && e.touches.length;
var pageX = isTouchEvent ? e.touches[0].pageX : e.pageX;
var pageY = isTouchEvent ? e.touches[0].pageY : e.pageY;
var pointerX = pageX - offset.left;
var pointerY = pageY - offset.top;
var topLeftDiag = this._calcDiag(pointerX, pointerY);
Expand Down

0 comments on commit 23790d6

Please sign in to comment.