From 7abfd23b90db08b426c3c91b0cb6d01d161a9b9e Mon Sep 17 00:00:00 2001 From: Oleg Lokhvitsky Date: Thu, 16 May 2019 18:11:45 -0700 Subject: [PATCH] Fix error in Animated Interpolation when inputMin === inputMax Summary: This is already handled cleanly on the JS side of things in AnimatedInterpolation.js: https://github.com/facebook/react-native/blob/0ee5f68929610106ee6864baa04ea90be0fc5160/Libraries/Animated/src/nodes/AnimatedInterpolation.js#L133-L142 However, the native driver interpolation will try to divide by 0, produce NaN and then crash. This change just copies the logic from the JS version of the interpolation logic and adds it to the Java version. Note that this bug only reproduces on Android Q. It seems that RenderNode::setCameraDistance now crashes when receiving NaN on Android Q. Reviewed By: sahrens Differential Revision: D15380844 fbshipit-source-id: cfa82d8f58574e1040a851aaa5b5af1e23c9daa8 --- .../react/animated/InterpolationAnimatedNode.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/animated/InterpolationAnimatedNode.java b/ReactAndroid/src/main/java/com/facebook/react/animated/InterpolationAnimatedNode.java index 0b91c37814b..be2f38c055d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/animated/InterpolationAnimatedNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/animated/InterpolationAnimatedNode.java @@ -71,6 +71,17 @@ import javax.annotation.Nullable; } } + if (outputMin == outputMax) { + return outputMin; + } + + if (inputMin == inputMax) { + if (value <= inputMin) { + return outputMin; + } + return outputMax; + } + return outputMin + (outputMax - outputMin) * (result - inputMin) / (inputMax - inputMin); }