DEV Community

Way Lau
Way Lau

Posted on

The application of SwiperAnimationMode introduced in HarmonyOS API 15

This article highlights the new event changeIndex(index: number, animationMode?: SwiperAnimationMode| boolean) added in API 15, which allows setting the animation mode when flipping to a specified page within a swiper component. The default value is SwiperAnimationMode.NO_ANIMATION. There are three types of animation modes available:

  • NO_ANIMATION: Flips to the specified page without any animation.
  • DEFAULT_ANIMATION: Flips to the specified page with an animation effect.
  • FAST_ANIMATION: Quickly flips to a nearby page without animation, then animates to the final target page.

The example provided demonstrates triggering these effects through three buttons. Each button click invokes the changeIndex method with different parameters to switch pages using one of the above animation modes. Specifically:

  • Clicking 'NO_ANIMATION 0' will change the index to 0 without any animation.
  • Clicking 'DEFAULT_ANIMATION 10' will animate the transition to index 10.
  • Clicking 'FAST_ANIMATION 20' first rapidly moves near the target page and then animates to index 20.

These examples show how to apply different animation effects when navigating between pages in a swiper component. The source code for this example can be found in the "Learning HarmonyOS Development with Old Wei" project on GitHub: https://github.com/waylau/harmonyos-tutorial.

Image description

Image description

Image description

Enterprise-level in-app dashboards. Startup-level speed.

Enterprise-level in-app dashboards. Startup-level speed.

Ship pixel-perfect dashboards that feel native to your app with Embeddable. It's fast, flexible, and built for devs.

Get early access

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

Discover fresh viewpoints in this insightful post, supported by our vibrant DEV Community. Every developer’s experience matters—add your thoughts and help us grow together.

A simple “thank you” can uplift the author and spark new discussions—leave yours below!

On DEV, knowledge-sharing connects us and drives innovation. Found this useful? A quick note of appreciation makes a real impact.

Okay