From 17fd1bceb5a86c239eb2674fa3bfb6400d2e8bad Mon Sep 17 00:00:00 2001 From: Naman Goel Date: Thu, 1 Nov 2018 16:20:13 -0700 Subject: [PATCH] Improved Types Summary: Improves the types for Easing and bezier to make them script. Differential Revision: D10346234 fbshipit-source-id: e941110c62f7dcd17b0d022497cf29e0935db5a3 --- Libraries/Animated/src/Easing.js | 19 ++++++++----------- Libraries/Animated/src/bezier.js | 11 +++++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Libraries/Animated/src/Easing.js b/Libraries/Animated/src/Easing.js index 8f38322a873df1..9932038e6329fd 100644 --- a/Libraries/Animated/src/Easing.js +++ b/Libraries/Animated/src/Easing.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; @@ -175,10 +175,7 @@ class Easing { * * - http://tiny.cc/back_default (s = 1.70158, default) */ - static back(s: number): (t: number) => number { - if (s === undefined) { - s = 1.70158; - } + static back(s: number = 1.70158): (t: number) => number { return t => t * t * ((s + 1) * t - s); } @@ -193,17 +190,17 @@ class Easing { } if (t < 2 / 2.75) { - t -= 1.5 / 2.75; - return 7.5625 * t * t + 0.75; + const t2 = t - 1.5 / 2.75; + return 7.5625 * t2 * t2 + 0.75; } if (t < 2.5 / 2.75) { - t -= 2.25 / 2.75; - return 7.5625 * t * t + 0.9375; + const t2 = t - 2.25 / 2.75; + return 7.5625 * t2 * t2 + 0.9375; } - t -= 2.625 / 2.75; - return 7.5625 * t * t + 0.984375; + const t2 = t - 2.625 / 2.75; + return 7.5625 * t2 * t2 + 0.984375; } /** diff --git a/Libraries/Animated/src/bezier.js b/Libraries/Animated/src/bezier.js index 5fffd867ea9ac1..727872b848aacd 100644 --- a/Libraries/Animated/src/bezier.js +++ b/Libraries/Animated/src/bezier.js @@ -7,7 +7,7 @@ * BezierEasing - use bezier curve for transition easing function * https://github.com/gre/bezier-easing * - * @flow + * @flow strict * @format * @copyright 2014-2015 Gaƫtan Renaudeau. MIT License. */ @@ -45,10 +45,12 @@ function getSlope(aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); } -function binarySubdivide(aX, aA, aB, mX1, mX2) { +function binarySubdivide(aX, _aA, _aB, mX1, mX2) { let currentX, currentT, - i = 0; + i = 0, + aA = _aA, + aB = _aB; do { currentT = aA + (aB - aA) / 2.0; currentX = calcBezier(currentT, mX1, mX2) - aX; @@ -64,7 +66,8 @@ function binarySubdivide(aX, aA, aB, mX1, mX2) { return currentT; } -function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) { +function newtonRaphsonIterate(aX, _aGuessT, mX1, mX2) { + let aGuessT = _aGuessT; for (let i = 0; i < NEWTON_ITERATIONS; ++i) { const currentSlope = getSlope(aGuessT, mX1, mX2); if (currentSlope === 0.0) {