@@ -33,6 +33,7 @@ export function usePointerInput({
3333 onTouchPreview,
3434} : UsePointerInputOptions ) {
3535 const activePointerRef = useRef < number | null > ( null ) ;
36+ const sentMoveThisFrameRef = useRef ( false ) ;
3637 const moveFrameRef = useRef < number > ( 0 ) ;
3738 const panningRef = useRef < {
3839 startX : number ;
@@ -52,17 +53,34 @@ export function usePointerInput({
5253 } , [ ] ) ;
5354
5455 function queueMove ( coords : Point ) {
56+ if ( ! sentMoveThisFrameRef . current ) {
57+ sentMoveThisFrameRef . current = true ;
58+ onTouch ( "moved" , coords ) ;
59+ if ( ! moveFrameRef . current ) {
60+ moveFrameRef . current = requestAnimationFrame ( ( ) => {
61+ moveFrameRef . current = 0 ;
62+ sentMoveThisFrameRef . current = false ;
63+ const nextCoords = queuedMoveRef . current ;
64+ queuedMoveRef . current = null ;
65+ if ( nextCoords ) {
66+ queueMove ( nextCoords ) ;
67+ }
68+ } ) ;
69+ }
70+ return ;
71+ }
5572 queuedMoveRef . current = coords ;
5673 if ( moveFrameRef . current ) {
5774 return ;
5875 }
5976
6077 moveFrameRef . current = requestAnimationFrame ( ( ) => {
6178 moveFrameRef . current = 0 ;
79+ sentMoveThisFrameRef . current = false ;
6280 const nextCoords = queuedMoveRef . current ;
6381 queuedMoveRef . current = null ;
6482 if ( nextCoords ) {
65- onTouch ( "moved" , nextCoords ) ;
83+ queueMove ( nextCoords ) ;
6684 }
6785 } ) ;
6886 }
@@ -73,6 +91,7 @@ export function usePointerInput({
7391 moveFrameRef . current = 0 ;
7492 }
7593 queuedMoveRef . current = null ;
94+ sentMoveThisFrameRef . current = false ;
7695 }
7796
7897 function startPanning ( event : React . PointerEvent < HTMLElement > ) {
0 commit comments