React Native Web Linear Gradient

1.1.2 · active · verified Sun Apr 19

react-native-web-linear-gradient provides a web-compatible implementation of `react-native-linear-gradient` for use in React Native for Web projects. It allows developers to render linear gradients on the web using standard CSS gradients, effectively bridging the gap for a common UI component across native and web platforms. The current stable version is 1.1.2. The package follows an active maintenance release cadence, addressing compatibility issues and adding prop support as needed. Its key differentiator is providing a drop-in replacement via webpack aliasing, allowing a single codebase to use `react-native-linear-gradient` and automatically resolve to the web-specific implementation when bundled for the web. It maintains API compatibility with its native counterpart, simplifying cross-platform development.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates installation, the required webpack alias configuration, and basic usage of the LinearGradient component to display a simple gradient on the web.

import React from 'react';
import { View, Text } from 'react-native';
import LinearGradient from 'react-native-linear-gradient'; // Alias will redirect to react-native-web-linear-gradient

// Webpack configuration (in webpack.config.js or similar)
// module.exports = {
//   resolve: {
//     alias: {
//       'react-native': 'react-native-web',
//       'react-native-linear-gradient': 'react-native-web-linear-gradient',
//     }
//   },
//   // other webpack config
// };

const App = () => {
  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <LinearGradient
        colors={['#4c669f', '#3b5998', '#192f6a']}
        style={{
          width: 200,
          height: 150,
          borderRadius: 10,
          justifyContent: 'center',
          alignItems: 'center',
        }}
        start={{ x: 0, y: 0 }}
        end={{ x: 1, y: 1 }}
      >
        <Text style={{ color: 'white', fontSize: 20 }}>
          Gradient Text
        </Text>
      </LinearGradient>
    </View>
  );
};

export default App;

view raw JSON →