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

Ripple triggers twice on mobile #646

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/ripple/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export function withRipple <
};

handleTouchEnd = (e: React.TouchEvent<Surface>) => {
e.preventDefault();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

facebook/react#9809 (comment)
touchEnd event causes mouseDown to fire which causes the double ripple on mobile

this.props.onTouchEnd && this.props.onTouchEnd(e);
this.deactivateRipple(e);
};
Expand All @@ -259,9 +260,9 @@ export function withRipple <
activateRipple = (e: ActivateEventTypes<Surface>) => {
// https://reactjs.org/docs/events.html#event-pooling
e.persist();
requestAnimationFrame(() => {
this.foundation.activate(e);
});
/* requestAnimationFrame(() => { */
this.foundation.activate(e)
/* }); */
};

deactivateRipple = (e: ActivateEventTypes<Surface>) => {
Expand All @@ -273,7 +274,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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without requestAnimationFrame wrapping this.foundation.activate(e) previous style is not merged. Adding prevState.style to updatedStyle fixes this.

updatedStyle[varName] = value;
return Object.assign(prevState, {
style: updatedStyle,
Expand Down