|
@@ -1,11 +1,11 @@
|
1
|
|
-//@flow
|
|
1
|
+// @flow
|
2
|
2
|
import React, { Component } from "react";
|
3
|
3
|
import { View, NativeModules, Platform, findNodeHandle } from "react-native";
|
4
|
4
|
const { RNViewShot } = NativeModules;
|
5
|
5
|
|
6
|
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
|
10
|
const neverEndingPromise = new Promise(() => {});
|
11
|
11
|
|
|
@@ -41,11 +41,11 @@ const defaultOptions = {
|
41
|
41
|
|
42
|
42
|
// validate and coerce options
|
43
|
43
|
function validateOptions(
|
44
|
|
- options: ?Object
|
|
44
|
+ input: ?$Shape<Options>
|
45
|
45
|
): { options: Options, errors: Array<string> } {
|
46
|
|
- options = {
|
|
46
|
+ const options: Options = {
|
47
|
47
|
...defaultOptions,
|
48
|
|
- ...options
|
|
48
|
+ ...input
|
49
|
49
|
};
|
50
|
50
|
const errors = [];
|
51
|
51
|
if (
|
|
@@ -103,22 +103,23 @@ export function ensureModuleIsLoaded() {
|
103
|
103
|
}
|
104
|
104
|
|
105
|
105
|
export function captureRef<T: ElementType>(
|
106
|
|
- view: number | ?View | Ref<T>,
|
|
106
|
+ input: number | ?View | Ref<T>,
|
107
|
107
|
optionsObject?: Object
|
108
|
108
|
): Promise<string> {
|
109
|
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
|
114
|
if (!view) {
|
114
|
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
|
120
|
if (!node) {
|
120
|
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
|
125
|
view = node;
|
|
@@ -130,7 +131,7 @@ export function captureRef<T: ElementType>(
|
130
|
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
|
137
|
export function releaseCapture(uri: string): void {
|
|
@@ -190,17 +191,14 @@ function checkCompatibleProps(props: Props) {
|
190
|
191
|
export default class ViewShot extends Component<Props> {
|
191
|
192
|
static captureRef = captureRef;
|
192
|
193
|
static releaseCapture = releaseCapture;
|
193
|
|
- constructor(props) {
|
194
|
|
- super(props);
|
195
|
|
- this.state = {};
|
196
|
|
- }
|
|
194
|
+
|
197
|
195
|
root: ?View;
|
198
|
196
|
|
199
|
197
|
_raf: *;
|
200
|
198
|
lastCapturedURI: ?string;
|
201
|
199
|
|
202
|
200
|
resolveFirstLayout: (layout: Object) => void;
|
203
|
|
- firstLayoutPromise = new Promise(resolve => {
|
|
201
|
+ firstLayoutPromise: Promise<Object> = new Promise(resolve => {
|
204
|
202
|
this.resolveFirstLayout = resolve;
|
205
|
203
|
});
|
206
|
204
|
|
|
@@ -272,7 +270,7 @@ export default class ViewShot extends Component<Props> {
|
272
|
270
|
}
|
273
|
271
|
}
|
274
|
272
|
|
275
|
|
- componentDidUpdate(prevProps) {
|
|
273
|
+ componentDidUpdate(prevProps: Props) {
|
276
|
274
|
if (this.props.captureMode !== undefined) {
|
277
|
275
|
if (this.props.captureMode !== prevProps.captureMode) {
|
278
|
276
|
this.syncCaptureLoop(this.props.captureMode);
|