Browse Source

Refactor usingScale

iou90 4 years ago
parent
commit
7fecddb8d4
1 changed files with 3 additions and 7 deletions
  1. 3
    7
      autoHeightWebView/utils.js

+ 3
- 7
autoHeightWebView/utils.js View File

14
 
14
 
15
 const updateSizeWithMessage = (element, scalesPageToFit) =>
15
 const updateSizeWithMessage = (element, scalesPageToFit) =>
16
   `
16
   `
17
-  var usingScale = 0;
17
+  var usingScale = ${scalesPageToFit} ? screen.width / window.innerWidth : 1};
18
   var scaling = false;
18
   var scaling = false;
19
   var zoomedin = false;
19
   var zoomedin = false;
20
   var lastHeight = 0;
20
   var lastHeight = 0;
40
     height = ${element}.offsetHeight || document.documentElement.offsetHeight;
40
     height = ${element}.offsetHeight || document.documentElement.offsetHeight;
41
     width = ${element}.offsetWidth || document.documentElement.offsetWidth;
41
     width = ${element}.offsetWidth || document.documentElement.offsetWidth;
42
 
42
 
43
-    if(!usingScale && window.innerWidth) {
44
-      usingScale = ${scalesPageToFit ? 'screen.width / window.innerWidth' : '1'};
45
-    }
46
-
47
     window.ReactNativeWebView.postMessage(JSON.stringify({ width: Math.min(width, screen.width), height: height * usingScale }));
43
     window.ReactNativeWebView.postMessage(JSON.stringify({ width: Math.min(width, screen.width), height: height * usingScale }));
48
 
44
 
49
     // Make additional height checks (required to fix issues wit twitter embeds)
45
     // Make additional height checks (required to fix issues wit twitter embeds)
83
   var lastScale = 1.0;
79
   var lastScale = 1.0;
84
   var doubleTapDelay = 400;
80
   var doubleTapDelay = 400;
85
   function detectZoomChanged() {
81
   function detectZoomChanged() {
86
-    var tempZoomedin = (screen.width / window.innerWidth) > (usingScale || 1);
82
+    var tempZoomedin = (screen.width / window.innerWidth) > usingScale;
87
     tempZoomedin !== zoomedin && window.ReactNativeWebView.postMessage(JSON.stringify({ zoomedin: tempZoomedin }));
83
     tempZoomedin !== zoomedin && window.ReactNativeWebView.postMessage(JSON.stringify({ zoomedin: tempZoomedin }));
88
     zoomedin = tempZoomedin;
84
     zoomedin = tempZoomedin;
89
   }
85
   }
242
     }
238
     }
243
   }
239
   }
244
   return false;
240
   return false;
245
-};
241
+};