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