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,7 +25,7 @@ import {
25 25
 } from './WebViewShared';
26 26
 import {
27 27
   NativeWebViewWindows,
28
-  WindowsWebViewProps,
28
+  WebViewSharedProps,
29 29
   WebViewProgressEvent,
30 30
   WebViewNavigationEvent,
31 31
   WebViewErrorEvent,
@@ -41,7 +41,25 @@ const RCTWebView: typeof NativeWebViewWindows = requireNativeComponent(
41 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 64
   static defaultProps = {
47 65
     javaScriptEnabled: true,
@@ -73,30 +91,27 @@ export default class WebView extends React.Component<WindowsWebViewProps, State>
73 91
       otherView = this.props.renderLoading && this.props.renderLoading();
74 92
     } else if (this.state.viewState === 'ERROR') {
75 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 96
           errorEvent.domain,
80 97
           errorEvent.code,
81 98
           errorEvent.description,
82 99
         );
83 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 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 109
       // if we're in either LOADING or ERROR states, don't show the webView
95 110
       webViewStyles.push(styles.hidden);
96 111
     }
97 112
 
98 113
     const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
99
-      this.onShouldStartLoadWithRequestCallback,
114
+      ()=>{},
100 115
       // casting cause it's in the default props
101 116
       originWhitelist as readonly string[],
102 117
       onShouldStartLoadWithRequestProp,
@@ -175,7 +190,9 @@ export default class WebView extends React.Component<WindowsWebViewProps, State>
175 190
 
176 191
   onLoadingStart = (event: WebViewNavigationEvent) => {
177 192
     const { onLoadStart } = this.props;
178
-    onLoadStart && onLoadStart(event);
193
+    if(onLoadStart) {
194
+      onLoadStart(event);
195
+    }
179 196
     this.updateNavigationState(event);
180 197
   }
181 198
 
@@ -189,8 +206,12 @@ export default class WebView extends React.Component<WindowsWebViewProps, State>
189 206
   onLoadingError = (event: WebViewErrorEvent) => {
190 207
     event.persist(); // persist this event because we need to store it
191 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 215
     console.error('Encountered an error loading page', event.nativeEvent);
195 216
     this.setState({
196 217
       lastErrorEvent: event.nativeEvent,
@@ -200,8 +221,12 @@ export default class WebView extends React.Component<WindowsWebViewProps, State>
200 221
 
201 222
   onLoadingFinish =(event: WebViewNavigationEvent) => {
202 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 230
     this.setState({
206 231
       viewState: 'IDLE',
207 232
     });
@@ -222,31 +247,4 @@ export default class WebView extends React.Component<WindowsWebViewProps, State>
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,7 +319,7 @@ export interface MacOSNativeWebViewProps extends CommonNativeWebViewProps {
319 319
 }
320 320
 
321 321
 export interface WindowsNativeWebViewProps extends CommonNativeWebViewProps {
322
-  testID?:string
322
+  testID?: string
323 323
 }
324 324
 
325 325
 export interface IOSWebViewProps extends WebViewSharedProps {
@@ -766,9 +766,6 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
766 766
   allowsFullscreenVideo?: boolean;
767 767
 }
768 768
 
769
-export interface WindowsWebViewProps extends WebViewSharedProps{
770
-}
771
-
772 769
 export interface WebViewSharedProps extends ViewProps {
773 770
   /**
774 771
    * Loads static html or a uri (with optional headers) in the WebView.