Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions packages/core/src/AnimationRunners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,26 @@ export const decay = (params: DecayParams) => {
from: 0,
...params,
};

const state: Animated.DecayState = {
finished: new Value(0),
position: new Value(0),
time: new Value(0),
velocity: new Value(0),
};

const config: Animated.DecayConfig = {
deceleration,
};

return block([
cond(not(clockRunning(clock)), [set(state.velocity, velocity)]),
animate<DecayAnimation>({
clock,
fn: reDecay,
state,
config,
from,
}),
] as ReadonlyArray<Animated.Node<number>>);
cond(not(clockRunning(clock)), [
set(state.finished, 0),
set(state.position, from),
set(state.velocity, velocity),
set(state.time, 0),
startClock(clock),
]),
reDecay(clock, state, config),
state.position,
]);
};

export interface SpringParams {
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/Vectors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Animated from "react-native-reanimated";
import Animated, { Clock } from "react-native-reanimated";

import { clamp as clamp1 } from "./Math";

Expand Down Expand Up @@ -29,6 +29,8 @@ const create: Create = <T extends Animated.Adaptable<number>>(
y: y ?? x ?? 0,
});

const createClock = () => create(new Clock(), new Clock());

const createValue = (x = 0, y?: number) =>
create(new Value(x), new Value(y ?? x));

Expand Down Expand Up @@ -69,6 +71,9 @@ const set = (a: Vector<Animated.Value<number>>, b: Adaptable) =>
Animated.set(a.y, isAdaptable(b) ? b : b.y),
]);

const debug = (label: string, v: Vector<Animated.Node<number>>) =>
block([Animated.debug(`${label}.x`, v.x), Animated.debug(`${label}.y`, v.y)]);

const length = (v: Vector) =>
Animated.sqrt(Animated.add(Animated.pow(v.x, 2), Animated.pow(v.y, 2)));
const normalize = (v: Vector) => div(v, length(v));
Expand All @@ -78,6 +83,7 @@ const cross = (v1: Vector, v2: Vector) =>
sub(Animated.multiply(v1.x, v2.y), Animated.multiply(v1.y, v2.x));

export const vec = {
debug,
create,
createValue,
minus,
Expand All @@ -100,4 +106,5 @@ export const vec = {
length,
normalize,
cross,
createClock,
};