Просмотр исходного кода

Apply zoomDisabled prop for utils

iou90 4 лет назад
Родитель
Сommit
817f498921
1 измененных файлов: 22 добавлений и 18 удалений
  1. 22
    18
      autoHeightWebView/utils.js

+ 22
- 18
autoHeightWebView/utils.js Просмотреть файл

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
   var meta = document.createElement("meta");
58
   var meta = document.createElement("meta");
63
   meta.setAttribute("name", "viewport");
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
   document.getElementsByTagName("head")[0].appendChild(meta);
61
   document.getElementsByTagName("head")[0].appendChild(meta);
66
 `;
62
 `;
67
 
63
 
68
 const detectZoomChanged = `
64
 const detectZoomChanged = `
69
-  var zoomin = false;
65
+  var zoomedin = false;
70
   var latestTapStamp = 0;
66
   var latestTapStamp = 0;
71
   var lastScale = false;
67
   var lastScale = false;
72
   var doubleTapDelay = 400;
68
   var doubleTapDelay = 400;
73
   function detectZoomChanged() {
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
   window.addEventListener('touchend', event => {
74
   window.addEventListener('touchend', event => {
79
     var tempScale = event.scale; 
75
     var tempScale = event.scale; 
82
     var timeSince = new Date().getTime() - latestTapStamp;
78
     var timeSince = new Date().getTime() - latestTapStamp;
83
     // double tap   
79
     // double tap   
84
     if(timeSince < 600 && timeSince > 0) {
80
     if(timeSince < 600 && timeSince > 0) {
85
-      zoominTimeOut = setTimeout(() => {
86
-        clearTimeout(zoominTimeOut);
81
+      zoomedinTimeOut = setTimeout(() => {
82
+        clearTimeout(zoomedinTimeOut);
87
         detectZoomChanged();
83
         detectZoomChanged();
88
       }, doubleTapDelay);
84
       }, doubleTapDelay);
89
     }
85
     }
90
     latestTapStamp = new Date().getTime();
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
   if (!document.getElementById("rnahw-wrapper")) {
93
   if (!document.getElementById("rnahw-wrapper")) {
106
   window.addEventListener('load', updateSize);
102
   window.addEventListener('load', updateSize);
107
   window.addEventListener('resize', updateSize);
103
   window.addEventListener('resize', updateSize);
108
   ${domMutationObserveScript}
104
   ${domMutationObserveScript}
109
-  ${makeScalePageToFit(zoomable, scalesPageToFit)}
110
-  ${scrollEnabledWithZoomedin ? detectZoomChanged : ''}
105
+  ${zoomDisabled ? disableZoom : ''}
106
+  ${!zoomDisabled && scrollEnabledWithZoomedin ? detectZoomChanged : ''}
111
   updateSize();
107
   updateSize();
112
   `;
108
   `;
113
 
109
 
155
   </script>
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
   script = files && files.length > 0 ? appendFilesToHead({ files, script }) : script;
164
   script = files && files.length > 0 ? appendFilesToHead({ files, script }) : script;
161
   script = appendStylesToHead({ style: customStyle, script });
165
   script = appendStylesToHead({ style: customStyle, script });
162
   customScript && (script = customScript + script);
166
   customScript && (script = customScript + script);