Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyframe fixes #1355

Merged
merged 7 commits into from Nov 19, 2021
Merged

Keyframe fixes #1355

merged 7 commits into from Nov 19, 2021

Conversation

mattgperry
Copy link
Collaborator

This PR makes a few keyframe fixes:

  1. If keyframes in two variants are the same, but the variant has changed, re-run the keyframes animation.
<motion.div
  animate={is ? "a" : "b"}
  variants={{ a: { x: [0,100] }, b: {x: [0,100] }  }}
/>

Fixes #1346

  1. If animate contains keyframes, set the initial value/style to the initial keyframe
<motion.div animate={{ opacity: [0, 1] }} />
// <div style="opacity: 0"></div>
  1. If initial={false} and animate contains keyframes, set the initial value/style to the final keyframe
<motion.div initial={false} animate={{ opacity: [0, 1] }} />
// <div style="opacity: 1"></div>

@mattgperry mattgperry requested a review from nvh November 17, 2021 14:20
@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 17, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 70118d4:

Sandbox Source
Framer Motion: Simple animation Configuration
App Store UI using React and Framer Motion Configuration
Framer Motion: Reorder animation Configuration
Framer Motion: growing item positionTransition issue Configuration
Framer Motion: Image lightbox Configuration
loving-yonath-f7x8b Issue #1346

@@ -201,8 +201,12 @@ export function createAnimationState(
* a changed value or a value that was removed in a higher priority, we set
* this to true and add this prop to the animation list.
*/
const isVariantChanged = variantsHaveChanged(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe variantDidChange?

Comment on lines +126 to +132
const index = initialAnimationIsBlocked
? valueTarget.length - 1
: 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why we take the last element here?

@mattgperry mattgperry requested a review from nvh November 19, 2021 08:26
@mattgperry mattgperry added the automerge Land this PR label Nov 19, 2021
@mattgperry mattgperry removed the request for review from nvh November 19, 2021 08:27
@mattgperry mattgperry force-pushed the fix/replay-keyframes-when-variant-changes branch from dee62a3 to 5c8a191 Compare November 19, 2021 08:45
@mergetron mergetron bot merged commit 8ea98e2 into main Nov 19, 2021
@mergetron mergetron bot deleted the fix/replay-keyframes-when-variant-changes branch November 19, 2021 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Land this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keyframes don't replay when variant label changes
2 participants