mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-05 11:19:34 +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) {
|
if (win.visualViewport) {
|
||||||
const visualViewport = 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 {
|
} else {
|
||||||
const docEl = win.document.documentElement;
|
const docEl = win.document.documentElement;
|
||||||
height = docEl.clientHeight;
|
height = docEl.clientHeight;
|
||||||
|
|||||||
Reference in New Issue
Block a user