Thibault Malbranche 5 years ago
parent
commit
ed520940af
10 changed files with 1383 additions and 198 deletions
  1. 11
    0
      .editorconfig
  2. 55
    0
      .eslintrc.js
  3. 12
    0
      .prettierrc.js
  4. 9
    0
      .vscode/settings.json
  5. 14
    8
      package.json
  6. 49
    46
      src/WebView.android.tsx
  7. 78
    78
      src/WebView.ios.tsx
  8. 0
    28
      tsconfig.base.json
  9. 28
    4
      tsconfig.json
  10. 1127
    34
      yarn.lock

+ 11
- 0
.editorconfig View File

1
+# http://editorconfig.org
2
+
3
+root = true
4
+
5
+[**]
6
+indent_style = space
7
+indent_size = 2
8
+end_of_line = lf
9
+charset = utf-8
10
+trim_trailing_whitespace = true
11
+insert_final_newline = true

+ 55
- 0
.eslintrc.js View File

1
+module.exports = {
2
+  // Airbnb is the base, prettier is here so that eslint doesn't conflict with prettier
3
+  extends: ['airbnb', 'prettier'],
4
+  parser: 'babel-eslint',
5
+  plugins: ['react', 'import'],
6
+  rules: {
7
+    // Parens will be needed for arrow functions
8
+    'arrow-parens': ['error', 'as-needed', { requireForBlockBody: true }],
9
+    // Lines will be broken before binary operators
10
+    'operator-linebreak': ['error', 'before'],
11
+    // Allow imports from dev and peer dependencies
12
+    'import/no-extraneous-dependencies': [
13
+      'error',
14
+      { devDependencies: true, peerDependencies: true },
15
+    ],
16
+    // Allows writing JSX in JS & TS files
17
+    // 'react/jsx-filename-extension': ['error', { extensions: ['.js', '.ts'] }],
18
+    // This rule doesn't play nice with Prettier
19
+    'react/jsx-one-expression-per-line': 'off',
20
+    // This rule doesn't play nice with Prettier
21
+    'react/jsx-wrap-multilines': 'off',
22
+    // Remove this rule because we only destructure props, but never state
23
+    'react/destructuring-assignment': 'off',
24
+    // Restrict imports that should be used carefully. Usually we have created a wrapper around them
25
+  },
26
+  overrides: [
27
+    {
28
+      files: ['*.ts', '*.tsx'],
29
+      parser: 'typescript-eslint-parser',
30
+      plugins: ['react', 'import', 'typescript'],
31
+      rules: {
32
+        'typescript/adjacent-overload-signatures': 'error',
33
+        'typescript/explicit-function-return-type': 'error',
34
+        'typescript/no-angle-bracket-type-assertion': 'error',
35
+        'typescript/no-empty-interface': 'error',
36
+        'typescript/no-explicit-any': 'error',
37
+        'typescript/no-inferrable-types': 'error',
38
+        'typescript/no-namespace': 'error',
39
+        'typescript/no-non-null-assertion': 'error',
40
+        'typescript/no-triple-slash-reference': 'error',
41
+        'typescript/no-type-alias': 'error',
42
+        'typescript/prefer-namespace-keyword': 'error',
43
+        'typescript/type-annotation-spacing': 'error',
44
+      },
45
+    },
46
+  ],
47
+  settings: {
48
+    'import/resolver': {
49
+      node: { extensions: ['.tsx', '.ts'] },
50
+    },
51
+    'import/cache:': {
52
+      lifetime: 2,
53
+    },
54
+  },
55
+};

+ 12
- 0
.prettierrc.js View File

1
+// https://prettier.io/docs/en/options.html
2
+
3
+module.exports = {
4
+  // Allow to parse .ts files and TS annotations
5
+  parser: 'typescript',
6
+  // Enables semicolons at the end of statements
7
+  semi: true,
8
+  // Formats strings with single quotes ('') instead of quotes ("")
9
+  singleQuote: true,
10
+  // Adds a trailing comma at the end of all lists (including function arguments)
11
+  trailingComma: 'all',
12
+};

+ 9
- 0
.vscode/settings.json View File

1
+{
2
+  "prettier.disableLanguages": [
3
+    "json"
4
+  ],
5
+  "prettier.eslintIntegration": true,
6
+  "prettier.stylelintIntegration": true,
7
+  "prettier.singleQuote": true,
8
+  "prettier.trailingComma": "all",
9
+}

+ 14
- 8
package.json View File

11
   "version": "2.13.0",
11
   "version": "2.13.0",
12
   "homepage": "https://github.com/react-native-community/react-native-webview#readme",
12
   "homepage": "https://github.com/react-native-community/react-native-webview#readme",
13
   "scripts": {
13
   "scripts": {
14
-    "prebuild": "rimraf lib",
15
-    "prepare": "npm run build",
16
-    "build": "tsc -p tsconfig.base.json && cp ./index.js ./lib/index.js",
17
     "ci:publish": "yarn semantic-release",
14
     "ci:publish": "yarn semantic-release",
18
-    "ci:test": "yarn ci:test:build",
19
-    "ci:test:build": "yarn build",
15
+    "ci:test": "yarn ci:test:tsc",
16
+    "ci:test:tsc": "yarn tsc --noEmit -p tsconfig.json",
20
     "semantic-release": "semantic-release"
17
     "semantic-release": "semantic-release"
21
   },
18
   },
