Flowify a bunch of Libraries

This commit is contained in:
Marshall Roch 2015-03-24 18:33:05 -07:00
parent d71bfa104d
commit 9eec8aa9d5
9 changed files with 69 additions and 21 deletions

View File

@ -7,12 +7,25 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule queryLayoutByID * @providesModule queryLayoutByID
* @flow
*/ */
'use strict'; 'use strict';
var ReactIOSTagHandles = require('ReactIOSTagHandles'); var ReactIOSTagHandles = require('ReactIOSTagHandles');
var RCTUIManager = require('NativeModules').UIManager; var RCTUIManager = require('NativeModules').UIManager;
type OnSuccessCallback = (
left: number,
top: number,
width: number,
height: number,
pageX: number,
pageY: number
) => void
// I don't know what type error is...
type OnErrorCallback = (error: any) => void
/** /**
* Queries the layout of a view. The layout does not reflect the element as * Queries the layout of a view. The layout does not reflect the element as
* seen by the user, rather it reflects the position within the layout system, * seen by the user, rather it reflects the position within the layout system,
@ -32,7 +45,11 @@ var RCTUIManager = require('NativeModules').UIManager;
* @param {function} onError `func(error)` * @param {function} onError `func(error)`
* @param {function} onSuccess `func(left, top, width, height, pageX, pageY)` * @param {function} onSuccess `func(left, top, width, height, pageX, pageY)`
*/ */
var queryLayoutByID = function(rootNodeID, onError, onSuccess) { var queryLayoutByID = function(
rootNodeID: string,
onError: OnErrorCallback,
onSuccess: OnSuccessCallback
): void {
// Native bridge doesn't *yet* surface errors. // Native bridge doesn't *yet* surface errors.
RCTUIManager.measure( RCTUIManager.measure(
ReactIOSTagHandles.rootNodeIDToTag[rootNodeID], ReactIOSTagHandles.rootNodeIDToTag[rootNodeID],

View File

@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule ReactIOSGlobalInteractionHandler * @providesModule ReactIOSGlobalInteractionHandler
* @flow
*/ */
'use strict'; 'use strict';
@ -17,7 +18,7 @@ var InteractionManager = require('InteractionManager');
var interactionHandle = null; var interactionHandle = null;
var ReactIOSGlobalInteractionHandler = { var ReactIOSGlobalInteractionHandler = {
onChange: function(numberActiveTouches) { onChange: function(numberActiveTouches: number) {
if (numberActiveTouches === 0) { if (numberActiveTouches === 0) {
if (interactionHandle) { if (interactionHandle) {
InteractionManager.clearInteractionHandle(interactionHandle); InteractionManager.clearInteractionHandle(interactionHandle);

View File

@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule ReactIOSGlobalResponderHandler * @providesModule ReactIOSGlobalResponderHandler
* @flow
*/ */
'use strict'; 'use strict';
@ -14,7 +15,7 @@ var RCTUIManager = require('NativeModules').UIManager;
var ReactIOSTagHandles = require('ReactIOSTagHandles'); var ReactIOSTagHandles = require('ReactIOSTagHandles');
var ReactIOSGlobalResponderHandler = { var ReactIOSGlobalResponderHandler = {
onChange: function(from, to) { onChange: function(from: string, to: string) {
if (to !== null) { if (to !== null) {
RCTUIManager.setJSResponder( RCTUIManager.setJSResponder(
ReactIOSTagHandles.mostRecentMountedNodeHandleForRootNodeID(to) ReactIOSTagHandles.mostRecentMountedNodeHandleForRootNodeID(to)

View File

@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule ReactIOSMount * @providesModule ReactIOSMount
* @flow
*/ */
'use strict'; 'use strict';
@ -83,7 +84,10 @@ var ReactIOSMount = {
* @param {ReactComponent} instance Instance to render. * @param {ReactComponent} instance Instance to render.
* @param {containerTag} containerView Handle to native view tag * @param {containerTag} containerView Handle to native view tag
*/ */
renderComponent: function(descriptor, containerTag) { renderComponent: function(
descriptor: ReactComponent,
containerTag: number
) {
var instance = instantiateReactComponent(descriptor); var instance = instantiateReactComponent(descriptor);
if (!ReactIOSTagHandles.reactTagIsNativeTopRootID(containerTag)) { if (!ReactIOSTagHandles.reactTagIsNativeTopRootID(containerTag)) {
@ -152,7 +156,9 @@ var ReactIOSMount = {
* asynchronously, it's easier to just have this method be the one that calls * asynchronously, it's easier to just have this method be the one that calls
* for removal of the view. * for removal of the view.
*/ */
unmountComponentAtNodeAndRemoveContainer: function(containerTag) { unmountComponentAtNodeAndRemoveContainer: function(
containerTag: number
) {
ReactIOSMount.unmountComponentAtNode(containerTag); ReactIOSMount.unmountComponentAtNode(containerTag);
// call back into native to remove all of the subviews from this container // call back into native to remove all of the subviews from this container
RCTUIManager.removeRootView(containerTag); RCTUIManager.removeRootView(containerTag);
@ -163,7 +169,7 @@ var ReactIOSMount = {
* that has been rendered and unmounting it. There should just be one child * that has been rendered and unmounting it. There should just be one child
* component at this time. * component at this time.
*/ */
unmountComponentAtNode: function(containerTag) { unmountComponentAtNode: function(containerTag: number): bool {
var containerID = ReactIOSTagHandles.tagToRootNodeID[containerTag]; var containerID = ReactIOSTagHandles.tagToRootNodeID[containerTag];
invariant( invariant(
@ -185,20 +191,25 @@ var ReactIOSMount = {
* Unmounts a component and sends messages back to iOS to remove its subviews. * Unmounts a component and sends messages back to iOS to remove its subviews.
* *
* @param {ReactComponent} instance React component instance. * @param {ReactComponent} instance React component instance.
* @param {int} containerID ID of container we're removing from. * @param {string} containerID ID of container we're removing from.
* @final * @final
* @internal * @internal
* @see {ReactIOSMount.unmountComponentAtNode} * @see {ReactIOSMount.unmountComponentAtNode}
*/ */
unmountComponentFromNode: function(instance, containerID) { unmountComponentFromNode: function(
instance: ReactComponent,
containerID: string
) {
// call back into native to remove all of the subviews from this container // call back into native to remove all of the subviews from this container
instance.unmountComponent(); // TODO: ReactComponent.prototype.unmountComponent is missing from Flow's
// react lib.
(instance: any).unmountComponent();
var containerTag = var containerTag =
ReactIOSTagHandles.mostRecentMountedNodeHandleForRootNodeID(containerID); ReactIOSTagHandles.mostRecentMountedNodeHandleForRootNodeID(containerID);
RCTUIManager.removeSubviewsFromContainerWithID(containerTag); RCTUIManager.removeSubviewsFromContainerWithID(containerTag);
}, },
getNode: function(id) { getNode: function<T>(id: T): T {
return id; return id;
} }
}; };

View File

@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule ReactIOSNativeComponent * @providesModule ReactIOSNativeComponent
* @flow
*/ */
'use strict'; 'use strict';
@ -28,13 +29,20 @@ var registrationNames = ReactIOSEventEmitter.registrationNames;
var putListener = ReactIOSEventEmitter.putListener; var putListener = ReactIOSEventEmitter.putListener;
var deleteAllListeners = ReactIOSEventEmitter.deleteAllListeners; var deleteAllListeners = ReactIOSEventEmitter.deleteAllListeners;
type ReactIOSNativeComponentViewConfig = {
validAttributes: Object;
uiViewClassName: string;
}
/** /**
* @constructor ReactIOSNativeComponent * @constructor ReactIOSNativeComponent
* @extends ReactComponent * @extends ReactComponent
* @extends ReactMultiChild * @extends ReactMultiChild
* @param {!object} UIKit View Configuration. * @param {!object} UIKit View Configuration.
*/ */
var ReactIOSNativeComponent = function(viewConfig) { var ReactIOSNativeComponent = function(
viewConfig: ReactIOSNativeComponentViewConfig
) {
this.viewConfig = viewConfig; this.viewConfig = viewConfig;
}; };

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule ReactIOSReconcileTransaction * @providesModule ReactIOSReconcileTransaction
* @typechecks static-only * @flow
*/ */
"use strict"; "use strict";

View File

@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule ReactIOSStyleAttributes * @providesModule ReactIOSStyleAttributes
* @flow
*/ */
"use strict"; "use strict";

View File

@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule ReactIOSTagHandles * @providesModule ReactIOSTagHandles
* @flow
*/ */
'use strict'; 'use strict';
@ -31,7 +32,7 @@ var ReactIOSTagHandles = {
tagsStartAt: INITIAL_TAG_COUNT, tagsStartAt: INITIAL_TAG_COUNT,
tagCount: INITIAL_TAG_COUNT, tagCount: INITIAL_TAG_COUNT,
allocateTag: function() { allocateTag: function(): number {
// Skip over root IDs as those are reserved for native // Skip over root IDs as those are reserved for native
while (this.reactTagIsNativeTopRootID(ReactIOSTagHandles.tagCount)) { while (this.reactTagIsNativeTopRootID(ReactIOSTagHandles.tagCount)) {
ReactIOSTagHandles.tagCount++; ReactIOSTagHandles.tagCount++;
@ -50,13 +51,18 @@ var ReactIOSTagHandles = {
* `unmountComponent` isn't the correct time because that doesn't imply that * `unmountComponent` isn't the correct time because that doesn't imply that
* the native node has been natively unmounted. * the native node has been natively unmounted.
*/ */
associateRootNodeIDWithMountedNodeHandle: function(rootNodeID, tag) { associateRootNodeIDWithMountedNodeHandle: function(
rootNodeID: ?string,
tag: ?number
) {
warning(rootNodeID && tag, 'Root node or tag is null when associating'); warning(rootNodeID && tag, 'Root node or tag is null when associating');
ReactIOSTagHandles.tagToRootNodeID[tag] = rootNodeID; if (rootNodeID && tag) {
ReactIOSTagHandles.rootNodeIDToTag[rootNodeID] = tag; ReactIOSTagHandles.tagToRootNodeID[tag] = rootNodeID;
ReactIOSTagHandles.rootNodeIDToTag[rootNodeID] = tag;
}
}, },
allocateRootNodeIDForTag: function(tag) { allocateRootNodeIDForTag: function(tag: number): string {
invariant( invariant(
this.reactTagIsNativeTopRootID(tag), this.reactTagIsNativeTopRootID(tag),
'Expect a native root tag, instead got ', tag 'Expect a native root tag, instead got ', tag
@ -64,7 +70,7 @@ var ReactIOSTagHandles = {
return '.r[' + tag + ']{TOP_LEVEL}'; return '.r[' + tag + ']{TOP_LEVEL}';
}, },
reactTagIsNativeTopRootID: function(reactTag) { reactTagIsNativeTopRootID: function(reactTag: number): bool {
// We reserve all tags that are 1 mod 10 for native root views // We reserve all tags that are 1 mod 10 for native root views
return reactTag % 10 === 1; return reactTag % 10 === 1;
}, },
@ -81,13 +87,15 @@ var ReactIOSTagHandles = {
* @return {number} Tag ID of native view for most recent mounting of * @return {number} Tag ID of native view for most recent mounting of
* `rootNodeID`. * `rootNodeID`.
*/ */
mostRecentMountedNodeHandleForRootNodeID: function(rootNodeID) { mostRecentMountedNodeHandleForRootNodeID: function(
rootNodeID: string
): number {
return ReactIOSTagHandles.rootNodeIDToTag[rootNodeID]; return ReactIOSTagHandles.rootNodeIDToTag[rootNodeID];
}, },
tagToRootNodeID: [], tagToRootNodeID: ([] : Array<string>),
rootNodeIDToTag: {} rootNodeIDToTag: ({} : {[key: string]: number})
}; };
module.exports = ReactIOSTagHandles; module.exports = ReactIOSTagHandles;

View File

@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule ReactIOSViewAttributes * @providesModule ReactIOSViewAttributes
* @flow
*/ */
"use strict"; "use strict";