Explorar el Código

Apply zoomDisabled prop for utils

iou90 hace 5 años
padre
commit
817f498921
Se han modificado 1 ficheros con 22 adiciones y 18 borrados
  1. 22
    18
      autoHeightWebView/utils.js

+ 22
- 18
autoHeightWebView/utils.js Ver fichero

@@ -54,26 +54,22 @@ const updateSizeWithMessage = (element, scalesPageToFit) =>
54 54
   }
55 55
   `;
56 56
 
57
-// add viewport setting to meta
58
-const makeScalePageToFit = (zoomable, scalesPageToFit) =>
59
-  scalesPageToFit || Platform.OS === 'android'
60
-    ? ''
61
-    : `
57
+const disableZoom = `
62 58
   var meta = document.createElement("meta");
63 59
   meta.setAttribute("name", "viewport");
64
-  meta.setAttribute("content", "width=device-width, user-scalable=${zoomable ? 'yes' : 'no'}");
60
+  meta.setAttribute("content", "width=device-width, user-scalable=no");
65 61
   document.getElementsByTagName("head")[0].appendChild(meta);
66 62
 `;
67 63
 
68 64
 const detectZoomChanged = `
69
-  var zoomin = false;
65
+  var zoomedin = false;
70 66
   var latestTapStamp = 0;
71 67
   var lastScale = false;
72 68
   var doubleTapDelay = 400;
73 69
   function detectZoomChanged() {
74
-    var tempZoomin = (screen.width / window.innerWidth) > 1;
75
-    tempZoomin !== zoomin && window.ReactNativeWebView.postMessage(JSON.stringify({ zoomin: tempZoomin }));
76
-    zoomin = tempZoomin;
70
+    var tempZoomedin = (screen.width / window.innerWidth) > 1;
71
+    tempZoomedin !== zoomedin && window.ReactNativeWebView.postMessage(JSON.stringify({ zoomedin: tempZoomedin }));
72
+    zoomedin = tempZoomedin;
77 73
   }
78 74
   window.addEventListener('touchend', event => {
79 75
     var tempScale = event.scale; 
@@ -82,16 +78,16 @@ const detectZoomChanged = `
82 78
     var timeSince = new Date().getTime() - latestTapStamp;
83 79
     // double tap   
84 80
     if(timeSince < 600 && timeSince > 0) {
85
-      zoominTimeOut = setTimeout(() => {
86
-        clearTimeout(zoominTimeOut);
81
+      zoomedinTimeOut = setTimeout(() => {
82
+        clearTimeout(zoomedinTimeOut);
87 83
         detectZoomChanged();
88 84
       }, doubleTapDelay);
89 85
     }
90 86
     latestTapStamp = new Date().getTime();
91 87
   });
92
-`
88
+`;
93 89
 
94
-const getBaseScript = ({ style, zoomable, scalesPageToFit, scrollEnabledWithZoomedin }) =>
90
+const getBaseScript = ({ style, zoomDisabled, scalesPageToFit, scrollEnabledWithZoomedin }) =>
95 91
   `
96 92
   ;
97 93
   if (!document.getElementById("rnahw-wrapper")) {
@@ -106,8 +102,8 @@ const getBaseScript = ({ style, zoomable, scalesPageToFit, scrollEnabledWithZoom
106 102
   window.addEventListener('load', updateSize);
107 103
   window.addEventListener('resize', updateSize);
108 104
   ${domMutationObserveScript}
109
-  ${makeScalePageToFit(zoomable, scalesPageToFit)}
110
-  ${scrollEnabledWithZoomedin ? detectZoomChanged : ''}
105
+  ${zoomDisabled ? disableZoom : ''}
106
+  ${!zoomDisabled && scrollEnabledWithZoomedin ? detectZoomChanged : ''}
111 107
   updateSize();
112 108
   `;
113 109
 
@@ -155,8 +151,16 @@ const getInjectedSource = ({ html, script }) => `
155 151
   </script>
156 152
 `;
157 153
 
158
-const getScript = ({ files, customStyle, customScript, style, zoomable, scalesPageToFit, scrollEnabledWithZoomedin }) => {
159
-  let script = getBaseScript({ style, zoomable, scalesPageToFit, scrollEnabledWithZoomedin });
154
+const getScript = ({
155
+  files,
156
+  customStyle,
157
+  customScript,
158
+  style,
159
+  zoomDisabled,
160
+  scalesPageToFit,
161
+  scrollEnabledWithZoomedin
162
+}) => {
163
+  let script = getBaseScript({ style, zoomDisabled, scalesPageToFit, scrollEnabledWithZoomedin });
160 164
   script = files && files.length > 0 ? appendFilesToHead({ files, script }) : script;
161 165
   script = appendStylesToHead({ style: customStyle, script });
162 166
   customScript && (script = customScript + script);