Skip to content

Commit

Permalink
fix: 使用ResizeObserver代替
Browse files Browse the repository at this point in the history
  • Loading branch information
xuying.xu committed Feb 5, 2024
1 parent e7a3c43 commit e8c2ab7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/f-react/src/createCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const createCanvas = (CanvasClass: typeof Canvas) => {
width: number;
height: number;
};
observer: MutationObserver;
observer: ResizeObserver;

constructor(props: CanvasProps) {
super(props);
Expand Down Expand Up @@ -120,11 +120,12 @@ const createCanvas = (CanvasClass: typeof Canvas) => {
this.resize();
});

const observerConfig = { attributes: true };
this.observer = new MutationObserver(() => {
this.resize();
});
this.observer.observe(targetNode, observerConfig);
if (typeof ResizeObserver !== 'undefined') {
this.observer = new ResizeObserver(() => {
this.resize();
});
this.observer.observe(targetNode);
}
}

resize() {
Expand Down

0 comments on commit e8c2ab7

Please sign in to comment.