Javascript 反应本机动态网络视图高度
我有WebView内容,它根据内容的数量改变高度。 因此,我找到了一种方法,可以通过导航StateChange上的document.title属性获取内容的高度。 看起来像这样:Javascript 反应本机动态网络视图高度,javascript,webview,reactjs,react-native,Javascript,Webview,Reactjs,React Native,我有WebView内容,它根据内容的数量改变高度。 因此,我找到了一种方法,可以通过导航StateChange上的document.title属性获取内容的高度。 看起来像这样: let html = '<!DOCTYPE html><html><body><script>document.title = document.height;</script></body></html>'; 在实际的WebView
let html = '<!DOCTYPE html><html><body><script>document.title = document.height;</script></body></html>';
在实际的WebView渲染中,我执行以下操作:
<WebView style={this._setWebviewHeight()}
automaticallyAdjustContentInsets={false}
scrollEnabled={false}
onNavigationStateChange={this.onNavigationStateChange.bind(this)}
html={html}>
</WebView>
在这种情况下,我得到了错误,我无法通过状态获得内容的高度。那我该怎么办
解决方案的想法来源于此:我在一个RN第三方库的实现中找到了解决方案。 以下是它的链接: 用这种方法,一切都很好 试试这个库:
它可以在iOS和Android上运行您会遇到什么错误?它返回未定义的
<WebView style={this._setWebviewHeight()}
automaticallyAdjustContentInsets={false}
scrollEnabled={false}
onNavigationStateChange={this.onNavigationStateChange.bind(this)}
html={html}>
</WebView>
_setWebviewHeight() {
return {
height: this.state.height,
padding: 20,
}
}