Scrolling fixes and motion timeline changes (#10295)

* scrolling updates

* only scroll by 1 segment on desktop
This commit is contained in:
Josh Hawkins
2024-03-06 15:35:10 -06:00
committed by GitHub
parent fb81e44283
commit 90db27e3c8
8 changed files with 220 additions and 139 deletions

View File

@@ -0,0 +1,36 @@
import { useCallback } from "react";
interface TapUtils {
handleTouchStart: (
event: React.TouchEvent<Element>,
onClick: () => void,
) => void;
}
const useTapUtils = (): TapUtils => {
const handleTouchStart = useCallback(
(event: React.TouchEvent<Element>, onClick: () => void) => {
event.preventDefault();
const element = event.target as Element;
const { clientX, clientY } = event.changedTouches[0];
// Determine if the touch is within the element's bounds
const rect = element.getBoundingClientRect();
if (
clientX >= rect.left &&
clientX <= rect.right &&
clientY >= rect.top &&
clientY <= rect.bottom
) {
// Call the onClick handler
onClick();
}
},
[],
);
return { handleTouchStart };
};
export default useTapUtils;