Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Ultra-fast web version of `react-native-linear-gradient` package

NotificationsYou must be signed in to change notification settings

retyui/react-native-linear-gradient-web

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This package offers fast linear gradient implementation specifically forReact Native Web.

Its exceptional speed comes from being fully stateless, meaning it avoids setState during layout events. This key difference sets it apart from similar packages likereact-native-web-linear-gradient andexpo-linear-gradient.

Plus, this component supports theReact Compiler out of the box.


⚠️ Warning⚠️

Also, You don't need any third-party libraries to use linear gradients in React Native.You can use theexperimental_backgroundImage style property, which is available inReact Native 0.76.x and later.

import{Platform,StyleSheet,View}from"react-native";conststyles=StyleSheet.create({gradient:Platform.select({web:{backgroundImage:"linear-gradient(...)"},// works in `react-native-web` by defaultdefault:{experimental_backgroundImage:"linear-gradient(...)"},// 0.76.x +}),});functionApp(){return<Viewstyle={styles.gradient}/>;}

Installation

Install the package using either npm or yarn:

yarn add react-native-linear-gradient-web

Usage

You can create a wrapper component that uses thereact-native-linear-gradient-web package instead ofreact-native-linear-gradient:

// ./my-linear-gradient.web.jsimportLinearGradientWebfrom"react-native-linear-gradient-web";exportdefaultLinearGradientWeb;// ./my-linear-gradient.jsimportLinearGradientfrom"react-native-linear-gradient";exportdefaultLinearGradient;

Then you can import./my-linear-gradient.js in your codebase, and it will work seamlessly with both web and native platforms.

importReactfrom"react";import{View}from"react-native";importLinearGradientfrom"./my-linear-gradient";functionApp(){return<LinearGradientcolors={["red","gold"]}/>;}

or if you use a Webpack bundler you can use simply adjust yourwebpack.config.js to include the following alias:

module.exports = {  resolve: {    alias: {      'react-native': 'react-native-web',      // ...+     'react-native-linear-gradient': 'react-native-linear-gradient-web',    },  },};

Examples

Comparison

flickering when a component mountOffest & Angle
demo.mp4
well-well.mov

Known Issues

  • This package is not compatible with the Tizen runtime (SVG gradient as a background image won't work).

About

Ultra-fast web version of `react-native-linear-gradient` package

Resources

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp