Skip to content

Commit 7abfd23

Browse files
olegblfacebook-github-bot
authored andcommitted
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
1 parent d993089 commit 7abfd23

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/animated/InterpolationAnimatedNode.java

+11
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ private static double interpolate(
7171
}
7272
}
7373

74+
if (outputMin == outputMax) {
75+
return outputMin;
76+
}
77+
78+
if (inputMin == inputMax) {
79+
if (value <= inputMin) {
80+
return outputMin;
81+
}
82+
return outputMax;
83+
}
84+
7485
return outputMin + (outputMax - outputMin) *
7586
(result - inputMin) / (inputMax - inputMin);
7687
}

0 commit comments

Comments
 (0)