Browse Source

Fixes flow

closes #275
Gaëtan Renaudeau 4 years ago
parent
commit
323b613ef2
No account linked to committer's email address
6 changed files with 5536 additions and 542 deletions
  1. 5
    40
      .flowconfig
  2. 19
    19
      example/package.json
  3. 813
    463
      example/yarn.lock
  4. 5
    0
      package.json
  5. 18
    20
      src/index.js
  6. 4676
    0
      yarn.lock

+ 5
- 40
.flowconfig View File

1
 [ignore]
1
 [ignore]
2
-
3
-# We fork some components by platform.
4
-.*/*[.]android.js
5
-
6
-# Ignore templates with `@flow` in header
7
-.*/local-cli/generator.*
8
-
9
-# Ignore malformed json
10
-.*/node_modules/y18n/test/.*\.json
11
-
12
-# Ignore unexpected extra @providesModule
13
-.*/node_modules/commoner/test/source/widget/share.js
14
-
15
-# Ignore duplicate module providers
16
-# For RN Apps installed via npm, "Libraries" folder is inside node_modules/react-native but in the source repo it is in the root
17
-.*/Libraries/react-native/React.js
18
-.*/Libraries/react-native/ReactNative.js
19
-.*/node_modules/jest-runtime/build/__tests__/.*
2
+<PROJECT_ROOT>/example/
20
 
3
 
21
 [include]
4
 [include]
22
 
5
 
23
 [libs]
6
 [libs]
24
-node_modules/react-native/Libraries/react-native/react-native-interface.js
25
 node_modules/react-native/flow
7
 node_modules/react-native/flow
26
-flow/
27
-
28
-[options]
29
-module.system=haste
30
-
31
-esproposal.class_static_fields=enable
32
-esproposal.class_instance_fields=enable
33
-
34
-experimental.strict_type_args=true
35
-
36
-munge_underscores=true
37
-
38
-module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
39
-module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
8
+node_modules/react-native/Libraries/react-native/react-native-interface.js
40
 
9
 
41
-suppress_type=$FlowIssue
42
-suppress_type=$FlowFixMe
43
-suppress_type=$FixMe
10
+[lints]
44
 
11
 
45
-suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-2]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
46
-suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-2]\\|1[0-9]\\|[1-2][0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
47
-suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
12
+[options]
48
 
13
 
49
-unsafe.enable_getters_and_setters=true
14
+[strict]

+ 19
- 19
example/package.json View File

7
     "lint": "eslint ."
7
     "lint": "eslint ."
8
   },
8
   },
9
   "dependencies": {
9
   "dependencies": {
10
-    "@react-native-community/art": "^1.0.1",
11
-    "@react-native-community/slider": "^2.0.0",
10
+    "@react-native-community/art": "^1.1.2",
11
+    "@react-native-community/slider": "^2.0.8",
12
     "gl-react": "2",
12
     "gl-react": "2",
13
     "gl-react-native": "2",
13
     "gl-react-native": "2",
14
     "lodash": "^4.17.15",
14
     "lodash": "^4.17.15",
15
-    "react": "16.8.6",
16
-    "react-native": "0.60.4",
17
-    "react-native-canvas": "^0.1.33",
18
-    "react-native-fs": "^2.14.1",
19
-    "react-native-gesture-handler": "^1.3.0",
20
-    "react-native-maps": "^0.25.0",
21
-    "react-native-reanimated": "^1.2.0",
22
-    "react-native-svg": "^9.6.2",
15
+    "react": "16.12.0",
16
+    "react-native": "0.61.5",
17
+    "react-native-canvas": "^0.1.36",
18
+    "react-native-fs": "^2.16.2",
19
+    "react-native-gesture-handler": "^1.5.3",
20
+    "react-native-maps": "^0.26.1",
21
+    "react-native-reanimated": "^1.7.0",
22
+    "react-native-svg": "^11.0.1",
23
     "react-native-svg-uri": "^1.2.3",
23
     "react-native-svg-uri": "^1.2.3",
24
-    "react-native-video": "^5.0.0",
24
+    "react-native-video": "^5.0.2",
25
     "react-native-view-shot": "^3.0.2",
25
     "react-native-view-shot": "^3.0.2",
26
-    "react-native-webview": "^6.9.0",
27
-    "react-navigation": "^3.11.1"
26
+    "react-native-webview": "^8.0.3",
27
+    "react-navigation": "^4.0.10"
28
   },
28
   },
29
   "devDependencies": {
29
   "devDependencies": {
30
-    "@babel/core": "^7.5.5",
31
-    "@babel/runtime": "^7.5.5",
32
-    "@react-native-community/eslint-config": "^0.0.5",
33
-    "eslint": "^6.1.0",
30
+    "@babel/core": "^7.8.3",
31
+    "@babel/runtime": "^7.8.3",
32
+    "@react-native-community/eslint-config": "^0.0.6",
33
+    "eslint": "^6.8.0",
34
     "flow-bin": "0.98.0",
34
     "flow-bin": "0.98.0",
35
-    "metro-react-native-babel-preset": "^0.55.0",
36
-    "react-test-renderer": "16.8.6"
35
+    "metro-react-native-babel-preset": "^0.56.4",
36
+    "react-test-renderer": "16.12.0"
37
   }
37
   }
38
 }
38
 }

+ 813
- 463
example/yarn.lock
File diff suppressed because it is too large
View File


+ 5
- 0
package.json View File

22
   "peerDependencies": {
22
   "peerDependencies": {
23
     "react": "*",
23
     "react": "*",
24
     "react-native": "*"
24
     "react-native": "*"
25
+  },
26
+  "devDependencies": {
27
+    "flow-bin": "^0.116.1",
28
+    "react": "^16.12.0",
29
+    "react-native": "^0.61.5"
25
   }
30
   }
26
 }
31
 }

+ 18
- 20
src/index.js View File

1
-//@flow
1
+// @flow
2
 import React, { Component } from "react";
2
 import React, { Component } from "react";
3
 import { View, NativeModules, Platform, findNodeHandle } from "react-native";
3
 import { View, NativeModules, Platform, findNodeHandle } from "react-native";
4
 const { RNViewShot } = NativeModules;
4
 const { RNViewShot } = NativeModules;
5
 
5
 
6
 import type { Element, ElementRef, ElementType, Ref } from "react";
6
 import type { Element, ElementRef, ElementType, Ref } from "react";
7
-import type { ViewStyleProp } from "StyleSheet";
8
-import type { LayoutEvent } from "CoreEventTypes";
7
+import type { ViewStyleProp } from "react-native/Libraries/StyleSheet/StyleSheet";
8
+import type { LayoutEvent } from "react-native/Libraries/Types/CoreEventTypes";
9
 
9
 
10
 const neverEndingPromise = new Promise(() => {});
10
 const neverEndingPromise = new Promise(() => {});
11
 
11
 
41
 
41
 
42
 // validate and coerce options
42
 // validate and coerce options
43
 function validateOptions(
43
 function validateOptions(
44
-  options: ?Object
44
+  input: ?$Shape<Options>
45
 ): { options: Options, errors: Array<string> } {
45
 ): { options: Options, errors: Array<string> } {
46
-  options = {
46
+  const options: Options = {
47
     ...defaultOptions,
47
     ...defaultOptions,
48
-    ...options
48
+    ...input
49
   };
49
   };
50
   const errors = [];
50
   const errors = [];
51
   if (
51
   if (
103
 }
103
 }
104
 
104
 
105
 export function captureRef<T: ElementType>(
105
 export function captureRef<T: ElementType>(
106
-  view: number | ?View | Ref<T>,
106
+  input: number | ?View | Ref<T>,
107
   optionsObject?: Object
107
   optionsObject?: Object
108
 ): Promise<string> {
108
 ): Promise<string> {
109
   ensureModuleIsLoaded();
109
   ensureModuleIsLoaded();
110
-  if (view && typeof view === "object" && "current" in view && view.current) {
111
-    // React.RefObject
112
-    view = view.current;
110
+  let view;
111
+  if (input && typeof input === "object" && "current" in input) {
112
+    // $FlowFixMe input is a ref
113
+    view = input.current;
113
     if (!view) {
114
     if (!view) {
114
       return Promise.reject(new Error("ref.current is null"));
115
       return Promise.reject(new Error("ref.current is null"));
115
     }
116
     }
116
   }
117
   }
117
-  if (typeof view !== "number") {
118
-    const node = findNodeHandle(view);
118
+  if (typeof input !== "number") {
119
+    const node = findNodeHandle(input);
119
     if (!node) {
120
     if (!node) {
120
       return Promise.reject(
121
       return Promise.reject(
121
-        new Error("findNodeHandle failed to resolve view=" + String(view))
122
+        new Error("findNodeHandle failed to resolve view=" + String(input))
122
       );
123
       );
123
     }
124
     }
124
     view = node;
125
     view = node;
130
         errors.map(e => `- ${e}`).join("\n")
131
         errors.map(e => `- ${e}`).join("\n")
131
     );
132
     );
132
   }
133
   }
133
-  return RNViewShot.captureRef(view, options);
134
+  return RNViewShot.captureRef(input, options);
134
 }
135
 }
135
 
136
 
136
 export function releaseCapture(uri: string): void {
137
 export function releaseCapture(uri: string): void {
190
 export default class ViewShot extends Component<Props> {
191
 export default class ViewShot extends Component<Props> {
191
   static captureRef = captureRef;
192
   static captureRef = captureRef;
192
   static releaseCapture = releaseCapture;
193
   static releaseCapture = releaseCapture;
193
-  constructor(props) {
194
-    super(props);
195
-    this.state = {};
196
-  }
194
+
197
   root: ?View;
195
   root: ?View;
198
 
196
 
199
   _raf: *;
197
   _raf: *;
200
   lastCapturedURI: ?string;
198
   lastCapturedURI: ?string;
201
 
199
 
202
   resolveFirstLayout: (layout: Object) => void;
200
   resolveFirstLayout: (layout: Object) => void;
203
-  firstLayoutPromise = new Promise(resolve => {
201
+  firstLayoutPromise: Promise<Object> = new Promise(resolve => {
204
     this.resolveFirstLayout = resolve;
202
     this.resolveFirstLayout = resolve;
205
   });
203
   });
206
 
204
 
272
     }
270
     }
273
   }
271
   }
274
 
272
 
275
-  componentDidUpdate(prevProps) {
273
+  componentDidUpdate(prevProps: Props) {
276
     if (this.props.captureMode !== undefined) {
274
     if (this.props.captureMode !== undefined) {
277
       if (this.props.captureMode !== prevProps.captureMode) {
275
       if (this.props.captureMode !== prevProps.captureMode) {
278
         this.syncCaptureLoop(this.props.captureMode);
276
         this.syncCaptureLoop(this.props.captureMode);

+ 4676
- 0
yarn.lock
File diff suppressed because it is too large
View File