Flowify a bunch of Libraries
This commit is contained in:
parent
d71bfa104d
commit
9eec8aa9d5
|
@ -7,12 +7,25 @@
|
|||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule queryLayoutByID
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var ReactIOSTagHandles = require('ReactIOSTagHandles');
|
||||
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
|
||||
* 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} 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.
|
||||
RCTUIManager.measure(
|
||||
ReactIOSTagHandles.rootNodeIDToTag[rootNodeID],
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactIOSGlobalInteractionHandler
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
|
@ -17,7 +18,7 @@ var InteractionManager = require('InteractionManager');
|
|||
var interactionHandle = null;
|
||||
|
||||
var ReactIOSGlobalInteractionHandler = {
|
||||
onChange: function(numberActiveTouches) {
|
||||
onChange: function(numberActiveTouches: number) {
|
||||
if (numberActiveTouches === 0) {
|
||||
if (interactionHandle) {
|
||||
InteractionManager.clearInteractionHandle(interactionHandle);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactIOSGlobalResponderHandler
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
|
@ -14,7 +15,7 @@ var RCTUIManager = require('NativeModules').UIManager;
|
|||
var ReactIOSTagHandles = require('ReactIOSTagHandles');
|
||||
|
||||
var ReactIOSGlobalResponderHandler = {
|
||||
onChange: function(from, to) {
|
||||
onChange: function(from: string, to: string) {
|
||||
if (to !== null) {
|
||||
RCTUIManager.setJSResponder(
|
||||
ReactIOSTagHandles.mostRecentMountedNodeHandleForRootNodeID(to)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactIOSMount
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
|
@ -83,7 +84,10 @@ var ReactIOSMount = {
|
|||
* @param {ReactComponent} instance Instance to render.
|
||||
* @param {containerTag} containerView Handle to native view tag
|
||||
*/
|
||||
renderComponent: function(descriptor, containerTag) {
|
||||
renderComponent: function(
|
||||
descriptor: ReactComponent,
|
||||
containerTag: number
|
||||
) {
|
||||
var instance = instantiateReactComponent(descriptor);
|
||||
|
||||
if (!ReactIOSTagHandles.reactTagIsNativeTopRootID(containerTag)) {
|
||||
|
@ -152,7 +156,9 @@ var ReactIOSMount = {
|
|||
* asynchronously, it's easier to just have this method be the one that calls
|
||||
* for removal of the view.
|
||||
*/
|
||||
unmountComponentAtNodeAndRemoveContainer: function(containerTag) {
|
||||
unmountComponentAtNodeAndRemoveContainer: function(
|
||||
containerTag: number
|
||||
) {
|
||||
ReactIOSMount.unmountComponentAtNode(containerTag);
|
||||
// call back into native to remove all of the subviews from this container
|
||||
RCTUIManager.removeRootView(containerTag);
|
||||
|
@ -163,7 +169,7 @@ var ReactIOSMount = {
|
|||
* that has been rendered and unmounting it. There should just be one child
|
||||
* component at this time.
|
||||
*/
|
||||
unmountComponentAtNode: function(containerTag) {
|
||||
unmountComponentAtNode: function(containerTag: number): bool {
|
||||
var containerID = ReactIOSTagHandles.tagToRootNodeID[containerTag];
|
||||
|
||||
invariant(
|
||||
|
@ -185,20 +191,25 @@ var ReactIOSMount = {
|
|||
* Unmounts a component and sends messages back to iOS to remove its subviews.
|
||||
*
|
||||
* @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
|
||||
* @internal
|
||||
* @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
|
||||
instance.unmountComponent();
|
||||
// TODO: ReactComponent.prototype.unmountComponent is missing from Flow's
|
||||
// react lib.
|
||||
(instance: any).unmountComponent();
|
||||
var containerTag =
|
||||
ReactIOSTagHandles.mostRecentMountedNodeHandleForRootNodeID(containerID);
|
||||
RCTUIManager.removeSubviewsFromContainerWithID(containerTag);
|
||||
},
|
||||
|
||||
getNode: function(id) {
|
||||
getNode: function<T>(id: T): T {
|
||||
return id;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactIOSNativeComponent
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
|
@ -28,13 +29,20 @@ var registrationNames = ReactIOSEventEmitter.registrationNames;
|
|||
var putListener = ReactIOSEventEmitter.putListener;
|
||||
var deleteAllListeners = ReactIOSEventEmitter.deleteAllListeners;
|
||||
|
||||
type ReactIOSNativeComponentViewConfig = {
|
||||
validAttributes: Object;
|
||||
uiViewClassName: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @constructor ReactIOSNativeComponent
|
||||
* @extends ReactComponent
|
||||
* @extends ReactMultiChild
|
||||
* @param {!object} UIKit View Configuration.
|
||||
*/
|
||||
var ReactIOSNativeComponent = function(viewConfig) {
|
||||
var ReactIOSNativeComponent = function(
|
||||
viewConfig: ReactIOSNativeComponentViewConfig
|
||||
) {
|
||||
this.viewConfig = viewConfig;
|
||||
};
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactIOSReconcileTransaction
|
||||
* @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 ReactIOSStyleAttributes
|
||||
* @flow
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactIOSTagHandles
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
|
@ -31,7 +32,7 @@ var ReactIOSTagHandles = {
|
|||
tagsStartAt: INITIAL_TAG_COUNT,
|
||||
tagCount: INITIAL_TAG_COUNT,
|
||||
|
||||
allocateTag: function() {
|
||||
allocateTag: function(): number {
|
||||
// Skip over root IDs as those are reserved for native
|
||||
while (this.reactTagIsNativeTopRootID(ReactIOSTagHandles.tagCount)) {
|
||||
ReactIOSTagHandles.tagCount++;
|
||||
|
@ -50,13 +51,18 @@ var ReactIOSTagHandles = {
|
|||
* `unmountComponent` isn't the correct time because that doesn't imply that
|
||||
* 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');
|
||||
ReactIOSTagHandles.tagToRootNodeID[tag] = rootNodeID;
|
||||
ReactIOSTagHandles.rootNodeIDToTag[rootNodeID] = tag;
|
||||
if (rootNodeID && tag) {
|
||||
ReactIOSTagHandles.tagToRootNodeID[tag] = rootNodeID;
|
||||
ReactIOSTagHandles.rootNodeIDToTag[rootNodeID] = tag;
|
||||
}
|
||||
},
|
||||
|
||||
allocateRootNodeIDForTag: function(tag) {
|
||||
allocateRootNodeIDForTag: function(tag: number): string {
|
||||
invariant(
|
||||
this.reactTagIsNativeTopRootID(tag),
|
||||
'Expect a native root tag, instead got ', tag
|
||||
|
@ -64,7 +70,7 @@ var ReactIOSTagHandles = {
|
|||
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
|
||||
return reactTag % 10 === 1;
|
||||
},
|
||||
|
@ -81,13 +87,15 @@ var ReactIOSTagHandles = {
|
|||
* @return {number} Tag ID of native view for most recent mounting of
|
||||
* `rootNodeID`.
|
||||
*/
|
||||
mostRecentMountedNodeHandleForRootNodeID: function(rootNodeID) {
|
||||
mostRecentMountedNodeHandleForRootNodeID: function(
|
||||
rootNodeID: string
|
||||
): number {
|
||||
return ReactIOSTagHandles.rootNodeIDToTag[rootNodeID];
|
||||
},
|
||||
|
||||
tagToRootNodeID: [],
|
||||
tagToRootNodeID: ([] : Array<string>),
|
||||
|
||||
rootNodeIDToTag: {}
|
||||
rootNodeIDToTag: ({} : {[key: string]: number})
|
||||
};
|
||||
|
||||
module.exports = ReactIOSTagHandles;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactIOSViewAttributes
|
||||
* @flow
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
|
Loading…
Reference in New Issue