DEV Community

Cover image for Adding a Shimmer Effect in React Native
Amit Kumar
Amit Kumar

Posted on

5 1 1 1 1

Adding a Shimmer Effect in React Native

In my previous article, I discussed implementing a pull-to-refresh feature in a React Native app using Reanimated and Lottie. Now, let's take it a step further and enhance the UI by integrating a shimmer effect while the data is loading.



Why Use a Shimmer Effect?

A shimmer effect, also known as a skeleton loader, improves user experience by displaying a placeholder while the actual content is being fetched. It provides a smooth transition between loading and displaying real data, making the app feel more responsive.


Integrating react-native-skeleton-placeholder

We will use the react-native-skeleton-placeholder package to create a shimmer effect. First, install the package using:

npm install react-native-skeleton-placeholder
Enter fullscreen mode Exit fullscreen mode

Implementing the Skeleton Loader

Below is the function that renders the skeleton loader while the data is being fetched:

import SkeletonPlaceholder from 'react-native-skeleton-placeholder';
import { View, StyleSheet } from 'react-native';

const renderSkeletonView = () => {
  return (
    <View style={styles.skeletonContainer}>
      {[1, 2, 3, 4, 5, 6].map((_, index) => (
        <SkeletonPlaceholder key={index} backgroundColor="#333">
          <SkeletonPlaceholder.Item
            flexDirection="column"
            alignItems="center"
            style={{ marginBottom: 20 }}>
            <SkeletonPlaceholder.Item
              width={160}
              height={240}
              borderRadius={8}
            />
            <SkeletonPlaceholder.Item
              width={120}
              height={20}
              marginTop={15}
            />
            <SkeletonPlaceholder.Item
              width={90}
              height={15}
              marginTop={10}
            />
          </SkeletonPlaceholder.Item>
        </SkeletonPlaceholder>
      ))}
    </View>
  );
};

const styles = StyleSheet.create({
  skeletonContainer: {
    flexDirection: 'row',
    flexWrap: 'wrap',
    justifyContent: 'space-between',
    paddingHorizontal: 10,
  },
});
Enter fullscreen mode Exit fullscreen mode

Integrating Skeleton Loader into FlatList

Now, let’s integrate this skeleton loader into our main component. When isLoaderActive is true, the shimmer effect will be displayed. Otherwise, the data list will be shown.

import Animated from 'react-native-reanimated';

const [isLoaderActive, setIsLoaderActive] = useState(false);

  const onRefresh = useCallback(done => {
    setIsLoaderActive(true);
    setTimeout(() => {
      setIsLoaderActive(false);
      isReadyToRefresh.value = false;
      done();
    }, 3000);
  }, []);

{isLoaderActive ? (
  renderSkeletonView()
) : (
  <Animated.FlatList
    data={data}
    scrollEventThrottle={16}
    bounces={false}
    renderItem={renderItem}
    key={2}
    numColumns={2}
    keyExtractor={(_, index) => index.toString()}
    ItemSeparatorComponent={() => <View style={{ height: 20 }} />}
  />
)}
Enter fullscreen mode Exit fullscreen mode

Final Thoughts

Adding a shimmer effect significantly improves the user experience by making the UI feel more interactive and polished. This simple yet effective implementation enhances perceived performance and keeps users engaged while the data loads.

Feel free to experiment with different skeleton structures to match your app's UI design. Happy coding!

Sonar image

Explore the coding personalities of leading LLMs

Understanding the unique coding "personality" of each LLM—where it excels and where it's likely to make mistakes—is key to generating code safely and securely. Check out this deep-dive study on GPT-4o, Claude, Llama, and more to see how you can use AI responsibly in your dev workflow.

Learn more

Top comments (0)

Heroku

Build AI apps faster with Heroku.

Heroku makes it easy to build with AI, without the complexity of managing your own AI services. Access leading AI models and build faster with Managed Inference and Agents, and extend your AI with MCP.

Get Started

👋 Kindness is contagious

Explore this practical breakdown on DEV’s open platform, where developers from every background come together to push boundaries. No matter your experience, your viewpoint enriches the conversation.

Dropping a simple “thank you” or question in the comments goes a long way in supporting authors—your feedback helps ideas evolve.

At DEV, shared discovery drives progress and builds lasting bonds. If this post resonated, a quick nod of appreciation can make all the difference.

Okay