react-native动态获取网页高度

很简单,上代码!

    <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,
        }} />
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容