22
   "peerDependencies": {
19
   "peerDependencies": {
31
     "@semantic-release/git": "7.0.5",
28
     "@semantic-release/git": "7.0.5",
32
     "@types/invariant": "^2.2.29",
29
     "@types/invariant": "^2.2.29",
33
     "@types/react-native": "^0.57.6",
30
     "@types/react-native": "^0.57.6",
34
-    "rimraf": "^2.6.2",
31
+    "eslint": "5.9.0",
32
+    "eslint-config-airbnb": "17.1.0",
33
+    "eslint-config-prettier": "3.3.0",
34
+    "eslint-plugin-import": "2.14.0",
35
+    "eslint-plugin-jsx-a11y": "6.1.2",
36
+    "eslint-plugin-react": "7.11.1",
37
+    "eslint-plugin-react-native": "3.5.0",
38
+    "eslint-plugin-typescript": "0.13.0",
39
+    "prettier-eslint-cli": "4.7.1",
35
     "semantic-release": "15.10.3",
40
     "semantic-release": "15.10.3",
36
-    "typescript": "^3.1.6"
41
+    "typescript": "3.1.6",
42
+    "typescript-eslint-parser": "21.0.1"
37
   },
43
   },
38
   "repository": {
44
   "repository": {
39
     "type": "git",
45
     "type": "git",
40
     "url": "https://github.com/react-native-community/react-native-webview.git"
46
     "url": "https://github.com/react-native-community/react-native-webview.git"
41
   }
47
   }
42
-}
48
+}

+ 49
- 46
src/WebView.android.tsx View File

1
-import React from "react";
1
+import React from 'react';
2
 
2
 
3
-import ReactNative from "react-native";
3
+import ReactNative from 'react-native';
4
 import {
4
 import {
5
   ActivityIndicator,
5
   ActivityIndicator,
6
   StyleSheet,
6
   StyleSheet,
9
   requireNativeComponent,
9
   requireNativeComponent,
10
   NativeModules,
10
   NativeModules,
11
   Image,
11
   Image,
12
-  NativeSyntheticEvent
13
-} from "react-native";
12
+  NativeSyntheticEvent,
13
+} from 'react-native';
14
 
14
 
15
-import invariant from "invariant";
15
+import invariant from 'invariant';
16
 
16
 
17
-import WebViewShared from "./WebViewShared";
17
+import WebViewShared from './WebViewShared';
18
 import {
18
 import {
19
   WebViewSourceUri,
19
   WebViewSourceUri,
20
   WebViewError,
20
   WebViewError,
23
   WebViewNavigationEvent,
23
   WebViewNavigationEvent,
24
   WebViewSharedProps,
24
   WebViewSharedProps,
25
   WebViewSource,
25
   WebViewSource,
26
-  WebViewProgressEvent
27
-} from "./types/WebViewTypes";
28
-import { isWebViewUriSource } from "./utils";
26
+  WebViewProgressEvent,
27
+} from './types/WebViewTypes';
28
+import { isWebViewUriSource } from './utils';
29
 
29
 
30
 enum WebViewState {
30
 enum WebViewState {
31
-  IDLE = "IDLE",
32
-  LOADING = "LOADING",
33
-  ERROR = "ERROR"
31
+  IDLE = 'IDLE',
32
+  LOADING = 'LOADING',
33
+  ERROR = 'ERROR',
34
 }
34
 }
35
 
35
 
