-
-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding failing test * Tidy test * Fixing switching between components * Fixing double render * Cleaning * Replacing if * Latest * Fixing test * Making concurrent safe * Removing log * v11.3.18-alpha.0 * Updating version * Publish * Updating animatepresence * Updating * adding test file for wait * Latest * Updating
- Loading branch information
1 parent
8ee3628
commit 680d5e9
Showing
23 changed files
with
426 additions
and
257 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { motion, AnimatePresence } from "framer-motion" | ||
import { useState } from "react" | ||
|
||
/** | ||
* An example of a single-child AnimatePresence animation | ||
*/ | ||
|
||
const style = { | ||
width: 100, | ||
height: 100, | ||
background: "red", | ||
opacity: 1, | ||
} | ||
|
||
export const App = () => { | ||
const [key, setKey] = useState("a") | ||
|
||
return ( | ||
<div | ||
onClick={() => { | ||
setKey(key === "a" ? "b" : "a") | ||
}} | ||
> | ||
<AnimatePresence | ||
initial={false} | ||
onExitComplete={() => console.log("rest")} | ||
> | ||
<motion.div | ||
key={key} | ||
initial={{ opacity: 0 }} | ||
animate={{ opacity: 1 }} | ||
exit={{ opacity: 0 }} | ||
transition={{ duration: 1 }} | ||
style={{ | ||
...style, | ||
background: key === "a" ? "green" : "blue", | ||
}} | ||
/> | ||
</AnimatePresence> | ||
</div> | ||
) | ||
} |
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,43 @@ | ||
import { motion, AnimatePresence } from "framer-motion" | ||
import { useState } from "react" | ||
|
||
/** | ||
* An example of a single-child AnimatePresence animation | ||
*/ | ||
|
||
const style = { | ||
width: 100, | ||
height: 100, | ||
background: "red", | ||
opacity: 1, | ||
} | ||
|
||
export const App = () => { | ||
const [key, setKey] = useState(0) | ||
|
||
return ( | ||
<div | ||
onClick={() => { | ||
setKey(key + 1) | ||
}} | ||
> | ||
<AnimatePresence | ||
initial={false} | ||
mode="wait" | ||
onExitComplete={() => console.log("rest")} | ||
> | ||
<motion.div | ||
key={key} | ||
initial={{ opacity: 0 }} | ||
animate={{ opacity: 1 }} | ||
exit={{ opacity: 0 }} | ||
transition={{ duration: 1 }} | ||
style={{ | ||
...style, | ||
background: `hsla(${key * 15}, 100%, 50%, 1)`, | ||
}} | ||
/> | ||
</AnimatePresence> | ||
</div> | ||
) | ||
} |
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,37 @@ | ||
import { AnimatePresence, motion, useMotionValue } from "framer-motion" | ||
import { useState } from "react" | ||
|
||
export const App = () => { | ||
const count = useMotionValue(0) | ||
const [state, setState] = useState(0) | ||
|
||
return ( | ||
<> | ||
<button | ||
id="switch" | ||
onClick={() => { | ||
state === 0 ? setState(1) : setState(0) | ||
}} | ||
> | ||
Switch | ||
</button> | ||
<div> | ||
Animation count: <motion.span id="count">{count}</motion.span> | ||
</div> | ||
<AnimatePresence initial={false}> | ||
<motion.div | ||
id={state.toString()} | ||
className="item" | ||
key={state} | ||
initial={{ opacity: 0 }} | ||
animate={{ opacity: 1 }} | ||
exit={{ opacity: 0 }} | ||
transition={{ duration: 0.2 }} | ||
onAnimationStart={() => count.set(count.get() + 1)} | ||
> | ||
{state} | ||
</motion.div> | ||
</AnimatePresence> | ||
</> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "11.3.17", | ||
"version": "11.3.18-alpha.0", | ||
"packages": [ | ||
"packages/*" | ||
], | ||
|
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
60 changes: 60 additions & 0 deletions
60
packages/framer-motion/cypress/integration/animate-presence-switch-waapi.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,60 @@ | ||
describe("AnimatePresence with WAAPI animations", () => { | ||
it("Interrupting exiting animation doesn't break exit", () => { | ||
cy.visit("?test=animate-presence-switch-waapi") | ||
.wait(50) | ||
.get(".item") | ||
.should((items: any) => { | ||
expect(items.length).to.equal(1) | ||
expect(items[0].textContent).to.equal("0") | ||
}) | ||
.get("#switch") | ||
.trigger("click", 10, 10, { force: true }) | ||
.wait(50) | ||
.get(".item") | ||
.should((items: any) => { | ||
expect(items.length).to.equal(2) | ||
expect(items[0].textContent).to.equal("0") | ||
expect(items[1].textContent).to.equal("1") | ||
}) | ||
.wait(200) | ||
.get(".item") | ||
.should((items: any) => { | ||
expect(items.length).to.equal(1) | ||
expect(items[0].textContent).to.equal("1") | ||
}) | ||
.get("#switch") | ||
.trigger("click", 10, 10, { force: true }) | ||
.wait(20) | ||
.get("#switch") | ||
.trigger("click", 10, 10, { force: true }) | ||
.wait(20) | ||
.get("#switch") | ||
.trigger("click", 10, 10, { force: true }) | ||
.wait(300) | ||
.get(".item") | ||
.should((items: any) => { | ||
expect(items.length).to.equal(1) | ||
expect(items[0].textContent).to.equal("0") | ||
}) | ||
}) | ||
|
||
it("Interrupting exiting animation fire more animations than expected", () => { | ||
cy.visit("?test=animate-presence-switch-waapi") | ||
.wait(50) | ||
.get(".item") | ||
.should((items: any) => { | ||
expect(items.length).to.equal(1) | ||
expect(items[0].textContent).to.equal("0") | ||
}) | ||
.get("#switch") | ||
.trigger("click", 10, 10, { force: true }) | ||
.wait(20) | ||
.get("#switch") | ||
.trigger("click", 10, 10, { force: true }) | ||
.wait(300) | ||
.get("#count") | ||
.should((count: any) => { | ||
expect(count[0].textContent).to.equal("4") | ||
}) | ||
}) | ||
}) |
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.