Can createAnimatedComponent accept functional components? #1527
-
Currently, there is a check if the component passed is functional or not. However, I couldn't detect any code that relies on the component being a class component. Is it because of the ref? Then could the check be refined maybe? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 12 replies
-
The biggest blocker with using functional components is that they don't have \cc @Szymon20000 EDIT: changing keys removes entire subtrees in the RN and calling |
Beta Was this translation helpful? Give feedback.
-
Thanks for that @jakub-gonet I did notice it afterward. Let's say that I want to animate a prop myself (just as an educational exercise, for instance, I would like to explore the idea of animating opengl shaders). How would I go about it? |
Beta Was this translation helpful? Give feedback.
-
Here's a workaround I came up with to get
In this example If this does indeed work as well as it seems to then perhaps this could be rolled into |
Beta Was this translation helpful? Give feedback.
-
Per the above, here's a generic import {FC, ComponentClass} from 'react'
import Animated from 'react-native-reanimated'
const wrapFunctionComponent = <TProps,>(
Component: FC<TProps>
): ComponentClass<TProps> =>
class extends React.Component<TProps> {
constructor(props: TProps) {
super(props)
}
render() {
return <Component {...this.props} />
}
}
export const createAnimatedFunctionComponent = <TProps,>(
Component: FC<TProps>
) => Animated.createAnimatedComponent(wrapFunctionComponent(Component)) |
Beta Was this translation helpful? Give feedback.
-
Hello everyone I am getting this error can anyone help me? ERROR Invariant Violation: |
Beta Was this translation helpful? Give feedback.
-
Hey, if you want to animate functional components, you can always wrap them with |
Beta Was this translation helpful? Give feedback.
Hey, if you want to animate functional components, you can always wrap them with
React.forwardRef
, as suggested in the updated version of the error message.