|
@@ -31,8 +31,7 @@ export default class AutoHeightWebView extends Component {
|
31
|
31
|
}
|
32
|
32
|
|
33
|
33
|
componentDidMount() {
|
34
|
|
- this.stopInterval = false;
|
35
|
|
- this.intervalPostMessage();
|
|
34
|
+ this.startInterval();
|
36
|
35
|
}
|
37
|
36
|
|
38
|
37
|
componentWillReceiveProps(nextProps) {
|
|
@@ -59,7 +58,7 @@ export default class AutoHeightWebView extends Component {
|
59
|
58
|
if (this.htmlHasChanged) {
|
60
|
59
|
if (this.state.isOnLoadingStart && this.state.height === 0 && this.state.heightOffset === 0) {
|
61
|
60
|
this.stopInterval = false;
|
62
|
|
- this.intervalPostMessage();
|
|
61
|
+ this.startInterval();
|
63
|
62
|
this.htmlHasChanged = false;
|
64
|
63
|
this.setState({ isOnLoadingStart: false });
|
65
|
64
|
}
|
|
@@ -67,7 +66,7 @@ export default class AutoHeightWebView extends Component {
|
67
|
66
|
}
|
68
|
67
|
|
69
|
68
|
componentWillUnmount() {
|
70
|
|
- clearInterval(this.interval);
|
|
69
|
+ this.stopInterval();
|
71
|
70
|
}
|
72
|
71
|
|
73
|
72
|
onLoadingStart() {
|
|
@@ -84,7 +83,8 @@ export default class AutoHeightWebView extends Component {
|
84
|
83
|
);
|
85
|
84
|
};
|
86
|
85
|
|
87
|
|
- intervalPostMessage() {
|
|
86
|
+ startInterval() {
|
|
87
|
+ this.stopInterval = false;
|
88
|
88
|
this.interval = setInterval(() => {
|
89
|
89
|
if (!this.stopInterval) {
|
90
|
90
|
this.postMessage('getBodyHeight');
|
|
@@ -92,11 +92,15 @@ export default class AutoHeightWebView extends Component {
|
92
|
92
|
}, 205);
|
93
|
93
|
}
|
94
|
94
|
|
|
95
|
+ stopInterval() {
|
|
96
|
+ this.stopInterval = true;
|
|
97
|
+ clearInterval(this.interval);
|
|
98
|
+ }
|
|
99
|
+
|
95
|
100
|
onMessage(e) {
|
96
|
101
|
const height = parseInt(e.nativeEvent.data);
|
97
|
102
|
if (height) {
|
98
|
|
- this.stopInterval = true;
|
99
|
|
- clearInterval(this.interval);
|
|
103
|
+ this.stopInterval();
|
100
|
104
|
this.setState({
|
101
|
105
|
heightOffset: this.props.heightOffset,
|
102
|
106
|
height
|