Browse Source

using function instead of arrow function for getInjectedSource to fix arrow function not supported problem below android 6.0, https://github.com/iou90/react-native-autoheight-webview/issues/139

iou90 4 years ago
parent
commit
10bb38ea0a
1 changed files with 4 additions and 2 deletions
  1. 4
    2
      autoHeightWebView/utils.js

+ 4
- 2
autoHeightWebView/utils.js View File

20
   var maxHeightTheSameTimes = 5;
20
   var maxHeightTheSameTimes = 5;
21
   var forceRefreshDelay = 1000;
21
   var forceRefreshDelay = 1000;
22
   var forceRefreshTimeout;
22
   var forceRefreshTimeout;
23
+  var checkPostMessageTimeout;
23
 
24
 
24
   function updateSize(event) {
25
   function updateSize(event) {
25
     if (
26
     if (
26
       !window.hasOwnProperty('ReactNativeWebView') || 
27
       !window.hasOwnProperty('ReactNativeWebView') || 
27
       !window.ReactNativeWebView.hasOwnProperty('postMessage')
28
       !window.ReactNativeWebView.hasOwnProperty('postMessage')
28
     ) {
29
     ) {
29
-      setTimeout(updateSize, 200);
30
+      checkPostMessageTimeout = setTimeout(updateSize, 200);
30
       return;
31
       return;
31
     }
32
     }
33
+    clearTimeout(checkPostMessageTimeout);
32
     height = ${element}.offsetHeight || document.documentElement.offsetHeight;
34
     height = ${element}.offsetHeight || document.documentElement.offsetHeight;
33
     width = ${element}.offsetWidth || document.documentElement.offsetWidth;
35
     width = ${element}.offsetWidth || document.documentElement.offsetWidth;
34
     var needScale = width > screen.width;
36
     var needScale = width > screen.width;
121
 ${html}
123
 ${html}
122
 <script>
124
 <script>
123
 // prevents code colissions with global scope
125
 // prevents code colissions with global scope
124
-(() => {
126
+(function() {
125
   ${script}
127
   ${script}
126
 })();
128
 })();
127
 </script>
129
 </script>