mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
f63d4e7deb
Summary: This PR refactors the Animated directory to use ESModule imports/exports instead of using a mixture of the 2 module formats, as requested on https://github.com/facebook/react-native/issues/34425. ## Changelog [Internal] [Changed] - Convert all files in the Animated directory to use ESModule imports/exports Pull Request resolved: https://github.com/facebook/react-native/pull/34539 Test Plan: This doesn't really add or modify any existing features so checking if CI passes should be enough Reviewed By: yungsters Differential Revision: D39235720 Pulled By: yungsters fbshipit-source-id: 84b4c0a71dc9fca1ab7053263f1cf7c336df58c1
99 lines
2.3 KiB
JavaScript
99 lines
2.3 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow strict
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
type SpringConfigType = {
|
|
stiffness: number,
|
|
damping: number,
|
|
...
|
|
};
|
|
|
|
function stiffnessFromOrigamiValue(oValue: number) {
|
|
return (oValue - 30) * 3.62 + 194;
|
|
}
|
|
|
|
function dampingFromOrigamiValue(oValue: number) {
|
|
return (oValue - 8) * 3 + 25;
|
|
}
|
|
|
|
export function fromOrigamiTensionAndFriction(
|
|
tension: number,
|
|
friction: number,
|
|
): SpringConfigType {
|
|
return {
|
|
stiffness: stiffnessFromOrigamiValue(tension),
|
|
damping: dampingFromOrigamiValue(friction),
|
|
};
|
|
}
|
|
|
|
export function fromBouncinessAndSpeed(
|
|
bounciness: number,
|
|
speed: number,
|
|
): SpringConfigType {
|
|
function normalize(value: number, startValue: number, endValue: number) {
|
|
return (value - startValue) / (endValue - startValue);
|
|
}
|
|
|
|
function projectNormal(n: number, start: number, end: number) {
|
|
return start + n * (end - start);
|
|
}
|
|
|
|
function linearInterpolation(t: number, start: number, end: number) {
|
|
return t * end + (1 - t) * start;
|
|
}
|
|
|
|
function quadraticOutInterpolation(t: number, start: number, end: number) {
|
|
return linearInterpolation(2 * t - t * t, start, end);
|
|
}
|
|
|
|
function b3Friction1(x: number) {
|
|
return 0.0007 * Math.pow(x, 3) - 0.031 * Math.pow(x, 2) + 0.64 * x + 1.28;
|
|
}
|
|
|
|
function b3Friction2(x: number) {
|
|
return 0.000044 * Math.pow(x, 3) - 0.006 * Math.pow(x, 2) + 0.36 * x + 2;
|
|
}
|
|
|
|
function b3Friction3(x: number) {
|
|
return (
|
|
0.00000045 * Math.pow(x, 3) -
|
|
0.000332 * Math.pow(x, 2) +
|
|
0.1078 * x +
|
|
5.84
|
|
);
|
|
}
|
|
|
|
function b3Nobounce(tension: number) {
|
|
if (tension <= 18) {
|
|
return b3Friction1(tension);
|
|
} else if (tension > 18 && tension <= 44) {
|
|
return b3Friction2(tension);
|
|
} else {
|
|
return b3Friction3(tension);
|
|
}
|
|
}
|
|
|
|
let b = normalize(bounciness / 1.7, 0, 20);
|
|
b = projectNormal(b, 0, 0.8);
|
|
const s = normalize(speed / 1.7, 0, 20);
|
|
const bouncyTension = projectNormal(s, 0.5, 200);
|
|
const bouncyFriction = quadraticOutInterpolation(
|
|
b,
|
|
b3Nobounce(bouncyTension),
|
|
0.01,
|
|
);
|
|
|
|
return {
|
|
stiffness: stiffnessFromOrigamiValue(bouncyTension),
|
|
damping: dampingFromOrigamiValue(bouncyFriction),
|
|
};
|
|
}
|