mirror of
https://github.com/zoriya/react-native-web.git
synced 2025-12-06 06:36:13 +00:00
[fix] Dimensions measurements with window zoom
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
This commit is contained in:
committed by
Nicolas Gallagher
parent
9b69c73938
commit
6ab9b6125b
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user