From 59a8b9d663ccd9e4f7a7adee9acaf8848c9c8c0b Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Thu, 8 Jul 2021 20:31:30 +0800 Subject: [PATCH] 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. --- ui/component/common/wait-until-on-page.jsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ui/component/common/wait-until-on-page.jsx b/ui/component/common/wait-until-on-page.jsx index 51d78ae8a..032dd8b90 100644 --- a/ui/component/common/wait-until-on-page.jsx +++ b/ui/component/common/wait-until-on-page.jsx @@ -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 &&