我目前正在一个React-native项目中,尝试从功能组件创建动画组件。当我使用类组件时,它工作得很好。但是,将类组件更改为功能组件会引发以下错误:
'createAnimatedComponent' does not support stateless functional components; use a class component instead.
代码如下:
GradientHelper.tsx
const GradientHelper: React.FC<IGradientHelperProps> = (props) => {
const { style, color1, color2, startX, startY, endX, endY, children } = props
return (
<LinearGradient
colors={[color1, color2]}
start={{
x: startX,
y: startY,
}}
end={{
x: endX,
y: endY,
}}
style={style}
>
{children}
</LinearGradient>
)
}
export default GradientHelper;
index.tsx
const AnimatedGradientHelper = Animated.createAnimatedComponent(GradientHelper)
const AnimatedGradient: React.FC<IAnimateGradientProps> = (props) => {
...
}
调用Animated.createAnimatedComponent(GradientHelper)时引发错误。有人知道如何解决此问题吗?