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

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

9
   "dependencies": {
9
   "dependencies": {
10
     "react": "15.4.2",
10
     "react": "15.4.2",
11
     "react-native": "0.40.0",
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
   "devDependencies": {
14
   "devDependencies": {
15
     "babel-jest": "18.0.0",
15
     "babel-jest": "18.0.0",

+ 1
- 1
package.json View File

1
 {
1
 {
2
   "name": "react-native-autoheightwebview",
2
   "name": "react-native-autoheightwebview",
3
-  "version": "0.0.11",
3
+  "version": "0.0.12",
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": ["android/", "autoHeightWebView/"],
6
   "files": ["android/", "autoHeightWebView/"],