【问题标题】:React Native dynamic webview heightReact Native 动态 webview 高度
【发布时间】:2015-12-24 14:32:36
【问题描述】:

我有 WebView 内容,它会根据内容的数量改变它的高度。 所以我找到了一种方法,如何通过document.title属性onNavigationStateChange来获取内容的高度。 看起来像这样:

let html = '<!DOCTYPE html><html><body><script>document.title = document.height;</script></body></html>';

在 onNavigationStateChange 上

onNavigationStateChange(navState) {
  this.setState({
    height: navState.title
  });
  console.log("DATA");
  console.log(this.state.height)
}

在我做的实际 WebView 渲染中:

<WebView style={this._setWebviewHeight()}
           automaticallyAdjustContentInsets={false}
           scrollEnabled={false}
           onNavigationStateChange={this.onNavigationStateChange.bind(this)}
           html={html}>
</WebView>

地点:

_setWebviewHeight() {
 return {
  height: this.state.height,
  padding: 20,
 }
}

在这种情况下,我遇到了错误,我无法通过状态获取内容的高度。那我该怎么办?

解决思路取自这里:React native: Is it possible to have the height of a html content in a webview?

【问题讨论】:

  • 你得到什么错误?

标签: javascript webview reactjs react-native


【解决方案1】:

我在 RN 第三方库之一的实现中找到了解决方案。 这是它的链接: https://github.com/danrigsby/react-native-web-container/blob/master/index.js

使用这种方法,一切都很好。

【讨论】:

  • 返回未定义
【解决方案2】:

试试这个库:https://github.com/iou90/react-native-autoheight-webview 它适用于 iOS 和 Android

【讨论】:

    猜你喜欢
    • 2020-06-09
    • 1970-01-01
    • 2020-08-07
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 2021-01-14
    • 2013-03-13
    相关资源
    最近更新 更多