From d4e7c8a0550891208284bd1d900bd9721d899f8f Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Tue, 7 Jun 2016 16:22:56 -0700 Subject: [PATCH] Properly validate layout animation config Summary: The type key for a layout animation config must be supplied otherwise the app crashes (on Android). I added a isRequired check in JS as well as an explicit exception in java otherwise it crashed at a very hard to debug place. The crash happens when passing null to `Animation.setInterpolator` so this makes sure it never happens. **Test plan (required)** Tested that the error is caught properly in JS when passing an invalid animation config like ``` LayoutAnimation.configureNext({ duration: 250, update: { type: undefined }, // or LayoutAnimation.Types.easeInEastOut in my case haha :) }); ``` Also tested the java exception. Closes https://github.com/facebook/react-native/pull/7958 Differential Revision: D3401760 Pulled By: nicklockwood fbshipit-source-id: 83c019d863c2b2294405b60e87297c562add0f49 --- Libraries/LayoutAnimation/LayoutAnimation.js | 2 +- .../uimanager/layoutanimation/AbstractLayoutAnimation.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Libraries/LayoutAnimation/LayoutAnimation.js b/Libraries/LayoutAnimation/LayoutAnimation.js index 8a8f221ce0..6f28182873 100644 --- a/Libraries/LayoutAnimation/LayoutAnimation.js +++ b/Libraries/LayoutAnimation/LayoutAnimation.js @@ -40,7 +40,7 @@ var animChecker = createStrictShapeTypeChecker({ initialVelocity: PropTypes.number, type: PropTypes.oneOf( Object.keys(Types) - ), + ).isRequired, property: PropTypes.oneOf( // Only applies to create/delete Object.keys(Properties) ), diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/AbstractLayoutAnimation.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/AbstractLayoutAnimation.java index c29d7ae0be..8d234269a9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/AbstractLayoutAnimation.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/AbstractLayoutAnimation.java @@ -61,8 +61,10 @@ import com.facebook.react.uimanager.IllegalViewOperationException; AnimatedPropertyType.fromString(data.getString("property")) : null; mDurationMs = data.hasKey("duration") ? data.getInt("duration") : globalDuration; mDelayMs = data.hasKey("delay") ? data.getInt("delay") : 0; - mInterpolator = data.hasKey("type") ? - getInterpolator(InterpolatorType.fromString(data.getString("type"))) : null; + if (!data.hasKey("type")) { + throw new IllegalArgumentException("Missing interpolation type."); + } + mInterpolator = getInterpolator(InterpolatorType.fromString(data.getString("type"))); if (!isValid()) { throw new IllegalViewOperationException("Invalid layout animation : " + data);