Animated in react-native with expo-linear-gradient cause "createAnimatedComponent does not support stateless functional components"
See original GitHub issue🐛 Bug Report
Summary of Issue
Invariant Violation: createAnimatedComponent
does not support stateless functional components; use a class component instead.
Reproducible Demo
import React, { Component } from 'react'
import { LinearGradient } from "expo-linear-gradient";
import { Animated } from "react-native";
class Project extends Component {
render() {
return (
<AnimatedLinearGradient
colors={["rgba(255,255,255, 0)", "rgba(255,255,255, 1)"]}
style={{ ... }}
/>
)
}
}
export default Project
const AnimatedLinearGradient = Animated.createAnimatedComponent(LinearGradient); // This line will cause an error.
Version
"expo-linear-gradient": "~8.3.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-39.0.2.tar.gz",
Expected Behavior vs Actual Behavior
I want to use Animated with LinearGradient, but it not work.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:5 (1 by maintainers)
Top Results From Across the Web
I have a class Component but I get this ...
I have a class Component but I get this `createAnimatedComponent` does not support stateless functional components; use a class component ...
Read more >LinearGradient - Expo Documentation
LinearGradient. expo-linear-gradient provides a native React view that transitions between multiple colors in a linear direction.
Read more >Use Functional component as Animated Component - FyndX
In React Native at this moment Animated.createAnimatedComponent can be used only with class based components but not with functional components.
Read more >Fullstack React Native
One of the major problems that teams face when writing native mobile applications is becoming familiar with all the different technologies.
Read more >How to Add Linear Gradients as Backgrounds to Your Expo ...
Hi everyone!Today I just have a small tutorial for you on how to use the LinearGradient component from the expo - linear -...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
in https://github.com/expo/expo/commit/257e88788838257c4983e001fd3b31c8577f293b#diff-3e93ce91136d0e7afb9dc92f5d0c1fe6 we rewrote it to be a function component. it looks like we need to use
React.forwardRef
and pass the ref through to the native componentfound a temporary fix using this HOC for this if anyone else is looking
const AnimatedLinearGradient = withAnimated(LinearGradient);