From b296f24dd29aadc0c89333c9b44cccaba203e2d4 Mon Sep 17 00:00:00 2001 From: Tyler Alves Date: Mon, 23 Sep 2019 01:44:26 -0700 Subject: [PATCH] fix(android): redirect and renderLoading issues (#548) * Filter out extra onLoadProgress calls; add url to onLoadProgress * remove note about onLoadProgress not having the url property in docs * fix redirect renderLoading on android by checking that onLoadingFinish and onLoadingStart urls are equal * add fallback to set viewState to idle when progress is 1 --- src/WebView.android.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/WebView.android.tsx b/src/WebView.android.tsx index 1151e4d..f183173 100644 --- a/src/WebView.android.tsx +++ b/src/WebView.android.tsx @@ -61,6 +61,8 @@ class WebView extends React.Component { return NativeModules.RNCWebView.isFileUploadSupported(); }; + startUrl: string | null = null; + state: State = { viewState: this.props.startInLoadingState ? 'LOADING' : 'IDLE', lastErrorEvent: null, @@ -156,6 +158,8 @@ class WebView extends React.Component { onLoadingStart = (event: WebViewNavigationEvent) => { const { onLoadStart } = this.props; + const { nativeEvent: { url } } = event; + this.startUrl = url; if (onLoadStart) { onLoadStart(event); } @@ -188,15 +192,18 @@ class WebView extends React.Component { onLoadingFinish = (event: WebViewNavigationEvent) => { const { onLoad, onLoadEnd } = this.props; + const { nativeEvent: { url } } = event; if (onLoad) { onLoad(event); } if (onLoadEnd) { onLoadEnd(event); } - this.setState({ - viewState: 'IDLE', - }); + if (url === this.startUrl) { + this.setState({ + viewState: 'IDLE', + }); + } this.updateNavigationState(event); }; @@ -209,6 +216,12 @@ class WebView extends React.Component { onLoadingProgress = (event: WebViewProgressEvent) => { const { onLoadProgress } = this.props; + const { nativeEvent: { progress } } = event; + if (progress === 1) { + this.setState({ + viewState: 'IDLE', + }); + } if (onLoadProgress) { onLoadProgress(event); }