36
 const defaultRenderLoading = () => (
36
 const defaultRenderLoading = () => (
41
 
41
 
42
 type State = {
42
 type State = {
43
   viewState: WebViewState;
43
   viewState: WebViewState;
44
-  lastErrorEvent: WebViewError;
44
+  lastErrorEvent: WebViewError | null;
45
 };
45
 };
46
 
46
 
47
 /**
47
 /**
48
  * Renders a native WebView.
48
  * Renders a native WebView.
49
  */
49
  */
50
-export default class WebView extends React.Component<WebViewSharedProps, State> {
50
+export default class WebView extends React.Component<
51
+  WebViewSharedProps,
52
+  State
53
+> {
51
   static defaultProps = {
54
   static defaultProps = {
52
-    overScrollMode: "always",
55
+    overScrollMode: 'always',
53
     javaScriptEnabled: true,
56
     javaScriptEnabled: true,
54
     thirdPartyCookiesEnabled: true,
57
     thirdPartyCookiesEnabled: true,
55
     scalesPageToFit: true,
58
     scalesPageToFit: true,
56
     allowFileAccess: false,
59
     allowFileAccess: false,
57
     saveFormDataDisabled: false,
60
     saveFormDataDisabled: false,
58
-    originWhitelist: WebViewShared.defaultOriginWhitelist
61
+    originWhitelist: WebViewShared.defaultOriginWhitelist,
59
   };
62
   };
60
 
63
 
61
   static isFileUploadSupported = async () => {
64
   static isFileUploadSupported = async () => {
67
     viewState: this.props.startInLoadingState
70
     viewState: this.props.startInLoadingState
68
       ? WebViewState.LOADING
71
       ? WebViewState.LOADING
69
       : WebViewState.IDLE,
72
       : WebViewState.IDLE,
70
-    lastErrorEvent: null
73
+    lastErrorEvent: null,
71
   };
74
   };
72
 
75
 
73
   webViewRef = React.createRef<React.ComponentClass>();
76
   webViewRef = React.createRef<React.ComponentClass>();
79
       otherView = (this.props.renderLoading || defaultRenderLoading)();
82
       otherView = (this.props.renderLoading || defaultRenderLoading)();
80
     } else if (this.state.viewState === WebViewState.ERROR) {
83
     } else if (this.state.viewState === WebViewState.ERROR) {
81
       const errorEvent = this.state.lastErrorEvent;
84
       const errorEvent = this.state.lastErrorEvent;
82
-      invariant(errorEvent != null, "lastErrorEvent expected to be non-null");
85
+      invariant(errorEvent != null, 'lastErrorEvent expected to be non-null');
83
       otherView =
86
       otherView =
84
         this.props.renderError &&
87
         this.props.renderError &&
85
         this.props.renderError(
88
         this.props.renderError(
86
-          errorEvent.domain,
87
-          errorEvent.code,
88
-          errorEvent.description
89
+          errorEvent!.domain,
90
+          errorEvent!.code,
91
+          errorEvent!.description,
89
         );
92
         );
90
     } else if (this.state.viewState !== WebViewState.IDLE) {
93
     } else if (this.state.viewState !== WebViewState.IDLE) {
91
       console.error(
94
       console.error(
92
-        "RNCWebView invalid state encountered: " + this.state.viewState
95
+        'RNCWebView invalid state encountered: ' + this.state.viewState,
93
       );
96
       );
94
     }
97
     }
95
 
98
 
110
     }
113
     }
111
 
114
 
112
     if (isWebViewUriSource(source)) {
115
     if (isWebViewUriSource(source)) {
113
-      if (source.method === "POST" && source.headers) {
116
+      if (source.method === 'POST' && source.headers) {
114
         console.warn(
117
         console.warn(
115
-          "WebView: `source.headers` is not supported when using POST."
118
+          'WebView: `source.headers` is not supported when using POST.',
116
         );
119
         );
117
-      } else if (source.method === "GET" && source.body) {
118
-        console.warn("WebView: `source.body` is not supported when using GET.");
120
+      } else if (source.method === 'GET' && source.body) {
121
+        console.warn('WebView: `source.body` is not supported when using GET.');
119
       }
122
       }
120
     }
123
     }
121
 
124
 
122
     const nativeConfig = this.props.nativeConfig || {};
125
     const nativeConfig = this.props.nativeConfig || {};
123
 
126
 
124
     const originWhitelist = (this.props.originWhitelist || []).map(
127
     const originWhitelist = (this.props.originWhitelist || []).map(
125
-      WebViewShared.originWhitelistToRegex
128
+      WebViewShared.originWhitelistToRegex,
126
     );
129
     );
127
 
130
 
128
     let NativeWebView = nativeConfig.component || RNCWebView;
131
     let NativeWebView = nativeConfig.component || RNCWebView;
140
         javaScriptEnabled={this.props.javaScriptEnabled}
143
         javaScriptEnabled={this.props.javaScriptEnabled}
141
         thirdPartyCookiesEnabled={this.props.thirdPartyCookiesEnabled}
144
         thirdPartyCookiesEnabled={this.props.thirdPartyCookiesEnabled}
142
         domStorageEnabled={this.props.domStorageEnabled}
145
         domStorageEnabled={this.props.domStorageEnabled}
143
-        messagingEnabled={typeof this.props.onMessage === "function"}
146
+        messagingEnabled={typeof this.props.onMessage === 'function'}
144
         onMessage={this.onMessage}
147
         onMessage={this.onMessage}
145
         overScrollMode={this.props.overScrollMode}
148
         overScrollMode={this.props.overScrollMode}
146
         contentInset={this.props.contentInset}
149
         contentInset={this.props.contentInset}
180
     UIManager.dispatchViewManagerCommand(
183
     UIManager.dispatchViewManagerCommand(
181
       this.getWebViewHandle(),
184
       this.getWebViewHandle(),
182
       UIManager.RNCWebView.Commands.goForward,
185
       UIManager.RNCWebView.Commands.goForward,
183
-      null
186
+      null,
184
     );
187
     );
185
   };
188
   };
186
 
189
 
188
     UIManager.dispatchViewManagerCommand(
191
     UIManager.dispatchViewManagerCommand(
189
       this.getWebViewHandle(),
192
       this.getWebViewHandle(),
190
       UIManager.RNCWebView.Commands.goBack,
193
       UIManager.RNCWebView.Commands.goBack,
191
-      null
194
+      null,
192
     );
195
     );
193
   };
196
   };
194
 
197
 
