Skip to content

Commit 2c7f5b4

Browse files
authored
Merge pull request #196 from gaykov/flow-fixes
Fix flow types
2 parents 322de51 + 4e6c435 commit 2c7f5b4

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/index.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import React, { Component } from "react";
33
import { View, NativeModules, Platform, findNodeHandle } from "react-native";
44
const { RNViewShot } = NativeModules;
55

6+
import type { Element, ElementRef } from 'react';
7+
import type { ViewStyleProp } from 'StyleSheet';
8+
import type { LayoutEvent } from 'CoreEventTypes';
9+
610
const neverEndingPromise = new Promise(() => {});
711

812
type Options = {
@@ -85,7 +89,7 @@ function validateOptions(
8589
}
8690

8791
export function captureRef(
88-
view: number | ReactElement<*>,
92+
view: number | ?View,
8993
optionsObject?: Object
9094
): Promise<string> {
9195
if (typeof view !== "number") {
@@ -132,10 +136,11 @@ export function captureScreen(
132136
type Props = {
133137
options?: Object,
134138
captureMode?: "mount" | "continuous" | "update",
135-
children: React.Element<*>,
139+
children: Element<*>,
136140
onLayout?: (e: *) => void,
137141
onCapture?: (uri: string) => void,
138-
onCaptureFailure?: (e: Error) => void
142+
onCaptureFailure?: (e: Error) => void,
143+
style?: ViewStyleProp
139144
};
140145

141146
function checkCompatibleProps(props: Props) {
@@ -160,17 +165,16 @@ function checkCompatibleProps(props: Props) {
160165
}
161166
}
162167

163-
export default class ViewShot extends Component {
168+
export default class ViewShot extends Component<Props> {
164169
static captureRef = captureRef;
165170
static releaseCapture = releaseCapture;
166-
props: Props;
167171
root: ?View;
168172

169173
_raf: *;
170174
lastCapturedURI: ?string;
171175

172176
resolveFirstLayout: (layout: Object) => void;
173-
firstLayoutPromise = new Promise(resolve => {
177+
firstLayoutPromise = new Promise<void>(resolve => {
174178
this.resolveFirstLayout = resolve;
175179
});
176180

@@ -223,11 +227,11 @@ export default class ViewShot extends Component {
223227
}
224228
};
225229

226-
onRef = (ref: View) => {
230+
onRef = (ref: ElementRef<*>) => {
227231
this.root = ref;
228232
};
229233

230-
onLayout = (e: { nativeEvent: { layout: Object } }) => {
234+
onLayout = (e: LayoutEvent) => {
231235
const { onLayout } = this.props;
232236
this.resolveFirstLayout(e.nativeEvent.layout);
233237
if (onLayout) onLayout(e);

0 commit comments

Comments
 (0)