Skip to content

Commit

Permalink
fix: centerOnInit timing issue (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheStu committed Mar 28, 2024
1 parent 53e1d38 commit 8dacc27
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/core/instance.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,22 @@ export class ZoomPanPinch {
if (centerOnInit) {
this.setCenter();
this.observer = new ResizeObserver(() => {
this.onInitCallbacks.forEach((callback) => callback(getContext(this)));
this.setCenter();
this.observer?.disconnect();
const currentWidth = contentComponent.offsetWidth;
const currentHeight = contentComponent.offsetHeight;

if (currentWidth > 0 || currentHeight > 0) {
this.onInitCallbacks.forEach((callback) => callback(getContext(this)));
this.setCenter();

this.observer?.disconnect();
}
});

// if nothing about the contentComponent has changed after 5 seconds, disconnect the observer
setTimeout(() => {
this.observer?.disconnect();
}, 5000);

// Start observing the target node for configured mutations
this.observer.observe(contentComponent);
}
Expand Down

0 comments on commit 8dacc27

Please sign in to comment.