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

@@ -0,0 +1,11 @@
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

@@ -0,0 +1,55 @@
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

@@ -0,0 +1,12 @@
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

@@ -0,0 +1,9 @@
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,12 +11,9 @@
11 11
   "version": "2.13.0",
12 12
   "homepage": "https://github.com/react-native-community/react-native-webview#readme",
13 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 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 17
     "semantic-release": "semantic-release"
21 18
   },
22 19
   "peerDependencies": {
@@ -31,12 +28,21 @@
31 28
     "@semantic-release/git": "7.0.5",
32 29
     "@types/invariant": "^2.2.29",
33 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 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 44
   "repository": {
39 45
     "type": "git",
40 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,6 +1,6 @@
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 4
 import {
5 5
   ActivityIndicator,
6 6
   StyleSheet,
@@ -9,12 +9,12 @@ import {
9 9
   requireNativeComponent,
10 10
   NativeModules,
11 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 18
 import {
19 19
   WebViewSourceUri,
20 20
   WebViewError,
@@ -23,14 +23,14 @@ import {
23 23
   WebViewNavigationEvent,
24 24
   WebViewSharedProps,
25 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 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 36
 const defaultRenderLoading = () => (
@@ -41,21 +41,24 @@ const defaultRenderLoading = () => (
41 41
 
42 42
 type State = {
43 43
   viewState: WebViewState;
44
-  lastErrorEvent: WebViewError;
44
+  lastErrorEvent: WebViewError | null;
45 45
 };
46 46
 
47 47
 /**
48 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 54
   static defaultProps = {
52
-    overScrollMode: "always",
55
+    overScrollMode: 'always',
53 56
     javaScriptEnabled: true,
54 57
     thirdPartyCookiesEnabled: true,
55 58
     scalesPageToFit: true,
56 59
     allowFileAccess: false,
57 60
     saveFormDataDisabled: false,
58
-    originWhitelist: WebViewShared.defaultOriginWhitelist
61
+    originWhitelist: WebViewShared.defaultOriginWhitelist,
59 62
   };
60 63
 
61 64
   static isFileUploadSupported = async () => {
@@ -67,7 +70,7 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
67 70
     viewState: this.props.startInLoadingState
68 71
       ? WebViewState.LOADING
69 72
       : WebViewState.IDLE,
70
-    lastErrorEvent: null
73
+    lastErrorEvent: null,
71 74
   };
72 75
 
73 76
   webViewRef = React.createRef<React.ComponentClass>();
@@ -79,17 +82,17 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
79 82
       otherView = (this.props.renderLoading || defaultRenderLoading)();
80 83
     } else if (this.state.viewState === WebViewState.ERROR) {
81 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 86
       otherView =
84 87
         this.props.renderError &&
85 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 93
     } else if (this.state.viewState !== WebViewState.IDLE) {
91 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,19 +113,19 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
110 113
     }
111 114
 
112 115
     if (isWebViewUriSource(source)) {
113
-      if (source.method === "POST" && source.headers) {
116
+      if (source.method === 'POST' && source.headers) {
114 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 125
     const nativeConfig = this.props.nativeConfig || {};
123 126
 
124 127
     const originWhitelist = (this.props.originWhitelist || []).map(
125
-      WebViewShared.originWhitelistToRegex
128
+      WebViewShared.originWhitelistToRegex,
126 129
     );
127 130
 
128 131
     let NativeWebView = nativeConfig.component || RNCWebView;
@@ -140,7 +143,7 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
140 143
         javaScriptEnabled={this.props.javaScriptEnabled}
141 144
         thirdPartyCookiesEnabled={this.props.thirdPartyCookiesEnabled}
142 145
         domStorageEnabled={this.props.domStorageEnabled}
143
-        messagingEnabled={typeof this.props.onMessage === "function"}
146
+        messagingEnabled={typeof this.props.onMessage === 'function'}
144 147
         onMessage={this.onMessage}
145 148
         overScrollMode={this.props.overScrollMode}
146 149
         contentInset={this.props.contentInset}
@@ -180,7 +183,7 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
180 183
     UIManager.dispatchViewManagerCommand(
181 184
       this.getWebViewHandle(),
182 185
       UIManager.RNCWebView.Commands.goForward,
183
-      null
186
+      null,
184 187
     );
185 188
   };
186 189
 
@@ -188,18 +191,18 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
188 191
     UIManager.dispatchViewManagerCommand(
189 192
       this.getWebViewHandle(),
190 193
       UIManager.RNCWebView.Commands.goBack,
191
-      null
194
+      null,
192 195
     );
193 196
   };
194 197
 
195 198
   reload = () => {
196 199
     this.setState({
197
-      viewState: WebViewState.LOADING
200
+      viewState: WebViewState.LOADING,
198 201
     });
199 202
     UIManager.dispatchViewManagerCommand(
200 203
       this.getWebViewHandle(),
201 204
       UIManager.RNCWebView.Commands.reload,
202
-      null
205
+      null,
203 206
     );
204 207
   };
205 208
 
@@ -207,7 +210,7 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
207 210
     UIManager.dispatchViewManagerCommand(
208 211
       this.getWebViewHandle(),
209 212
       UIManager.RNCWebView.Commands.stopLoading,
210
-      null
213
+      null,
211 214
     );
212 215
   };
213 216
 
@@ -215,7 +218,7 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
215 218
     UIManager.dispatchViewManagerCommand(
216 219
       this.getWebViewHandle(),
217 220
       UIManager.RNCWebView.Commands.postMessage,
218
-      [String(data)]
221
+      [String(data)],
219 222
     );
220 223
   };
221 224
 
@@ -229,7 +232,7 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
229 232
     UIManager.dispatchViewManagerCommand(
230 233
       this.getWebViewHandle(),
231 234
       UIManager.RNCWebView.Commands.injectJavaScript,
232
-      [data]
235
+      [data],
233 236
     );
234 237
   };
235 238
 
@@ -258,11 +261,11 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
258 261
     const { onError, onLoadEnd } = this.props;
259 262
     onError && onError(event);
260 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 266
     this.setState({
264 267
       lastErrorEvent: event.nativeEvent,
265
-      viewState: WebViewState.ERROR
268
+      viewState: WebViewState.ERROR,
266 269
     });
267 270
   };
268 271
 
@@ -271,7 +274,7 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
271 274
     onLoad && onLoad(event);
272 275
     onLoadEnd && onLoadEnd(event);
273 276
     this.setState({
274
-      viewState: WebViewState.IDLE
277
+      viewState: WebViewState.IDLE,
275 278
     });
276 279
     this.updateNavigationState(event);
277 280
   };
@@ -287,22 +290,22 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
287 290
   };
288 291
 }
289 292
 
290
-const RNCWebView = requireNativeComponent("RNCWebView");
293
+const RNCWebView = requireNativeComponent('RNCWebView');
291 294
 
292 295
 const styles = StyleSheet.create({
293 296
   container: {
294
-    flex: 1
297
+    flex: 1,
295 298
   },
296 299
   hidden: {
297 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 303
   loadingView: {
301 304
     flex: 1,
302
-    justifyContent: "center",
303
-    alignItems: "center"
305
+    justifyContent: 'center',
306
+    alignItems: 'center',
304 307
   },
305 308
   loadingProgressBar: {
306
-    height: 20
307
-  }
308
-});
309
+    height: 20,
310
+  },
311
+});

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

@@ -1,4 +1,4 @@
1
-import React from "react";
1
+import React from 'react';
2 2
 import {
3 3
   ActivityIndicator,
4 4
   Linking,
@@ -10,12 +10,12 @@ import {
10 10
   NativeModules,
11 11
   Image,
12 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 19
 import {
20 20
   WebViewSourceUri,
21 21
   WebViewError,
@@ -25,16 +25,16 @@ import {
25 25
   WebViewNavigationEvent,
26 26
   WebViewSharedProps,
27 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 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 36
     decelerationRate = 0.998;
37
-  } else if (decelerationRate === "fast") {
37
+  } else if (decelerationRate === 'fast') {
38 38
     decelerationRate = 0.99;
39 39
   }
40 40
   return decelerationRate;
@@ -43,28 +43,28 @@ function processDecelerationRate(decelerationRate: DecelerationRate) {
43 43
 const RNCUIWebViewManager = NativeModules.RNCUIWebViewManager;
44 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 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 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 65
 type State = {
66 66
   viewState: WebViewState;
67
-  lastErrorEvent: WebViewError;
67
+  lastErrorEvent: WebViewError | null;
68 68
 };
69 69
 
70 70
 const defaultRenderLoading = () => (
@@ -73,15 +73,15 @@ const defaultRenderLoading = () => (
73 73
   </View>
74 74
 );
75 75
 const defaultRenderError = (
76
-  errorDomain: string,
76
+  errorDomain: string | undefined,
77 77
   errorCode: number,
78
-  errorDesc: string
78
+  errorDesc: string,
79 79
 ) => (
80 80
   <View style={styles.errorContainer}>
81 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 85
   </View>
86 86
 );
87 87
 
@@ -116,7 +116,7 @@ export default class WebView extends React.Component<
116 116
 
117 117
   static defaultProps = {
118 118
     useWebKit: true,
119
-    originWhitelist: WebViewShared.defaultOriginWhitelist
119
+    originWhitelist: WebViewShared.defaultOriginWhitelist,
120 120
   };
121 121
 
122 122
   static isFileUploadSupported = async () => {
@@ -128,7 +128,7 @@ export default class WebView extends React.Component<
128 128
     viewState: this.props.startInLoadingState
129 129
       ? WebViewState.LOADING
130 130
       : WebViewState.IDLE,
131
-    lastErrorEvent: null
131
+    lastErrorEvent: null,
132 132
   };
133 133
 
134 134
   webViewRef = React.createRef<React.ComponentClass>();
@@ -139,7 +139,7 @@ export default class WebView extends React.Component<
139 139
       this.props.scalesPageToFit !== undefined
140 140
     ) {
141 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 145
     if (
@@ -147,7 +147,7 @@ export default class WebView extends React.Component<
147 147
       this.props.allowsBackForwardNavigationGestures
148 148
     ) {
149 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,15 +167,15 @@ export default class WebView extends React.Component<
167 167
       otherView = (this.props.renderLoading || defaultRenderLoading)();
168 168
     } else if (this.state.viewState === WebViewState.ERROR) {
169 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 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 176
     } else if (this.state.viewState !== WebViewState.IDLE) {
177 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,17 +199,17 @@ export default class WebView extends React.Component<
199 199
     }
200 200
 
201 201
     const compiledWhitelist = [
202
-      "about:blank",
203
-      ...(this.props.originWhitelist || [])
202
+      'about:blank',
203
+      ...(this.props.originWhitelist || []),
204 204
     ].map(WebViewShared.originWhitelistToRegex);
205 205
     const onShouldStartLoadWithRequest = (
206
-      event: NativeSyntheticEvent<WebViewIOSLoadRequestEvent>
206
+      event: NativeSyntheticEvent<WebViewIOSLoadRequestEvent>,
207 207
     ) => {
208 208
       let shouldStart = true;
209 209
       const { url } = event.nativeEvent;
210 210
       const origin = WebViewShared.extractOrigin(url);
211 211
       const passesWhitelist = compiledWhitelist.some(x =>
212
-        new RegExp(x).test(origin)
212
+        new RegExp(x).test(origin),
213 213
       );
214 214
       shouldStart = shouldStart && passesWhitelist;
215 215
       if (!passesWhitelist) {
@@ -220,15 +220,15 @@ export default class WebView extends React.Component<
220 220
           shouldStart &&
221 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 224
       viewManager.startLoadWithResult(
225 225
         !!shouldStart,
226
-        event.nativeEvent.lockIdentifier
226
+        event.nativeEvent.lockIdentifier,
227 227
       );
228 228
     };
229 229
 
230 230
     const decelerationRate = processDecelerationRate(
231
-      this.props.decelerationRate
231
+      this.props.decelerationRate,
232 232
     );
233 233
 
234 234
     let source: WebViewSource = this.props.source || {};
@@ -238,7 +238,7 @@ export default class WebView extends React.Component<
238 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 243
     let NativeWebView = nativeConfig.component;
244 244
 
@@ -309,7 +309,7 @@ export default class WebView extends React.Component<
309 309
     UIManager.dispatchViewManagerCommand(
310 310
       this.getWebViewHandle(),
311 311
       this._getCommands().goForward,
312
-      null
312
+      null,
313 313
     );
314 314
   };
315 315
 
@@ -320,7 +320,7 @@ export default class WebView extends React.Component<
320 320
     UIManager.dispatchViewManagerCommand(
321 321
       this.getWebViewHandle(),
322 322
       this._getCommands().goBack,
323
-      null
323
+      null,
324 324
     );
325 325
   };
326 326
 
@@ -332,7 +332,7 @@ export default class WebView extends React.Component<
332 332
     UIManager.dispatchViewManagerCommand(
333 333
       this.getWebViewHandle(),
334 334
       this._getCommands().reload,
335
-      null
335
+      null,
336 336
     );
337 337
   };
338 338
 
@@ -343,7 +343,7 @@ export default class WebView extends React.Component<
343 343
     UIManager.dispatchViewManagerCommand(
344 344
       this.getWebViewHandle(),
345 345
       this._getCommands().stopLoading,
346
-      null
346
+      null,
347 347
     );
348 348
   };
349 349
 
@@ -361,7 +361,7 @@ export default class WebView extends React.Component<
361 361
     UIManager.dispatchViewManagerCommand(
362 362
       this.getWebViewHandle(),
363 363
       this._getCommands().postMessage,
364
-      [String(data)]
364
+      [String(data)],
365 365
     );
366 366
   };
367 367
 
@@ -375,7 +375,7 @@ export default class WebView extends React.Component<
375 375
     UIManager.dispatchViewManagerCommand(
376 376
       this.getWebViewHandle(),
377 377
       this._getCommands().injectJavaScript,
378
-      [data]
378
+      [data],
379 379
     );
380 380
   };
381 381
 
@@ -407,11 +407,11 @@ export default class WebView extends React.Component<
407 407
     const { onError, onLoadEnd } = this.props;
408 408
     onError && onError(event);
409 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 412
     this.setState({
413 413
       lastErrorEvent: event.nativeEvent,
414
-      viewState: WebViewState.ERROR
414
+      viewState: WebViewState.ERROR,
415 415
     });
416 416
   };
417 417
 
@@ -420,7 +420,7 @@ export default class WebView extends React.Component<
420 420
     onLoad && onLoad(event);
421 421
     onLoadEnd && onLoadEnd(event);
422 422
     this.setState({
423
-      viewState: WebViewState.IDLE
423
+      viewState: WebViewState.IDLE,
424 424
     });
425 425
     this._updateNavigationState(event);
426 426
   };
@@ -440,13 +440,13 @@ export default class WebView extends React.Component<
440 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 447
     if (this.props.scalesPageToFit !== undefined) {
448 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,53 +454,53 @@ export default class WebView extends React.Component<
454 454
   _showRedboxOnPropChanges(
455 455
     prevProps: WebViewSharedProps,
456 456
     propName:
457
-      | "allowsInlineMediaPlayback"
458
-      | "mediaPlaybackRequiresUserAction"
459
-      | "dataDetectorTypes"
457
+      | 'allowsInlineMediaPlayback'
458
+      | 'mediaPlaybackRequiresUserAction'
459
+      | 'dataDetectorTypes',
460 460
   ) {
461 461
     if (this.props[propName] !== prevProps[propName]) {
462 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 472
 const styles = StyleSheet.create({
473 473
   container: {
474
-    flex: 1
474
+    flex: 1,
475 475
   },
476 476
   errorContainer: {
477 477
     flex: 1,
478
-    justifyContent: "center",
479
-    alignItems: "center",
480
-    backgroundColor: BGWASH
478
+    justifyContent: 'center',
479
+    alignItems: 'center',
480
+    backgroundColor: BGWASH,
481 481
   },
482 482
   errorText: {
483 483
     fontSize: 14,
484
-    textAlign: "center",
485
-    marginBottom: 2
484
+    textAlign: 'center',
485
+    marginBottom: 2,
486 486
   },
487 487
   errorTextTitle: {
488 488
     fontSize: 15,
489
-    fontWeight: "500",
490
-    marginBottom: 10
489
+    fontWeight: '500',
490
+    marginBottom: 10,
491 491
   },
492 492
   hidden: {
493 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 496
   loadingView: {
497 497
     backgroundColor: BGWASH,
498 498
     flex: 1,
499
-    justifyContent: "center",
500
-    alignItems: "center",
501
-    height: 100
499
+    justifyContent: 'center',
500
+    alignItems: 'center',
501
+    height: 100,
502 502
   },
503 503
   webView: {
504
-    backgroundColor: "#ffffff"
505
-  }
504
+    backgroundColor: '#ffffff',
505
+  },
506 506
 });

+ 0
- 28
tsconfig.base.json View File

@@ -1,28 +0,0 @@
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,5 +1,29 @@
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