[fix] Flow type checking and annotations

Fixes dozens of Flow errors; adds type annotations; marks more files for
Flow type checking. Fixes a bug in 'AppState'.

15 Flow errors remaining. Several React Native files are still not type
checked (e.g., PanResponder, Touchables)

Ref #465
This commit is contained in:
Nicolas Gallagher
2017-05-27 10:43:04 -07:00
parent edef737249
commit bcdeda5dab
40 changed files with 212 additions and 52 deletions

View File

@@ -15,6 +15,29 @@ import UIManager from '../../apis/UIManager';
const hyphenPattern = /-([a-z])/g;
const toCamelCase = str => str.replace(hyphenPattern, m => m[1].toUpperCase());
type MeasureOnSuccessCallback = (
x: number,
y: number,
width: number,
height: number,
pageX: number,
pageY: number
) => void;
type MeasureInWindowOnSuccessCallback = (
x: number,
y: number,
width: number,
height: number
) => void;
type MeasureLayoutOnSuccessCallback = (
left: number,
top: number,
width: number,
height: number
) => void;
const NativeMethodsMixin = {
/**
* Removes focus from an input or view. This is the opposite of `focus()`.
@@ -34,7 +57,7 @@ const NativeMethodsMixin = {
/**
* Determines the position and dimensions of the view
*/
measure(callback) {
measure(callback: MeasureOnSuccessCallback) {
UIManager.measure(findNodeHandle(this), callback);
},
@@ -53,14 +76,18 @@ const NativeMethodsMixin = {
* Note that these measurements are not available until after the rendering
* has been completed.
*/
measureInWindow(callback) {
measureInWindow(callback: MeasureInWindowOnSuccessCallback) {
UIManager.measureInWindow(findNodeHandle(this), callback);
},
/**
* Measures the view relative to another view (usually an ancestor)
*/
measureLayout(relativeToNativeNode, onSuccess, onFail) {
measureLayout(
relativeToNativeNode: Object,
onSuccess: MeasureLayoutOnSuccessCallback,
onFail: () => void
) {
UIManager.measureLayout(findNodeHandle(this), relativeToNativeNode, onFail, onSuccess);
},

View File

@@ -35,7 +35,7 @@ const safeOverride = (original, next) => {
return next;
};
const applyLayout = Component => {
const applyLayout = (Component: ReactClass<any>) => {
const componentDidMount = Component.prototype.componentDidMount;
const componentDidUpdate = Component.prototype.componentDidUpdate;
const componentWillUnmount = Component.prototype.componentWillUnmount;

View File

@@ -7,7 +7,7 @@
import NativeMethodsMixin from '../NativeMethodsMixin';
const applyNativeMethods = Component => {
const applyNativeMethods = (Component: ReactClass<any>) => {
Object.keys(NativeMethodsMixin).forEach(method => {
if (!Component.prototype[method]) {
Component.prototype[method] = NativeMethodsMixin[method];