From 2cc1033d99fa2b575e849cccb7e5f45dc58138d6 Mon Sep 17 00:00:00 2001 From: siam Date: Thu, 15 Aug 2024 15:32:54 +0800 Subject: [PATCH] fix: update drawing panel state at end of changing --- .../src/views/panel/DrawingTransform.tsx | 113 +++++++++--------- 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/packages/drawing-ui/src/views/panel/DrawingTransform.tsx b/packages/drawing-ui/src/views/panel/DrawingTransform.tsx index ca95f788883..420036a76cc 100644 --- a/packages/drawing-ui/src/views/panel/DrawingTransform.tsx +++ b/packages/drawing-ui/src/views/panel/DrawingTransform.tsx @@ -177,64 +177,65 @@ export const DrawingTransform = (props: IDrawingTransformProps) => { }; useEffect(() => { - const changeStartSub = transformer.changeStart$.subscribe((state) => { - changeObs(state); - }); - - const changingSub = transformer.changing$.subscribe((state) => { - changeObs(state); - }); - - const focusSub = drawingManagerService.focus$.subscribe((drawings) => { - if (drawings.length !== 1) { - return; - } - - const drawingParam = drawingManagerService.getDrawingByParam(drawings[0]); - - if (drawingParam == null) { - return; - } - - const transform = drawingParam.transform; - - if (transform == null) { - return; - } - - const { - width: originWidth, - height: originHeight, - left: originX, - top: originY, - angle: originRotation, - } = transform; - - if (originWidth != null) { - setWidth(originWidth); - } - - if (originHeight != null) { - setHeight(originHeight); - } - - if (originX != null) { - setXPosition(originX); - } - - if (originY != null) { - setYPosition(originY); - } - - if (originRotation != null) { - setRotation(originRotation); - } - }); + const subscriptions = [ + transformer.changeStart$.subscribe((state) => { + changeObs(state); + }), + transformer.changing$.subscribe((state) => { + changeObs(state); + }), + transformer.changeEnd$.subscribe((state) => { + changeObs(state); + }), + drawingManagerService.focus$.subscribe((drawings) => { + if (drawings.length !== 1) { + return; + } + + const drawingParam = drawingManagerService.getDrawingByParam(drawings[0]); + + if (drawingParam == null) { + return; + } + + const transform = drawingParam.transform; + + if (transform == null) { + return; + } + + const { + width: originWidth, + height: originHeight, + left: originX, + top: originY, + angle: originRotation, + } = transform; + + if (originWidth != null) { + setWidth(originWidth); + } + + if (originHeight != null) { + setHeight(originHeight); + } + + if (originX != null) { + setXPosition(originX); + } + + if (originY != null) { + setYPosition(originY); + } + + if (originRotation != null) { + setRotation(originRotation); + } + }), + ]; return () => { - changingSub.unsubscribe(); - changeStartSub.unsubscribe(); - focusSub.unsubscribe(); + subscriptions.forEach((sub) => sub.unsubscribe()); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []);