Parcourir la source

add hasIframe property to support iframe on iOS; bump version to 0.3.4

iou90 il y a 6 ans
Parent
révision
2449cc93a2
4 fichiers modifiés avec 28 ajouts et 6 suppressions
  1. 2
    0
      README.md
  2. 23
    3
      autoHeightWebView/index.ios.js
  3. 1
    1
      demo/yarn.lock
  4. 2
    2
      package.json

+ 2
- 0
README.md Voir le fichier

23
 ```javascript
23
 ```javascript
24
 <AutoHeightWebView
24
 <AutoHeightWebView
25
     onHeightUpdated={height => console.log(height)},
25
     onHeightUpdated={height => console.log(height)},
26
+    // if page contains iframe on iOS, use a specific script for it
27
+    hasIframe={true}
26
     /*
28
     /*
27
     if set to false may cause some layout issues (width of container not fit for screen) on android
29
     if set to false may cause some layout issues (width of container not fit for screen) on android
28
     if set to true may cause some layout issues (smaller font size) on ios
30
     if set to true may cause some layout issues (smaller font size) on ios

+ 23
- 3
autoHeightWebView/index.ios.js Voir le fichier

15
 
15
 
16
 export default class AutoHeightWebView extends PureComponent {
16
 export default class AutoHeightWebView extends PureComponent {
17
     static propTypes = {
17
     static propTypes = {
18
+        hasIframe: PropTypes.bool,
18
         source: WebView.propTypes.source,
19
         source: WebView.propTypes.source,
19
         onHeightUpdated: PropTypes.func,
20
         onHeightUpdated: PropTypes.func,
20
         customScript: PropTypes.string,
21
         customScript: PropTypes.string,
47
         if (this.props.enableAnimation) {
48
         if (this.props.enableAnimation) {
48
             this.opacityAnimatedValue = new Animated.Value(0);
49
             this.opacityAnimatedValue = new Animated.Value(0);
49
         }
50
         }
50
-        const initialScript = props.files ? this.appendFilesToHead(props.files, BaseScript) : BaseScript;
51
+        const initialScript = props.files ? this.appendFilesToHead(props.files, props.hasIframe ? IframeBaseScript : BaseScript) : props.hasIframe ? IframeBaseScript : BaseScript;
51
         this.state = {
52
         this.state = {
52
             height: 0,
53
             height: 0,
53
             script: initialScript
54
             script: initialScript
55
     }
56
     }
56
 
57
 
57
     componentWillReceiveProps(nextProps) {
58
     componentWillReceiveProps(nextProps) {
58
-        let currentScript = BaseScript;
59
+        let currentScript = nextProps.hasIframe ? IframeBaseScript : BaseScript;
59
         if (nextProps.files) {
60
         if (nextProps.files) {
60
-            currentScript = this.appendFilesToHead(nextProps.files, BaseScript);
61
+            currentScript = this.appendFilesToHead(nextProps.files, nextProps.hasIframe ? IframeBaseScript : BaseScript);
61
         }
62
         }
62
         this.setState({ script: currentScript });
63
         this.setState({ script: currentScript });
63
     }
64
     }
162
         window.addEventListener('load', updateHeight);
163
         window.addEventListener('load', updateHeight);
163
         window.addEventListener('resize', updateHeight);
164
         window.addEventListener('resize', updateHeight);
164
     } ());
165
     } ());
166
+    `;
167
+
168
+const IframeBaseScript =
169
+    `
170
+    ; 
171
+    (function () {
172
+        var i = 0;
173
+        var height = 0;
174
+        function updateHeight() {
175
+            if(document.body.offsetHeight !== height) {
176
+                height = document.body.firstChild.clientHeight;
177
+                document.title = document.body.firstChild.clientHeight;
178
+                window.location.hash = ++i;
179
+            }
180
+        }
181
+        updateHeight();
182
+        window.addEventListener('load', updateHeight);
183
+        window.addEventListener('resize', updateHeight);
184
+    } ());
165
     `;
185
     `;

+ 1
- 1
demo/yarn.lock Voir le fichier

3241
     ws "^2.0.3"
3241
     ws "^2.0.3"
3242
 
3242
 
3243
 react-native-autoheight-webview@../:
3243
 react-native-autoheight-webview@../:
3244
-  version "0.3.3"
3244
+  version "0.3.4"
3245
   dependencies:
3245
   dependencies:
3246
     immutable "^3.8.1"
3246
     immutable "^3.8.1"
3247
     prop-types "^15.5.10"
3247
     prop-types "^15.5.10"

+ 2
- 2
package.json Voir le fichier

1
 {
1
 {
2
   "name": "react-native-autoheight-webview",
2
   "name": "react-native-autoheight-webview",
3
-  "version": "0.3.3",
3
+  "version": "0.3.4",
4
   "description": "An auto height webview for React Native",
4
   "description": "An auto height webview for React Native",
5
   "main": "autoHeightWebView",
5
   "main": "autoHeightWebView",
6
   "files": [
6
   "files": [
30
     "immutable": "^3.8.1",
30
     "immutable": "^3.8.1",
31
     "prop-types": "^15.5.10"
31
     "prop-types": "^15.5.10"
32
   }
32
   }
33
-}
33
+}