Skip to content

Commit

Permalink
Refactor, new release
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbabenko committed Mar 31, 2021
1 parent 7083e78 commit 128c0e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-awesome-gallery",
"version": "0.0.5",
"version": "0.0.6",
"description": "Awesome gallery with Reanimated v2",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down Expand Up @@ -75,8 +75,8 @@
"peerDependencies": {
"react": "*",
"react-native": "*",
"react-native-reanimated": "^2.0.0-rc.3",
"react-native-gesture-handler": "^1.10.1"
"react-native-gesture-handler": "^1.10.1",
"react-native-reanimated": "^2.0.0-rc.3"
},
"jest": {
"preset": "react-native",
Expand Down
11 changes: 6 additions & 5 deletions src/utils/withDecaySpring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function withDecaySpring(
const m = config.mass;
const k = config.stiffness;

const v0 = -velocity;
const springV0 = -velocity;
const x0 = toValue - current;

const zeta = c / (2 * Math.sqrt(k * m)); // damping ratio
Expand All @@ -62,23 +62,24 @@ export function withDecaySpring(
const underDampedEnvelope = Math.exp(-zeta * omega0 * t);
const underDampedFrag1 =
underDampedEnvelope *
(sin1 * ((v0 + zeta * omega0 * x0) / omega1) + x0 * cos1);
(sin1 * ((springV0 + zeta * omega0 * x0) / omega1) + x0 * cos1);

const underDampedPosition = toValue - underDampedFrag1;
// This looks crazy -- it's actually just the derivative of the oscillation function
const underDampedVelocity =
zeta * omega0 * underDampedFrag1 -
underDampedEnvelope *
(cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);
(cos1 * (springV0 + zeta * omega0 * x0) - omega1 * x0 * sin1);

// critically damped
const criticallyDampedEnvelope = Math.exp(-omega0 * t);
const criticallyDampedPosition =
toValue - criticallyDampedEnvelope * (x0 + (v0 + omega0 * x0) * t);
toValue -
criticallyDampedEnvelope * (x0 + (springV0 + omega0 * x0) * t);

const criticallyDampedVelocity =
criticallyDampedEnvelope *
(v0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);
(springV0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);

const isOvershooting = () => {
if (config.overshootClamping && config.stiffness !== 0) {
Expand Down

0 comments on commit 128c0e8

Please sign in to comment.