Skip to content

Commit

Permalink
Use a different approach for preventing ghost click ripples
Browse files Browse the repository at this point in the history
Resolves mui#456.
  • Loading branch information
pomerantsev committed Apr 30, 2015
1 parent 817770c commit e38c9cd
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/ripples/touch-ripple.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ var TouchRipple = React.createClass({
key: 0,
started: false,
ending: false
}],
touchInProgress: false
}]
};
},

Expand Down Expand Up @@ -48,17 +47,26 @@ var TouchRipple = React.createClass({
);
},

start: function(e) {
start: function(e, isRippleTouchGenerated) {
var ripples = this.state.ripples;
var nextKey = ripples[ripples.length-1].key + 1;
var style = !this.props.centerRipple ? this._getRippleStyle(e) : {};
var ripple;

//Do nothing if we're starting a click-event-generated ripple
//while having touch-generated ripples
if (!isRippleTouchGenerated) {
for (var i = 0; i < ripples.length; i++) {
if (ripples[i].touchGenerated) return;
}
}

//Start the next unstarted ripple
for (var i = 0; i < ripples.length; i++) {
ripple = ripples[i];
if (!ripple.started) {
ripple.started = true;
ripple.touchGenerated = isRippleTouchGenerated;
ripple.style = style;
break;
}
Expand Down Expand Up @@ -113,29 +121,22 @@ var TouchRipple = React.createClass({

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

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

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

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

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

this.end();
},

Expand Down

0 comments on commit e38c9cd

Please sign in to comment.