Skip to content

Commit

Permalink
- CR fix 3: Creating a new object reference every wheel change to sup…
Browse files Browse the repository at this point in the history
…port same wheel `deltaY` on every change
  • Loading branch information
omri.g committed Dec 21, 2020
1 parent a2a275a commit 0e60a35
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const Preview: React.FC<PreviewProps> = props => {
const currentPreviewIndex = previewUrlsKeys.indexOf(current);
const combinationSrc = isPreviewGroup ? previewUrls.get(current) : src;
const showLeftOrRightSwitches = isPreviewGroup && previewGroupCount > 1;
const [lastWheelZoomDirection, setLastWheelZoomDirection] = React.useState(0);
const [lastWheelZoomDirection, setLastWheelZoomDirection] = React.useState({});

const onAfterClose = () => {
setScale(1);
Expand Down Expand Up @@ -181,13 +181,14 @@ const Preview: React.FC<PreviewProps> = props => {
if (!visible) return;
event.preventDefault();
const wheelDirection = event.deltaY;
setLastWheelZoomDirection(wheelDirection);
setLastWheelZoomDirection({ wheelDirection });
};

useEffect(() => {
if (lastWheelZoomDirection > 0) {
const { wheelDirection } = lastWheelZoomDirection;
if (wheelDirection > 0) {
onZoomOut();
} else if (lastWheelZoomDirection < 0) {
} else if (wheelDirection < 0) {
onZoomIn();
}
}, [lastWheelZoomDirection]);
Expand Down

0 comments on commit 0e60a35

Please sign in to comment.