Skip to content

Commit f5677c5

Browse files
authored
Fix: Prevent Incorrect Displacement during Animation (#533)
* update-links-n-context-doc * fix indent * fix issue where the image zooms while animation is happening
1 parent 65a1fd9 commit f5677c5

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/core/instance.core.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
} from "./double-click/double-click.logic";
5050

5151
type StartCoordsType = { x: number; y: number } | null;
52+
type ClientCoordsType = StartCoordsType;
5253

5354
export class ZoomPanPinch {
5455
public props: ReactZoomPanPinchProps;
@@ -79,6 +80,7 @@ export class ZoomPanPinch {
7980
public isPanning = false;
8081
public isWheelPanning = false;
8182
public startCoords: StartCoordsType = null;
83+
public clientCoords: ClientCoordsType = null;
8284
public lastTouch: number | null = null;
8385
// pinch helpers
8486
public distance: null | number = null;

src/core/pan/panning.logic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function handlePanning(
6060
clientX: number,
6161
clientY: number,
6262
): void {
63-
const { startCoords, setup } = contextInstance;
63+
const { startCoords, clientCoords, setup } = contextInstance;
6464
const { sizeX, sizeY } = setup.alignmentAnimation;
6565

6666
if (!startCoords) return;
@@ -69,7 +69,7 @@ export function handlePanning(
6969
const paddingValueX = getPaddingValue(contextInstance, sizeX);
7070
const paddingValueY = getPaddingValue(contextInstance, sizeY);
7171

72-
handleCalculateVelocity(contextInstance, { x, y });
72+
if(clientCoords?.x != clientX && clientCoords?.y != clientY) handleCalculateVelocity(contextInstance, { x, y });
7373
handleNewPosition(contextInstance, x, y, paddingValueX, paddingValueY);
7474
}
7575

src/core/pan/panning.utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const handlePanningSetup = (
6464
const y = event.clientY;
6565

6666
contextInstance.startCoords = { x: x - positionX, y: y - positionY };
67+
contextInstance.clientCoords = {x: x, y: y};
6768
};
6869

6970
export const handleTouchPanningSetup = (
@@ -81,6 +82,7 @@ export const handleTouchPanningSetup = (
8182
const x = touches[0].clientX;
8283
const y = touches[0].clientY;
8384
contextInstance.startCoords = { x: x - positionX, y: y - positionY };
85+
contextInstance.clientCoords = {x: x, y: y};
8486
}
8587
};
8688
export function handlePanToBounds(

0 commit comments

Comments
 (0)