195
   reload = () => {
198
   reload = () => {
196
     this.setState({
199
     this.setState({
197
-      viewState: WebViewState.LOADING
200
+      viewState: WebViewState.LOADING,
198
     });
201
     });
199
     UIManager.dispatchViewManagerCommand(
202
     UIManager.dispatchViewManagerCommand(
200
       this.getWebViewHandle(),
203
       this.getWebViewHandle(),
201
       UIManager.RNCWebView.Commands.reload,
204
       UIManager.RNCWebView.Commands.reload,
202
-      null
205
+      null,
203
     );
206
     );
204
   };
207
   };
205
 
208
 
207
     UIManager.dispatchViewManagerCommand(
210
     UIManager.dispatchViewManagerCommand(
208
       this.getWebViewHandle(),
211
       this.getWebViewHandle(),
209
       UIManager.RNCWebView.Commands.stopLoading,
212
       UIManager.RNCWebView.Commands.stopLoading,
210
-      null
213
+      null,
211
     );
214
     );
212
   };
215
   };
213
 
216
 
215
     UIManager.dispatchViewManagerCommand(
218
     UIManager.dispatchViewManagerCommand(
216
       this.getWebViewHandle(),
219
       this.getWebViewHandle(),
217
       UIManager.RNCWebView.Commands.postMessage,
220
       UIManager.RNCWebView.Commands.postMessage,
218
-      [String(data)]
221
+      [String(data)],
219
     );
222
     );
220
   };
223
   };
221
 
224
 
229
     UIManager.dispatchViewManagerCommand(
232
     UIManager.dispatchViewManagerCommand(
230
       this.getWebViewHandle(),
233
       this.getWebViewHandle(),
231
       UIManager.RNCWebView.Commands.injectJavaScript,
234
       UIManager.RNCWebView.Commands.injectJavaScript,
232
-      [data]
235
+      [data],
233
     );
236
     );
234
   };
237
   };
235
 
238
 
258
     const { onError, onLoadEnd } = this.props;
261
     const { onError, onLoadEnd } = this.props;
259
     onError && onError(event);
262
     onError && onError(event);
260
     onLoadEnd && onLoadEnd(event);
263
     onLoadEnd && onLoadEnd(event);
261
-    console.warn("Encountered an error loading page", event.nativeEvent);
264
+    console.warn('Encountered an error loading page', event.nativeEvent);
262
 
265
 
263
     this.setState({
266
     this.setState({
264
       lastErrorEvent: event.nativeEvent,
267
       lastErrorEvent: event.nativeEvent,
265
-      viewState: WebViewState.ERROR
268
+      viewState: WebViewState.ERROR,
266
     });
269
     });
267
   };
270
   };
268
 
271
 
271
     onLoad && onLoad(event);
274
     onLoad && onLoad(event);
272
     onLoadEnd && onLoadEnd(event);
275
     onLoadEnd && onLoadEnd(event);
273
     this.setState({
276
     this.setState({
274
-      viewState: WebViewState.IDLE
277
+      viewState: WebViewState.IDLE,
275
     });
278
     });
276
     this.updateNavigationState(event);
279
     this.updateNavigationState(event);
277
   };
280
   };
287
   };
290
   };
288
 }
291
 }
289
 
292
 
290
-const RNCWebView = requireNativeComponent("RNCWebView");
293
+const RNCWebView = requireNativeComponent('RNCWebView');
291
 
294
 
292
 const styles = StyleSheet.create({
295
 const styles = StyleSheet.create({
293
   container: {
296
   container: {
294
-    flex: 1
297
+    flex: 1,
295
   },
298
   },
296
   hidden: {
299
   hidden: {
297
     height: 0,
300
     height: 0,
298
-    flex: 0 // disable 'flex:1' when hiding a View
301
+    flex: 0, // disable 'flex:1' when hiding a View
299
   },
302
   },
300
   loadingView: {
303
   loadingView: {
301
     flex: 1,
304
     flex: 1,
302
-    justifyContent: "center",
303
-    alignItems: "center"
305
+    justifyContent: 'center',
306
+    alignItems: 'center',
304
   },
307
   },
305
   loadingProgressBar: {
308
   loadingProgressBar: {
306
-    height: 20
307
-  }
308
-});
309
+    height: 20,
310
+  },
311
+});

+ 78
- 78
src/WebView.ios.tsx View File

1
-import React from "react";
1
+import React from 'react';
2
 import {
2
 import {
3
   ActivityIndicator,
3
   ActivityIndicator,
4
   Linking,
4
   Linking,
10
   NativeModules,
10
   NativeModules,
11
   Image,
11
   Image,
12
   findNodeHandle,
12
   findNodeHandle,
13
-  NativeSyntheticEvent
14
-} from "react-native";
13
+  NativeSyntheticEvent,
14
+} from 'react-native';
15
 
15
 
16
-import invariant from "invariant";
16
+import invariant from 'invariant';
17
 
17
 
18
-import WebViewShared from "./WebViewShared";
18
+import WebViewShared from './WebViewShared';
19
 import {
19
 import {
20
   WebViewSourceUri,
20
   WebViewSourceUri,
21
   WebViewError,
21
   WebViewError,
25
   WebViewNavigationEvent,
25
   WebViewNavigationEvent,
26
   WebViewSharedProps,
26
   WebViewSharedProps,
27
   WebViewSource,
27
   WebViewSource,
28
-  WebViewProgressEvent
29
-} from "./types/WebViewTypes";
28
+  WebViewProgressEvent,
29
+} from './types/WebViewTypes';
30
 
