很簡單勘畔,上代碼蜓氨!
<WebView
ref={ref => this.webView = ref}
bounces={false}
scrollEnabled={false}
source={{
html: detail,
baseUrl: webViewBaseUrl,
}}
scalesPageToFit
automaticallyAdjustContentInsets
onLoadEnd={() => {
// 加載結(jié)束后動態(tài)獲取網(wǎng)頁高度
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,
}} />