-
-
Notifications
You must be signed in to change notification settings - Fork 865
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
repeat
in timeline sequence (#2945)
* Adding tests * Destructuring repeat options * Latest * UPdating tests
- Loading branch information
1 parent
1108bd5
commit 0e54f81
Showing
6 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/framer-motion/src/animation/sequence/utils/__tests__/calc-repeat-duration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { calculateRepeatDuration } from "../calc-repeat-duration" | ||
|
||
describe("calculateRepeatDuration", () => { | ||
test("It correctly calculates the duration", () => { | ||
expect(calculateRepeatDuration(1, 0, 0)).toEqual(1) | ||
expect(calculateRepeatDuration(1, 1, 0)).toEqual(2) | ||
expect(calculateRepeatDuration(1, 2, 0)).toEqual(3) | ||
}) | ||
}) |
10 changes: 10 additions & 0 deletions
10
packages/framer-motion/src/animation/sequence/utils/__tests__/normalize-times.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { normalizeTimes } from "../normalize-times" | ||
|
||
describe("normalizeTimes", () => { | ||
test("It correctly scales times", () => { | ||
const times = [0, 0.5, 1, 1, 1.5, 2] | ||
const repeat = 1 | ||
normalizeTimes(times, repeat) | ||
expect(times).toEqual([0, 0.25, 0.5, 0.5, 0.75, 1]) | ||
}) | ||
}) |
7 changes: 7 additions & 0 deletions
7
packages/framer-motion/src/animation/sequence/utils/calc-repeat-duration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function calculateRepeatDuration( | ||
duration: number, | ||
repeat: number, | ||
_repeatDelay: number | ||
): number { | ||
return duration * (repeat + 1) | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/framer-motion/src/animation/sequence/utils/normalize-times.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Take an array of times that represent repeated keyframes. For instance | ||
* if we have original times of [0, 0.5, 1] then our repeated times will | ||
* be [0, 0.5, 1, 1, 1.5, 2]. Loop over the times and scale them back | ||
* down to a 0-1 scale. | ||
*/ | ||
export function normalizeTimes(times: number[], repeat: number): void { | ||
for (let i = 0; i < times.length; i++) { | ||
times[i] = times[i] / (repeat + 1) | ||
} | ||
} |