1.1.5 ā€¢ Published 10 months ago

react-native-gradient-shimmer v1.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

React-Native Gradient Shimmer

License MIT npm version npm downloads

āš› A pure JavaScript, performant, typed shimmer component for Android, iOS and Web.

It uses React Native Animated API for animation, and expo-linear-gradient or react-native-linear-gradient for the gradient effect.

Take a look at the Online demo.

AndroidiOSWeb

Requirements

Install

Install dependency package

yarn add react-native-gradient-shimmer

Or

npm i -S react-native-gradient-shimmer

Basic usage

Render the GradientShimmer directly:

import LinearGradient from 'react-native-linear-gradient'; // or 'expo-linear-gradient'
import GradientShimmer from 'react-native-gradient-shimmer';

const App = () => {
   return (
      <SafeAreaView style={{flex: 1}}>
         <GradientShimmer
            LinearGradientComponent={LinearGradient}
            backgroundColor="red"
            highlightColor="blue"
            height={120}
            width={120}
            style={{
              borderRadius: 60,
              margin: 8,
            }}
         />
      </SafeAreaView>
   );
}

export default App;

Or create your own GradientShimmer instance with default props:

import LinearGradient from 'react-native-linear-gradient'; // or 'expo-linear-gradient'
import {createGradientShimmer} from 'react-native-gradient-shimmer';

const CustomGradientShimmer = createGradientShimmer({
  backgroundColor: 'red',
  highlightColor: 'blue',
  LinearGradientComponent: LinearGradient,
})

const App = () => {
   return (
      <SafeAreaView style={{flex: 1}}>
         <CustomGradientShimmer
            height={120}
            width={120}
            style={{
              borderRadius: 60,
              margin: 8,
            }}
         />
      </SafeAreaView>
   );
}

export default App;

See more in the Sample project.

Shimmer layout

For more complex layouts, you can use the ShimmerLayout component.

import LinearGradient from 'react-native-linear-gradient'; // or 'expo-linear-gradient'
import {ShimmerLayout, ShimmerLayoutContainerType} from 'react-native-gradient-shimmer';

const layoutExample: ShimmerLayoutContainerType = {
   content: [
      {
         flexDirection: 'row',
         content: [
            {
               height: 150,
               width: 100,
               marginRight: 16,
            },
            {
               justifyContent: 'space-between',
               content: [
               {
                  height: 40,
                  width: 250,
               },
               {
                  height: 40,
                  width: 250,
               },
               {
                  height: 40,
                  width: 120,
               },
               ],
            },
         ],
      },
      // ....
   ],
};

const App = () => {
   return (
      <SafeAreaView style={{flex: 1}}>
         <ShimmerLayout
            LinearGradientComponent={LinearGradient}
            layout={layoutExample}
         />
      </SafeAreaView>
   );
}

export default App;

See more in the Sample project.

Props and types

GradientShimmer props

NameTypeDefaultDescription
LinearGradientComponentComponentTypeLinear gradient component from expo-linear-gradient or react-native-linear-gradient
widthnumberComponent width in DPI
heightnumberComponent height in DPI
backgroundColorstring'rgb(200,200,200)'Background color in HEX or RGB
highlightColorstring'rgb(210,210,210)'Highlight color in HEX or RGB
highlightWidthnumber200The size of the highlight effect in DPI
durationnumber1500Duration of the animation in milliseconds
animatingbooleantrueStart or stop the animation
easing(value: number) => numberEasing.linearEasing function used by Animated.timing() to convey physically believable motion in animations. Read more at https://reactnative.dev/docs/easing
styleViewStyleStyles passed to the LinearGradient component

ShimmerLayout props

Inherits GradientShimmer props

NameTypeDescription
layoutShimmerLayoutContainerTypeLayout config tree

ShimmerLayoutContainerType

NameTypeDescription
flexDirection'row' | 'column' | 'row-reverse' | 'column-reverse' | undefinedFlexBox flexDirection
alignItemsFlexAlignTypeFlexBox alignItems
justifyContentFlexAlignTypeFlexBox justifyContent
gapnumberSet the gaps (gutters) between rows and columns
rowGapnumberSet the size of the gap (gutter) between an element's rows
columnGapnumberSet the size of the gap (gutter) between an element's columns
contentArray<ShimmerLayoutItemType \| ShimmerLayoutContainerType>Children content layout

ShimmerLayoutItemType

NameTypeDescription
widthnumberItem width in DPI
heightnumberItem height in DPI

Contribute

New features, bug fixes and improvements are welcome! For questions and suggestions use the issues.

Donate

Star History

Star History Chart

License

The MIT License (MIT)

Copyright (c) 2023 Douglas Nassif Roma Junior

See the full license file.

1.1.1

12 months ago

1.1.5

10 months ago

1.1.4

10 months ago

1.1.3

10 months ago

1.1.2

11 months ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago