From 25d397651ec46454394895eaad998a2acebba59b Mon Sep 17 00:00:00 2001 From: Andrew Schenk Date: Tue, 12 Mar 2019 22:41:37 -0700 Subject: [PATCH] =?UTF-8?q?adds=20type=20checking=20to=20Animated=20toValu?= =?UTF-8?q?e=20and=20iterations=20key=20values=20to=20m=E2=80=A6=20(#23812?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: …ake sure Android does not crash from bad params when using useNativeDriver Android apps crash when using Animated useNativeDriver: true and the toValue is not a number. See issue here with test case. [Issue](https://github.com/facebook/react-native/issues/23810) [Android] [fixed] - Fix crash when using Animated with useNativeDriver and a non Number toValue Pull Request resolved: https://github.com/facebook/react-native/pull/23812 Differential Revision: D14436113 Pulled By: cpojer fbshipit-source-id: 89fb3180c08cc5ffb817b3984dacda0a80b4f703 --- .../react/animated/FrameBasedAnimationDriver.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/animated/FrameBasedAnimationDriver.java b/ReactAndroid/src/main/java/com/facebook/react/animated/FrameBasedAnimationDriver.java index 84551c418..9f29c6195 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/animated/FrameBasedAnimationDriver.java +++ b/ReactAndroid/src/main/java/com/facebook/react/animated/FrameBasedAnimationDriver.java @@ -9,6 +9,7 @@ package com.facebook.react.animated; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.bridge.ReadableType; /** * Implementation of {@link AnimationDriver} which provides a support for simple time-based @@ -41,8 +42,17 @@ class FrameBasedAnimationDriver extends AnimationDriver { for (int i = 0; i < numberOfFrames; i++) { mFrames[i] = frames.getDouble(i); } - mToValue = config.hasKey("toValue") ? config.getDouble("toValue") : 0; - mIterations = config.hasKey("iterations") ? config.getInt("iterations") : 1; + if(config.hasKey("toValue")) { + mToValue = config.getType("toValue") == ReadableType.Number ? config.getDouble("toValue") : 0; + } else { + mToValue = 0; + } + if(config.hasKey("iterations")) { + mIterations = config.getType("iterations") == ReadableType.Number ? + config.getInt("iterations") : 1; + } else { + mIterations = 1; + } mCurrentLoop = 1; mHasFinished = mIterations == 0; mStartFrameTimeNanos = -1;