WaitUntilOnPage: take scaling into account

It was waiting too near the viewport to load on certain zoom levels. This will maintain the same physical distance for the "approaching viewport" buffer regardless of zoom levels.
This commit is contained in:
infinite-persistence 2021-07-08 20:31:30 +08:00 committed by Thomas Zarebczan
parent ad1c826f2c
commit 59a8b9d663

View file

@ -4,6 +4,14 @@ import debounce from 'util/debounce';
const DEBOUNCE_SCROLL_HANDLER_MS = 50;
function scaleToDevicePixelRatio(value) {
const devicePixelRatio = window.devicePixelRatio || 1.0;
if (devicePixelRatio < 1.0) {
return Math.ceil(value / devicePixelRatio);
}
return Math.ceil(value * devicePixelRatio);
}
type Props = {
children: any,
skipWait?: boolean,
@ -26,7 +34,7 @@ export default function WaitUntilOnPage(props: Props) {
// $FlowFixMe
const windowW = window.innerWidth || document.documentElement.clientWidth;
const isApproachingViewport = yOffset && bounding.top < windowH + yOffset;
const isApproachingViewport = yOffset && bounding.top < windowH + scaleToDevicePixelRatio(yOffset);
const isInViewport = // also covers "element is larger than viewport".
bounding.width > 0 &&
bounding.height > 0 &&