From dccd3fbf736e90cc7ce9c3ef30a1289b333beb6a Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Fri, 3 Dec 2021 15:28:56 -0500 Subject: [PATCH] Media editor minor improvements --- ts/components/MediaEditor.tsx | 11 +++++++++++ ts/mediaEditor/MediaEditorFabricCropRect.ts | 4 ++++ ts/mediaEditor/MediaEditorFabricPath.ts | 11 ++++++++--- ts/mediaEditor/util/customFabricObjectControls.ts | 8 ++++---- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/ts/components/MediaEditor.tsx b/ts/components/MediaEditor.tsx index 8d18f387fb..99a78c9a12 100644 --- a/ts/components/MediaEditor.tsx +++ b/ts/components/MediaEditor.tsx @@ -399,6 +399,7 @@ export const MediaEditor = ({ const [canRedo, setCanRedo] = useState(false); const [canUndo, setCanUndo] = useState(false); + const [canCrop, setCanCrop] = useState(false); const [cropAspectRatioLock, setcropAspectRatioLock] = useState(false); const [drawTool, setDrawTool] = useState(DrawTool.Pen); const [drawWidth, setDrawWidth] = useState(DrawWidth.Regular); @@ -572,6 +573,13 @@ export const MediaEditor = ({ width, }); + rect.on('modified', () => { + const { height: currHeight, width: currWidth } = + rect.getBoundingRect(true); + + setCanCrop(currHeight < height || currWidth < width); + }); + rect.on('deselected', () => { setEditMode(undefined); }); @@ -589,6 +597,8 @@ export const MediaEditor = ({ } }); } + + setCanCrop(false); }, [editMode, fabricCanvas, imageState.height, imageState.width, zoom]); useEffect(() => { @@ -857,6 +867,7 @@ export const MediaEditor = ({