Skip to content

🎥 Make videos programmatically with React

spring reverse fix

Jonny Burgerba690ef18bee
diff --git a/packages/core/src/spring/index.ts b/packages/core/src/spring/index.ts
index 07e228e567..27a96924fe 100644
--- a/packages/core/src/spring/index.ts
+++ b/packages/core/src/spring/index.ts
@@ -79,7 +79,7 @@ export function spring({
const frame =
(reverse
? (passedDurationInFrames ?? naturalDurationGetter.get()) - passedFrame
- : passedFrame) - delay;
+ : passedFrame) - (reverse ? -delay : delay);
const spr = springCalculation({
fps,
diff --git a/packages/core/src/test/spring.test.ts b/packages/core/src/test/spring.test.ts
index 4f64021720..331191c8e6 100644
--- a/packages/core/src/test/spring.test.ts
+++ b/packages/core/src/test/spring.test.ts
@@ -64,6 +64,14 @@ test('Should be able to set duration for spring when in reverse', () => {
reverse: true,
})
).toBeCloseTo(0);
+ expect(
+ spring({
+ fps: 30,
+ frame: 0,
+ durationInFrames: 5,
+ reverse: true,
+ })
+ ).toBeCloseTo(1);
});
test('Should be able to set duration for spring when in reverse', () => {
@@ -164,3 +172,31 @@ test('Should apply delay in the right order', () => {
})
);
});
+
+test('weird case', () => {
+ const val = spring({
+ fps: 30,
+ frame: 12 * 30,
+ config: {
+ damping: 200,
+ },
+ delay: 12 * 30,
+ durationInFrames: 60,
+ reverse: true,
+ });
+
+ expect(val).toBeCloseTo(1);
+
+ const val2 = spring({
+ fps: 30,
+ frame: 12 * 30 + 60,
+ config: {
+ damping: 200,
+ },
+ delay: 12 * 30,
+ durationInFrames: 60,
+ reverse: true,
+ });
+
+ expect(val2).toBeCloseTo(0);
+});