30
 
31
-type DecelerationRate = number | "normal" | "fast";
31
+type DecelerationRate = number | 'normal' | 'fast';
32
 
32
 
33
 // Imported from https://github.com/facebook/react-native/blob/master/Libraries/Components/ScrollView/processDecelerationRate.js
33
 // Imported from https://github.com/facebook/react-native/blob/master/Libraries/Components/ScrollView/processDecelerationRate.js
34
-function processDecelerationRate(decelerationRate: DecelerationRate) {
35
-  if (decelerationRate === "normal") {
34
+function processDecelerationRate(decelerationRate?: DecelerationRate) {
35
+  if (decelerationRate === 'normal') {
36
     decelerationRate = 0.998;
36
     decelerationRate = 0.998;
37
-  } else if (decelerationRate === "fast") {
37
+  } else if (decelerationRate === 'fast') {
38
     decelerationRate = 0.99;
38
     decelerationRate = 0.99;
39
   }
39
   }
40
   return decelerationRate;
40
   return decelerationRate;
43
 const RNCUIWebViewManager = NativeModules.RNCUIWebViewManager;
43
 const RNCUIWebViewManager = NativeModules.RNCUIWebViewManager;
44
 const RNCWKWebViewManager = NativeModules.RNCWKWebViewManager;
44
 const RNCWKWebViewManager = NativeModules.RNCWKWebViewManager;
45
 
45
 
46
-const BGWASH = "rgba(255,255,255,0.8)";
46
+const BGWASH = 'rgba(255,255,255,0.8)';
47
 
47
 
48
 enum WebViewState {
48
 enum WebViewState {
49
-  IDLE = "IDLE",
50
-  LOADING = "LOADING",
51
-  ERROR = "ERROR"
49
+  IDLE = 'IDLE',
50
+  LOADING = 'LOADING',
51
+  ERROR = 'ERROR',
52
 }
52
 }
53
 
53
 
54
 enum NavigationType {
54
 enum NavigationType {
55
-  click = "click",
56
-  formsubmit = "formsubmit",
57
-  backforward = "backforward",
58
-  reload = "reload",
59
-  formresubmit = "formresubmit",
60
-  other = "other"
55
+  click = 'click',
56
+  formsubmit = 'formsubmit',
57
+  backforward = 'backforward',
58
+  reload = 'reload',
59
+  formresubmit = 'formresubmit',
60
+  other = 'other',
61
 }
61
 }
62
 
62
 
63
-const JSNavigationScheme = "react-js-navigation";
63
+const JSNavigationScheme = 'react-js-navigation';
64
 
64
 
65
 type State = {
65
 type State = {
66
   viewState: WebViewState;
66
   viewState: WebViewState;
67
-  lastErrorEvent: WebViewError;
67
+  lastErrorEvent: WebViewError | null;
68
 };
68
 };
69
 
69
 
70
 const defaultRenderLoading = () => (
70
 const defaultRenderLoading = () => (
73
   </View>
73
   </View>
74
 );
74
 );
75
 const defaultRenderError = (
75
 const defaultRenderError = (
76
-  errorDomain: string,
76
+  errorDomain: string | undefined,
77
   errorCode: number,
77
   errorCode: number,
78
-  errorDesc: string
78
+  errorDesc: string,
79
 ) => (
79
 ) => (
80
   <View style={styles.errorContainer}>
80
   <View style={styles.errorContainer}>
81
     <Text style={styles.errorTextTitle}>Error loading page</Text>
81
     <Text style={styles.errorTextTitle}>Error loading page</Text>
82
-    <Text style={styles.errorText}>{"Domain: " + errorDomain}</Text>
83
-    <Text style={styles.errorText}>{"Error Code: " + errorCode}</Text>
84
-    <Text style={styles.errorText}>{"Description: " + errorDesc}</Text>
82
+    <Text style={styles.errorText}>{'Domain: ' + errorDomain}</Text>
83
+    <Text style={styles.errorText}>{'Error Code: ' + errorCode}</Text>
84
+    <Text style={styles.errorText}>{'Description: ' + errorDesc}</Text>
85
   </View>
85
   </View>
86
 );
86
 );
87
 
87
 
116
 
116
 
117
   static defaultProps = {
117
   static defaultProps = {
118
     useWebKit: true,
118
     useWebKit: true,
119
-    originWhitelist: WebViewShared.defaultOriginWhitelist
119
+    originWhitelist: WebViewShared.defaultOriginWhitelist,
120
   };
120
   };
121
 
121
 
122
   static isFileUploadSupported = async () => {
122
   static isFileUploadSupported = async () => {
128
     viewState: this.props.startInLoadingState
128
     viewState: this.props.startInLoadingState
129
       ? WebViewState.LOADING
129
       ? WebViewState.LOADING
130
       : WebViewState.IDLE,
130
       : WebViewState.IDLE,
131
-    lastErrorEvent: null
131
+    lastErrorEvent: null,
132
   };
132
   };
133
 
133
 
134
   webViewRef = React.createRef<React.ComponentClass>();
134
   webViewRef = React.createRef<React.ComponentClass>();
139
       this.props.scalesPageToFit !== undefined
139
       this.props.scalesPageToFit !== undefined
140
     ) {
140
     ) {
141
       console.warn(
141
       console.warn(
142
-        "The scalesPageToFit property is not supported when useWebKit = true"
142
+        'The scalesPageToFit property is not supported when useWebKit = true',
143
       );
143
       );
144
     }
144
     }
