【问题标题】:React Native Webview OnLoad called twiceReact Native Webview OnLoad 调用了两次
【发布时间】:2020-07-07 15:50:26
【问题描述】:

React native webview onLoad(), onLoadStart(), onLoadEnd() 都调用了两次

在下面找到我的代码

<WebView
  source={{
    uri,
  }}
  // eslint-disable-next-line no-return-assign
  ref={ref => (this.webview = ref)}
  startInLoadingState
  style={{ marginTop: 0, flex: 1 }}
  renderLoading={() => this.displaySpinner()}
  javaScriptEnabled
  geolocationEnabled
  injectedJavaScript={setTimeoutInjection}
  onLoad={() => this.pageLoadEnd(renderTime)}
  onLoadStart={() => {
    Alert.alert('On load event', `Loading time : ${Date.now() - renderTime}`)
  }}
  onLoadEnd={() => {
    Alert.alert('On load event End', `Loading time : ${Date.now() - renderTime}`)
  }}
  sharedCookiesEnabled
  useWebKit
  onNavigationStateChange={this._onNavigationStateChange.bind(this)}
/>

我应该改变什么以便只调用一次 onload() 事件?

【问题讨论】:

  • 你能分享setTimeoutInjectionpageLoadEnd
  • 函数在你的代码中做了什么?
  • @aytek 请在下面找到 setTimeoutInjection 的代码,pageLoadEnd 在页面加载后注入JS。 const setTimeoutInjection = setTimeout(function(){RCI.postLogin.handleSessionExpirationWarningResponse = function(response){ }; true;},0);
  • @hongdeveloper 什么意思?
  • 请编辑您的问题并在此处提供更多信息。您需要分享您的组件的所有代码,以便我们了解问题。

标签: react-native webview onload-event


【解决方案1】:

我遇到了这个问题,结果是源属性中 uri 末尾缺少一个简单的“/”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-26
    • 2020-08-18
    • 2019-10-11
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多