Skip to content

Commit

Permalink
Improved Types
Browse files Browse the repository at this point in the history
Summary: Improves the types for Easing and bezier to make them script.

Differential Revision: D10346234

fbshipit-source-id: e941110c62f7dcd17b0d022497cf29e0935db5a3
  • Loading branch information
nmn authored and facebook-github-bot committed Nov 1, 2018
1 parent 2b603fd commit 17fd1bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
19 changes: 8 additions & 11 deletions Libraries/Animated/src/Easing.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
* @flow strict
*/

'use strict';
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}

/**
Expand Down
11 changes: 7 additions & 4 deletions Libraries/Animated/src/bezier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit 17fd1bc

Please sign in to comment.