Browse Source

fix not clear setinterval on android; update version to 0.0.12

iou90 7 years ago
parent
commit
5751a6b8c9

+ 6
- 2
autoHeightWebView/index.android.js View File

@@ -31,6 +31,7 @@ export default class AutoHeightWebView extends Component {
31 31
     }
32 32
 
33 33
     componentDidMount() {
34
+        this.stopInterval = false;
34 35
         this.intervalPostMessage();
35 36
     }
36 37
 
@@ -57,6 +58,7 @@ export default class AutoHeightWebView extends Component {
57 58
     componentDidUpdate(prevProps, prevState) {
58 59
         if (this.htmlHasChanged) {
59 60
             if (this.state.isOnLoadingStart && this.state.height === 0 && this.state.heightOffset === 0) {
61
+                this.stopInterval = false;
60 62
                 this.intervalPostMessage();
61 63
                 this.htmlHasChanged = false;
62 64
                 this.setState({ isOnLoadingStart: false });
@@ -84,14 +86,16 @@ export default class AutoHeightWebView extends Component {
84 86
 
85 87
     intervalPostMessage() {
86 88
         this.interval = setInterval(() => {
87
-            this.postMessage('getBodyHeight');
89
+            if (!this.stopInterval) {
90
+                this.postMessage('getBodyHeight');
91
+            }
88 92
         }, 205);
89 93
     }
90 94
 
91 95
     onMessage(e) {
92 96
         const height = parseInt(e.nativeEvent.data);
93
-        console.log(height);
94 97
         if (height) {
98
+            this.stopInterval = true;
95 99
             clearInterval(this.interval);
96 100
             this.setState({
97 101
                 heightOffset: this.props.heightOffset,

+ 1
- 1
examples/autoHeightWebViewExplorer/package.json View File

@@ -9,7 +9,7 @@
9 9
   "dependencies": {
10 10
     "react": "15.4.2",
11 11
     "react-native": "0.40.0",
12
-    "react-native-autoheightwebview": "0.0.11"
12
+    "react-native-autoheightwebview": "file:///Users/iou90/Works/Lab/react-native-autoheightwebview"
13 13
   },
14 14
   "devDependencies": {
15 15
     "babel-jest": "18.0.0",

+ 1
- 1
package.json View File

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "react-native-autoheightwebview",
3
-  "version": "0.0.11",
3
+  "version": "0.0.12",
4 4
   "description": "An auto height webview for React Native",
5 5
   "main": "autoHeightWebView",
6 6
   "files": ["android/", "autoHeightWebView/"],