Don't zoom on wheel end

This commit is contained in:
Mitchell McCaffrey 2021-03-21 17:20:37 +11:00
parent 9bd1ff2d97
commit 2015399466

View File

@ -51,30 +51,34 @@ function useStageInteraction(
if (preventInteraction || !isInteractingWithCanvas.current) { if (preventInteraction || !isInteractingWithCanvas.current) {
return; return;
} }
const { event } = props; const { event, last } = props;
const { pixelY } = normalizeWheel(event); if (!last) {
const { pixelY } = normalizeWheel(event);
const newScale = Math.min( const newScale = Math.min(
Math.max( Math.max(
stageScale + stageScale +
(pixelY * wheelZoomSpeed * stageScale * zoomSpeed) / (pixelY * wheelZoomSpeed * stageScale * zoomSpeed) /
window.innerHeight, window.innerHeight,
minZoom minZoom
), ),
maxZoom maxZoom
); );
// Center on pointer // Center on pointer
const pointer = stage.getPointerPosition(); const pointer = stage.getPointerPosition();
const newTranslate = { const newTranslate = {
x: pointer.x - ((pointer.x - stage.x()) / stageScale) * newScale, x: pointer.x - ((pointer.x - stage.x()) / stageScale) * newScale,
y: pointer.y - ((pointer.y - stage.y()) / stageScale) * newScale, y: pointer.y - ((pointer.y - stage.y()) / stageScale) * newScale,
}; };
stage.position(newTranslate); stage.position(newTranslate);
stageTranslateRef.current = newTranslate;
stageTranslateRef.current = newTranslate;
onStageScaleChange(newScale);
}
onStageScaleChange(newScale);
gesture.onWheel && gesture.onWheel(props); gesture.onWheel && gesture.onWheel(props);
}, },
onPinchStart: (props) => { onPinchStart: (props) => {