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

Incorrect rounding of element sizes while animating #191

Open
sippeangelo opened this issue Jan 19, 2024 · 2 comments
Open

Incorrect rounding of element sizes while animating #191

sippeangelo opened this issue Jan 19, 2024 · 2 comments

Comments

@sippeangelo
Copy link

https://github.com/formkit/auto-animate/blame/b62aa87b0ce6b90c92fb7ebb06a3da49f74b7f77/src/index.ts#L428

Due to this Math.round, element sizes are changed from their actual size while animating, causing flex elements with text to wrap.

Screen.Recording.2024-01-19.at.17.35.30.mov

For example, here I have a flex item with three elements. The first and third element are fixed in width, while the middle text element's width is dynamic. When rendered, it measures up to 245.17px. Once the element is removed and auto-animate starts fading it out, it sets width: 245px for whatever reason, causing the text inside to wrap to the next line. Removing the round in the code above fixes this.

@justin-schroeder
Copy link
Member

Are you sure that’s due to rounding? I would be thrilled if it was because we could fix it, but up till now my working hypothesis is this: some "paints" take 2 paints and some take 1. Text is particularly tricky because the browser itself doesnt know how big/wide the text will be until it has painted it. So it paints, measures it, then paints again. Unfortunately autoanimate is only informed of the first paint (which wrapped) and thus sets the size to that instead of the second paint. Ive looked for a way around this but been unable to find one.

This tends to happen with things were the width of the item is determined by its context, like width-less flex items, table cells (those have other issues too), floats, etc.

If you can demonstrate that it is indeed a rounding issue I would be thrilled to accept a PR or look into it further!

@sippeangelo
Copy link
Author

sippeangelo commented Jan 22, 2024

It looks to be. If I break just as the element is fading out and check its size in the inspector, its width has been rounded down, and if I remove the rounding from the line I mentioned it works fine. I don't know why the rounding was added originally so I'm hesitant to create a PR, but it works a lot better without it for my specific case!

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants