Giter VIP home page Giter VIP logo

react-native-gradients's Introduction

🎨React Native Gradients

npm version

A React Native alternative to Linear and Radial gradients, using SVG!

React Native Gradients Demo 1 React Native Gradients Demo 2 React Native Gradients Demo 3

⚙️Installation

Note: This library supports only React Native 0.60+ versions

Install react-native-gradients using your package manager

  • npm
npm install --save react-native-gradients react-native-svg
  • yarn
yarn add react-native-gradients react-native-svg

iOS installation

As it uses React Native SVG, you need to install the pod dependencies using following command

cd ios
pod install

✌️Usage

Linear Gradient

const colorList = [
  {offset: '0%', color: '#231557', opacity: '1'},
  {offset: '29%', color: '#44107A', opacity: '1'},
  {offset: '67%', color: '#FF1361', opacity: '1'},
  {offset: '100%', color: '#FFF800', opacity: '1'}
]
<LinearGradient colorList={colorList} angle={90}/>

Radial Gradient

const colorList = [
  {offset: '0%', color: '#231557', opacity: '1'},
  {offset: '29%', color: '#44107A', opacity: '1'},
  {offset: '67%', color: '#FF1361', opacity: '1'},
  {offset: '100%', color: '#FFF800', opacity: '1'}
]
<RadialGradient x="50%" y="50%" rx="50%" ry="50%" colorList={colorList}/>

With Content

This library uses <svg /> components. An option for other formats of "images" is using the React Native component <ImageBackground /> but for svgs that is not possible (at least for now).

A good option is wrap your Gradient component into a <View /> component and make that component has position: absolute style such as

import { RadialGradient } from 'react-native-gradients';

const BackgroundGradient = ({ style, children }) => (
  <View style={[styles.gradientBg, style]}>
    <RadialGradient />
  </View>
);

const styles = StyleSheet.create({
  gradientBg: {
    position: absolute,
    width: "100%",
    height: "100%",
  },
});

For every case a specific solution could be used and this could work as a base to your case.

SonarCloud

react-native-gradients's People

Contributors

caiangums avatar yildizberkay avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.