Skip to content

Commit

Permalink
fix(ripple): Ripple triggers twice on mobile (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
aluminick authored and Matt Goo committed Feb 7, 2019
1 parent a376474 commit d141be1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/ripple/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type ActivateEventTypes<S>
export interface RippledComponentInterface<Surface, Activator = Element> {
foundation?: MDCRippleFoundation;
isComponentMounted: boolean;
isTouched: boolean;
initializeFoundation: (surface: Surface, activator?: Activator) => void;
handleFocus: React.FocusEventHandler<Surface>;
handleBlur: React.FocusEventHandler<Surface>;
Expand Down Expand Up @@ -101,6 +102,7 @@ export function withRipple <
> implements RippledComponentInterface<Surface, Activator> {
foundation?: MDCRippleFoundation;
isComponentMounted: boolean = true;
isTouched: boolean = false;

displayName = `WithRipple(${getDisplayName<P>(WrappedComponent)})`;

Expand Down Expand Up @@ -228,7 +230,9 @@ export function withRipple <

handleMouseDown = (e: React.MouseEvent<Surface>) => {
this.props.onMouseDown && this.props.onMouseDown(e);
this.activateRipple(e);
if (!this.isTouched) {
this.activateRipple(e);
}
};

handleMouseUp = (e: React.MouseEvent<Surface>) => {
Expand All @@ -237,6 +241,7 @@ export function withRipple <
};

handleTouchStart = (e: React.TouchEvent<Surface>) => {
this.isTouched = true;
this.props.onTouchStart && this.props.onTouchStart(e);
this.activateRipple(e);
};
Expand All @@ -259,9 +264,7 @@ export function withRipple <
activateRipple = (e: ActivateEventTypes<Surface>) => {
// https://reactjs.org/docs/events.html#event-pooling
e.persist();
requestAnimationFrame(() => {
this.foundation.activate(e);
});
this.foundation.activate(e);
};

deactivateRipple = (e: ActivateEventTypes<Surface>) => {
Expand All @@ -273,7 +276,7 @@ export function withRipple <
return;
}
this.setState((prevState) => {
const updatedStyle = Object.assign({}, this.state.style) as React.CSSProperties;
const updatedStyle = Object.assign({}, this.state.style, prevState.style) as React.CSSProperties;
updatedStyle[varName] = value;
return Object.assign(prevState, {
style: updatedStyle,
Expand Down

0 comments on commit d141be1

Please sign in to comment.