|
@@ -6,7 +6,7 @@ import { Animated, StyleSheet, ViewPropTypes, WebView } from 'react-native';
|
6
|
6
|
|
7
|
7
|
import PropTypes from 'prop-types';
|
8
|
8
|
|
9
|
|
-import { getWidth, getScript, handleSizeUpdated, domMutationObserveScript } from './common.js';
|
|
9
|
+import { needChangeSource, getWidth, getScript, handleSizeUpdated, domMutationObserveScript } from './common.js';
|
10
|
10
|
|
11
|
11
|
export default class AutoHeightWebView extends PureComponent {
|
12
|
12
|
static propTypes = {
|
|
@@ -66,6 +66,7 @@ export default class AutoHeightWebView extends PureComponent {
|
66
|
66
|
height && this.setState({ height });
|
67
|
67
|
}
|
68
|
68
|
this.setState({ script: getScript(nextProps, getBaseScript, getIframeBaseScript) });
|
|
69
|
+ this.needChangeSource = needChangeSource(nextProps, this.props);
|
69
|
70
|
}
|
70
|
71
|
|
71
|
72
|
handleNavigationStateChange = navState => {
|
|
@@ -116,11 +117,14 @@ export default class AutoHeightWebView extends PureComponent {
|
116
|
117
|
enableAnimation,
|
117
|
118
|
source,
|
118
|
119
|
heightOffset,
|
119
|
|
- customScript,
|
120
|
120
|
style,
|
121
|
121
|
scrollEnabled
|
122
|
122
|
} = this.props;
|
123
|
|
- const webViewSource = Object.assign({}, source, { baseUrl: 'web/' });
|
|
123
|
+ let webViewSource = Object.assign({}, source, { baseUrl: 'web/' });
|
|
124
|
+ if (this.needChangeSource) {
|
|
125
|
+ this.changeSourceFlag = !this.changeSourceFlag;
|
|
126
|
+ webViewSource = Object.assign(webViewSource, { changeSourceFlag: this.changeSourceFlag });
|
|
127
|
+ }
|
124
|
128
|
return (
|
125
|
129
|
<Animated.View
|
126
|
130
|
style={[
|
|
@@ -141,8 +145,8 @@ export default class AutoHeightWebView extends PureComponent {
|
141
|
145
|
onLoadEnd={onLoadEnd}
|
142
|
146
|
onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
|
143
|
147
|
style={styles.webView}
|
144
|
|
- injectedJavaScript={script + customScript}
|
145
|
|
- scrollEnabled={scrollEnabled}
|
|
148
|
+ injectedJavaScript={script}
|
|
149
|
+ scrollEnabled={!!scrollEnabled}
|
146
|
150
|
scalesPageToFit={scalesPageToFit}
|
147
|
151
|
source={webViewSource}
|
148
|
152
|
onNavigationStateChange={this.handleNavigationStateChange}
|
|
@@ -184,7 +188,6 @@ function getBaseScript(style) {
|
184
|
188
|
;
|
185
|
189
|
${getSize}
|
186
|
190
|
(function () {
|
187
|
|
- var i = 0;
|
188
|
191
|
var height = 0;
|
189
|
192
|
var width = ${getWidth(style)};
|
190
|
193
|
var wrapper = document.createElement('div');
|
|
@@ -199,7 +202,6 @@ function getBaseScript(style) {
|
199
|
202
|
height = size.height;
|
200
|
203
|
width = size.width;
|
201
|
204
|
document.title = height.toString() + ',' + width.toString();
|
202
|
|
- window.location.hash = ++i;
|
203
|
205
|
}
|
204
|
206
|
}
|
205
|
207
|
${commonScript}
|
|
@@ -213,7 +215,6 @@ function getIframeBaseScript(style) {
|
213
|
215
|
;
|
214
|
216
|
${getSize}
|
215
|
217
|
(function () {
|
216
|
|
- var i = 0;
|
217
|
218
|
var height = 0;
|
218
|
219
|
var width = ${getWidth(style)};
|
219
|
220
|
function updateSize() {
|
|
@@ -222,7 +223,6 @@ function getIframeBaseScript(style) {
|
222
|
223
|
height = size.height;
|
223
|
224
|
width = size.width;
|
224
|
225
|
document.title = height.toString() + ',' + width.toString();
|
225
|
|
- window.location.hash = ++i;
|
226
|
226
|
}
|
227
|
227
|
}
|
228
|
228
|
${commonScript}
|