-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Animations before unmounting (and in general) #161
Comments
This is a really great question. We've discussed and heard several very interesting proposals for new APsI that allow us to express animations. We'll definitely be working on this going forward. My current belief is that it would be best to form an API that is layered on top of the declarative API that is at the heart of React. Currently, some animations are very functional, and those are very well suited to React's current API. Many animations can be elegantly expressed using CSS rules - React's current API is also is very well suited to those. Other types of animations that are more difficult to express functionally, take more effort and may require that you implement Here's one proposal that may be worth considering: Imagine if upon transitioning states, all DOM mutations that occur as a result may be passed through a separate declarative animation configuration:
Because we have a central place in the framework where we intercept all DOM mutations, we can make this work fairly easily. One nice thing about this proposed API, is that it might give us the power to pierce through the encapsulation boundary of sub-components, without ever leaking implementation details. We're able to "animate the implementation details" of sub-components, but without ever assuming anything about their nature. One tradeoff with this API is that I anticipate being able to perform animations very easily, but anticipate difficulty in getting animations to do exactly what we want with millisecond precision. There's also other types of animation APIs that we can provide for situations where the animated properties don't pierce through the encapsulation boundary:
That would simply invoke state transitions within a |
This sounds like good news. I definitely think webapps is/should be moving toward animated interactions not just of individual components, but as a coherent unit. What worries me in this situation is how the DOM will be reconciliated and how it'll affect the rest of the flow. Take todomvc for example. Ignoring the design of react's animation API, how would it achieve the followings?
I'm really buying the idea of react, and I think it's a just natural progression to express HTML, then potentially CSS, and then animation all in javascript. I love the smoothness of CSS animation, but as todomvc showed, these kind of animated elements in normal js/CSS frameworks are still constrained to minimal eye candies such as color transition when applying a checkmark, or the x button growing bigger on hover. They're very bland and frankly, feel like web-grade apps (as much as I love the web). To reiterate, I'm just worried that given react's (albeit extremely clever) diff rendering technique, the framework gets constrained in this aspect of UI. You know what would be a sick API? If we can somehow achieve the above two kind of animated interactions directly on top of the existing todomvc, without altering the structure of the app. Animations will only get ubiquitous if it doesn't interfere with the actual sketching of the app. |
I totally agree! |
As far as "animations on unmounting" goes, I usually just toggle a "shown" or "visible" prop on an owner component instead of unmounting directly, since then you can do the transition first and then finally unmount. But YMMV. As far as "animations in general" goes, I've prepared this example for you: https://github.com/petehunt/react-animations. It's a pretty performant way to tween your state, interpret touch gestures, and animate in a performant way. Let me know if this is helpful! |
@petehunt i know it's an old comment, but your react-animations repo is 404ing |
@WickyNilliams pete removed it. You can still find the commits here |
@chenglou thanks! |
Don't materialize typed array until the transfer
(Context: my pull request for fixing the bootstrap modal example: #160).
Animation in
componentDidMount
works, but doesn't incomponentWillUnmount
for obvious reason.Let's say I have three divs side by side. When the middle one closes, it does a shrinking animation and disappears, and the one on the right moves left to take its place. Currently it takes a bit of circumventing to make this work (and kills the nice structure and semantic react's aiming for), and at the end it kind of defeats the purpose of the diff rendering technique.
I was wondering if there'd be a clean way, maybe even a new api, to make this work well.
The text was updated successfully, but these errors were encountered: