美文网首页React Native学习
react-native动态获取网页高度

react-native动态获取网页高度

作者: 逝水流无痕 | 来源:发表于2018-08-20 15:53 被阅读6次

很简单,上代码!

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

相关文章

网友评论

    本文标题:react-native动态获取网页高度

    本文链接:https://www.haomeiwen.com/subject/kxsliftx.html