Skip to content

Instantly share code, notes, and snippets.

View StephenHaney's full-sized avatar

Stephen Haney StephenHaney

View GitHub Profile
@StephenHaney
StephenHaney / AutoPan.tsx
Created September 11, 2023 05:00
Modulz AutoPan on dragging
import { autorun } from 'mobx';
import { observer } from 'mobx-react-lite';
import React, { useEffect, useRef } from 'react';
import { useAppState } from 'src/store/context/AppStateProvider';
/** Moves the pan of the canvas if a cursor leaves the edges of the canvas during a drag */
export const AutoPan = observer(() => {
const { hoverState, dragState, cameraState, toolState, selectionState } = useAppState();
/** A RAF for the autopan function */
const autoPanAnimationFrame = useRef<number>(0);