Browse Source

Fix flow types

Sergey 5 years ago
parent
commit
4e6c435adc
No account linked to committer's email address
1 changed files with 12 additions and 8 deletions
  1. 12
    8
      src/index.js

+ 12
- 8
src/index.js View File

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 } from 'react';
7
+import type { ViewStyleProp } from 'StyleSheet';
8
+import type { LayoutEvent } from 'CoreEventTypes';
9
+
6
 const neverEndingPromise = new Promise(() => {});
10
 const neverEndingPromise = new Promise(() => {});
7
 
11
 
8
 type Options = {
12
 type Options = {
85
 }
89
 }
86
 
90
 
87
 export function captureRef(
91
 export function captureRef(
88
-  view: number | ReactElement<*>,
92
+  view: number | ?View,
89
   optionsObject?: Object
93
   optionsObject?: Object
90
 ): Promise<string> {
94
 ): Promise<string> {
91
   if (typeof view !== "number") {
95
   if (typeof view !== "number") {
132
 type Props = {
136
 type Props = {
133
   options?: Object,
137
   options?: Object,
134
   captureMode?: "mount" | "continuous" | "update",
138
   captureMode?: "mount" | "continuous" | "update",
135
-  children: React.Element<*>,
139
+  children: Element<*>,
136
   onLayout?: (e: *) => void,
140
   onLayout?: (e: *) => void,
137
   onCapture?: (uri: string) => void,
141
   onCapture?: (uri: string) => void,
138
-  onCaptureFailure?: (e: Error) => void
142
+  onCaptureFailure?: (e: Error) => void,
143
+  style?: ViewStyleProp
139
 };
144
 };
140
 
145
 
141
 function checkCompatibleProps(props: Props) {
146
 function checkCompatibleProps(props: Props) {
160
   }
165
   }
161
 }
166
 }
162
 
167
 
163
-export default class ViewShot extends Component {
168
+export default class ViewShot extends Component<Props> {
164
   static captureRef = captureRef;
169
   static captureRef = captureRef;
165
   static releaseCapture = releaseCapture;
170
   static releaseCapture = releaseCapture;
166
-  props: Props;
167
   root: ?View;
171
   root: ?View;
168
 
172
 
169
   _raf: *;
173
   _raf: *;
170
   lastCapturedURI: ?string;
174
   lastCapturedURI: ?string;
171
 
175
 
172
   resolveFirstLayout: (layout: Object) => void;
176
   resolveFirstLayout: (layout: Object) => void;
173
-  firstLayoutPromise = new Promise(resolve => {
177
+  firstLayoutPromise = new Promise<void>(resolve => {
174
     this.resolveFirstLayout = resolve;
178
     this.resolveFirstLayout = resolve;
175
   });
179
   });
176
 
180
 
223
     }
227
     }
224
   };
228
   };
225
 
229
 
226
-  onRef = (ref: View) => {
230
+  onRef = (ref: ElementRef<*>) => {
227
     this.root = ref;
231
     this.root = ref;
228
   };
232
   };
229
 
233
 
230
-  onLayout = (e: { nativeEvent: { layout: Object } }) => {
234
+  onLayout = (e: LayoutEvent) => {
231
     const { onLayout } = this.props;
235
     const { onLayout } = this.props;
232
     this.resolveFirstLayout(e.nativeEvent.layout);
236
     this.resolveFirstLayout(e.nativeEvent.layout);
233
     if (onLayout) onLayout(e);
237
     if (onLayout) onLayout(e);