Skip to content

Commit

Permalink
Fix #5771: Image mask click handling (#5772)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Jan 15, 2024
1 parent f926a04 commit 53de29b
Showing 1 changed file with 5 additions and 26 deletions.
31 changes: 5 additions & 26 deletions components/lib/image/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const Image = React.memo(
const imageRef = React.useRef(null);
const maskRef = React.useRef(null);
const previewRef = React.useRef(null);
const previewClick = React.useRef(false);
const previewButton = React.useRef(null);
const zoomOutDisabled = scaleState <= 0.5;
const zoomInDisabled = scaleState >= 1.5;
Expand Down Expand Up @@ -70,18 +69,10 @@ export const Image = React.memo(
};

const hide = () => {
if (!previewClick.current) {
setPreviewVisibleState(false);
DomHandler.unblockBodyScroll();
setRotateState(0);
setScaleState(1);
}

previewClick.current = false;
};

const onPreviewImageClick = () => {
previewClick.current = true;
setPreviewVisibleState(false);
DomHandler.unblockBodyScroll();
setRotateState(0);
setScaleState(1);
};

const onMaskClick = (event) => {
Expand All @@ -91,13 +82,7 @@ export const Image = React.memo(
return;
}

if (!previewClick.current) {
setPreviewVisibleState(false);
setRotateState(0);
setScaleState(0);
}

previewClick.current = false;
hide();
};

const onMaskKeydown = (event) => {
Expand All @@ -120,17 +105,14 @@ export const Image = React.memo(
const { alt: name, src } = props;

DomHandler.saveAs({ name, src });
previewClick.current = true;
};

const rotateRight = () => {
setRotateState((prevRotate) => prevRotate + 90);
previewClick.current = true;
};

const rotateLeft = () => {
setRotateState((prevRotate) => prevRotate - 90);
previewClick.current = true;
};

const zoomIn = () => {
Expand All @@ -139,7 +121,6 @@ export const Image = React.memo(

return prevScale + 0.1;
});
previewClick.current = true;
};

const zoomOut = () => {
Expand All @@ -148,7 +129,6 @@ export const Image = React.memo(

return prevScale - 0.1;
});
previewClick.current = true;
};

const onEntering = () => {
Expand Down Expand Up @@ -305,7 +285,6 @@ export const Image = React.memo(
src: props.zoomSrc || props.src,
className: cx('preview'),
style: sx('preview', { rotateState, scaleState }),
onClick: onPreviewImageClick,
crossOrigin: crossOrigin,
referrerPolicy: referrerPolicy,
useMap: useMap,
Expand Down

0 comments on commit 53de29b

Please sign in to comment.