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
This commit is contained in:
Tyler Alves
2019-09-23 10:44:26 +02:00
committed by Thibault Malbranche
parent ef4c2d57ea
commit b296f24dd2
+16 -3
View File
@@ -61,6 +61,8 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
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<AndroidWebViewProps, State> {
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<AndroidWebViewProps, State> {
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<AndroidWebViewProps, State> {
onLoadingProgress = (event: WebViewProgressEvent) => {
const { onLoadProgress } = this.props;
const { nativeEvent: { progress } } = event;
if (progress === 1) {
this.setState({
viewState: 'IDLE',
});
}
if (onLoadProgress) {
onLoadProgress(event);
}