Skip to content

Commit

Permalink
[fix] Dimensions measurements with window zoom
Browse files Browse the repository at this point in the history
Fixes `window.height` and `window.width` so that they do not change when
pinch-zoomed. This issue was introduced by #2438 when `documentElement`
measurements were replaced by `visualViewport`.

Close #2520
  • Loading branch information
alitoshmatov authored and necolas committed Jun 16, 2023
1 parent 9b69c73 commit 6ab9b61
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/react-native-web/src/exports/Dimensions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ function update() {
*/
if (win.visualViewport) {
const visualViewport = win.visualViewport;
height = Math.round(visualViewport.height);
width = Math.round(visualViewport.width);
/**
* We are multiplying by scale because height and width from visual viewport
* also react to pinch zoom, and become smaller when zoomed. But it is not desired
* behaviour, since originally documentElement client height and width were used,
* and they do not react to pinch zoom.
*/
height = Math.round(visualViewport.height * visualViewport.scale);
width = Math.round(visualViewport.width * visualViewport.scale);
} else {
const docEl = win.document.documentElement;
height = docEl.clientHeight;
Expand Down

0 comments on commit 6ab9b61

Please sign in to comment.