Преглед изворни кода

fix the iframe issue & clean up code style

iou90 пре 6 година
родитељ
комит
62acbcedce
3 измењених фајлова са 13 додато и 18 уклоњено
  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 Прегледај датотеку

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

+ 10
- 14
autoHeightWebView/index.android.js Прегледај датотеку

109
     };
109
     };
110
     if (enableAnimation) {
110
     if (enableAnimation) {
111
       Object.assign(state, {
111
       Object.assign(state, {
112
-        heightValue: new Animated.Value(initHeight + heightOffset),
112
+        heightValue: new Animated.Value(initHeight ? initHeight + heightOffset : 0),
113
         widthValue: new Animated.Value(initWidth)
113
         widthValue: new Animated.Value(initWidth)
114
       });
114
       });
115
     }
115
     }
154
       if (enableAnimation) {
154
       if (enableAnimation) {
155
         Animated.parallel([
155
         Animated.parallel([
156
           Animated.timing(heightValue, {
156
           Animated.timing(heightValue, {
157
-            toValue: height + heightOffset,
157
+            toValue: height ? height + heightOffset : 0,
158
             easing: animationEasing,
158
             easing: animationEasing,
159
             duration: animationDuration
159
             duration: animationDuration
160
           }),
160
           }),
326
     ${commonScript}
326
     ${commonScript}
327
     var width = ${getWidth(style)};
327
     var width = ${getWidth(style)};
328
     function updateSize() {
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
     (function () {
334
     (function () {
337
       AutoHeightWebView.onMessage = updateSize;
335
       AutoHeightWebView.onMessage = updateSize;
345
     ${commonScript}
343
     ${commonScript}
346
     var width = ${getWidth(style)};
344
     var width = ${getWidth(style)};
347
     function updateSize() {
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
     (function () {
351
     (function () {
356
       document.addEventListener("message", updateSize);
352
       document.addEventListener("message", updateSize);

+ 2
- 3
autoHeightWebView/index.ios.js Прегледај датотеку

2
 
2
 
3
 import React, { PureComponent } from 'react';
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
 import PropTypes from 'prop-types';
7
 import PropTypes from 'prop-types';
8
 
8
 
13
   isSizeChanged,
13
   isSizeChanged,
14
   handleSizeUpdated,
14
   handleSizeUpdated,
15
   domMutationObserveScript,
15
   domMutationObserveScript,
16
-  getCurrentSize,
17
-  getRenderSize
16
+  getCurrentSize
18
 } from './common.js';
17
 } from './common.js';
19
 
18
 
20
 import momoize from './momoize';
19
 import momoize from './momoize';