feat: calculate offsets when excalidraw container resizes (#3374)

* feat: calculate offsets when excalidraw container resizes

* fix

* rename

* update docs

* Update src/packages/excalidraw/README_NEXT.md

Co-authored-by: David Luzar <luzar.david@gmail.com>
This commit is contained in:
Aakansha Doshi 2021-04-01 21:10:11 +05:30 committed by GitHub
parent 1310256dcc
commit edc7f7bf47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View file

@ -298,6 +298,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
height: window.innerHeight,
};
private scene: Scene;
private resizeObserver: ResizeObserver | undefined;
constructor(props: ExcalidrawProps) {
super(props);
const defaultAppState = getDefaultAppState();
@ -786,6 +787,15 @@ class App extends React.Component<ExcalidrawProps, AppState> {
this.scene.addCallback(this.onSceneUpdated);
this.addEventListeners();
if (
"ResizeObserver" in window &&
this.excalidrawContainerRef?.current?.parentElement
) {
this.resizeObserver = new ResizeObserver(() => this.setCanvasOffsets());
this.resizeObserver?.observe(
this.excalidrawContainerRef.current.parentElement,
);
}
const searchParams = new URLSearchParams(window.location.search.slice(1));
if (searchParams.has("web-share-target")) {
@ -799,6 +809,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
}
public componentWillUnmount() {
this.resizeObserver?.disconnect();
this.unmounted = true;
this.removeEventListeners();
this.scene.destroy();