|
@@ -15,6 +15,7 @@ import PropTypes from 'prop-types';
|
15
|
15
|
|
16
|
16
|
export default class AutoHeightWebView extends PureComponent {
|
17
|
17
|
static propTypes = {
|
|
18
|
+ hasIframe: PropTypes.bool,
|
18
|
19
|
source: WebView.propTypes.source,
|
19
|
20
|
onHeightUpdated: PropTypes.func,
|
20
|
21
|
customScript: PropTypes.string,
|
|
@@ -47,7 +48,7 @@ export default class AutoHeightWebView extends PureComponent {
|
47
|
48
|
if (this.props.enableAnimation) {
|
48
|
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
|
52
|
this.state = {
|
52
|
53
|
height: 0,
|
53
|
54
|
script: initialScript
|
|
@@ -55,9 +56,9 @@ export default class AutoHeightWebView extends PureComponent {
|
55
|
56
|
}
|
56
|
57
|
|
57
|
58
|
componentWillReceiveProps(nextProps) {
|
58
|
|
- let currentScript = BaseScript;
|
|
59
|
+ let currentScript = nextProps.hasIframe ? IframeBaseScript : BaseScript;
|
59
|
60
|
if (nextProps.files) {
|
60
|
|
- currentScript = this.appendFilesToHead(nextProps.files, BaseScript);
|
|
61
|
+ currentScript = this.appendFilesToHead(nextProps.files, nextProps.hasIframe ? IframeBaseScript : BaseScript);
|
61
|
62
|
}
|
62
|
63
|
this.setState({ script: currentScript });
|
63
|
64
|
}
|
|
@@ -162,4 +163,23 @@ const BaseScript =
|
162
|
163
|
window.addEventListener('load', updateHeight);
|
163
|
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
|
`;
|