Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
TAAT

Resetting an animation in React is not setting to inital state

Recommended Posts

I have a simple animation -

1. Lines get highlighted one after the other on click on a button.

2. Clicking on button again, while the animation is running, should de-highlight the lines to original state.

 

However, on setting the timeline progress of animation to 0, all the values get reset, but the last one modified continues to remain in same state. 

 

To reproduce, click the button, and after a couple lines have highlighted, click the button again. 

 

Code Sandbox : https://codesandbox.io/s/inspiring-gates-poozb

Share this post


Link to post
Share on other sites

Set the state yourself in your return function.

setHighlightA(false);
setHighlightB(false);
setHighlightC(false);
setHighlightD(false);

 

And trying to animate a boolean is strange. It's converting them to strings. Something a little simpler.

 

timeLineLength.to(animationData, 1, { onStart() { setHighlightA(true); } })
timeLineLength.to(animationData, 1, { onStart() { setHighlightB(true); } })
timeLineLength.to(animationData, 1, { onStart() { setHighlightC(true); } })
timeLineLength.to(animationData, 1, { onStart() { setHighlightD(true); } })

 

Share this post


Link to post
Share on other sites
37 minutes ago, OSUblake said:

Set the state yourself in your return function.


setHighlightA(false);
setHighlightB(false);
setHighlightC(false);
setHighlightD(false);

 

And trying to animate a boolean is strange. It's converting them to strings. Something a little simpler.

 


timeLineLength.to(animationData, 1, { onStart() { setHighlightA(true); } })
timeLineLength.to(animationData, 1, { onStart() { setHighlightB(true); } })
timeLineLength.to(animationData, 1, { onStart() { setHighlightC(true); } })
timeLineLength.to(animationData, 1, { onStart() { setHighlightD(true); } })

 

Thanks, I did try setting the Highlights manually and typecasting the boolean values, but didn't give the expected behavior. 

 

I have realized that on updating the react-dom version, it does behave the way it is expected. I have raised an issue with React as well : https://github.com/facebook/react/issues/17112

 

In case someone has some insights, please do let know. 

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×