Fix prop-types warning in LayoutAnimation

Summary:
And clean it up.

**TestPlan**

No more warning when launching RNTester

LayoutAnimationExample still works, also without warnings.

Reviewed By: fkgozali

Differential Revision: D5055050

fbshipit-source-id: a3a6cdf25632dc4f9455d795e8a2e3c00f968e09
This commit is contained in:
Spencer Ahrens 2017-05-12 15:01:24 -07:00 committed by Facebook Github Bot
parent fb99f55939
commit 962e664c33
1 changed files with 29 additions and 34 deletions

View File

@ -8,16 +8,18 @@
*
* @providesModule LayoutAnimation
* @flow
* @format
*/
'use strict';
var UIManager = require('UIManager');
const PropTypes = require('prop-types');
const UIManager = require('UIManager');
var keyMirror = require('fbjs/lib/keyMirror');
const keyMirror = require('fbjs/lib/keyMirror');
var {checkPropTypes, PropTypes} = require('react');
const {checkPropTypes} = PropTypes;
var TypesEnum = {
const TypesEnum = {
spring: true,
linear: true,
easeInEaseOut: true,
@ -25,24 +27,23 @@ var TypesEnum = {
easeOut: true,
keyboard: true,
};
var Types = keyMirror(TypesEnum);
const Types = keyMirror(TypesEnum);
var PropertiesEnum = {
const PropertiesEnum = {
opacity: true,
scaleXY: true,
};
var Properties = keyMirror(PropertiesEnum);
const Properties = keyMirror(PropertiesEnum);
var animType = PropTypes.shape({
const animType = PropTypes.shape({
duration: PropTypes.number,
delay: PropTypes.number,
springDamping: PropTypes.number,
initialVelocity: PropTypes.number,
type: PropTypes.oneOf(
Object.keys(Types)
).isRequired,
property: PropTypes.oneOf( // Only applies to create/delete
Object.keys(Properties)
type: PropTypes.oneOf(Object.keys(Types)).isRequired,
property: PropTypes.oneOf(
// Only applies to create/delete
Object.keys(Properties),
),
});
@ -53,9 +54,9 @@ type Anim = {
initialVelocity?: number,
type?: $Enum<typeof TypesEnum>,
property?: $Enum<typeof PropertiesEnum>,
}
};
var configType = PropTypes.shape({
const configType = PropTypes.shape({
duration: PropTypes.number.isRequired,
create: animType,
update: animType,
@ -67,7 +68,7 @@ type Config = {
create?: Anim,
update?: Anim,
delete?: Anim,
}
};
function checkConfig(config: Config, location: string, name: string) {
checkPropTypes({config: configType}, {config}, location, name);
@ -78,7 +79,11 @@ function configureNext(config: Config, onAnimationDidEnd?: Function) {
checkConfig(config, 'config', 'LayoutAnimation.configureNext');
}
UIManager.configureNextLayoutAnimation(
config, onAnimationDidEnd || function() {}, function() { /* unused */ }
config,
onAnimationDidEnd || function() {},
function() {
/* unused */
},
);
}
@ -99,13 +104,9 @@ function create(duration: number, type, creationProp): Config {
};
}
var Presets = {
easeInEaseOut: create(
300, Types.easeInEaseOut, Properties.opacity
),
linear: create(
500, Types.linear, Properties.opacity
),
const Presets = {
easeInEaseOut: create(300, Types.easeInEaseOut, Properties.opacity),
linear: create(500, Types.linear, Properties.opacity),
spring: {
duration: 700,
create: {
@ -133,7 +134,7 @@ var Presets = {
*
* UIManager.setLayoutAnimationEnabledExperimental && UIManager.setLayoutAnimationEnabledExperimental(true);
*/
var LayoutAnimation = {
const LayoutAnimation = {
/**
* Schedules an animation to happen on the next layout.
*
@ -157,15 +158,9 @@ var LayoutAnimation = {
Properties,
checkConfig,
Presets,
easeInEaseOut: configureNext.bind(
null, Presets.easeInEaseOut
),
linear: configureNext.bind(
null, Presets.linear
),
spring: configureNext.bind(
null, Presets.spring
),
easeInEaseOut: configureNext.bind(null, Presets.easeInEaseOut),
linear: configureNext.bind(null, Presets.linear),
spring: configureNext.bind(null, Presets.spring),
};
module.exports = LayoutAnimation;