Browse Source

fix the iframe issue & clean up code style

iou90 6 years ago
parent
commit
62acbcedce
3 changed files with 13 additions and 18 deletions
  1. 1
    1
      autoHeightWebView/common.js
  2. 10
    14
      autoHeightWebView/index.android.js
  3. 2
    3
      autoHeightWebView/index.ios.js

+ 1
- 1
autoHeightWebView/common.js View File

@@ -70,7 +70,7 @@ function getInjectedSource(html, script) {
70 70
 export function getScript(props, getBaseScript, getIframeBaseScript) {
71 71
   const { hasIframe, files, customStyle, customScript, style } = getReloadRelatedData(props);
72 72
   const baseScript = getBaseScript(style);
73
-  let script = hasIframe ? getIframeBaseScript(style) : baseScript;
73
+  let script = hasIframe && getIframeBaseScript ? getIframeBaseScript(style) : baseScript;
74 74
   script = files ? appendFilesToHead(files, baseScript) : baseScript;
75 75
   script = appendStylesToHead(customStyle, script);
76 76
   customScript && (script = customScript + script);

+ 10
- 14
autoHeightWebView/index.android.js View File

@@ -109,7 +109,7 @@ export default class AutoHeightWebView extends PureComponent {
109 109
     };
110 110
     if (enableAnimation) {
111 111
       Object.assign(state, {
112
-        heightValue: new Animated.Value(initHeight + heightOffset),
112
+        heightValue: new Animated.Value(initHeight ? initHeight + heightOffset : 0),
113 113
         widthValue: new Animated.Value(initWidth)
114 114
       });
115 115
     }
@@ -154,7 +154,7 @@ export default class AutoHeightWebView extends PureComponent {
154 154
       if (enableAnimation) {
155 155
         Animated.parallel([
156 156
           Animated.timing(heightValue, {
157
-            toValue: height + heightOffset,
157
+            toValue: height ? height + heightOffset : 0,
158 158
             easing: animationEasing,
159 159
             duration: animationDuration
160 160
           }),
@@ -326,12 +326,10 @@ const getBaseScript = isBelowKitKat
326 326
     ${commonScript}
327 327
     var width = ${getWidth(style)};
328 328
     function updateSize() {
329
-      if(document.body.offsetHeight !== height || document.body.offsetWidth !== width) {
330
-        var size = getSize(document.body.firstChild); 
331
-        height = size.height;
332
-        width = size.width;
333
-        AutoHeightWebView.send(JSON.stringify({ width, height }));
334
-      }
329
+      var size = getSize(document.body.firstChild); 
330
+      height = size.height;
331
+      width = size.width;
332
+      AutoHeightWebView.send(JSON.stringify({ width, height }));
335 333
     }
336 334
     (function () {
337 335
       AutoHeightWebView.onMessage = updateSize;
@@ -345,12 +343,10 @@ const getBaseScript = isBelowKitKat
345 343
     ${commonScript}
346 344
     var width = ${getWidth(style)};
347 345
     function updateSize() {
348
-      if(document.body.offsetHeight !== height || document.body.offsetWidth !== width) {
349
-        var size = getSize(document.body.firstChild); 
350
-        height = size.height;
351
-        width = size.width;
352
-        window.postMessage(JSON.stringify({ width, height }), '*');
353
-      }
346
+      var size = getSize(document.body.firstChild); 
347
+      height = size.height;
348
+      width = size.width;
349
+      window.postMessage(JSON.stringify({ width, height }), '*');
354 350
     }
355 351
     (function () {
356 352
       document.addEventListener("message", updateSize);

+ 2
- 3
autoHeightWebView/index.ios.js View File

@@ -2,7 +2,7 @@
2 2
 
3 3
 import React, { PureComponent } from 'react';
4 4
 
5
-import { Animated, Easing, StyleSheet, ViewPropTypes, WebView } from 'react-native';
5
+import { Animated, StyleSheet, ViewPropTypes, WebView } from 'react-native';
6 6
 
7 7
 import PropTypes from 'prop-types';
8 8
 
@@ -13,8 +13,7 @@ import {
13 13
   isSizeChanged,
14 14
   handleSizeUpdated,
15 15
   domMutationObserveScript,
16
-  getCurrentSize,
17
-  getRenderSize
16
+  getCurrentSize
18 17
 } from './common.js';
19 18
 
20 19
 import momoize from './momoize';