Browse Source

Fix lint errors

Kai Guo 4 years ago
parent
commit
ec3cd24b0d
2 changed files with 43 additions and 48 deletions
  1. 42
    44
      src/WebView.windows.tsx
  2. 1
    4
      src/WebViewTypes.ts

+ 42
- 44
src/WebView.windows.tsx View File

25
 } from './WebViewShared';
25
 } from './WebViewShared';
26
 import {
26
 import {
27
   NativeWebViewWindows,
27
   NativeWebViewWindows,
28
-  WindowsWebViewProps,
28
+  WebViewSharedProps,
29
   WebViewProgressEvent,
29
   WebViewProgressEvent,
30
   WebViewNavigationEvent,
30
   WebViewNavigationEvent,
31
   WebViewErrorEvent,
31
   WebViewErrorEvent,
41
   'RCTWebView',
41
   'RCTWebView',
42
 );
42
 );
43
 
43
 
44
-export default class WebView extends React.Component<WindowsWebViewProps, State> {
44
+const styles = StyleSheet.create({
45
+  container: {
46
+    flex: 1,
47
+  },
48
+  hidden: {
49
+    height: 0,
50
+    flex: 0, // disable 'flex:1' when hiding a View
51
+  },
52
+  loadingView: {
53
+    flex: 1,
54
+    justifyContent: 'center',
55
+    alignItems: 'center',
56
+  },
57
+  loadingProgressBar: {
58
+    height: 20,
59
+  },
60
+});
61
+
62
+export default class WebView extends React.Component<WebViewSharedProps, State> {
45
 
63
 
46
   static defaultProps = {
64
   static defaultProps = {
47
     javaScriptEnabled: true,
65
     javaScriptEnabled: true,
73
       otherView = this.props.renderLoading && this.props.renderLoading();
91
       otherView = this.props.renderLoading && this.props.renderLoading();
74
     } else if (this.state.viewState === 'ERROR') {
92
     } else if (this.state.viewState === 'ERROR') {
75
       const errorEvent = this.state.lastErrorEvent;
93
       const errorEvent = this.state.lastErrorEvent;
76
-      otherView =
77
-        this.props.renderError &&
78
-        this.props.renderError(
94
+      otherView = this.props.renderError
95
+        && this.props.renderError(
79
           errorEvent.domain,
96
           errorEvent.domain,
80
           errorEvent.code,
97
           errorEvent.code,
81
           errorEvent.description,
98
           errorEvent.description,
82
         );
99
         );
83
     } else if (this.state.viewState !== 'IDLE') {
100
     } else if (this.state.viewState !== 'IDLE') {
84
-      console.error(
85
-        'RCTWebView invalid state encountered: ' + this.state.viewState,
86
-      );
101
+      console.error('RCTWebView invalid state encountered: ', this.state.viewState);
87
     }
102
     }
88
 
103
 
89
-    let webViewStyles = [styles.container, this.props.style];
104
+    const webViewStyles = [styles.container, this.props.style];
90
     if (
105
     if (
91
-      this.state.viewState === 'LOADING' ||
92
-      this.state.viewState === 'ERROR'
106
+      this.state.viewState === 'LOADING'
107
+      || this.state.viewState === 'ERROR'
93
     ) {
108
     ) {
94
       // if we're in either LOADING or ERROR states, don't show the webView
109
       // if we're in either LOADING or ERROR states, don't show the webView
95
       webViewStyles.push(styles.hidden);
110
       webViewStyles.push(styles.hidden);
96
     }
111
     }
97
 
112
 
98
     const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
113
     const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
99
-      this.onShouldStartLoadWithRequestCallback,
114
+      ()=>{},
100
       // casting cause it's in the default props
115
       // casting cause it's in the default props
101
       originWhitelist as readonly string[],
116
       originWhitelist as readonly string[],
102
       onShouldStartLoadWithRequestProp,
117
       onShouldStartLoadWithRequestProp,
175
 
190
 
176
   onLoadingStart = (event: WebViewNavigationEvent) => {
191
   onLoadingStart = (event: WebViewNavigationEvent) => {
177
     const { onLoadStart } = this.props;
192
     const { onLoadStart } = this.props;
178
-    onLoadStart && onLoadStart(event);
193
+    if(onLoadStart) {
194
+      onLoadStart(event);
195
+    }
179
     this.updateNavigationState(event);
196
     this.updateNavigationState(event);
180
   }
197
   }
181
 
198
 
189
   onLoadingError = (event: WebViewErrorEvent) => {
206
   onLoadingError = (event: WebViewErrorEvent) => {
190
     event.persist(); // persist this event because we need to store it
207
     event.persist(); // persist this event because we need to store it
191
     const {onError, onLoadEnd} = this.props;
208
     const {onError, onLoadEnd} = this.props;
192
-    onError && onError(event);
193
-    onLoadEnd && onLoadEnd(event);
209
+    if(onError) {
210
+      onError(event);
211
+    }
212
+    if(onLoadEnd) {
213
+      onLoadEnd(event);
214
+    }
194
     console.error('Encountered an error loading page', event.nativeEvent);
215
     console.error('Encountered an error loading page', event.nativeEvent);
195
     this.setState({
216
     this.setState({
196
       lastErrorEvent: event.nativeEvent,
217
       lastErrorEvent: event.nativeEvent,
200
 
221
 
201
   onLoadingFinish =(event: WebViewNavigationEvent) => {
222
   onLoadingFinish =(event: WebViewNavigationEvent) => {
202
     const {onLoad, onLoadEnd} = this.props;
223
     const {onLoad, onLoadEnd} = this.props;
203
-    onLoad && onLoad(event);
204
-    onLoadEnd && onLoadEnd(event);
224
+    if(onLoad) {
225
+      onLoad(event);
226
+    }
227
+    if(onLoadEnd) {
228
+      onLoadEnd(event);
229
+    }
205
     this.setState({
230
     this.setState({
206
       viewState: 'IDLE',
231
       viewState: 'IDLE',
207
     });
232
     });
222
     }
247
     }
223
   }
248
   }
224
 
249
 
225
-  onShouldStartLoadWithRequestCallback = (
226
-    _shouldStart: boolean,
227
-    _url: string,
228
-    _lockIdentifier: number,
229
-  ) => {
230
-  };
231
-
232
 }
250
 }
233
-
234
-const styles = StyleSheet.create({
235
-  container: {
236
-    flex: 1,
237
-  },
238
-  hidden: {
239
-    height: 0,
240
-    flex: 0, // disable 'flex:1' when hiding a View
241
-  },
242
-  loadingView: {
243
-    flex: 1,
244
-    justifyContent: 'center',
245
-    alignItems: 'center',
246
-  },
247
-  loadingProgressBar: {
248
-    height: 20,
249
-  },
250
-});
251
-
252
-module.exports = WebView;

+ 1
- 4
src/WebViewTypes.ts View File

319
 }
319
 }
320
 
320
 
321
 export interface WindowsNativeWebViewProps extends CommonNativeWebViewProps {
321
 export interface WindowsNativeWebViewProps extends CommonNativeWebViewProps {
322
-  testID?:string
322
+  testID?: string
323
 }
323
 }
324
 
324
 
325
 export interface IOSWebViewProps extends WebViewSharedProps {
325
 export interface IOSWebViewProps extends WebViewSharedProps {
766
   allowsFullscreenVideo?: boolean;
766
   allowsFullscreenVideo?: boolean;
767
 }
767
 }
768
 
768
 
769
-export interface WindowsWebViewProps extends WebViewSharedProps{
770
-}
771
-
772
 export interface WebViewSharedProps extends ViewProps {
769
 export interface WebViewSharedProps extends ViewProps {
773
   /**
770
   /**
774
    * Loads static html or a uri (with optional headers) in the WebView.
771
    * Loads static html or a uri (with optional headers) in the WebView.