145
     if (
145
     if (
147
       this.props.allowsBackForwardNavigationGestures
147
       this.props.allowsBackForwardNavigationGestures
148
     ) {
148
     ) {
149
       console.warn(
149
       console.warn(
150
-        "The allowsBackForwardNavigationGestures property is not supported when useWebKit = false"
150
+        'The allowsBackForwardNavigationGestures property is not supported when useWebKit = false',
151
       );
151
       );
152
     }
152
     }
153
   }
153
   }
167
       otherView = (this.props.renderLoading || defaultRenderLoading)();
167
       otherView = (this.props.renderLoading || defaultRenderLoading)();
168
     } else if (this.state.viewState === WebViewState.ERROR) {
168
     } else if (this.state.viewState === WebViewState.ERROR) {
169
       const errorEvent = this.state.lastErrorEvent;
169
       const errorEvent = this.state.lastErrorEvent;
170
-      invariant(errorEvent != null, "lastErrorEvent expected to be non-null");
170
+      invariant(errorEvent != null, 'lastErrorEvent expected to be non-null');
171
       otherView = (this.props.renderError || defaultRenderError)(
171
       otherView = (this.props.renderError || defaultRenderError)(
172
-        errorEvent.domain,
173
-        errorEvent.code,
174
-        errorEvent.description
172
+        errorEvent!.domain,
173
+        errorEvent!.code,
174
+        errorEvent!.description,
175
       );
175
       );
176
     } else if (this.state.viewState !== WebViewState.IDLE) {
176
     } else if (this.state.viewState !== WebViewState.IDLE) {
177
       console.error(
177
       console.error(
178
-        "RNCWebView invalid state encountered: " + this.state.viewState
178
+        'RNCWebView invalid state encountered: ' + this.state.viewState,
179
       );
179
       );
180
     }
180
     }
181
 
181
 
199
     }
199
     }
200
 
200
 
201
     const compiledWhitelist = [
201
     const compiledWhitelist = [
202
-      "about:blank",
203
-      ...(this.props.originWhitelist || [])
202
+      'about:blank',
203
+      ...(this.props.originWhitelist || []),
204
     ].map(WebViewShared.originWhitelistToRegex);
204
     ].map(WebViewShared.originWhitelistToRegex);
205
     const onShouldStartLoadWithRequest = (
205
     const onShouldStartLoadWithRequest = (
206
-      event: NativeSyntheticEvent<WebViewIOSLoadRequestEvent>
206
+      event: NativeSyntheticEvent<WebViewIOSLoadRequestEvent>,
207
     ) => {
207
     ) => {
208
       let shouldStart = true;
208
       let shouldStart = true;
209
       const { url } = event.nativeEvent;
209
       const { url } = event.nativeEvent;
210
       const origin = WebViewShared.extractOrigin(url);
210
       const origin = WebViewShared.extractOrigin(url);
211
       const passesWhitelist = compiledWhitelist.some(x =>
211
       const passesWhitelist = compiledWhitelist.some(x =>
212
-        new RegExp(x).test(origin)
212
+        new RegExp(x).test(origin),
213
       );
213
       );
214
       shouldStart = shouldStart && passesWhitelist;
214
       shouldStart = shouldStart && passesWhitelist;
215
       if (!passesWhitelist) {
215
       if (!passesWhitelist) {
220
           shouldStart &&
220
           shouldStart &&
221
           this.props.onShouldStartLoadWithRequest(event.nativeEvent);
221
           this.props.onShouldStartLoadWithRequest(event.nativeEvent);
222
       }
222
       }
223
-      invariant(viewManager != null, "viewManager expected to be non-null");
223
+      invariant(viewManager != null, 'viewManager expected to be non-null');
224
       viewManager.startLoadWithResult(
224
       viewManager.startLoadWithResult(
225
         !!shouldStart,
225
         !!shouldStart,
226
-        event.nativeEvent.lockIdentifier
226
+        event.nativeEvent.lockIdentifier,
227
       );
227
       );
228
     };
228
     };
229
 
229
 
230
     const decelerationRate = processDecelerationRate(
230
     const decelerationRate = processDecelerationRate(
231
-      this.props.decelerationRate
231
+      this.props.decelerationRate,
232
     );
232
     );
233
 
233
 
234
     let source: WebViewSource = this.props.source || {};
234
     let source: WebViewSource = this.props.source || {};
238
       source = { uri: this.props.url };
238
       source = { uri: this.props.url };
239
     }
239
     }
240
 
240
 
241
-    const messagingEnabled = typeof this.props.onMessage === "function";
241
+    const messagingEnabled = typeof this.props.onMessage === 'function';
242
 
