-
Notifications
You must be signed in to change notification settings - Fork 651
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
how to set dynamic animations? #182
Comments
This is a typical unmounting animation problem, I've run into it before. My solution back then was to call setState to update the |
yeah the issue is that you can't really change the animations on an item from the outside the "normal" way because you unrender it. There is the childFactory prop for addressing this, which is called with the item and the state even for the items you don't "see" anymore |
For anyone else that finds their way here - there's a great Q&A on StackOverflow with a detailed explanation on how to use childFactory: https://stackoverflow.com/questions/41404232/react-transitiongroup-and-react-cloneelement-do-not-send-updated-props |
@Chopinsky I'm not sure I follow. Could you paste an example demonstrating how you achieved that? |
childFactory is definitely the way to go. Thanks to the SO link provided by @m-allanson, I was able to use the childFactory as follows to correctly update the animation:
|
@cjnaude Does this really work with React 16 and React Transition Group v2?
|
@marshall-cho Here are my dependencies: Are you getting any specific errors, or is the animation just not updating? |
I just wanted to share an article I just wrote dealing with this issue: https://medium.com/lalilo/dynamic-transitions-with-react-router-and-react-transition-group-69ab795815c9. This thread helped me a lot. Thanks |
@nicgirault Greate article. |
https://codesandbox.io/s/p93vp612w0 Heres a sandbox app with my implementation if anyones struggling with this. |
If anyone else is struggling with this problem, the way we fixed it was to wrap the entire inside a div. Then when we want the components to slide in either direction we dynamically change the class of that parent div which targets (selects) the classes of the child elements inside the transition component. That way the classes inside the transition stay static while the classes of parent div change thereby controlling the direction of the transitions using CSS selectors. |
@nicgirault Thanks for the article mate, I was really struggling to get this right |
2022 and the issue is still here! Solved by example of @moneydance (comment above): thanks a lot, you saved my day! One-string solver: const dynamicChildFactory = classNames => child => React.cloneElement(child, { classNames }); |
I am using react-transition-group v2.2.0 and react-router v4.1.1 to do the page sliding animation. Once a component is mounted, its exit animation is specified, not changeable, which troubles me.
The css:
The animation:
If only sliding from '/' to '/games' and then from '/games' back to '/', everything is fine. But with more routes, it gets complicated.
For the Games component:
As the Games component mounted, its exit animation classNames is 'pageSliderLeft' or 'pageSliderRight'. No matter which class, there is only one animation. But Games component has two exit types.
How to make the Games component's exiting show different animations?
The text was updated successfully, but these errors were encountered: