Skip to content

Commit

Permalink
remove raf
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Oct 15, 2020
1 parent e6631f9 commit 5274172
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions packages/grid/_modules_/grid/components/ScrollArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const ScrollArea = React.memo(function ScrollArea(props: ScrollAreaProps)
const { scrollDirection } = props;
const rootRef = React.useRef<HTMLDivElement>(null);
const api = React.useContext(ApiContext);
const rafRef = React.useRef(0);
const timeout = React.useRef<number>();
const [dragging, setDragging] = React.useState<boolean>(false);
const scrollPosition = React.useRef<ScrollParams>({
Expand All @@ -42,17 +41,12 @@ export const ScrollArea = React.memo(function ScrollArea(props: ScrollAreaProps)

offset = (offset - CLIFF) * SLOP + CLIFF;

// Throttle, max 60 Hz
cancelAnimationFrame(rafRef.current);

rafRef.current = requestAnimationFrame(() => {
// Wait for the frame to pain before updating the scroll position
clearTimeout(timeout.current);
timeout.current = setTimeout(() => {
api!.current.scroll({
left: scrollPosition.current.left + offset,
top: scrollPosition.current.top,
});
clearTimeout(timeout.current);
// Avoid freeze and inertia.
timeout.current = setTimeout(() => {
api!.current.scroll({
left: scrollPosition.current.left + offset,
top: scrollPosition.current.top,
});
});
},
Expand All @@ -61,7 +55,6 @@ export const ScrollArea = React.memo(function ScrollArea(props: ScrollAreaProps)

React.useEffect(() => {
return () => {
cancelAnimationFrame(rafRef.current);
clearTimeout(timeout.current);
};
}, []);
Expand Down

0 comments on commit 5274172

Please sign in to comment.