mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-16 12:12:20 +08:00
Summary: This was done by running the command on: https://our.intern.facebook.com/intern/wiki/Flow_Strict/ ``` ag -L --ignore __snapshots__ 'flow strict$|noflow|generated|partially-generated' | ag '\.js$' | xargs ag -l 'flow' | sort > ~/temp cat ~/temp | xargs ag -L 'flow strict' | xargs sed -i 's/flow$/flow strict/' cat ~/temp | xargs ag -L 'flow strict$' | xargs sed -i 's/flow strict-local$/flow strict/' until flow; do flow --json | jq -r '.errors[].message[0].path' | sort | uniq | xargs hg revert; done ``` Reviewed By: sahrens Differential Revision: D8530207 fbshipit-source-id: c28c7ac5ed3e9b80f3d126d5f30463be8a8a744d
103 lines
2.2 KiB
JavaScript
103 lines
2.2 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* 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) {
|
|
return (oValue - 30) * 3.62 + 194;
|
|
}
|
|
|
|
function dampingFromOrigamiValue(oValue) {
|
|
return (oValue - 8) * 3 + 25;
|
|
}
|
|
|
|
function fromOrigamiTensionAndFriction(
|
|
tension: number,
|
|
friction: number,
|
|
): SpringConfigType {
|
|
return {
|
|
stiffness: stiffnessFromOrigamiValue(tension),
|
|
damping: dampingFromOrigamiValue(friction),
|
|
};
|
|
}
|
|
|
|
function fromBouncinessAndSpeed(
|
|
bounciness: number,
|
|
speed: number,
|
|
): SpringConfigType {
|
|
function normalize(value, startValue, endValue) {
|
|
return (value - startValue) / (endValue - startValue);
|
|
}
|
|
|
|
function projectNormal(n, start, end) {
|
|
return start + n * (end - start);
|
|
}
|
|
|
|
function linearInterpolation(t, start, end) {
|
|
return t * end + (1 - t) * start;
|
|
}
|
|
|
|
function quadraticOutInterpolation(t, start, end) {
|
|
return linearInterpolation(2 * t - t * t, start, end);
|
|
}
|
|
|
|
function b3Friction1(x) {
|
|
return 0.0007 * Math.pow(x, 3) - 0.031 * Math.pow(x, 2) + 0.64 * x + 1.28;
|
|
}
|
|
|
|
function b3Friction2(x) {
|
|
return 0.000044 * Math.pow(x, 3) - 0.006 * Math.pow(x, 2) + 0.36 * x + 2;
|
|
}
|
|
|
|
function b3Friction3(x) {
|
|
return (
|
|
0.00000045 * Math.pow(x, 3) -
|
|
0.000332 * Math.pow(x, 2) +
|
|
0.1078 * x +
|
|
5.84
|
|
);
|
|
}
|
|
|
|
function b3Nobounce(tension) {
|
|
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),
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
fromOrigamiTensionAndFriction,
|
|
fromBouncinessAndSpeed,
|
|
};
|