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

Enable pathLength animations for more SVG shapes #1325

Merged
merged 6 commits into from Nov 3, 2021
Merged

Conversation

mattgperry
Copy link
Collaborator

@mattgperry mattgperry commented Nov 2, 2021

Instead of measuring path length with getTotalLength, we now set the pathLength attribute to 1.

This change:

  • Fixes path animations for elements with vector-effect="non-scaling-stroke" applied
  • Extends path animations from path to circle, ellipse, line, polygon, polyline and rect components
  • Adds SSR support for pathLength

Fixes #521

@mattgperry mattgperry changed the title Fix/path length Enable pathLength animations for more SVG shapes Nov 2, 2021
@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 2, 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 54ae9a4:

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
nervous-zeh-bk1vs Issue #521

@mattgperry mattgperry force-pushed the fix/path-length branch 2 times, most recently from a5b92cb to c508c62 Compare November 2, 2021 13:38
@mattgperry mattgperry requested review from shuangq and removed request for adamseckel and shuangq November 3, 2021 09:02
@mattgperry mattgperry added the automerge Land this PR label Nov 3, 2021
@mergetron mergetron bot merged commit 6bce8a1 into main Nov 3, 2021
@mergetron mergetron bot deleted the fix/path-length branch November 3, 2021 13:01
@willhindson
Copy link

willhindson commented Mar 14, 2024

I'm not sure this is the best way to get my issue fixed, but I think that a problem I am having aligns mostly to this previously flagged issue.

I'm using framer-motion to animate a simple path with a start point, end point and two control points from 0 to 1 in length.

The animation works smoothly and correctly but when I add vectorEffect="non-scaling-stroke" on motion.path (which is necessary for this stretched svg) you can clearly see the strokeDasharray — the line only gets half filled. As though the pathLength is not being correctly calculated

It seems from this issue that it should have been solved long ago, but maybe something was broken recently?

@willhindson
Copy link

willhindson commented Mar 14, 2024

I am wondering if the issue is related to the fact that the path animates from stroke-dasharray="0px 1px" to stroke-dasharray="1px 1px"

I am using initial={{ pathLength: 0 }} and whileInView={{ pathLength: 1 }}

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.

pathLength doens't work on non-scaling-stroke [BUG]
2 participants