Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 6876e62

Browse files
aluminickMatt Goo
authored and
Matt Goo
committed
fix(ripple): Ripple triggers twice on mobile (#646)
1 parent c5e87a6 commit 6876e62

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/ripple/index.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type ActivateEventTypes<S>
6565
export interface RippledComponentInterface<Surface, Activator = Element> {
6666
foundation?: MDCRippleFoundation;
6767
isComponentMounted: boolean;
68+
isTouched: boolean;
6869
initializeFoundation: (surface: Surface, activator?: Activator) => void;
6970
handleFocus: React.FocusEventHandler<Surface>;
7071
handleBlur: React.FocusEventHandler<Surface>;
@@ -101,6 +102,7 @@ export function withRipple <
101102
> implements RippledComponentInterface<Surface, Activator> {
102103
foundation?: MDCRippleFoundation;
103104
isComponentMounted: boolean = true;
105+
isTouched: boolean = false;
104106

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

@@ -228,7 +230,9 @@ export function withRipple <
228230

229231
handleMouseDown = (e: React.MouseEvent<Surface>) => {
230232
this.props.onMouseDown && this.props.onMouseDown(e);
231-
this.activateRipple(e);
233+
if (!this.isTouched) {
234+
this.activateRipple(e);
235+
}
232236
};
233237

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

239243
handleTouchStart = (e: React.TouchEvent<Surface>) => {
244+
this.isTouched = true;
240245
this.props.onTouchStart && this.props.onTouchStart(e);
241246
this.activateRipple(e);
242247
};
@@ -259,9 +264,7 @@ export function withRipple <
259264
activateRipple = (e: ActivateEventTypes<Surface>) => {
260265
// https://reactjs.org/docs/events.html#event-pooling
261266
e.persist();
262-
requestAnimationFrame(() => {
263-
this.foundation.activate(e);
264-
});
267+
this.foundation.activate(e);
265268
};
266269

267270
deactivateRipple = (e: ActivateEventTypes<Surface>) => {
@@ -273,7 +276,7 @@ export function withRipple <
273276
return;
274277
}
275278
this.setState((prevState) => {
276-
const updatedStyle = Object.assign({}, this.state.style) as React.CSSProperties;
279+
const updatedStyle = Object.assign({}, this.state.style, prevState.style) as React.CSSProperties;
277280
updatedStyle[varName] = value;
278281
return Object.assign(prevState, {
279282
style: updatedStyle,

0 commit comments

Comments
 (0)