Skip to content

Commit f53ef2b

Browse files
AliceLannisteQiu-Jun
authored andcommitted
fix(plugin): 优化resize功能
1 parent 96cad24 commit f53ef2b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/core/plugin/WorkspacePlugin.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class WorkspacePlugin implements IPluginTempl {
2626
];
2727
workspaceEl!: HTMLElement;
2828
workspace: null | fabric.Rect;
29+
resizeObserver!: ResizeObserver;
2930
option: any;
3031
zoomRatio: number;
3132
constructor(public canvas: fabric.Canvas, public editor: IEditor) {
@@ -99,7 +100,6 @@ class WorkspacePlugin implements IPluginTempl {
99100
if (this.canvas.clearHistory) {
100101
this.canvas.clearHistory();
101102
}
102-
this.auto();
103103
}
104104

105105
// 返回workspace对象
@@ -129,7 +129,8 @@ class WorkspacePlugin implements IPluginTempl {
129129
this.auto();
130130
}, 50)
131131
);
132-
resizeObserver.observe(this.workspaceEl);
132+
this.resizeObserver = resizeObserver;
133+
this.resizeObserver.observe(this.workspaceEl);
133134
}
134135

135136
setSize(width: number | undefined, height: number | undefined) {
@@ -143,7 +144,6 @@ class WorkspacePlugin implements IPluginTempl {
143144
this.workspace.set('width', width);
144145
this.workspace.set('height', height);
145146
this.editor.emit('sizeChange', this.workspace.width, this.workspace.height);
146-
this.auto();
147147
}
148148

149149
setZoomAuto(scale: number, cb?: (left?: number, top?: number) => void) {
@@ -224,6 +224,7 @@ class WorkspacePlugin implements IPluginTempl {
224224
}
225225

226226
destroy() {
227+
this.resizeObserver.disconnect();
227228
console.log('pluginDestroy');
228229
}
229230
}

0 commit comments

Comments
 (0)