Skip to content

Commit

Permalink
Fix error in Animated Interpolation when inputMin === inputMax
Browse files Browse the repository at this point in the history
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
  • Loading branch information
olegbl authored and facebook-github-bot committed May 17, 2019
1 parent d993089 commit 7abfd23
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ private static double interpolate(
}
}

if (outputMin == outputMax) {
return outputMin;
}

if (inputMin == inputMax) {
if (value <= inputMin) {
return outputMin;
}
return outputMax;
}

return outputMin + (outputMax - outputMin) *
(result - inputMin) / (inputMax - inputMin);
}
Expand Down

0 comments on commit 7abfd23

Please sign in to comment.