Browse Source

Only insert wrapper element once

Jørgen Orehøj Erichsen 6 years ago
parent
commit
4aa522e38e
1 changed files with 17 additions and 15 deletions
  1. 17
    15
      autoHeightWebView/index.ios.js

+ 17
- 15
autoHeightWebView/index.ios.js View File

@@ -205,24 +205,26 @@ function getBaseScript(style) {
205 205
     ;
206 206
     ${getCurrentSize}
207 207
     (function () {
208
-        var height = 0;
209
-        var width = ${getWidth(style)};
210
-        var wrapper = document.createElement('div');
211
-        wrapper.id = 'rnahw-wrapper';
212
-        while (document.body.firstChild instanceof Node) {
213
-            wrapper.appendChild(document.body.firstChild);
214
-        }
215
-        document.body.appendChild(wrapper);
216
-        function updateSize() {
217
-            if(document.body.offsetHeight !== height || document.body.offsetWidth !== width) {
218
-                var size = getSize(wrapper);
219
-                height = size.height;
220
-                width = size.width;
221
-                document.title = height.toString() + ',' + width.toString();
208
+      if (!document.getElementById("rnahw-wrapper")) { 
209
+          var height = 0;
210
+          var width = ${getWidth(style)};
211
+          var wrapper = document.createElement('div');
212
+          wrapper.id = 'rnahw-wrapper';
213
+          while (document.body.firstChild instanceof Node) {
214
+              wrapper.appendChild(document.body.firstChild);
215
+          }
216
+          document.body.appendChild(wrapper);
217
+          function updateSize() {
218
+            if (document.body.offsetHeight !== height || document.body.offsetWidth !== width) {
219
+               var size = getSize(wrapper);
220
+               height = size.height;
221
+               width = size.width;
222
+               document.title = height.toString() + ',' + width.toString();
222 223
             }
223
-        }
224
+          }
224 225
         ${commonScript}
225 226
         ${domMutationObserveScript}
227
+        }
226 228
     } ());
227 229
     `;
228 230
 }