Kaynağa Gözat

Refactor usingScale

iou90 4 yıl önce
ebeveyn
işleme
7fecddb8d4
1 değiştirilmiş dosya ile 3 ekleme ve 7 silme
  1. 3
    7
      autoHeightWebView/utils.js

+ 3
- 7
autoHeightWebView/utils.js Dosyayı Görüntüle

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