flowify Libraries/ReactIOS
This commit is contained in:
parent
f124c32143
commit
7ffa7942aa
|
@ -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
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule IOSDefaultEventPluginOrder
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule React
|
||||
* @flow
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactIOSComponentEnvironment
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactIOSComponentMixin
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactIOSDefaultInjection
|
||||
* @flow
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 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;
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,3 +12,7 @@
|
|||
// see also react-native.js
|
||||
|
||||
declare var __DEV__: boolean;
|
||||
|
||||
declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{
|
||||
inject: ?((stuff: Object) => void)
|
||||
};*/
|
||||
|
|
Loading…
Reference in New Issue