Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 反应本机动态网络视图高度_Javascript_Webview_Reactjs_React Native - Fatal编程技术网

Javascript 反应本机动态网络视图高度

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

我有WebView内容,它根据内容的数量改变高度。 因此,我找到了一种方法,可以通过导航StateChange上的document.title属性获取内容的高度。 看起来像这样:

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