react-native-linear-gradient provides a highly performant `<LinearGradient>` component for React Native applications, allowing developers to easily render linear color gradients. It leverages native modules for both iOS and Android to ensure smooth performance and integration, making it a staple for UI enhancements. The current stable version is 2.8.3, with version 3.0.0 actively under development (currently in beta), which introduces support for React Native's New Architecture. The project maintains a steady release cadence, addressing bugs and adding features, with major versions typically focusing on compatibility with newer React Native architectures and platforms. Its primary differentiation is its native implementation, offering better performance compared to JavaScript-only solutions for gradients.
npm install react-native-linear-gradientVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic usage of LinearGradient component with multiple colors, custom start/end points, and embedded text, styled within a React Native view.
Users targeting React Native for Windows will need to find an alternative gradient solution or remain on a version prior to 3.0.0-beta.2. Consider `react-native-windows` specific gradient components if available.
Upgrade to v2.8.2 or newer, which removes the problematic `compileOptions` and resolves the Android compilation issues.
Review the official React Native New Architecture migration guide. For existing projects, consider upgrading incrementally or remaining on the `2.x.x` series until full New Architecture migration is feasible.
Ensure you are using v2.7.3 or later to avoid potential runtime errors or unexpected gradient behavior on Android related to coordinate parsing. The expected format for `start` and `end` is `{{ x: number, y: number }}`.Change your import statement from `import { LinearGradient } from 'react-native-linear-gradient';` to `import LinearGradient from 'react-native-linear-gradient';`Update `react-native-linear-gradient` to version 2.8.2 or higher to resolve the `build.gradle` compilation problem.
Ensure you have properly linked the native module (if not using autolinking), clean your Android/iOS build caches (`cd android && ./gradlew clean` or `cd ios && pod cache clean --all && pod install`), and check for compatibility between your `react-native` version and the `react-native-linear-gradient` version.