Skip to content

Commit

Permalink
fix: clear all Ripple effects after a hard deadline
Browse files Browse the repository at this point in the history
Fixes a bug where ripples were not being cleared
  • Loading branch information
hmerritt committed Dec 15, 2023
1 parent 5bf68cb commit 478e8d4
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/view/components/experimental/Ripple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const Ripple = ({
}

// Get the size of the button to determine how big the ripple should be
const size = Math.max(dimensions.width, dimensions.height) * 2;
const size = Math.max(dimensions.width, dimensions.height) * 2.5;

// Create a container for our ripple effect so we don't need to change the parent's style
const container = document.createElement("span");
Expand All @@ -84,6 +84,7 @@ export const Ripple = ({

// Create span to show the ripple effect
const ripple = document.createElement("span");
const duration = Math.min(size * 1.5, 350);

Object.assign(ripple.style, {
position: "absolute",
Expand All @@ -94,7 +95,7 @@ export const Ripple = ({

/* Transition configuration */
transitionProperty: "transform opacity",
transitionDuration: `${Math.min(size * 1.5, 350)}ms`,
transitionDuration: `${duration}ms`,
transitionTimingFunction: "linear",
transformOrigin: "center",

Expand Down Expand Up @@ -124,6 +125,12 @@ export const Ripple = ({
});
});
});

const reset = setTimeout(() => {
handleEnd(e);
}, duration + 400);

return () => clearTimeout(reset);
},
[centered, onTouchStart]
);
Expand All @@ -133,9 +140,7 @@ export const Ripple = ({
if (isMobile) onTouchEnd?.(e);
else onMouseUp?.(e);

const containers = e?.currentTarget?.querySelectorAll(
"[data-ripple]"
) as HTMLElement[];
const containers = document?.querySelectorAll("[data-ripple]");

requestAnimationFrame(() => {
requestAnimationFrame(() => {
Expand Down

0 comments on commit 478e8d4

Please sign in to comment.