mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
feat(component): helper function observeResize to observe size change via global ResizeObserver (#7241)
```ts
import { observeResize } from "@affine/component";
useEffect(() => {
const dispose = observeResize(element entry => {
console.log(entry.contentRect);
});
return () => dispose();
}, []);
```
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Button, IconButton } from '@affine/component';
|
||||
import { Button, IconButton, observeResize } from '@affine/component';
|
||||
import {
|
||||
ArrowDownSmallIcon,
|
||||
ArrowUpSmallIcon,
|
||||
@@ -63,13 +63,7 @@ const CanvasText = ({
|
||||
return;
|
||||
}
|
||||
drawText(canvas, text);
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
drawText(canvas, text);
|
||||
});
|
||||
resizeObserver.observe(canvas);
|
||||
return () => {
|
||||
resizeObserver.disconnect();
|
||||
};
|
||||
return observeResize(canvas, () => drawText(canvas, text));
|
||||
}, [text]);
|
||||
|
||||
return <canvas className={className} ref={ref} />;
|
||||
|
||||
Reference in New Issue
Block a user