Thibault Malbranche vor 5 Jahren
Ursprung
Commit
2e4cb88132
17 geänderte Dateien mit 2323 neuen und 189 gelöschten Zeilen
  1. 31
    24
      .eslintrc.js
  2. 0
    2
      .prettierrc.js
  3. 17
    4
      .vscode/settings.json
  4. 1
    0
      .yarnrc
  5. 4
    1
      index.js
  6. 2
    0
      js/WebViewTypes.js
  7. 10
    6
      package.json
  8. 21
    21
      src/WebView.android.tsx
  9. 18
    20
      src/WebView.ios.tsx
  10. 3
    4
      src/WebViewShared.ts
  11. 2
    2
      src/index.ts
  12. 4
    0
      src/test.ts
  13. 12
    0
      src/test.tsx
  14. 2
    2
      src/types/WebViewTypes.ts
  15. 3
    2
      src/utils.ts
  16. 5
    14
      tsconfig.json
  17. 2188
    87
      yarn.lock

+ 31
- 24
.eslintrc.js Datei anzeigen

@@ -1,8 +1,8 @@
1 1
 module.exports = {
2 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'],
3
+  extends: ['airbnb-base', 'prettier', 'prettier/react'],
4
+  parser: 'typescript-eslint-parser',
5
+  plugins: ['react', 'react-native', 'typescript'],
6 6
   rules: {
7 7
     // Parens will be needed for arrow functions
8 8
     'arrow-parens': ['error', 'as-needed', { requireForBlockBody: true }],
@@ -14,7 +14,7 @@ module.exports = {
14 14
       { devDependencies: true, peerDependencies: true },
15 15
     ],
16 16
     // Allows writing JSX in JS & TS files
17
-    // 'react/jsx-filename-extension': ['error', { extensions: ['.js', '.ts'] }],
17
+    'react/jsx-filename-extension': ['error', { extensions: ['.tsx'] }],
18 18
     // This rule doesn't play nice with Prettier
19 19
     'react/jsx-one-expression-per-line': 'off',
20 20
     // This rule doesn't play nice with Prettier
@@ -22,34 +22,41 @@ module.exports = {
22 22
     // Remove this rule because we only destructure props, but never state
23 23
     'react/destructuring-assignment': 'off',
24 24
     // Restrict imports that should be used carefully. Usually we have created a wrapper around them
25
+
26
+    'typescript/adjacent-overload-signatures': 'error',
27
+    'typescript/explicit-function-return-type': 'error',
28
+    'typescript/no-angle-bracket-type-assertion': 'error',
29
+    'typescript/no-empty-interface': 'error',
30
+    'typescript/no-explicit-any': 'error',
31
+    'typescript/no-inferrable-types': 'error',
32
+    'typescript/no-namespace': 'error',
33
+    'typescript/no-non-null-assertion': 'error',
34
+    'typescript/no-triple-slash-reference': 'error',
35
+    'typescript/no-type-alias': 'error',
36
+    'typescript/prefer-namespace-keyword': 'error',
37
+    'typescript/type-annotation-spacing': 'error',
38
+
39
+    'no-unused-vars': 'off',
25 40
   },
26 41
   overrides: [
27 42
     {
28
-      files: ['*.ts', '*.tsx'],
43
+      files: ['*.ts?(x)'],
29 44
       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
+      plugins: ['react', 'react-native', 'typescript'],
45 46
     },
46 47
   ],
47 48
   settings: {
48 49
     'import/resolver': {
49
-      node: { extensions: ['.tsx', '.ts'] },
50
-    },
51
-    'import/cache:': {
52
-      lifetime: 2,
50
+      node: {
51
+        extensions: [
52
+          '.tsx',
53
+          '.ts',
54
+          '.android.tsx',
55
+          '.android.ts',
56
+          '.ios.tsx',
57
+          '.ios.ts',
58
+        ],
59
+      },
53 60
     },
54 61
   },
55 62
 };

+ 0
- 2
.prettierrc.js Datei anzeigen

@@ -1,8 +1,6 @@
1 1
 // https://prettier.io/docs/en/options.html
2 2
 
3 3
 module.exports = {
4
-  // Allow to parse .ts files and TS annotations
5
-  parser: 'typescript',
6 4
   // Enables semicolons at the end of statements
7 5
   semi: true,
8 6
   // Formats strings with single quotes ('') instead of quotes ("")

+ 17
- 4
.vscode/settings.json Datei anzeigen

@@ -1,9 +1,22 @@
1 1
 {
2
-  "prettier.disableLanguages": [
3
-    "json"
4
-  ],
2
+  "files.associations": {
3
+    "*.test.js": "javascript",
4
+    "*.js": "javascriptreact",
5
+    "*.test.ts": "typescript",
6
+    "*.ts": "typescript",
7
+    "*.tsx": "typescriptreact"
8
+  },
9
+  "prettier.disableLanguages": ["json"],
5 10
   "prettier.eslintIntegration": true,
6
-  "prettier.stylelintIntegration": true,
7 11
   "prettier.singleQuote": true,
8 12
   "prettier.trailingComma": "all",
13
+  "eslint.options": {
14
+    "extensions": [".js", ".ts", ".tsx"]
15
+  },
16
+  "eslint.validate": [
17
+    "javascript",
18
+    "javascriptreact",
19
+    "typescript",
20
+    "typescriptreact"
21
+  ]
9 22
 }

+ 1
- 0
.yarnrc Datei anzeigen

@@ -0,0 +1 @@
1
+save-exact true

+ 4
- 1
index.js Datei anzeigen

@@ -1,3 +1,6 @@
1
-import WebView from "./WebView";
1
+import WebView from './src/WebView';
2 2
 
3
+// We keep this for compatibility reasons.
3 4
 export { WebView };
5
+
6
+export default WebView;

+ 2
- 0
js/WebViewTypes.js Datei anzeigen

@@ -8,6 +8,8 @@
8 8
  * @flow
9 9
  */
10 10
 
11
+ /* eslint-disable */
12
+
11 13
 'use strict';
12 14
 
13 15
 import type {Node, Element, ComponentType} from 'react';

+ 10
- 6
package.json Datei anzeigen

@@ -12,8 +12,10 @@
12 12
   "homepage": "https://github.com/react-native-community/react-native-webview#readme",
13 13
   "scripts": {
14 14
     "ci:publish": "yarn semantic-release",
15
-    "ci:test": "yarn ci:test:tsc",
16
-    "ci:test:tsc": "yarn tsc --noEmit -p tsconfig.json",
15
+    "ci:test": "yarn ci:test:types && yarn ci:test:lint",
16
+    "ci:test:types": "yarn tsc",
17
+    "ci:test:lint": "yarn eslint . --max-warnings=0 --ext .js,.ts,.tsx",
18
+    "eslint-check": "eslint --print-config . | eslint-config-prettier-check",
17 19
     "semantic-release": "semantic-release"
18 20
   },
19 21
   "peerDependencies": {
@@ -27,16 +29,18 @@
27 29
   "devDependencies": {
28 30
     "@semantic-release/git": "7.0.5",
29 31
     "@types/invariant": "^2.2.29",
32
+    "@types/react": "16.7.7",
30 33
     "@types/react-native": "^0.57.6",
31 34
     "eslint": "5.9.0",
32
-    "eslint-config-airbnb": "17.1.0",
35
+    "eslint-config-airbnb-base": "13.1.0",
33 36
     "eslint-config-prettier": "3.3.0",
34 37
     "eslint-plugin-import": "2.14.0",
35
-    "eslint-plugin-jsx-a11y": "6.1.2",
36 38
     "eslint-plugin-react": "7.11.1",
37 39
     "eslint-plugin-react-native": "3.5.0",
38
-    "eslint-plugin-typescript": "0.13.0",
39
-    "prettier-eslint-cli": "4.7.1",
40
+    "eslint-plugin-typescript": "0.14.0",
41
+    "prettier-eslint-cli": "^4.7.1",
42
+    "react": "16.6.1",
43
+    "react-native": "0.57.5",
40 44
     "semantic-release": "15.10.3",
41 45
     "typescript": "3.1.6",
42 46
     "typescript-eslint-parser": "21.0.1"

+ 21
- 21
src/WebView.android.tsx Datei anzeigen

@@ -1,6 +1,5 @@
1 1
 import React from 'react';
2 2
 
3
-import ReactNative from 'react-native';
4 3
 import {
5 4
   ActivityIndicator,
6 5
   StyleSheet,
@@ -10,6 +9,7 @@ import {
10 9
   NativeModules,
11 10
   Image,
12 11
   NativeSyntheticEvent,
12
+  findNodeHandle,
13 13
 } from 'react-native';
14 14
 
15 15
 import invariant from 'invariant';
@@ -33,7 +33,7 @@ enum WebViewState {
33 33
   ERROR = 'ERROR',
34 34
 }
35 35
 
36
-const defaultRenderLoading = () => (
36
+const defaultRenderLoading = (): React.ReactNode => (
37 37
   <View style={styles.loadingView}>
38 38
     <ActivityIndicator style={styles.loadingProgressBar} />
39 39
   </View>
@@ -61,10 +61,9 @@ export default class WebView extends React.Component<
61 61
     originWhitelist: WebViewShared.defaultOriginWhitelist,
62 62
   };
63 63
 
64
-  static isFileUploadSupported = async () => {
64
+  static isFileUploadSupported = async (): Promise<boolean> =>
65 65
     // native implementation should return "true" only for Android 5+
66
-    return NativeModules.RNCWebView.isFileUploadSupported();
67
-  };
66
+    NativeModules.RNCWebView.isFileUploadSupported();
68 67
 
69 68
   state: State = {
70 69
     viewState: this.props.startInLoadingState
@@ -75,31 +74,34 @@ export default class WebView extends React.Component<
75 74
 
76 75
   webViewRef = React.createRef<React.ComponentClass>();
77 76
 
78
-  render() {
77
+  render(): React.ReactNode {
79 78
     let otherView = null;
80 79
 
81 80
     if (this.state.viewState === WebViewState.LOADING) {
82 81
       otherView = (this.props.renderLoading || defaultRenderLoading)();
83 82
     } else if (this.state.viewState === WebViewState.ERROR) {
84 83
       const errorEvent = this.state.lastErrorEvent;
85
-      invariant(errorEvent != null, 'lastErrorEvent expected to be non-null');
86
-      otherView =
87
-        this.props.renderError &&
88
-        this.props.renderError(
89
-          errorEvent!.domain,
90
-          errorEvent!.code,
91
-          errorEvent!.description,
92
-        );
84
+      if (errorEvent) {
85
+        otherView
86
+          = this.props.renderError
87
+          && this.props.renderError(
88
+            errorEvent.domain,
89
+            errorEvent.code,
90
+            errorEvent.description,
91
+          );
92
+      } else {
93
+        invariant(errorEvent != null, 'lastErrorEvent expected to be non-null');
94
+      }
93 95
     } else if (this.state.viewState !== WebViewState.IDLE) {
94 96
       console.error(
95
-        'RNCWebView invalid state encountered: ' + this.state.viewState,
97
+        `RNCWebView invalid state encountered: ${this.state.viewState}`,
96 98
       );
97 99
     }
98 100
 
99 101
     const webViewStyles = [styles.container, this.props.style];
100 102
     if (
101
-      this.state.viewState === WebViewState.LOADING ||
102
-      this.state.viewState === WebViewState.ERROR
103
+      this.state.viewState === WebViewState.LOADING
104
+      || this.state.viewState === WebViewState.ERROR
103 105
     ) {
104 106
       // if we're in either LOADING or ERROR states, don't show the webView
105 107
       webViewStyles.push(styles.hidden);
@@ -128,7 +130,7 @@ export default class WebView extends React.Component<
128 130
       WebViewShared.originWhitelistToRegex,
129 131
     );
130 132
 
131
-    let NativeWebView = nativeConfig.component || RNCWebView;
133
+    const NativeWebView = nativeConfig.component || RNCWebView;
132 134
 
133 135
     const webView = (
134 136
       <NativeWebView
@@ -246,9 +248,7 @@ export default class WebView extends React.Component<
246 248
     }
247 249
   };
248 250
 
249
-  getWebViewHandle = () => {
250
-    return ReactNative.findNodeHandle(this.webViewRef.current);
251
-  };
251
+  getWebViewHandle = () => findNodeHandle(this.webViewRef.current);
252 252
 
253 253
   onLoadingStart = (event: WebViewNavigationEvent) => {
254 254
     const onLoadStart = this.props.onLoadStart;

+ 18
- 20
src/WebView.ios.tsx Datei anzeigen

@@ -79,9 +79,9 @@ const defaultRenderError = (
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
 
@@ -112,6 +112,7 @@ export default class WebView extends React.Component<
112 112
   State
113 113
 > {
114 114
   static JSNavigationScheme = JSNavigationScheme;
115
+
115 116
   static NavigationType = NavigationType;
116 117
 
117 118
   static defaultProps = {
@@ -119,10 +120,9 @@ export default class WebView extends React.Component<
119 120
     originWhitelist: WebViewShared.defaultOriginWhitelist,
120 121
   };
121 122
 
122
-  static isFileUploadSupported = async () => {
123
+  static isFileUploadSupported = async () =>
123 124
     // no native implementation for iOS, depends only on permissions
124
-    return true;
125
-  };
125
+    true;
126 126
 
127 127
   state: State = {
128 128
     viewState: this.props.startInLoadingState
@@ -135,16 +135,16 @@ export default class WebView extends React.Component<
135 135
 
136 136
   UNSAFE_componentWillMount() {
137 137
     if (
138
-      this.props.useWebKit === true &&
139
-      this.props.scalesPageToFit !== undefined
138
+      this.props.useWebKit === true
139
+      && this.props.scalesPageToFit !== undefined
140 140
     ) {
141 141
       console.warn(
142 142
         'The scalesPageToFit property is not supported when useWebKit = true',
143 143
       );
144 144
     }
145 145
     if (
146
-      !this.props.useWebKit &&
147
-      this.props.allowsBackForwardNavigationGestures
146
+      !this.props.useWebKit
147
+      && this.props.allowsBackForwardNavigationGestures
148 148
     ) {
149 149
       console.warn(
150 150
         'The allowsBackForwardNavigationGestures property is not supported when useWebKit = false',
@@ -152,7 +152,7 @@ export default class WebView extends React.Component<
152 152
     }
153 153
   }
154 154
 
155
-  render() {
155
+  render(): React.ReactNode {
156 156
     let otherView = null;
157 157
 
158 158
     let scalesPageToFit;
@@ -175,14 +175,14 @@ export default class WebView extends React.Component<
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
 
182 182
     const webViewStyles = [styles.container, styles.webView, this.props.style];
183 183
     if (
184
-      this.state.viewState === WebViewState.LOADING ||
185
-      this.state.viewState === WebViewState.ERROR
184
+      this.state.viewState === WebViewState.LOADING
185
+      || this.state.viewState === WebViewState.ERROR
186 186
     ) {
187 187
       // if we're in either LOADING or ERROR states, don't show the webView
188 188
       webViewStyles.push(styles.hidden);
@@ -216,9 +216,9 @@ export default class WebView extends React.Component<
216 216
         Linking.openURL(url);
217 217
       }
218 218
       if (this.props.onShouldStartLoadWithRequest) {
219
-        shouldStart =
220
-          shouldStart &&
221
-          this.props.onShouldStartLoadWithRequest(event.nativeEvent);
219
+        shouldStart
220
+          = shouldStart
221
+          && this.props.onShouldStartLoadWithRequest(event.nativeEvent);
222 222
       }
223 223
       invariant(viewManager != null, 'viewManager expected to be non-null');
224 224
       viewManager.startLoadWithResult(
@@ -392,9 +392,7 @@ export default class WebView extends React.Component<
392 392
   /**
393 393
    * Returns the native `WebView` node.
394 394
    */
395
-  getWebViewHandle = () => {
396
-    return findNodeHandle(this.webViewRef.current);
397
-  };
395
+  getWebViewHandle = () => findNodeHandle(this.webViewRef.current);
398 396
 
399 397
   _onLoadingStart = (event: WebViewNavigationEvent) => {
400 398
     const onLoadStart = this.props.onLoadStart;

+ 3
- 4
src/WebViewShared.ts Datei anzeigen

@@ -1,4 +1,4 @@
1
-const escapeStringRegexp = require('escape-string-regexp');
1
+import escapeStringRegexp from 'escape-string-regexp';
2 2
 
3 3
 const WebViewShared = {
4 4
   defaultOriginWhitelist: ['http://*', 'https://*'],
@@ -6,9 +6,8 @@ const WebViewShared = {
6 6
     const result = /^[A-Za-z0-9]+:(\/\/)?[^/]*/.exec(url);
7 7
     return result === null ? '' : result[0];
8 8
   },
9
-  originWhitelistToRegex: (originWhitelist: string): string => {
10
-    return escapeStringRegexp(originWhitelist).replace(/\\\*/g, '.*');
11
-  },
9
+  originWhitelistToRegex: (originWhitelist: string): string =>
10
+    escapeStringRegexp(originWhitelist).replace(/\\\*/g, '.*'),
12 11
 };
13 12
 
14 13
 export default WebViewShared;

+ 2
- 2
src/index.ts Datei anzeigen

@@ -1,2 +1,2 @@
1
-export * from './types/WebViewTypes'
2
-export * from './WebView.ios'
1
+export * from './types/WebViewTypes';
2
+export * from './WebView.ios';

+ 4
- 0
src/test.ts Datei anzeigen

@@ -0,0 +1,4 @@
1
+const a
2
+  = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
3
+
4
+console.log(a);

+ 12
- 0
src/test.tsx Datei anzeigen

@@ -0,0 +1,12 @@
1
+import React from 'react';
2
+
3
+const Test: React.SFC<{
4
+  show: boolean;
5
+}> = ({ show }): React.ReactElement<string> => show && <div />;
6
+
7
+const a =
8
+  'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
9
+
10
+console.log(a);
11
+
12
+export default Test;

+ 2
- 2
src/types/WebViewTypes.ts Datei anzeigen

@@ -68,8 +68,8 @@ export type WebViewMessageEvent = NativeSyntheticEvent<WebViewMessage>;
68 68
 
69 69
 export type WebViewErrorEvent = NativeSyntheticEvent<WebViewError>;
70 70
 
71
-export type DataDetectorTypes =
72
-  | 'phoneNumber'
71
+export type DataDetectorTypes
72
+  = | 'phoneNumber'
73 73
   | 'link'
74 74
   | 'address'
75 75
   | 'calendarEvent'

+ 3
- 2
src/utils.ts Datei anzeigen

@@ -1,3 +1,4 @@
1
-import { WebViewSourceUri } from "./types/WebViewTypes";
1
+import { WebViewSourceUri } from './types/WebViewTypes';
2
+
2 3
 export const isWebViewUriSource = (source: any): source is WebViewSourceUri =>
3
-  typeof source !== "number" && !("html" in source);
4
+  typeof source !== 'number' && !('html' in source);

+ 5
- 14
tsconfig.json Datei anzeigen

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

+ 2188
- 87
yarn.lock
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen