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:
parent
ef4c2d57ea
commit
b296f24dd2
|
@ -61,6 +61,8 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
|
||||||
return NativeModules.RNCWebView.isFileUploadSupported();
|
return NativeModules.RNCWebView.isFileUploadSupported();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
startUrl: string | null = null;
|
||||||
|
|
||||||
state: State = {
|
state: State = {
|
||||||
viewState: this.props.startInLoadingState ? 'LOADING' : 'IDLE',
|
viewState: this.props.startInLoadingState ? 'LOADING' : 'IDLE',
|
||||||
lastErrorEvent: null,
|
lastErrorEvent: null,
|
||||||
|
@ -156,6 +158,8 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
|
||||||
|
|
||||||
onLoadingStart = (event: WebViewNavigationEvent) => {
|
onLoadingStart = (event: WebViewNavigationEvent) => {
|
||||||
const { onLoadStart } = this.props;
|
const { onLoadStart } = this.props;
|
||||||
|
const { nativeEvent: { url } } = event;
|
||||||
|
this.startUrl = url;
|
||||||
if (onLoadStart) {
|
if (onLoadStart) {
|
||||||
onLoadStart(event);
|
onLoadStart(event);
|
||||||
}
|
}
|
||||||
|
@ -188,15 +192,18 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
|
||||||
|
|
||||||
onLoadingFinish = (event: WebViewNavigationEvent) => {
|
onLoadingFinish = (event: WebViewNavigationEvent) => {
|
||||||
const { onLoad, onLoadEnd } = this.props;
|
const { onLoad, onLoadEnd } = this.props;
|
||||||
|
const { nativeEvent: { url } } = event;
|
||||||
if (onLoad) {
|
if (onLoad) {
|
||||||
onLoad(event);
|
onLoad(event);
|
||||||
}
|
}
|
||||||
if (onLoadEnd) {
|
if (onLoadEnd) {
|
||||||
onLoadEnd(event);
|
onLoadEnd(event);
|
||||||
}
|
}
|
||||||
|
if (url === this.startUrl) {
|
||||||
this.setState({
|
this.setState({
|
||||||
viewState: 'IDLE',
|
viewState: 'IDLE',
|
||||||
});
|
});
|
||||||
|
}
|
||||||
this.updateNavigationState(event);
|
this.updateNavigationState(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -209,6 +216,12 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
|
||||||
|
|
||||||
onLoadingProgress = (event: WebViewProgressEvent) => {
|
onLoadingProgress = (event: WebViewProgressEvent) => {
|
||||||
const { onLoadProgress } = this.props;
|
const { onLoadProgress } = this.props;
|
||||||
|
const { nativeEvent: { progress } } = event;
|
||||||
|
if (progress === 1) {
|
||||||
|
this.setState({
|
||||||
|
viewState: 'IDLE',
|
||||||
|
});
|
||||||
|
}
|
||||||
if (onLoadProgress) {
|
if (onLoadProgress) {
|
||||||
onLoadProgress(event);
|
onLoadProgress(event);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue