很简单,上代码!
<WebView
ref={ref => this.webView = ref}
bounces={false}
scrollEnabled={false}
source={{
html: detail,
baseUrl: webViewBaseUrl,
}}
scalesPageToFit
automaticallyAdjustContentInsets
onLoadEnd={() => {
// 加载结束后动态获取网页高度
const script = `window.postMessage(document.body.scrollHeight)`;
this.webView && this.webView.injectJavaScript(script);
}}
onMessage={event => {
// 获取高度后改变webView高度
const webHeight = parseFloat(event.nativeEvent.data);
dispatch({
type: 'goods/updateState',
payload: { webHeight },
});
}}
style={{
height: webHeight,
margin: 10,
}} />
网友评论