Kaynağa Gözat

Merge pull request #196 from gaykov/flow-fixes

Fix flow types
Gaëtan Renaudeau 5 yıl önce
ebeveyn
işleme
2c7f5b4d63
No account linked to committer's email address
1 değiştirilmiş dosya ile 12 ekleme ve 8 silme
  1. 12
    8
      src/index.js

+ 12
- 8
src/index.js Dosyayı Görüntüle

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