question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reset: true breaks reverse animation

See original GitHub issue

🐛 Bug Report

I have a flip-like animation where items grow from a dynamic width/height/x/y to full width modals. Without reset:true, it seems to cache the last measurements’ values and therefore doesn’t work until I click it again at the correct position and it stores the right values.

When I use reset: true, it works perfectly, but just doesn’t run the reverse animation. It just disappears on reverse without executing the animation

Here’s my code:

  const containerRef = useRef();
  const contentRef = useRef();
  const config = { mass: 5, tension: 4000, friction: 400 };
  const getPercent = (x, y) => `${(x / y) * 100}%`;

  const widthPercent = useMemo(
    () => getPercent(measurements.width, window.innerWidth),
    [measurements.width]
  );

  const heightPercent = useMemo(
    () => getPercent(measurements.height, window.innerHeight),
    [measurements.height]
  );

  const overlayAnimation = useSpring({
    ref: containerRef,
    unique: true,
    reset: true,
    from: {
      width: widthPercent,
      height: heightPercent,
      transform: `translate3d(${measurements.x}px, ${measurements.y}px, 0)`,
      opacity: 0,
      pointerEvents: "none",
    },
    to: {
      width: overlayOpen ? "100%" : widthPercent,
      height: overlayOpen ? "100%" : heightPercent,
      transform: overlayOpen
        ? `translate3d(0,0,0)`
        : `translate3d(${measurements.x}px, ${measurements.y}px, 0)`,
      opacity: overlayOpen ? 1 : 0,
      pointerEvents: overlayOpen ? "auto" : "none",
    },
    config: config,
  });

  const transitions = useTransition(
    overlayOpen ? overlayItems : [],
    (item, index) => index,
    {
      ref: contentRef,
      unique: true,
      from: { opacity: 0, transform: "translateX(-70%)" },
      enter: { opacity: 1, transform: "translateX(0)" },
      leave: { opacity: 0, transform: "translateX(70%)" },
      config: { mass: 10, tension: 2000, friction: 350 },
    }
  );

  useChain(
    overlayOpen ? [containerRef, contentRef] : [contentRef, containerRef],
    [0, overlayOpen ? 0.3 : 0.4]
  );

The problematic animation is the spring overlayAnimation. It grows perfectly to width/height 100% but on reverse just suddenly disappears (as if display: none was set).

Environment

  • react-spring latest
  • react latest

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
aleclarsoncommented, May 24, 2020

Please provide a minimal sandbox (fork this one) or .git url that shows the issue. 👍

0reactions
clsecommented, May 24, 2020

Alright, alright, fair enough 😉 haha

Thanks for the help. Just curious though, is there a way to force recalculations on each animation? (which is why i assumed reset was for?)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reset: true breaks reverse animation · Issue #1025 - GitHub
The reset prop shouldn't be used here. It forces the animation to start at the from values. If you can reproduce the unexpected...
Read more >
How to reverse an animation on mouse out after hover
var el = document.getElementById('divID'); // create a timeline for this element in paused state var tl = new TimelineMax({paused: true}); // create your...
Read more >
Restart CSS Animation
remove ("run-animation"); // -> triggering reflow /* The actual magic */ // without this it wouldn't work. Try uncommenting the line and the ......
Read more >
Play animation in reverse? - MSDN - Microsoft
Here we set the AutoReverse to true so that after the original animation is played, it'll play in reverse automatically.
Read more >
Animation | Android Developers
Constant, Value, Description. restart, 1, The animation starts again from the beginning. reverse, 2, The animation plays backward.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found