flowify some Libraries

This commit is contained in:
Basil Hosmer 2015-03-24 13:26:29 -07:00
parent 6daf7d2634
commit e4bf45beee
6 changed files with 82 additions and 46 deletions

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 ActionSheetIOS * @providesModule ActionSheetIOS
* @flow
*/ */
'use strict'; 'use strict';
@ -15,7 +16,7 @@ var RCTActionSheetManager = require('NativeModules').ActionSheetManager;
var invariant = require('invariant'); var invariant = require('invariant');
var ActionSheetIOS = { var ActionSheetIOS = {
showActionSheetWithOptions(options, callback) { showActionSheetWithOptions(options: Object, callback: Function) {
invariant( invariant(
typeof options === 'object' && options !== null, typeof options === 'object' && options !== null,
'Options must a valid object' 'Options must a valid object'
@ -31,7 +32,11 @@ var ActionSheetIOS = {
); );
}, },
showShareActionSheetWithOptions(options, failureCallback, successCallback) { showShareActionSheetWithOptions(
options: Object,
failureCallback: Function,
successCallback: Function
) {
invariant( invariant(
typeof options === 'object' && options !== null, typeof options === 'object' && options !== null,
'Options must a valid object' 'Options must a valid object'

View File

@ -7,17 +7,18 @@
* 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 AdSupportIOS * @providesModule AdSupportIOS
* @flow
*/ */
'use strict'; 'use strict';
var AdSupport = require('NativeModules').AdSupport; var AdSupport = require('NativeModules').AdSupport;
module.exports = { module.exports = {
getAdvertisingId: function(onSuccess, onFailure) { getAdvertisingId: function(onSuccess: Function, onFailure: Function) {
AdSupport.getAdvertisingId(onSuccess, onFailure); AdSupport.getAdvertisingId(onSuccess, onFailure);
}, },
getAdvertisingTrackingEnabled: function(onSuccess, onFailure) { getAdvertisingTrackingEnabled: function(onSuccess: Function, onFailure: Function) {
AdSupport.getAdvertisingTrackingEnabled(onSuccess, onFailure); AdSupport.getAdvertisingTrackingEnabled(onSuccess, onFailure);
}, },
}; };

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 LayoutAnimation * @providesModule LayoutAnimation
* @flow
*/ */
'use strict'; 'use strict';
@ -42,6 +43,15 @@ var animChecker = createStrictShapeTypeChecker({
), ),
}); });
type Anim = {
duration?: number;
delay?: number;
springDamping?: number;
initialVelocity?: number;
type?: $Enum<typeof Types>;
property?: $Enum<typeof Properties>;
}
var configChecker = createStrictShapeTypeChecker({ var configChecker = createStrictShapeTypeChecker({
duration: PropTypes.number.isRequired, duration: PropTypes.number.isRequired,
create: animChecker, create: animChecker,
@ -49,12 +59,19 @@ var configChecker = createStrictShapeTypeChecker({
delete: animChecker, delete: animChecker,
}); });
var LayoutAnimation = { type Config = {
configureNext(config, onAnimationDidEnd, onError) { duration: number;
create?: Anim;
update?: Anim;
delete?: Anim;
}
function configureNext(config: Config, onAnimationDidEnd?: Function, onError?: Function) {
configChecker({config}, 'config', 'LayoutAnimation.configureNext'); configChecker({config}, 'config', 'LayoutAnimation.configureNext');
RCTUIManager.configureNextLayoutAnimation(config, onAnimationDidEnd, onError); RCTUIManager.configureNextLayoutAnimation(config, onAnimationDidEnd, onError);
}, }
create(duration, type, creationProp) {
function create(duration: number, type, creationProp): Config {
return { return {
duration, duration,
create: { create: {
@ -65,17 +82,19 @@ var LayoutAnimation = {
type, type,
}, },
}; };
}, }
Types: Types,
Properties: Properties,
configChecker: configChecker,
};
LayoutAnimation.Presets = { var LayoutAnimation = {
easeInEaseOut: LayoutAnimation.create( configureNext,
create,
Types,
Properties,
configChecker: configChecker,
Presets: {
easeInEaseOut: create(
0.3, Types.easeInEaseOut, Properties.opacity 0.3, Types.easeInEaseOut, Properties.opacity
), ),
linear: LayoutAnimation.create( linear: create(
0.5, Types.linear, Properties.opacity 0.5, Types.linear, Properties.opacity
), ),
spring: { spring: {
@ -89,6 +108,7 @@ LayoutAnimation.Presets = {
springDamping: 0.4, springDamping: 0.4,
}, },
}, },
}
}; };
module.exports = LayoutAnimation; module.exports = LayoutAnimation;

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 AppRegistry * @providesModule AppRegistry
* @flow
*/ */
'use strict'; 'use strict';
@ -21,6 +22,12 @@ if (__DEV__) {
var runnables = {}; var runnables = {};
type AppConfig = {
appKey: string;
component: ReactClass<any, any, any>;
run?: Function;
};
/** /**
* `AppRegistry` is the JS entry point to running all React Native apps. App * `AppRegistry` is the JS entry point to running all React Native apps. App
* root components should register themselves with * root components should register themselves with
@ -33,17 +40,18 @@ var runnables = {};
* `require`d. * `require`d.
*/ */
var AppRegistry = { var AppRegistry = {
registerConfig: function(config) { registerConfig: function(config: Array<AppConfig>) {
for (var i = 0; i < config.length; ++i) { for (var i = 0; i < config.length; ++i) {
if (config[i].run) { var appConfig = config[i];
AppRegistry.registerRunnable(config[i].appKey, config[i].run); if (appConfig.run) {
AppRegistry.registerRunnable(appConfig.appKey, appConfig.run);
} else { } else {
AppRegistry.registerComponent(config[i].appKey, config[i].component); AppRegistry.registerComponent(appConfig.appKey, appConfig.component);
} }
} }
}, },
registerComponent: function(appKey, getComponentFunc) { registerComponent: function(appKey: string, getComponentFunc: Function): string {
runnables[appKey] = { runnables[appKey] = {
run: (appParameters) => run: (appParameters) =>
renderApplication(getComponentFunc(), appParameters.initialProps, appParameters.rootTag) renderApplication(getComponentFunc(), appParameters.initialProps, appParameters.rootTag)
@ -51,12 +59,12 @@ var AppRegistry = {
return appKey; return appKey;
}, },
registerRunnable: function(appKey, func) { registerRunnable: function(appKey: string, func: Function): string {
runnables[appKey] = {run: func}; runnables[appKey] = {run: func};
return appKey; return appKey;
}, },
runApplication: function(appKey, appParameters) { runApplication: function(appKey: string, appParameters: any): void {
console.log( console.log(
'Running application "' + appKey + '" with appParams: ' + 'Running application "' + appKey + '" with appParams: ' +
JSON.stringify(appParameters) + '. ' + JSON.stringify(appParameters) + '. ' +

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 AppStateIOS * @providesModule AppStateIOS
* @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 AppStateIOS * @providesModule AppStateIOS
* @flow
*/ */
'use strict'; 'use strict';