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