Spring如何自然地渲染渲染?

时间:2019-03-12 09:30:07

标签: reactjs react-native react-spring

react spring带有animated函数,该函数允许在不重新渲染组件的情况下本地修改组件。我发现动画组件具有几种类似于react native's animated components的方法。两者之间是否有联系,或者.interpolate()这样的概念在动画库中是否很常见?

1 个答案:

答案 0 :(得分:1)

该库最初是Animated的一个分支,但在内部仍然有很多相似之处。克里斯托弗·切多(Christopher Chedeau)的Animated(动画)有一个专用于网络的仓库:https://github.com/animatedjs/animated很遗憾,它不再得到维护。

它的工作方式是通过createAnimatedComponent(被显示为“动画”)包装组件:https://github.com/react-spring/react-spring/blob/master/src/animated/createAnimatedComponent.tsx

这个高阶组件拦截样式和属性(不是原始值,而是自更新类)。它调用“ applyAnimatedValues”以在React外部写入目标。每个目标(dom,native,konva,三个等)都必须填写。例如,以下是dom如何应用这些道具的方法:https://github.com/react-spring/react-spring/blob/master/src/targets/web/globals.ts#L82-L127

希望有帮助!