242
 
243
     let NativeWebView = nativeConfig.component;
243
     let NativeWebView = nativeConfig.component;
244
 
244
 
309
     UIManager.dispatchViewManagerCommand(
309
     UIManager.dispatchViewManagerCommand(
310
       this.getWebViewHandle(),
310
       this.getWebViewHandle(),
311
       this._getCommands().goForward,
311
       this._getCommands().goForward,
312
-      null
312
+      null,
313
     );
313
     );
314
   };
314
   };
315
 
315
 
320
     UIManager.dispatchViewManagerCommand(
320
     UIManager.dispatchViewManagerCommand(
321
       this.getWebViewHandle(),
321
       this.getWebViewHandle(),
322
       this._getCommands().goBack,
322
       this._getCommands().goBack,
323
-      null
323
+      null,
324
     );
324
     );
325
   };
325
   };
326
 
326
 
332
     UIManager.dispatchViewManagerCommand(
332
     UIManager.dispatchViewManagerCommand(
333
       this.getWebViewHandle(),
333
       this.getWebViewHandle(),
334
       this._getCommands().reload,
334
       this._getCommands().reload,
335
-      null
335
+      null,
336
     );
336
     );
337
   };
337
   };
338
 
338
 
343
     UIManager.dispatchViewManagerCommand(
343
     UIManager.dispatchViewManagerCommand(
344
       this.getWebViewHandle(),
344
       this.getWebViewHandle(),
345
       this._getCommands().stopLoading,
345
       this._getCommands().stopLoading,
346
-      null
346
+      null,
347
     );
347
     );
348
   };
348
   };
349
 
349
 
361
     UIManager.dispatchViewManagerCommand(
361
     UIManager.dispatchViewManagerCommand(
362
       this.getWebViewHandle(),
362
       this.getWebViewHandle(),
363
       this._getCommands().postMessage,
363
       this._getCommands().postMessage,
364
-      [String(data)]
364
+      [String(data)],
365
     );
365
     );
366
   };
366
   };
367
 
367
 
375
     UIManager.dispatchViewManagerCommand(
375
     UIManager.dispatchViewManagerCommand(
376
       this.getWebViewHandle(),
376
       this.getWebViewHandle(),
377
       this._getCommands().injectJavaScript,
377
       this._getCommands().injectJavaScript,
378
-      [data]
378
+      [data],
379
     );
379
     );
380
   };
380
   };
381
 
381
 
407
     const { onError, onLoadEnd } = this.props;
407
     const { onError, onLoadEnd } = this.props;
408
     onError && onError(event);
408
     onError && onError(event);
409
     onLoadEnd && onLoadEnd(event);
409
     onLoadEnd && onLoadEnd(event);
410
-    console.warn("Encountered an error loading page", event.nativeEvent);
410
+    console.warn('Encountered an error loading page', event.nativeEvent);
411
 
411
 
412
     this.setState({
412
     this.setState({
413
       lastErrorEvent: event.nativeEvent,
413
       lastErrorEvent: event.nativeEvent,
414
-      viewState: WebViewState.ERROR
414
+      viewState: WebViewState.ERROR,
415
     });
415
     });
416
   };
416
   };
417
 
417
 
420
     onLoad && onLoad(event);
420
     onLoad && onLoad(event);
421
     onLoadEnd && onLoadEnd(event);
421
     onLoadEnd && onLoadEnd(event);
422
     this.setState({
422
     this.setState({
423
-      viewState: WebViewState.IDLE
423
+      viewState: WebViewState.IDLE,
424
     });
424
     });
425
     this._updateNavigationState(event);
425
     this._updateNavigationState(event);
426
   };
426
   };
440
       return;
440
       return;
441
     }
441
     }
442
 
442
 
443
-    this._showRedboxOnPropChanges(prevProps, "allowsInlineMediaPlayback");
444
-    this._showRedboxOnPropChanges(prevProps, "mediaPlaybackRequiresUserAction");
445
-    this._showRedboxOnPropChanges(prevProps, "dataDetectorTypes");
443
+    this._showRedboxOnPropChanges(prevProps, 'allowsInlineMediaPlayback');
444
+    this._showRedboxOnPropChanges(prevProps, 'mediaPlaybackRequiresUserAction');
445
+    this._showRedboxOnPropChanges(prevProps, 'dataDetectorTypes');
446
 
446
 
447
     if (this.props.scalesPageToFit !== undefined) {
447
     if (this.props.scalesPageToFit !== undefined) {
448
       console.warn(
448
       console.warn(
449
-        "The scalesPageToFit property is not supported when useWebKit = true"
449
+        'The scalesPageToFit property is not supported when useWebKit = true',
450
       );
450
       );
451
     }
451
     }
452
   }
452
   }
