react-native动态获取网页高度

很简单,上代码!

     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,
        }} />

你可能感兴趣的:(react-native动态获取网页高度)