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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: useResize is jumpy #2234

Open
1 of 5 tasks
flaff opened this issue Dec 15, 2023 · 0 comments
Open
1 of 5 tasks

[bug]: useResize is jumpy #2234

flaff opened this issue Dec 15, 2023 · 0 comments
Labels
template: bug This issue might be a bug

Comments

@flaff
Copy link

flaff commented Dec 15, 2023

Which react-spring target are you using?

  • @react-spring/web
  • @react-spring/three
  • @react-spring/native
  • @react-spring/konva
  • @react-spring/zdog

What version of react-spring are you using?

9.7.3

What's Wrong?

Hello 馃憢 useResize does not always animate to/from 0 height due to immediate attribute

sizeValues.width.get() === 0 || sizeValues.height.get() === 0,

Hook could be misused by me - there are not many examples in docs. Please correct me if I'm wrong 馃檹

To Reproduce

I created a sandbox where I tried disabling immediate flag inside useResize hook impl. Though then it animates on mount which is even worse... 馃し Sandbox contains both OG and modded useResize without that single attribute 馃槉

For the record: the workaround I found for now is to always provide at least 1px of content within the referenced container:

export function AnimateHeight({ children }) {
  const container = useRef();
  const { height } = useResize({ container });

  return (
    <animated.div style={{ height, overflow: 'hidden' }}>
      <div ref={container}>
        <div style={{ height: '1px', marginTop: '-1px' }} />
        {children}
      </div>
    </animated.div>
  );
}

Expected Behaviour

Animated wrapper should be animating height when referenced container height changes from/to 0

Link to repo

https://codesandbox.io/p/sandbox/react-spring-use-resize-jitter-p2npzl

@flaff flaff added the template: bug This issue might be a bug label Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
template: bug This issue might be a bug
Projects
None yet
Development

No branches or pull requests

1 participant