Browse Source

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
Tyler Alves 5 years ago
parent
commit
b296f24dd2
1 changed files with 16 additions and 3 deletions
  1. 16
    3
      src/WebView.android.tsx

+ 16
- 3
src/WebView.android.tsx View File

@@ -61,6 +61,8 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
61 61
     return NativeModules.RNCWebView.isFileUploadSupported();
62 62
   };
63 63
 
64
+  startUrl: string | null = null;
65
+
64 66
   state: State = {
65 67
     viewState: this.props.startInLoadingState ? 'LOADING' : 'IDLE',
66 68
     lastErrorEvent: null,
@@ -156,6 +158,8 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
156 158
 
157 159
   onLoadingStart = (event: WebViewNavigationEvent) => {
158 160
     const { onLoadStart } = this.props;
161
+    const { nativeEvent: { url } } = event;
162
+    this.startUrl = url;
159 163
     if (onLoadStart) {
160 164
       onLoadStart(event);
161 165
     }
@@ -188,15 +192,18 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
188 192
 
189 193
   onLoadingFinish = (event: WebViewNavigationEvent) => {
190 194
     const { onLoad, onLoadEnd } = this.props;
195
+    const { nativeEvent: { url } } = event;
191 196
     if (onLoad) {
192 197
       onLoad(event);
193 198
     }
194 199
     if (onLoadEnd) {
195 200
       onLoadEnd(event);
196 201
     }
197
-    this.setState({
198
-      viewState: 'IDLE',
199
-    });
202
+    if (url === this.startUrl) {
203
+      this.setState({
204
+        viewState: 'IDLE',
205
+      });
206
+    }
200 207
     this.updateNavigationState(event);
201 208
   };
202 209
 
@@ -209,6 +216,12 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
209 216
 
210 217
   onLoadingProgress = (event: WebViewProgressEvent) => {
211 218
     const { onLoadProgress } = this.props;
219
+    const { nativeEvent: { progress } } = event;
220
+    if (progress === 1) {
221
+      this.setState({
222
+        viewState: 'IDLE',
223
+      });
224
+    }
212 225
     if (onLoadProgress) {
213 226
       onLoadProgress(event);
214 227
     }