Skip to content

Commit

Permalink
Fix primefaces#5771: Image mask click handling
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Jan 15, 2024
1 parent f926a04 commit 0e1667d
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 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,9 @@ export const Image = React.memo(
return;
}

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

previewClick.current = false;
setPreviewVisibleState(false);
setRotateState(0);
setScaleState(1);
};

const onMaskKeydown = (event) => {
Expand All @@ -120,17 +107,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 +123,6 @@ export const Image = React.memo(

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

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

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

const onEntering = () => {
Expand Down Expand Up @@ -305,7 +287,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 0e1667d

Please sign in to comment.