UNPKG

@shopify/react-native-skia

Version:

High-performance React Native Graphics using Skia

98 lines (77 loc) 1.89 kB
// eslint-disable-next-line max-len // Taken from https://github.com/facebook/react-native/blob/0b9ea60b4fee8cacc36e7160e31b91fc114dbc0d/Libraries/Animated/src/Easing.js import { bezier } from "./functions"; export class Easing { static step0(n) { return n > 0 ? 1 : 0; } static step1(n) { return n >= 1 ? 1 : 0; } static linear(t) { return t; } static ease(t) { return Easing.bezier(0.42, 0, 1, 1)(t); } static quad(t) { return t * t; } static cubic(t) { return t * t * t; } static poly(n) { return t => t ** n; } static sin(t) { return 1 - Math.cos(t * Math.PI / 2); } static circle(t) { return 1 - Math.sqrt(1 - t * t); } static exp(t) { return 2 ** (10 * (t - 1)); } static elastic() { let bounciness = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; const p = bounciness * Math.PI; return t => 1 - Math.cos(t * Math.PI / 2) ** 3 * Math.cos(t * p); } static back() { let s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1.70158; return t => t * t * ((s + 1) * t - s); } static bounce(t) { if (t < 1 / 2.75) { return 7.5625 * t * t; } if (t < 2 / 2.75) { const t2_ = t - 1.5 / 2.75; return 7.5625 * t2_ * t2_ + 0.75; } if (t < 2.5 / 2.75) { const t2_ = t - 2.25 / 2.75; return 7.5625 * t2_ * t2_ + 0.9375; } const t2 = t - 2.625 / 2.75; return 7.5625 * t2 * t2 + 0.984375; } static bezier(x1, y1, x2, y2) { return bezier(x1, y1, x2, y2); } static in(easing) { return easing; } static out(easing) { return t => 1 - easing(1 - t); } static inOut(easing) { return t => { if (t < 0.5) { return easing(t * 2) / 2; } return 1 - easing((1 - t) * 2) / 2; }; } } //# sourceMappingURL=Easing.js.map