【发布时间】: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() 事件?
【问题讨论】:
-
你能分享
setTimeoutInjection和pageLoadEnd -
函数在你的代码中做了什么?
-
@aytek 请在下面找到 setTimeoutInjection 的代码,pageLoadEnd 在页面加载后注入JS。 const setTimeoutInjection =
setTimeout(function(){RCI.postLogin.handleSessionExpirationWarningResponse = function(response){ }; true;},0); -
@hongdeveloper 什么意思?
-
请编辑您的问题并在此处提供更多信息。您需要分享您的组件的所有代码,以便我们了解问题。
标签: react-native webview onload-event