Replies: 1 comment 7 replies
-
I will respond about the problem rather than about the proposed solution because I don’t have enough background info on the solution itself (other than that we’ve intentionally not pursued it so far). The problem you’re highlighting is animations. And specifically updating some parts of the tree very fast, and how diffing doesn’t scale to that. We agree it’s a different use case. First-class React Animations will not be a part of the React 18 release. This is both because it’s a large scope of work which would delay the release by a lot, and because it requires a bunch of research as well as a change in internal data structures. However, the thinking here is this. We would “teach” the reconciler to interpolate between two versions of the tree. In other words, before the animation starts, we’ll render (in memory) the tree before and the tree after the animation. We will diff them, taking into account an opt-in API that lets components specify their visual state on enter and exit, and recording any values that are different and can be interpolated. Then we would “hand it off” that list of values to a renderer-specific “driver” which would be a highly optimized piece of code that performs the interpolation — ideally, using the platform primitives when possible. I’m not sure we can use CSS transitions today given that they aren’t springy, but RN would use a native driver where possible, and maybe if CSS supports springs, we could switch to that as well. So it’s a constraint that for the common case we don’t want any tree re-renders during the animation at all. However, there would be ability to hand off the animation to a gesture-driven “driver” which might still execute on JS thread. In this case it would still use the precalculated interpolation though rather than do a re-render on every frame. This is still very high-level so I probably won’t be able to respond to detailed follow-up questions — but that’s more or less what we’re thinking. |
Beta Was this translation helpful? Give feedback.
-
In React we used to call setState 60fps to push animation forward (react-motion) but each update goes through diffing, hooks, sub-trees. This is something that time-slicing can't solve because here we really need fast access. Some animation libs handle updates outside of React (animated, framer-motion, react-spring), the price is internal complexity and inflexibility (they can't function cross platform bc they need to "know" the host).
One approach was setNativeProps but that was problematic. A simpler approach may be to give React the ability to handle transient values. In the following example React would re-hydrate the view if
count
is changed, given that it is static (non-changing). Thereby we would have zero overhead write access. The component would not re-render but simply update the dom.As for interpolation, where the same value creates different variants or interpretations of its own content:
Beta Was this translation helpful? Give feedback.
All reactions