From 962e664c33e514729de8a8bd3a7289c8ddb2d5d9 Mon Sep 17 00:00:00 2001 From: Spencer Ahrens Date: Fri, 12 May 2017 15:01:24 -0700 Subject: [PATCH] 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 --- Libraries/LayoutAnimation/LayoutAnimation.js | 63 +++++++++----------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/Libraries/LayoutAnimation/LayoutAnimation.js b/Libraries/LayoutAnimation/LayoutAnimation.js index ac2525a8870..1b218201b70 100644 --- a/Libraries/LayoutAnimation/LayoutAnimation.js +++ b/Libraries/LayoutAnimation/LayoutAnimation.js @@ -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, property?: $Enum, -} +}; -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;