iou90 5 years ago
parent
commit
0a9fc24017
1 changed files with 2 additions and 3 deletions
  1. 2
    3
      autoHeightWebView/utils.js

+ 2
- 3
autoHeightWebView/utils.js View File

14
 
14
 
15
 const updateSizeWithMessage = (element, scalesPageToFit) =>
15
 const updateSizeWithMessage = (element, scalesPageToFit) =>
16
   `
16
   `
17
-  var scale = ${scalesPageToFit ? 'screen.width / window.innerWidth' : '1'};
18
   var lastHeight = 0;
17
   var lastHeight = 0;
19
   var heightTheSameTimes = 0;
18
   var heightTheSameTimes = 0;
20
   var maxHeightTheSameTimes = 5;
19
   var maxHeightTheSameTimes = 5;
33
     clearTimeout(checkPostMessageTimeout);
32
     clearTimeout(checkPostMessageTimeout);
34
     height = ${element}.offsetHeight || document.documentElement.offsetHeight;
33
     height = ${element}.offsetHeight || document.documentElement.offsetHeight;
35
     width = ${element}.offsetWidth || document.documentElement.offsetWidth;
34
     width = ${element}.offsetWidth || document.documentElement.offsetWidth;
36
-    var needScale = width > screen.width;
37
-    window.ReactNativeWebView.postMessage(JSON.stringify({ width: needScale ? width * scale : width, height: needScale ? height * scale : height }));
35
+    var scale = ${scalesPageToFit ? 'screen.width / window.innerWidth' : '1'};
36
+    window.ReactNativeWebView.postMessage(JSON.stringify({ width: Math.min(width, screen.width), height: height * scale }));
38
 
37
 
39
     // Make additional height checks (required to fix issues wit twitter embeds)
38
     // Make additional height checks (required to fix issues wit twitter embeds)
40
     clearTimeout(forceRefreshTimeout);
39
     clearTimeout(forceRefreshTimeout);