Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update drawing panel state at end of changing #3069

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 57 additions & 56 deletions packages/drawing-ui/src/views/panel/DrawingTransform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}, []);
Expand Down
Loading