Skip to content

Commit

Permalink
fix: prevent panning on label edit or label drag
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Sep 26, 2024
1 parent cd6e87f commit bbec04f
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,9 @@ const AddLabelWithinFrame = (): JSX.Element => {
labelToDelete={labelToEdit}
/>
)}
<ImageFrame />
<Box
width="100%"
height="100%"
position="absolute"
top="0px"
left="0px"
onClick={showLabelForm}
sx={{ cursor: 'cell' }}
id={ADD_LABELS_IMAGE_CONTAINER_ID}
Expand All @@ -118,6 +114,7 @@ const AddLabelWithinFrame = (): JSX.Element => {
showEditForm={showEditForm}
/>
))}
<ImageFrame />
</Box>
</Box>
);
Expand All @@ -129,6 +126,9 @@ const AddLabelWithinFrameWrapper = (): JSX.Element => {
const { isDragging, labels } = useContext(LabelsContext);
const disabled = isDragging;

// should start enabled
const [disabledPanning, setDisablePanning] = useState(false);

return (
<Box sx={{ width: '100%' }}>
{labels.length === 0 && (
Expand All @@ -138,12 +138,30 @@ const AddLabelWithinFrameWrapper = (): JSX.Element => {
<TransformContainer
doubleClick={{ disabled: true }}
centerOnInit
panning={{ disabled }}
panning={{ disabled: disabledPanning }}
pinch={{ disabled }}
wheel={{ disabled }}
zoomAnimation={{ disabled }}
alignmentAnimation={{ disabled }}
velocityAnimation={{ disabled }}
onPanningStart={(_instance, event) => {
// panning start is always called, even when disabled

// enable panning only if the clicked element is the box
if (
event.target &&
'nodeName' in event.target &&
event.target.nodeName === 'IMG'
) {
setDisablePanning(false);
} else {
setDisablePanning(true);
}
}}
onPanningStop={() => {
// disable panning again
setDisablePanning(false);
}}
>
<TransformComponent
wrapperStyle={{
Expand Down

0 comments on commit bbec04f

Please sign in to comment.