Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) Make touch-ripple properly react to touch events #543

Merged
merged 2 commits into from
Apr 24, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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