Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1826 from framer/fix/motion-value-events
Adding animation events to motion value
- Loading branch information
Showing
17 changed files
with
181 additions
and
76 deletions.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { motionValue } from "../" | ||
import { animate } from "../../animation/animate" | ||
|
||
describe("motionValue", () => { | ||
test("change event fires when value changes", () => { | ||
const value = motionValue(0) | ||
const callback = jest.fn() | ||
|
||
value.on("change", callback) | ||
|
||
expect(callback).not.toBeCalled() | ||
value.set(1) | ||
expect(callback).toBeCalledTimes(1) | ||
value.set(1) | ||
expect(callback).toBeCalledTimes(1) | ||
}) | ||
|
||
test("renderRequest event fires", () => { | ||
const value = motionValue(0) | ||
const callback = jest.fn() | ||
|
||
value.on("renderRequest", callback) | ||
|
||
expect(callback).not.toBeCalled() | ||
value.set(1) | ||
expect(callback).toBeCalledTimes(1) | ||
}) | ||
|
||
test("animationStart event fires", () => { | ||
const value = motionValue(0) | ||
const callback = jest.fn() | ||
|
||
value.on("animationStart", callback) | ||
|
||
expect(callback).not.toBeCalled() | ||
|
||
animate(value, 2) | ||
|
||
expect(callback).toBeCalledTimes(1) | ||
}) | ||
|
||
test("animationCancel event fires", () => { | ||
const value = motionValue(0) | ||
const callback = jest.fn() | ||
|
||
value.on("animationCancel", callback) | ||
|
||
expect(callback).not.toBeCalled() | ||
|
||
animate(value, 1) | ||
animate(value, 2) | ||
|
||
expect(callback).toBeCalledTimes(1) | ||
}) | ||
|
||
test("animationComplete event fires", async () => { | ||
const value = motionValue(0) | ||
const callback = jest.fn() | ||
|
||
value.on("animationComplete", callback) | ||
|
||
expect(callback).not.toBeCalled() | ||
|
||
animate(value, 1, { duration: 0.01 }) | ||
|
||
return new Promise<void>((resolve) => { | ||
setTimeout(() => { | ||
expect(callback).toBeCalledTimes(1) | ||
resolve() | ||
}, 100) | ||
}) | ||
}) | ||
}) |
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
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
Oops, something went wrong.