454
   _showRedboxOnPropChanges(
454
   _showRedboxOnPropChanges(
455
     prevProps: WebViewSharedProps,
455
     prevProps: WebViewSharedProps,
456
     propName:
456
     propName:
457
-      | "allowsInlineMediaPlayback"
458
-      | "mediaPlaybackRequiresUserAction"
459
-      | "dataDetectorTypes"
457
+      | 'allowsInlineMediaPlayback'
458
+      | 'mediaPlaybackRequiresUserAction'
459
+      | 'dataDetectorTypes',
460
   ) {
460
   ) {
461
     if (this.props[propName] !== prevProps[propName]) {
461
     if (this.props[propName] !== prevProps[propName]) {
462
       console.error(
462
       console.error(
463
-        `Changes to property ${propName} do nothing after the initial render.`
463
+        `Changes to property ${propName} do nothing after the initial render.`,
464
       );
464
       );
465
     }
465
     }
466
   }
466
   }
467
 }
467
 }
468
 
468
 
469
-const RNCUIWebView = requireNativeComponent("RNCUIWebView");
470
-const RNCWKWebView = requireNativeComponent("RNCWKWebView");
469
+const RNCUIWebView = requireNativeComponent('RNCUIWebView');
470
+const RNCWKWebView = requireNativeComponent('RNCWKWebView');
471
 
471
 
472
 const styles = StyleSheet.create({
472
 const styles = StyleSheet.create({
473
   container: {
473
   container: {
474
-    flex: 1
474
+    flex: 1,
475
   },
475
   },
476
   errorContainer: {
476
   errorContainer: {
477
     flex: 1,
477
     flex: 1,
478
-    justifyContent: "center",
479
-    alignItems: "center",
480
-    backgroundColor: BGWASH
478
+    justifyContent: 'center',
479
+    alignItems: 'center',
480
+    backgroundColor: BGWASH,
481
   },
481
   },
482
   errorText: {
482
   errorText: {
483
     fontSize: 14,
483
     fontSize: 14,
484
-    textAlign: "center",
485
-    marginBottom: 2
484
+    textAlign: 'center',
485
+    marginBottom: 2,
486
   },
486
   },
487
   errorTextTitle: {
487
   errorTextTitle: {
488
     fontSize: 15,
488
     fontSize: 15,
489
-    fontWeight: "500",
490
-    marginBottom: 10
489
+    fontWeight: '500',
490
+    marginBottom: 10,
491
   },
491
   },
492
   hidden: {
492
   hidden: {
493
     height: 0,
493
     height: 0,
494
-    flex: 0 // disable 'flex:1' when hiding a View
494
+    flex: 0, // disable 'flex:1' when hiding a View
495
   },
495
   },
496
   loadingView: {
496
   loadingView: {
497
     backgroundColor: BGWASH,
497
     backgroundColor: BGWASH,
498
     flex: 1,
498
     flex: 1,
499
-    justifyContent: "center",
500
-    alignItems: "center",
501
-    height: 100
499
+    justifyContent: 'center',
500
+    alignItems: 'center',
501
+    height: 100,
502
   },
502
   },
503
   webView: {
503
   webView: {
504
-    backgroundColor: "#ffffff"
505
-  }
504
+    backgroundColor: '#ffffff',
505
+  },
506
 });
506
 });

+ 0
- 28
tsconfig.base.json View File

1
-{
2
-  "compilerOptions": {
3
-    "strictNullChecks": false,
4
-    "alwaysStrict": true,
5
-    "allowSyntheticDefaultImports": true,
6
-    "declaration": true,
7
-    "declarationDir": "lib",
8
-    "emitDecoratorMetadata": false,
9
-    "esModuleInterop": true,
10
-    "outDir": "lib",
11
-    "jsx": "react-native",
12
-    "lib": ["es6"],
13
-    "module": "esnext",
14
-    "moduleResolution": "node",
15
-    "noFallthroughCasesInSwitch": true,
16
-    "noImplicitAny": true,
17
-    "noImplicitReturns": true,
18
-    "noImplicitThis": true,
19
-    "noUnusedLocals": true,
20
-    "noUnusedParameters": true,
21
-    "pretty": true,
22
-    "removeComments": true,
23
-    "sourceMap": true,
24
-    "strict": true,
25
-    "stripInternal": true,
26
-    "target": "es5"
27
-  }
28
-}

+ 28
- 4
tsconfig.json View File

1
 {
1
 {
2
-  "extends": "./tsconfig.base.json",
3
-  "include": ["src", "./typings.d.ts", "types", "test"],
4
-  "exclude": ["node_modules", "dist"]  
5
-}
2
+  "compilerOptions": {
3
+    "allowSyntheticDefaultImports": true,
4
+    "esModuleInterop": true,
5
+    "jsx": "react-native",
6
+    "module": "esnext",
7
+    "moduleResolution": "node",
8
+    "noEmit": true,
9
+    "noFallthroughCasesInSwitch": true,
10
+    "noImplicitAny": true,
11
+    "noImplicitReturns": true,
12
+    "noImplicitThis": true,
13
+    "noUnusedLocals": true,
14
+    "noUnusedParameters": true,
15
+    "pretty": true,
16
+    "skipLibCheck": true,
17
+    "strict": true,
18
+  },
19
+  "include": [
20
+    "src",
21
+    "./typings.d.ts",
22
+    "types",
23
+    "test"
24
+  ],
25
+  "exclude": [
26
+    "node_modules",
27
+    "dist"
28
+  ]
29
+}

+ 1127
- 34
yarn.lock
File diff suppressed because it is too large
View File