DEV Community

Cover image for Rotate/Pusle Animation in React Native
Saumay Paul
Saumay Paul

Posted on

Rotate/Pusle Animation in React Native

Rotate/Pusle Animation in React Native

I implemented a continuous rotation and pulsing animation for an image using React Native's Animated API. This small gist demonstrates how to create smooth, looping animations that can enhance the visual appeal of mobile applications.

Project Overview

In this project, an image is animated to rotate continuously and pulse (scale up and down) simultaneously. Here’s a breakdown of how I achieved this:

Code Explanation

  1. Setting Up the Animated Values:

    • rotateValue: Controls the rotation of the image.
    • pulseValue: Controls the pulsing effect (scaling) of the image.
  2. Starting the Animations:

    • Rotation Animation:
      • Wrapped in Animated.loop to ensure it repeats indefinitely.
      • Uses Animated.sequence to create a smooth rotation effect.
      • Animated.timing changes rotateValue from 0 to 1 over 4000 milliseconds and from 1 to 2 over another 4000 milliseconds, creating a full rotation every 8000 milliseconds.
      • The Easing.linear function ensures a consistent rotation speed.
  • Pulse Animation:
    • Also wrapped in Animated.loop to repeat indefinitely.
    • Uses Animated.sequence with two Animated.timing calls to scale the image up to 1.5x its size and back down to its original size over 2000 milliseconds (1000 ms for scaling up and 1000 ms for scaling down).
  1. Combining Transformations:
    • Applied to an Animated.View containing the image.
    • Transformations include translateX, translateY (for spiral effect), rotate, and scale.

Code Snippet

You can view the full code on GitHub Gist: LINK

You can view the demo on Expo Snack: LINK

Conclusion

This project showcases how powerful and flexible the Animated API in React Native can be for creating engaging user interfaces. Animations like these can significantly improve user experience by adding a layer of interactivity and visual feedback.

Feel free to check out the code, and I'd love to hear your thoughts and feedback! 🌟


Top comments (0)