Giter Club home page Giter Club logo

react-native-easing-gradient's Introduction

React Native Easing Gradient

Stable Release license

Create smooth gradients in React Native

The problem

From https://larsenwork.com/easing-gradients/

Linear gradients often have hard edges where they start and/or end. We can avoid those by controlling the color mix with easing functions.

Usage

import { LinearGradient } from 'expo-linear-gradient'
import { easeGradient } from 'react-native-easing-gradient'

const { colors, locations } = easeGradient({
  colorStops: {
    0: {
      color: 'transparent',
    },
    1: {
      color: '#18181B',
    },
  },
})

function App() {
  return (
    <View style={styles.container}>
      <LinearGradient
        colors={colors}
        locations={locations}
        style={styles.overlay}
      />
    </View>
  )
}

You can also change the easing functions between the color stops

const { colors, locations } = easeGradient({
  colorStops: {
    0: {
      color: 'transparent',
      // The transition from `0` to `1` will now use `Easing.linear` instead of `Easing.ease`
      easing: Easing.linear,
    },
    1: {
      color: '#18181B',
    },
  },
  // The easing function used on all transitions, defaults to `ease-in-out` (Easing.bezier(0.42, 0, 0.58, 1))
  easing: Easing.ease,
})

Or the amount of extra color stops added to each transition

const { colors, locations } = easeGradient({
  colorStops: {
    0: {
      color: 'transparent',
    },
    1: {
      color: '#18181B',
    },
  },
  // The more color stops added, the smoother the transition is
  // Defaults to 12
  extraColorStopsPerTransition: 16
})

Credits

Example

To run the example project, follow these steps:

  • Clone the repo
  • Run these commands
yarn
cd example
yarn && yarn start

react-native-easing-gradient's People

Contributors

phamfoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-native-easing-gradient's Issues

Animate Gradient

Hello. Is there a way to animate the gradient so the colors would loop?

Low Gradient quality on 4k TV

The LinearGradient using react-native-easing-gradient
Only tested in Android TV

I saw improvements on the quality of the gradient but not enough.
I tried with different extraColorStopsPerTransition, but the result is similar.

On the Android Emulator the result is perfect, but on the TV the result is bad.

`    const { colors: gradientColours, locations } = easeGradient({
        colorStops: {
            0.1: {
                color: colors.secondary,
            },
            0.5: {
                color: colors.primary,
            },
            0.9: {
                color: colors.secondary,
            },
        },
        easing: Easing.linear,
        extraColorStopsPerTransition: 1000,
    });`
`        <LinearGradient
            style={{
                position: 'absolute',
                width: Dimensions.get('window').width,
                height: Dimensions.get('window').height,
            }}
            colors={gradientColours}
            locations={locations}
            useAngle={true}
            angle={90}
        />`

Packages
"react-native-linear-gradient": "^2.8.3",
"react-native-easing-gradient": "^1.1.1",

Running on Emulator
image

On TV
signal-2024-03-01-144001_003
signal-2024-03-01-144001_002

TypeError: AnimatedInterpolation.__createInterpolation is not a function (it is undefined)

Hi @phamfoo ,

Thanks for the cool lib. I really want to try it out but am getting this error on the latest RN (version "0.73.4"):

TypeError: AnimatedInterpolation.__createInterpolation is not a function (it is undefined)

I think the internal function being accessed here is no longer available in RN hence it breaks. Do you know how one might get around this? I am okay patch packaging it if you could point me towards a solution. Thanks!

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.