Browse Source

feat(loading): Changed loading/error rendering (#612)

Penar Musaraj 5 years ago
parent
commit
d429e82c3a
4 changed files with 8 additions and 31 deletions
  1. 0
    7
      src/WebView.android.tsx
  2. 0
    7
      src/WebView.ios.tsx
  3. 6
    15
      src/WebView.styles.ts
  4. 2
    2
      src/WebViewShared.tsx

+ 0
- 7
src/WebView.android.tsx View File

244
     }
244
     }
245
 
245
 
246
     const webViewStyles = [styles.container, styles.webView, style];
246
     const webViewStyles = [styles.container, styles.webView, style];
247
-    if (
248
-      this.state.viewState === 'LOADING'
249
-      || this.state.viewState === 'ERROR'
250
-    ) {
251
-      // if we're in either LOADING or ERROR states, don't show the webView
252
-      webViewStyles.push(styles.hidden);
253
-    }
254
 
247
 
255
     if (source && 'method' in source) {
248
     if (source && 'method' in source) {
256
       if (source.method === 'POST' && source.headers) {
249
       if (source.method === 'POST' && source.headers) {

+ 0
- 7
src/WebView.ios.tsx View File

346
     }
346
     }
347
 
347
 
348
     const webViewStyles = [styles.container, styles.webView, style];
348
     const webViewStyles = [styles.container, styles.webView, style];
349
-    if (
350
-      this.state.viewState === 'LOADING'
351
-      || this.state.viewState === 'ERROR'
352
-    ) {
353
-      // if we're in either LOADING or ERROR states, don't show the webView
354
-      webViewStyles.push(styles.hidden);
355
-    }
356
 
349
 
357
     const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
350
     const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
358
       this.onShouldStartLoadWithRequestCallback,
351
       this.onShouldStartLoadWithRequestCallback,

+ 6
- 15
src/WebView.styles.ts View File

2
 
2
 
3
 interface Styles {
3
 interface Styles {
4
   container: ViewStyle;
4
   container: ViewStyle;
5
-  errorContainer: ViewStyle;
6
   errorText: TextStyle;
5
   errorText: TextStyle;
7
   errorTextTitle: TextStyle;
6
   errorTextTitle: TextStyle;
8
-  hidden: ViewStyle;
9
-  loadingView: ViewStyle;
7
+  loadingOrErrorView: ViewStyle;
10
   webView: ViewStyle;
8
   webView: ViewStyle;
11
   loadingProgressBar: ViewStyle;
9
   loadingProgressBar: ViewStyle;
12
 }
10
 }
16
     flex: 1,
14
     flex: 1,
17
     overflow: 'hidden',
15
     overflow: 'hidden',
18
   },
16
   },
19
-  errorContainer: {
17
+  loadingOrErrorView: {
18
+    position: 'absolute',
20
     flex: 1,
19
     flex: 1,
21
     justifyContent: 'center',
20
     justifyContent: 'center',
22
     alignItems: 'center',
21
     alignItems: 'center',
23
-    backgroundColor: 'white',
24
-  },
25
-  hidden: {
26
-    height: 0,
27
-    flex: 0, // disable 'flex:1' when hiding a View
28
-  },
29
-  loadingView: {
30
-    flex: 1,
31
-    justifyContent: 'center',
32
-    alignItems: 'center',
33
-    backgroundColor: 'white',
22
+    height: '100%',
23
+    width: '100%',
24
+    backgroundColor: 'white'
34
   },
25
   },
35
   loadingProgressBar: {
26
   loadingProgressBar: {
36
     height: 20,
27
     height: 20,

+ 2
- 2
src/WebViewShared.tsx View File

75
 };
75
 };
76
 
76
 
77
 const defaultRenderLoading = () => (
77
 const defaultRenderLoading = () => (
78
-  <View style={styles.loadingView}>
78
+  <View style={styles.loadingOrErrorView}>
79
     <ActivityIndicator />
79
     <ActivityIndicator />
80
   </View>
80
   </View>
81
 );
81
 );
84
   errorCode: number,
84
   errorCode: number,
85
   errorDesc: string,
85
   errorDesc: string,
86
 ) => (
86
 ) => (
87
-  <View style={styles.errorContainer}>
87
+  <View style={styles.loadingOrErrorView}>
88
     <Text style={styles.errorTextTitle}>Error loading page</Text>
88
     <Text style={styles.errorTextTitle}>Error loading page</Text>
89
     <Text style={styles.errorText}>{`Domain: ${errorDomain}`}</Text>
89
     <Text style={styles.errorText}>{`Domain: ${errorDomain}`}</Text>
90
     <Text style={styles.errorText}>{`Error Code: ${errorCode}`}</Text>
90
     <Text style={styles.errorText}>{`Error Code: ${errorCode}`}</Text>