diff --git a/Libraries/Animated/src/Easing.js b/Libraries/Animated/src/Easing.js index 46c30aed0..a8685a718 100644 --- a/Libraries/Animated/src/Easing.js +++ b/Libraries/Animated/src/Easing.js @@ -72,14 +72,14 @@ class Easing { static elastic(bounciness: number = 1): (t: number) => number { var p = bounciness * Math.PI; return (t) => 1 - Math.pow(Math.cos(t * Math.PI / 2), 3) * Math.cos(t * p); - }; + } static back(s: number): (t: number) => number { if (s === undefined) { s = 1.70158; } return (t) => t * t * ((s + 1) * t - s); - }; + } static bounce(t: number): number { if (t < 1 / 2.75) { @@ -98,7 +98,7 @@ class Easing { t -= 2.625 / 2.75; return 7.5625 * t * t + 0.984375; - }; + } static bezier( x1: number, diff --git a/Libraries/Animated/src/bezier.js b/Libraries/Animated/src/bezier.js index 11b02f501..19cc855a4 100644 --- a/Libraries/Animated/src/bezier.js +++ b/Libraries/Animated/src/bezier.js @@ -42,7 +42,7 @@ module.exports = function(x1, y1, x2, y2, epsilon){ var derivativeCurveX = function(t){ var v = 1 - t; - return 3 * (2 * (t - 1) * t + v * v) * x1 + 3 * (- t * t * t + 2 * v * t) * x2; + return 3 * (2 * (t - 1) * t + v * v) * x1 + 3 * (-t * t * t + 2 * v * t) * x2; }; return function(t){ @@ -52,24 +52,26 @@ module.exports = function(x1, y1, x2, y2, epsilon){ // First try a few iterations of Newton's method -- normally very fast. for (t2 = x, i = 0; i < 8; i++){ x2 = curveX(t2) - x; - if (Math.abs(x2) < epsilon) return curveY(t2); + if (Math.abs(x2) < epsilon) { return curveY(t2); } d2 = derivativeCurveX(t2); - if (Math.abs(d2) < 1e-6) break; + if (Math.abs(d2) < 1e-6) { break; } t2 = t2 - x2 / d2; } - t0 = 0, t1 = 1, t2 = x; + t0 = 0; + t1 = 1; + t2 = x; - if (t2 < t0) return curveY(t0); - if (t2 > t1) return curveY(t1); + if (t2 < t0) { return curveY(t0); } + if (t2 > t1) { return curveY(t1); } // Fallback to the bisection method for reliability. while (t0 < t1){ x2 = curveX(t2); - if (Math.abs(x2 - x) < epsilon) return curveY(t2); - if (x > x2) t0 = t2; - else t1 = t2; - t2 = (t1 - t0) * .5 + t0; + if (Math.abs(x2 - x) < epsilon) { return curveY(t2); } + if (x > x2) { t0 = t2; } + else { t1 = t2; } + t2 = (t1 - t0) * 0.5 + t0; } // Failure