Skip to content

Commit

Permalink
Fix #3256: Ripple fixes for TouchStart (#3530)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Oct 31, 2022
1 parent 8937497 commit 8587d5b
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions components/lib/ripple/Ripple.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,28 @@ export const Ripple = React.memo(
};

const onTouchStart = (event) => {
onMouseDown(event);
event.preventDefault();
isTouching.current = true;
const offset = DomHandler.getOffset(targetRef.current);
const offsetX = event.targetTouches[0].pageX - offset.left + document.body.scrollTop - DomHandler.getWidth(inkRef.current) / 2;
const offsetY = event.targetTouches[0].pageY - offset.top + document.body.scrollLeft - DomHandler.getHeight(inkRef.current) / 2;

activateRipple(offsetX, offsetY);
};

const onMouseDown = (event) => {
if (DomHandler.isTouchDevice()) {
// already started ripple with onTouchStart
return;
}

const offset = DomHandler.getOffset(targetRef.current);
const offsetX = event.pageX - offset.left + document.body.scrollTop - DomHandler.getWidth(inkRef.current) / 2;
const offsetY = event.pageY - offset.top + document.body.scrollLeft - DomHandler.getHeight(inkRef.current) / 2;

activateRipple(offsetX, offsetY);
};

const activateRipple = (offsetX, offsetY) => {
if (!inkRef.current || getComputedStyle(inkRef.current, null).display === 'none') {
return;
}
Expand All @@ -45,12 +62,8 @@ export const Ripple = React.memo(
inkRef.current.style.width = d + 'px';
}

const offset = DomHandler.getOffset(targetRef.current);
const x = event.pageX - offset.left + document.body.scrollTop - DomHandler.getWidth(inkRef.current) / 2;
const y = event.pageY - offset.top + document.body.scrollLeft - DomHandler.getHeight(inkRef.current) / 2;

inkRef.current.style.top = y + 'px';
inkRef.current.style.left = x + 'px';
inkRef.current.style.top = offsetY + 'px';
inkRef.current.style.left = offsetX + 'px';
DomHandler.addClass(inkRef.current, 'p-ink-active');
};

Expand Down

0 comments on commit 8587d5b

Please sign in to comment.