Skip to content

Commit

Permalink
Merge pull request #278 from kipr/fix-safari-size-bugs
Browse files Browse the repository at this point in the history
Fix a couple major Safari issues
  • Loading branch information
tcorbly authored Aug 26, 2021
2 parents e1ef688 + e203d81 commit 09b409e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/components/ResizeListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,26 @@ class Evented implements ResizeListener {

private onResize_ = (entries: ResizeObserverEntry[]) => {
for (const entry of entries) {
this.callback_(Evented.getResizeObserverEntrySize(entry), entry.target);
}
};

private static getResizeObserverEntrySize(entry: ResizeObserverEntry): Vector2 {
if (entry.borderBoxSize) {
// Firefox implements borderBoxSize as an object instead of an array, so check for either
const borderBoxSize = entry.borderBoxSize as unknown;
const borderBox: ResizeObserverSize = Array.isArray(borderBoxSize)
? borderBoxSize[0] as ResizeObserverSize
: borderBoxSize as ResizeObserverSize;
this.callback_({ x: borderBox.inlineSize, y: borderBox.blockSize }, entry.target);
return { x: borderBox.inlineSize, y: borderBox.blockSize };
} else if (entry.contentRect) {
// Safari doesn't return borderBoxSize, so fall back to contentRect
return { x: entry.contentRect.width, y: entry.contentRect.height };
}
};

console.error('failed to get size of ResizeObserverEntry');
return { x: 0, y: 0 };
}

constructor(callback: ResizeCallback) {
this.callback_ = callback;
Expand Down

0 comments on commit 09b409e

Please sign in to comment.