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
latestreact
latest
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Please provide a minimal sandbox (fork this one) or
.git
url that shows the issue. 👍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?)