Skip to content

Commit

Permalink
refactor: zoom 기능 사용 시 렌더링 성능 개선 (#203)
Browse files Browse the repository at this point in the history
refactor: zoom 기능 사용 시 렌더링 성능 최적화
  • Loading branch information
heegenie authored Dec 3, 2024
1 parent cbd1cd1 commit d831bcc
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions packages/frontend/src/hooks/useZoomSpace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export function useZoomSpace({
minScale = 0.5,
maxScale = 2.5,
}: UseZoomSpaceProps) {
const animationFrameId = useRef<number | null>(null);

const zoomSpace = (event: KonvaEventObject<WheelEvent>) => {
event.evt.preventDefault();

Expand Down Expand Up @@ -80,16 +78,8 @@ export function useZoomSpace({
}

const newPosition = calculateNewPosition(pointer, mousePointTo, newScale);

if (animationFrameId.current) {
cancelAnimationFrame(animationFrameId.current);
}

animationFrameId.current = requestAnimationFrame(() => {
stage.scale({ x: newScale, y: newScale });
stage.position(newPosition);
stage.batchDraw();
});
stage.scale({ x: newScale, y: newScale });
stage.position(newPosition);
}
};

Expand Down

0 comments on commit d831bcc

Please sign in to comment.