项目作者: tienphaw

项目描述 :
Create smooth gradients in React Native
高级语言: TypeScript
项目地址: git://github.com/tienphaw/react-native-easing-gradient.git
创建时间: 2021-04-30T12:26:22Z
项目社区:https://github.com/tienphaw/react-native-easing-gradient

开源协议:MIT License

下载


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

  1. import { LinearGradient } from 'expo-linear-gradient'
  2. import { easeGradient } from 'react-native-easing-gradient'
  3. const { colors, locations } = easeGradient({
  4. colorStops: {
  5. 0: {
  6. color: 'transparent',
  7. },
  8. 1: {
  9. color: '#18181B',
  10. },
  11. },
  12. })
  13. function App() {
  14. return (
  15. <View style={styles.container}>
  16. <LinearGradient
  17. colors={colors}
  18. locations={locations}
  19. style={styles.overlay}
  20. ></LinearGradient>
  21. </View>
  22. )
  23. }

You can also change the easing functions between the color stops

  1. const { colors, locations } = easeGradient({
  2. colorStops: {
  3. 0: {
  4. color: 'transparent',
  5. // The transition from `0` to `1` will now use `Easing.linear` instead of `Easing.ease`
  6. easing: Easing.linear,
  7. },
  8. 1: {
  9. color: '#18181B',
  10. },
  11. },
  12. // The easing function used on all transitions, defaults to `ease-in-out` (Easing.bezier(0.42, 0, 0.58, 1))
  13. easing: Easing.ease,
  14. })

Or the amount of extra color stops added to each transition

  1. const { colors, locations } = easeGradient({
  2. colorStops: {
  3. 0: {
  4. color: 'transparent',
  5. },
  6. 1: {
  7. color: '#18181B',
  8. },
  9. },
  10. // The more color stops added, the smoother the transition is
  11. // Defaults to 12
  12. extraColorStopsPerTransition: 16
  13. })

Credits

Example

To run the example project, follow these steps:

  • Clone the repo
  • Run these commands
  1. yarn
  2. cd example
  3. yarn && yarn start