Install react-native-shimmer
masterFor modern React Native versions, install the package using yarn and then install the iOS dependencies using CocoaPods:
yarn add react-native-shimmer
cd ios && pod installrepository·master·Indexed 20 days ago
https://github.com/oblador/react-native-shimmerA React Native library that provides a simple shimmering effect for applications, based on Facebook's Shimmer implementations for iOS and Android. It allows developers to wrap a single child component with the Shimmer component to create skeleton screens, with customizable properties for animation direction, duration, opacity, and platform-specific settings for iOS and Android.
For modern React Native versions, install the package using yarn and then install the iOS dependencies using CocoaPods:
yarn add react-native-shimmer
cd ios && pod installFor manual Android installation on older React Native versions:
android/settings.gradle:rootProject.name = 'MyApp'
include ':app'
include ':react-native-shimmer'
project(':react-native-shimmer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-shimmer/android')android/app/build.gradle:
Add the project to your dependencies:dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+"
compile project(':react-native-shimmer')
}MainApplication.java:
Import the package and add it to the list of React packages:import com.oblador.shimmer.RNShimmerPackage;
// ... inside getPackages()
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNShimmerPackage()
);
}import com.oblador.shimmer.RNShimmerPackage;
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNShimmerPackage()
);
}If you are using an older version of React Native (<= 0.59), follow these steps:
Add the following to your Podfile and run pod update:
pod 'react-native-shimmer', :path => 'node_modules/react-native-shimmer'Run the following command:
$ react-native link react-native-shimmerios/RNShimmer.xcodeproj to Libraries.libRNShimmer.a to Link Binary With Libraries under Build Phases.Wrap a single child component with <Shimmer> to apply the shimmering effect.
Note: The Shimmer component may only have one child.
import Shimmer from 'react-native-shimmer';
<Shimmer>
<Text>Loading...</Text>
</Shimmer>;The metro.config.js file defines how the Metro bundler transforms files. In this project's example configuration, the transformer.getTransformOptions function is used to set specific transformation behaviors:
experimentalImportSupport: Set to false.inlineRequires: Set to true, which enables inline requires to improve startup performance by delaying the execution of modules until they are actually needed.module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
};The Shimmer component accepts the following props:
| Prop | Description | Default |
|---|---|---|
animating | Whether or not to show shimmering effect. | true |
direction | The direction of shimmering animation (up, down, left, right). | right |
duration | The shimmering animation duration in milliseconds. | 1000 |
pauseDuration | The time interval between shimmerings in milliseconds. | 400 |
animationOpacity | The opacity of the content while it is shimmering. | 1 |
opacity | The opacity of the content before it is shimmering. | 0.5 |
highlightLength | The highlight length of shimmering (Range 0–1). iOS only | 1 |
beginFadeDuration | The duration of the fade used when shimmer begins. iOS only | 0 |
endFadeDuration | The duration of the fade used when shimmer ends. iOS only | 0 |
tilt | The tilt angle of the highlight, in degrees. Android only | 0 |
intensity | The intensity of the highlight mask (Range 0–1). Android only | 0 |
The Shimmer component provides a shimmering animation effect used for skeleton screens in React Native. It wraps a native component RNShimmeringView. You can control the animation direction, opacity, speed, and visual intensity via props.
import Shimmer from 'react-native-shimmer';
// Basic usage
<Shimmer style={{ width: 200, height: 20 }} />
// Advanced usage with custom properties
<Shimmer
style={{ width: 200, height: 20 }}
animating={true}
direction="left"
duration={1500}
opacity={0.6}
tilt={15}
/>The Shimmer component accepts the following props to customize the animation effect:
{
animating: boolean (default: true),
direction: 'up' | 'down' | 'left' | 'right' (default: undefined),
duration: number (default: 1000),
pauseDuration: number (default: 400),
animationOpacity: number (default: 1),
opacity: number (default: 0.5),
tilt: number (default: 0),
intensity: number,
highlightLength: number,
beginFadeDuration: number (default: 0),
endFadeDuration: number (default: 0),
}