npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-momentum-carousel

v2.0.0

Published

A React Native carousel component enables smooth and interactive image or content sliders with swiping capabilities. Ideal for showcasing multiple items or images in a compact space, this carousel can be customized with features like infinite scrolling, p

Readme

CarouselMomentum

A customizable, animated, horizontal carousel component for React Native. The CarouselMomentum component enables smooth, momentum-based scrolling with features such as autoplay, looping, animated item scaling, and pagination. It is built using Animated.FlatList from react-native-reanimated to provide smooth transitions during item scroll.

Features

  • Momentum Scroll: Smooth transitions with momentum-based scrolling.
  • Autoplay: Automatically scrolls through the items at a specified interval.
  • Looping: Option to loop the carousel after reaching the last item.
  • Scaling Effect: Inactive items scale down as they move away from the center of the carousel.
  • Snapping: Items snap to position when scrolling stops.
  • Customizable: Easily configurable with props like sliderWidth, itemWidth, onSnap, etc.
  • Pagination: Optional pagination indicators for improved navigation.
  • Animations: Choose from different animation styles for transitions.

Installation

To use the CarouselMomentum component, you can install it through npm or yarn.

npm install react-native-momentum-carousel

or

yarn add react-native-momentum-carousel

Breaking Dependency from version 1.0.0

This library needs these dependencies to be installed in your project before you can use it:

npm install react-native-reanimated 

or

yarn add react-native-reanimated 

For more info on configuration: https://docs.swmansion.com/react-native-reanimated/

Example Usage

1. Basic Usage:

import React, { useState } from 'react';
import { View, Text, Image } from 'react-native';
import CarouselMomentum from 'react-native-momentum-carousel';

const App = () => {
  const [currentIndex, setCurrentIndex] = useState(0);

  const data = [
    { id: '1', title: 'Item 1', imageUrl: 'https://example.com/image1.jpg' },
    { id: '2', title: 'Item 2', imageUrl: 'https://example.com/image2.jpg' },
    { id: '3', title: 'Item 3', imageUrl: 'https://example.com/image3.jpg' },
  ];

  const renderItem = ({ item }) => (
    <View style={{ justifyContent: 'center', alignItems: 'center' }}>
      <Image source={{ uri: item.imageUrl }} style={{ width: 200, height: 200 }} />
      <Text>{item.title}</Text>
    </View>
  );

  const onSnap = (index: number) => {
    setCurrentIndex(index);
  };

  return (
    <View style={{ flex: 1 }}>
      <CarouselMomentum
        data={data}
        sliderWidth={300}
        itemWidth={200}
        renderItem={renderItem}
        onSnap={onSnap}
        autoPlay={true}
        autoPlayInterval={3000}
        loop={true}
        inactiveScale={0.8}
        showPagination={true}
      />
      <Text style={{ textAlign: 'center', marginTop: 20 }}>Current Index: {currentIndex}</Text>
    </View>
  );
};

export default App;

2. Customizing the Carousel

<CarouselMomentum
  data={data}
  sliderWidth={300}
  itemWidth={200}
  renderItem={renderItem}
  keyExtractor={(item) => item.id}
  onSnap={(index) => console.log('Snapped to item:', index)}
  autoPlay={true}
  autoPlayInterval={5000}
  loop={true}
  inactiveScale={0.7}
  showPagination={true}
  paginationStyle={{ container: {}, bullet: {}, activeBullet: {} }}
  animation={'Stack'}
  customAnimation={false}
/>

Props

Required Props:

  • data: Array of items to display in the carousel. Each item should have a unique id or key.
  • sliderWidth: The width of the carousel container.
  • itemWidth: The width of each individual item.
  • renderItem: Function to render each item. Receives an object with item and index properties.
  • onSnap: Callback function triggered when an item is snapped to the center.

Optional Props:

  • keyExtractor: Function to extract a unique key for each item. Defaults to using the index if not provided.
  • accessibilityLabelCarousel: Optional string for the carousel's accessibility label.
  • onMomentumScrollStart: Callback triggered when momentum scrolling starts.
  • onMomentumScrollEnd: Callback triggered when momentum scrolling ends.
  • autoPlay: If true, the carousel will automatically scroll through the items.
  • loop: If true, the carousel will loop back to the first item after reaching the end.
  • autoPlayInterval: Time interval (in ms) for auto-play. Defaults to 3000ms.
  • inactiveScale: Scale value for inactive items. Defaults to 0.8.
  • showPagination: Boolean to show pagination indicators.
  • paginationStyle: Style object for customizing pagination appearance.
  • animation: Enum defining the animation type (Default, Stack, Tinder).
  • customAnimation: Boolean to enable custom animations.

Methods

When using the CarouselMomentum component with a ref, you can access the following imperative methods:

  • getCurrentIndex(): Returns the current index of the carousel.
  • goToIndex(index: number): Scrolls the carousel to the specified index.

Example of Using Imperative Methods:

import React, { useRef } from 'react';
import { Button, View } from 'react-native';
import CarouselMomentum from 'react-native-momentum-carousel';

const App = () => {
  const carouselRef = useRef();

  const goToFirstItem = () => {
    carouselRef.current?.goToIndex(0);
  };

  return (
    <View style={{ flex: 1 }}>
      <CarouselMomentum
        ref={carouselRef}
        data={data}
        sliderWidth={300}
        itemWidth={200}
        renderItem={renderItem}
        onSnap={(index) => console.log('Snapped to item:', index)}
      />
      <Button title="Go to First Item" onPress={goToFirstItem} />
    </View>
  );
};

export default App;

🖼️ Demo

Here’s a quick demo of how the component works:

Demo GIF

Notes

  • To provide right behaviour for the Accessibility on snapping, you need to configure the full width/height. It means that the slider and item has to be the same size.

Contributing

We welcome contributions! Feel free to open issues or submit pull requests.

License

This component is open source and released under the MIT License.