-
-
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.
Ensure optimised appear animations are cancelled when styles differ (#…
…2772) * Ensure values cancelled on scroll * Fixing * Latest * Updating * Updating appear tests json * Remove logging * Cleaning PR * Adding tesst
- Loading branch information
1 parent
4c92d2f
commit d2484a8
Showing
10 changed files
with
243 additions
and
33 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
dev/html/public/optimized-appear/defer-handoff-external-values.html
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,132 @@ | ||
<html> | ||
<head> | ||
<style> | ||
body { | ||
padding: 100px; | ||
margin: 0; | ||
} | ||
|
||
#box { | ||
width: 100px; | ||
height: 100px; | ||
background-color: #0077ff; | ||
} | ||
|
||
[data-layout-correct="false"] { | ||
background: #dd1144 !important; | ||
opacity: 1 !important; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/imports/optimized-appear.js"></script> | ||
<script type="module" src="/src/imports/script-assert.js"></script> | ||
|
||
<script type="module"> | ||
const { | ||
motion, | ||
animateStyle, | ||
animate, | ||
startOptimizedAppearAnimation, | ||
optimizedAppearDataAttribute, | ||
motionValue, | ||
frame, | ||
} = window.Motion | ||
const { matchViewportBox } = window.Assert | ||
const root = document.getElementById("root") | ||
|
||
const duration = 0.5 | ||
const x = motionValue(0) | ||
const opacity = motionValue(0) | ||
const animateX = motionValue(0) | ||
const animateOpacity = motionValue(0) | ||
|
||
let isFirstFrame = true | ||
|
||
function Component() { | ||
React.useEffect(() => { | ||
setTimeout(() => { | ||
x.set(200) | ||
opacity.set(0.5) | ||
}, 200) | ||
}, []) | ||
|
||
return React.createElement(motion.div, { | ||
id: "box", | ||
initial: { x: 0, opacity: 0 }, | ||
animate: { x: 100, opacity: 1 }, | ||
transition: { | ||
duration, | ||
ease: "linear", | ||
layout: { ease: () => 0, duration: 10 }, | ||
}, | ||
style: { | ||
x, | ||
opacity, | ||
position: "relative", | ||
background: "blue", | ||
}, | ||
values: { x: animateX, opacity: animateOpacity }, | ||
onAnimationComplete: () => { | ||
const box = document.getElementById("box") | ||
const { left } = box.getBoundingClientRect() | ||
const { opacity } = box.style | ||
const { opacity: computedOpacity } = | ||
window.getComputedStyle(box) | ||
if (Math.round(left) !== 300) { | ||
showError( | ||
box, | ||
`transform optimised animation not cancelled by external value mismatch with rendered style` | ||
) | ||
} | ||
|
||
if (opacity !== computedOpacity) { | ||
showError( | ||
box, | ||
`opacity optimised animation not cancelled by external value mismatch with rendered style` | ||
) | ||
} | ||
}, | ||
[optimizedAppearDataAttribute]: "a", | ||
children: "Content", | ||
}) | ||
} | ||
|
||
// Emulate server rendering of element | ||
root.innerHTML = ReactDOMServer.renderToString( | ||
React.createElement(Component) | ||
) | ||
|
||
// Start optimised opacity animation | ||
startOptimizedAppearAnimation( | ||
document.getElementById("box"), | ||
"opacity", | ||
[0, 1], | ||
{ | ||
duration: duration * 1000, | ||
ease: "linear", | ||
} | ||
) | ||
|
||
// Start WAAPI animation | ||
const animation = startOptimizedAppearAnimation( | ||
document.getElementById("box"), | ||
"transform", | ||
["translateX(0px)", "translateX(100px)"], | ||
{ | ||
duration: duration * 1000, | ||
ease: "linear", | ||
}, | ||
(animation) => { | ||
setTimeout(() => { | ||
ReactDOM.hydrateRoot( | ||
root, | ||
React.createElement(Component) | ||
) | ||
}, (duration * 1000) / 4) | ||
} | ||
) | ||
</script> | ||
</body> | ||
</html> |
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 +1 @@ | ||
["defer-handoff-block.html","defer-handoff-layout-ancestor-suspend.html","defer-handoff-layout-ancestor.html","defer-handoff-layout-child.html","defer-handoff-layout-opacity.html","defer-handoff-layout-sibling-transform.html","defer-handoff-layout-sibling.html","defer-handoff-layout-useeffect.html","defer-handoff-layout-uselayouteffect.html","defer-handoff-layout.html","defer-handoff.html","interrupt-delay-after.html","interrupt-delay-before-accelerated.html","interrupt-delay-before.html","interrupt-spring.html","interrupt-tween-opacity-waapi.html","interrupt-tween-opacity.html","interrupt-tween-transforms.html","interrupt-tween-x.html","persist-optimised-animation.html","persist.html","portal.html","resync-delay.html","resync.html","start-after-hydration.html"] | ||
["defer-handoff-block.html","defer-handoff-external-values.html","defer-handoff-layout-ancestor-suspend.html","defer-handoff-layout-ancestor.html","defer-handoff-layout-child.html","defer-handoff-layout-opacity.html","defer-handoff-layout-sibling-transform.html","defer-handoff-layout-sibling.html","defer-handoff-layout-useeffect.html","defer-handoff-layout-uselayouteffect.html","defer-handoff-layout.html","defer-handoff.html","interrupt-delay-after.html","interrupt-delay-before-accelerated.html","interrupt-delay-before.html","interrupt-spring.html","interrupt-tween-opacity-waapi.html","interrupt-tween-opacity.html","interrupt-tween-transforms.html","interrupt-tween-x.html","persist-optimised-animation.html","persist.html","portal.html","resync-delay.html","resync.html","start-after-hydration.html"] |
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
6 changes: 3 additions & 3 deletions
6
packages/framer-motion/src/animation/optimized-appear/get-appear-id.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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { VisualElement } from "../../render/VisualElement" | ||
import { optimizedAppearDataAttribute } from "./data-id" | ||
import { WithAppearProps } from "./types" | ||
|
||
export function getOptimisedAppearId( | ||
visualElement: VisualElement | ||
visualElement: WithAppearProps | ||
): string | undefined { | ||
return visualElement.getProps()[optimizedAppearDataAttribute] | ||
return visualElement.props[optimizedAppearDataAttribute] | ||
} |
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
8 changes: 7 additions & 1 deletion
8
packages/framer-motion/src/animation/optimized-appear/store-id.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 |
---|---|---|
@@ -1 +1,7 @@ | ||
export const appearStoreId = (id: string, value: string) => `${id}: ${value}` | ||
import { transformProps } from "../../render/html/utils/transform" | ||
|
||
export const appearStoreId = (elementId: string, valueName: string) => { | ||
const key = transformProps.has(valueName) ? "transform" : valueName | ||
|
||
return `${elementId}: ${key}` | ||
} |
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