diff --git a/.flowconfig b/.flowconfig index 28625456dcd07a..c4265b9b2c6f0c 100644 --- a/.flowconfig +++ b/.flowconfig @@ -10,7 +10,8 @@ # Ignore react-tools where there are overlaps, but don't ignore anything that # react-native relies on .*/node_modules/react-tools/src/vendor/core/ExecutionEnvironment.js -.*/node_modules/react-tools/src/browser/.* +.*/node_modules/react-tools/src/browser/eventPlugins/ResponderEventPlugin.js +.*/node_modules/react-tools/src/browser/ui/React.js .*/node_modules/react-tools/src/core/ReactInstanceHandles.js .*/node_modules/react-tools/src/event/EventPropagators.js diff --git a/Libraries/ReactIOS/IOSDefaultEventPluginOrder.js b/Libraries/ReactIOS/IOSDefaultEventPluginOrder.js index b2336692087594..80098fc414f308 100644 --- a/Libraries/ReactIOS/IOSDefaultEventPluginOrder.js +++ b/Libraries/ReactIOS/IOSDefaultEventPluginOrder.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule IOSDefaultEventPluginOrder + * @flow */ 'use strict'; diff --git a/Libraries/ReactIOS/IOSNativeBridgeEventPlugin.js b/Libraries/ReactIOS/IOSNativeBridgeEventPlugin.js index c41ae82ab18eb8..b585db5a76f810 100644 --- a/Libraries/ReactIOS/IOSNativeBridgeEventPlugin.js +++ b/Libraries/ReactIOS/IOSNativeBridgeEventPlugin.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule IOSNativeBridgeEventPlugin + * @flow */ "use strict"; @@ -51,10 +52,11 @@ var IOSNativeBridgeEventPlugin = { * @see {EventPluginHub.extractEvents} */ extractEvents: function( - topLevelType, - topLevelTarget, - topLevelTargetID, - nativeEvent) { + topLevelType: string, + topLevelTarget: EventTarget, + topLevelTargetID: string, + nativeEvent: Event + ): ?Object { var bubbleDispatchConfig = customBubblingEventTypes[topLevelType]; var directDispatchConfig = customDirectEventTypes[topLevelType]; var event = SyntheticEvent.getPooled( diff --git a/Libraries/ReactIOS/NativeMethodsMixin.js b/Libraries/ReactIOS/NativeMethodsMixin.js index 3dbe233ee9e18d..ec72a0b4f4696b 100644 --- a/Libraries/ReactIOS/NativeMethodsMixin.js +++ b/Libraries/ReactIOS/NativeMethodsMixin.js @@ -7,10 +7,10 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule NativeMethodsMixin + * @flow */ 'use strict'; -var NativeModules = require('NativeModules'); var NativeModules = require('NativeModules'); var RCTPOPAnimationManager = NativeModules.POPAnimationManager; var RCTUIManager = NativeModules.UIManager; @@ -20,7 +20,26 @@ var flattenStyle = require('flattenStyle'); var invariant = require('invariant'); var mergeFast = require('mergeFast'); -var animationIDInvariant = function(funcName, anim) { +type MeasureOnSuccessCallback = ( + x: number, + y: number, + width: number, + height: number, + pageX: number, + pageY: number +) => void + +type MeasureLayoutOnSuccessCallback = ( + left: number, + top: number, + width: number, + height: number +) => void + +var animationIDInvariant = function( + funcName: string, + anim: number +) { invariant( anim, funcName + ' must be called with a valid animation ID returned from' + @@ -29,21 +48,25 @@ var animationIDInvariant = function(funcName, anim) { }; var NativeMethodsMixin = { - addAnimation: function(anim, callback) { + addAnimation: function(anim: number, callback?: (finished: bool) => void) { animationIDInvariant('addAnimation', anim); RCTPOPAnimationManager.addAnimation(this.getNodeHandle(), anim, callback); }, - removeAnimation: function(anim) { + removeAnimation: function(anim: number) { animationIDInvariant('removeAnimation', anim); RCTPOPAnimationManager.removeAnimation(this.getNodeHandle(), anim); }, - measure: function(callback) { + measure: function(callback: MeasureOnSuccessCallback) { RCTUIManager.measure(this.getNodeHandle(), callback); }, - measureLayout: function(relativeToNativeNode, onSuccess, onFail) { + measureLayout: function( + relativeToNativeNode: number, + onSuccess: MeasureLayoutOnSuccessCallback, + onFail: () => void /* currently unused */ + ) { RCTUIManager.measureLayout( this.getNodeHandle(), relativeToNativeNode, @@ -57,7 +80,7 @@ var NativeMethodsMixin = { * in future diff process, this means that if you do not include them in the * next render, they will remain active. */ - setNativeProps: function(nativeProps) { + setNativeProps: function(nativeProps: Object) { // nativeProps contains a style attribute that's going to be flattened // and all the attributes expanded in place. In order to make this // process do as few allocations and copies as possible, we return @@ -111,15 +134,19 @@ function throwOnStylesProp(component, props) { } } if (__DEV__) { + // hide this from Flow since we can't define these properties outside of + // __DEV__ without actually implementing them (setting them to undefined + // isn't allowed by ReactClass) + var NativeMethodsMixin_DEV = (NativeMethodsMixin: any); invariant( - !NativeMethodsMixin.componentWillMount && - !NativeMethodsMixin.componentWillReceiveProps, + !NativeMethodsMixin_DEV.componentWillMount && + !NativeMethodsMixin_DEV.componentWillReceiveProps, 'Do not override existing functions.' ); - NativeMethodsMixin.componentWillMount = function () { + NativeMethodsMixin_DEV.componentWillMount = function () { throwOnStylesProp(this, this.props); }; - NativeMethodsMixin.componentWillReceiveProps = function (newProps) { + NativeMethodsMixin_DEV.componentWillReceiveProps = function (newProps) { throwOnStylesProp(this, newProps); }; } diff --git a/Libraries/ReactIOS/React.js b/Libraries/ReactIOS/React.js index 34f19013866289..ce9de085221fdd 100644 --- a/Libraries/ReactIOS/React.js +++ b/Libraries/ReactIOS/React.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule React + * @flow */ "use strict"; diff --git a/Libraries/ReactIOS/ReactIOS.js b/Libraries/ReactIOS/ReactIOS.js index e1c9480650a83f..02857742933892 100644 --- a/Libraries/ReactIOS/ReactIOS.js +++ b/Libraries/ReactIOS/ReactIOS.js @@ -7,8 +7,8 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ReactIOS + * @flow */ - "use strict"; var ReactChildren = require('ReactChildren'); @@ -51,7 +51,7 @@ var resolveDefaultProps = function(element) { }; // Experimental optimized element creation -var augmentElement = function(element) { +var augmentElement = function(element: ReactElement) { if (__DEV__) { invariant( false, @@ -67,7 +67,7 @@ var augmentElement = function(element) { return element; }; -var render = function(component, mountInto) { +var render = function(component: ReactComponent, mountInto: number) { ReactIOSMount.renderComponent(component, mountInto); }; diff --git a/Libraries/ReactIOS/ReactIOSComponentEnvironment.js b/Libraries/ReactIOS/ReactIOSComponentEnvironment.js index 664ebb6ece9874..0dc0b1d1c929e6 100644 --- a/Libraries/ReactIOS/ReactIOSComponentEnvironment.js +++ b/Libraries/ReactIOS/ReactIOSComponentEnvironment.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ReactIOSComponentEnvironment + * @flow */ 'use strict'; diff --git a/Libraries/ReactIOS/ReactIOSComponentMixin.js b/Libraries/ReactIOS/ReactIOSComponentMixin.js index d8044e5eb67eed..94c708a433e863 100644 --- a/Libraries/ReactIOS/ReactIOSComponentMixin.js +++ b/Libraries/ReactIOS/ReactIOSComponentMixin.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ReactIOSComponentMixin + * @flow */ 'use strict'; diff --git a/Libraries/ReactIOS/ReactIOSDOMIDOperations.js b/Libraries/ReactIOS/ReactIOSDOMIDOperations.js index 7e266530aed23d..7d421442f5325b 100644 --- a/Libraries/ReactIOS/ReactIOSDOMIDOperations.js +++ b/Libraries/ReactIOS/ReactIOSDOMIDOperations.js @@ -7,7 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ReactIOSDOMIDOperations - * @typechecks static-only + * @flow */ "use strict"; diff --git a/Libraries/ReactIOS/ReactIOSDefaultInjection.js b/Libraries/ReactIOS/ReactIOSDefaultInjection.js index dd67987cccb514..d6b81da2cdcef3 100644 --- a/Libraries/ReactIOS/ReactIOSDefaultInjection.js +++ b/Libraries/ReactIOS/ReactIOSDefaultInjection.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ReactIOSDefaultInjection + * @flow */ "use strict"; diff --git a/Libraries/ReactIOS/createReactIOSNativeComponentClass.js b/Libraries/ReactIOS/createReactIOSNativeComponentClass.js index 19217cb72078fe..5a5af04dc815da 100644 --- a/Libraries/ReactIOS/createReactIOSNativeComponentClass.js +++ b/Libraries/ReactIOS/createReactIOSNativeComponentClass.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule createReactIOSNativeComponentClass + * @flow */ "use strict"; @@ -14,11 +15,19 @@ var ReactElement = require('ReactElement'); var ReactIOSNativeComponent = require('ReactIOSNativeComponent'); +// See also ReactIOSNativeComponent +type ReactIOSNativeComponentViewConfig = { + validAttributes: Object; + uiViewClassName: string; +} + /** * @param {string} config iOS View configuration. * @private */ -var createReactIOSNativeComponentClass = function(viewConfig) { +var createReactIOSNativeComponentClass = function( + viewConfig: ReactIOSNativeComponentViewConfig +): Function { // returning Function is lossy :/ var Constructor = function(element) { this._currentElement = element; diff --git a/Libraries/ReactIOS/diffRawProperties.js b/Libraries/ReactIOS/diffRawProperties.js index 2be542aaa76818..3a5de284f4910e 100644 --- a/Libraries/ReactIOS/diffRawProperties.js +++ b/Libraries/ReactIOS/diffRawProperties.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule diffRawProperties + * @flow */ 'use strict'; @@ -21,34 +22,41 @@ * previous. These properties are as supplied to component construction. * @return {?object} */ -function diffRawProperties(updatePayload, prevProps, nextProps, validAttributes) { +function diffRawProperties( + updatePayload: ?Object, + prevProps: ?Object, + nextProps: ?Object, + validAttributes: Object +): ?Object { var validAttributeConfig; var nextProp; var prevProp; var isScalar; var shouldUpdate; - for (var propKey in nextProps) { - validAttributeConfig = validAttributes[propKey]; - if (!validAttributeConfig) { - continue; // not a valid native prop - } - prevProp = prevProps && prevProps[propKey]; - nextProp = nextProps[propKey]; - if (prevProp !== nextProp) { - // If you want a property's diff to be detected, you must configure it - // to be so - *or* it must be a scalar property. For now, we'll allow - // creation with any attribute that is not scalar, but we should - // eventually even reject those unless they are properly configured. - isScalar = typeof nextProp !== 'object' || nextProp === null; - shouldUpdate = isScalar || - !prevProp || - validAttributeConfig.diff && - validAttributeConfig.diff(prevProp, nextProp); + if (nextProps) { + for (var propKey in nextProps) { + validAttributeConfig = validAttributes[propKey]; + if (!validAttributeConfig) { + continue; // not a valid native prop + } + prevProp = prevProps && prevProps[propKey]; + nextProp = nextProps[propKey]; + if (prevProp !== nextProp) { + // If you want a property's diff to be detected, you must configure it + // to be so - *or* it must be a scalar property. For now, we'll allow + // creation with any attribute that is not scalar, but we should + // eventually even reject those unless they are properly configured. + isScalar = typeof nextProp !== 'object' || nextProp === null; + shouldUpdate = isScalar || + !prevProp || + validAttributeConfig.diff && + validAttributeConfig.diff(prevProp, nextProp); - if (shouldUpdate) { - updatePayload = updatePayload || {}; - updatePayload[propKey] = nextProp; + if (shouldUpdate) { + updatePayload = updatePayload || {}; + updatePayload[propKey] = nextProp; + } } } } @@ -56,31 +64,33 @@ function diffRawProperties(updatePayload, prevProps, nextProps, validAttributes) // Also iterate through all the previous props to catch any that have been // removed and make sure native gets the signal so it can reset them to the // default. - for (var propKey in prevProps) { - validAttributeConfig = validAttributes[propKey]; - if (!validAttributeConfig) { - continue; // not a valid native prop - } - if (updatePayload && updatePayload[propKey] !== undefined) { - continue; // Prop already specified - } - prevProp = prevProps[propKey]; - nextProp = nextProps && nextProps[propKey]; - if (prevProp !== nextProp) { - if (nextProp === undefined) { - nextProp = null; // null is a sentinel we explicitly send to native + if (prevProps) { + for (var propKey in prevProps) { + validAttributeConfig = validAttributes[propKey]; + if (!validAttributeConfig) { + continue; // not a valid native prop + } + if (updatePayload && updatePayload[propKey] !== undefined) { + continue; // Prop already specified } - // If you want a property's diff to be detected, you must configure it - // to be so - *or* it must be a scalar property. For now, we'll allow - // creation with any attribute that is not scalar, but we should - // eventually even reject those unless they are properly configured. - isScalar = typeof nextProp !== 'object' || nextProp === null; - shouldUpdate = isScalar && prevProp !== nextProp || - validAttributeConfig.diff && - validAttributeConfig.diff(prevProp, nextProp); - if (shouldUpdate) { - updatePayload = updatePayload || {}; - updatePayload[propKey] = nextProp; + prevProp = prevProps[propKey]; + nextProp = nextProps && nextProps[propKey]; + if (prevProp !== nextProp) { + if (nextProp === undefined) { + nextProp = null; // null is a sentinel we explicitly send to native + } + // If you want a property's diff to be detected, you must configure it + // to be so - *or* it must be a scalar property. For now, we'll allow + // creation with any attribute that is not scalar, but we should + // eventually even reject those unless they are properly configured. + isScalar = typeof nextProp !== 'object' || nextProp === null; + shouldUpdate = isScalar && prevProp !== nextProp || + validAttributeConfig.diff && + validAttributeConfig.diff(prevProp, nextProp); + if (shouldUpdate) { + updatePayload = updatePayload || {}; + updatePayload[propKey] = nextProp; + } } } } diff --git a/Libraries/react-native/react-native-interface.js b/Libraries/react-native/react-native-interface.js index 2ace792922be62..6408526b812e6a 100644 --- a/Libraries/react-native/react-native-interface.js +++ b/Libraries/react-native/react-native-interface.js @@ -12,3 +12,7 @@ // see also react-native.js declare var __DEV__: boolean; + +declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{ + inject: ?((stuff: Object) => void) +};*/