Convert Figma logo to code with AI

meliorence logoreact-native-snap-carousel

Swiper/carousel component for React Native featuring previews, multiple layouts, parallax images, performant handling of huge numbers of items, and more. Compatible with Android & iOS.

10,344
2,286
10,344
391

Top Related Projects

The best Swiper component for React Native.

Swiper/carousel component for React Native featuring previews, multiple layouts, parallax images, performant handling of huge numbers of items, and more. Compatible with Android & iOS.

React Native wrapper for the Android ViewPager and iOS UIPageViewController.

🎠 React Native swiper/carousel component, fully implemented using reanimated v2, support to iOS/Android/Web. (Swiper/Carousel)

react-native-app-intro is a react native component implementing a parallax effect welcome page using base on react-native-swiper , similar to the one found in Google's app like Sheet, Drive, Docs...

Quick Overview

React Native Snap Carousel is a swiper/carousel component for React Native with previews, multiple layouts, parallax images, performant handling of huge numbers of items, and RTL support. It's highly customizable and feature-rich, making it suitable for various mobile app scenarios.

Pros

  • Highly customizable with numerous props and options
  • Supports multiple layouts (default, stack, tinder)
  • Performant even with a large number of items
  • Built-in parallax image component

Cons

  • No longer actively maintained (last update in 2021)
  • Some reported issues with TypeScript definitions
  • May require additional setup for certain advanced features
  • Limited documentation for some complex use cases

Code Examples

  1. Basic usage:
import Carousel from 'react-native-snap-carousel';

const MyCarousel = () => {
  const renderItem = ({ item }) => (
    <View>
      <Text>{item.title}</Text>
    </View>
  );

  return (
    <Carousel
      data={data}
      renderItem={renderItem}
      sliderWidth={350}
      itemWidth={300}
    />
  );
};
  1. Using parallax image:
import { ParallaxImage } from 'react-native-snap-carousel';

const MyParallaxCarousel = () => {
  const renderItem = ({ item }, parallaxProps) => (
    <View>
      <ParallaxImage
        source={{ uri: item.thumbnail }}
        containerStyle={styles.imageContainer}
        style={styles.image}
        parallaxFactor={0.4}
        {...parallaxProps}
      />
      <Text>{item.title}</Text>
    </View>
  );

  return (
    <Carousel
      data={data}
      renderItem={renderItem}
      sliderWidth={350}
      itemWidth={300}
      hasParallaxImages={true}
    />
  );
};
  1. Custom animation:
import { Animated } from 'react-native';

const MyAnimatedCarousel = () => {
  const renderItem = ({ item, index }, parallaxProps) => {
    const translateY = new Animated.Value(50);

    return (
      <Animated.View
        style={{ transform: [{ translateY }] }}
      >
        <Text>{item.title}</Text>
      </Animated.View>
    );
  };

  return (
    <Carousel
      data={data}
      renderItem={renderItem}
      sliderWidth={350}
      itemWidth={300}
      onSnapToItem={(index) => {
        // Custom animation logic here
      }}
    />
  );
};

Getting Started

  1. Install the package:

    npm install react-native-snap-carousel
    
  2. Import and use in your React Native component:

    import Carousel from 'react-native-snap-carousel';
    
    const MyComponent = () => {
      const data = [/* your carousel items */];
      const renderItem = ({ item }) => (
        <View>
          <Text>{item.title}</Text>
        </View>
      );
    
      return (
        <Carousel
          data={data}
          renderItem={renderItem}
          sliderWidth={350}
          itemWidth={300}
        />
      );
    };
    
  3. Customize as needed using the available props and options.

Competitor Comparisons

The best Swiper component for React Native.

Pros of react-native-swiper

  • Simpler API and easier to set up for basic swiping functionality
  • Smaller package size, potentially leading to better performance
  • Supports both horizontal and vertical swiping out of the box

Cons of react-native-swiper

  • Less customizable compared to react-native-snap-carousel
  • Fewer built-in animation options and effects
  • Less active maintenance and updates in recent years

Code Comparison

react-native-swiper:

<Swiper>
  <View style={styles.slide1}><Text>Slide 1</Text></View>
  <View style={styles.slide2}><Text>Slide 2</Text></View>
  <View style={styles.slide3}><Text>Slide 3</Text></View>
</Swiper>

react-native-snap-carousel:

<Carousel
  data={entries}
  renderItem={({item}) => <View><Text>{item.title}</Text></View>}
  sliderWidth={sliderWidth}
  itemWidth={itemWidth}
/>

The code comparison shows that react-native-swiper has a more straightforward implementation for basic slides, while react-native-snap-carousel requires more configuration but offers greater flexibility in terms of data handling and item rendering.

Swiper/carousel component for React Native featuring previews, multiple layouts, parallax images, performant handling of huge numbers of items, and more. Compatible with Android & iOS.

Pros of react-native-snap-carousel

  • Well-established and widely used in the React Native community
  • Extensive documentation and examples available
  • Supports both horizontal and vertical carousels

Cons of react-native-snap-carousel

  • No longer actively maintained (last commit in 2021)
  • May have compatibility issues with newer React Native versions
  • Limited built-in animation options

Code Comparison

Both repositories contain the same codebase, as they are the same project. Here's a sample of how to use react-native-snap-carousel:

import Carousel from 'react-native-snap-carousel';

<Carousel
  data={items}
  renderItem={renderItem}
  sliderWidth={sliderWidth}
  itemWidth={itemWidth}
/>

Summary

react-native-snap-carousel is a popular and feature-rich carousel component for React Native. However, it's important to note that both repositories point to the same project, which is no longer actively maintained. Users should consider alternative, actively maintained carousel libraries for newer React Native projects to ensure compatibility and ongoing support.

React Native wrapper for the Android ViewPager and iOS UIPageViewController.

Pros of react-native-pager-view

  • Native implementation for better performance and smoother animations
  • Supports both horizontal and vertical paging
  • Integrates well with React Native's gesture system

Cons of react-native-pager-view

  • Less customization options for carousel-like behavior
  • Requires more setup for advanced features like looping or auto-play
  • Limited built-in styling options compared to snap-carousel

Code Comparison

react-native-pager-view:

import PagerView from 'react-native-pager-view';

<PagerView style={styles.pagerView} initialPage={0}>
  <View key="1"><Text>First page</Text></View>
  <View key="2"><Text>Second page</Text></View>
</PagerView>

react-native-snap-carousel:

import Carousel from 'react-native-snap-carousel';

<Carousel
  data={entries}
  renderItem={({item}) => <Text>{item.title}</Text>}
  sliderWidth={sliderWidth}
  itemWidth={itemWidth}
/>

react-native-pager-view offers a more native-feeling paging experience with better performance, especially for simple paging needs. It's ideal for apps that require basic swiping between full-screen views. However, react-native-snap-carousel provides more out-of-the-box features for creating customized carousel experiences, including auto-play, looping, and various animation options. The choice between the two depends on the specific requirements of your project, with pager-view being better for performance-critical applications and snap-carousel for feature-rich, highly customized carousels.

🎠 React Native swiper/carousel component, fully implemented using reanimated v2, support to iOS/Android/Web. (Swiper/Carousel)

Pros of react-native-reanimated-carousel

  • Built on React Native Reanimated, offering smoother animations and better performance
  • More customizable with advanced animation options and parallax effects
  • Actively maintained with frequent updates and bug fixes

Cons of react-native-reanimated-carousel

  • Steeper learning curve due to Reanimated API complexity
  • Larger bundle size because of Reanimated dependency
  • May require additional setup and configuration

Code Comparison

react-native-snap-carousel:

<Carousel
  data={items}
  renderItem={renderItem}
  sliderWidth={sliderWidth}
  itemWidth={itemWidth}
/>

react-native-reanimated-carousel:

<Carousel
  width={width}
  height={height}
  data={items}
  renderItem={renderItem}
  mode="parallax"
/>

Both libraries offer similar basic usage, but react-native-reanimated-carousel provides more advanced options for customization and animation modes. The main difference lies in the underlying animation engine and the available props for fine-tuning the carousel behavior.

While react-native-snap-carousel is easier to set up and use, react-native-reanimated-carousel offers more powerful animation capabilities at the cost of increased complexity. The choice between the two depends on the specific project requirements and the desired level of customization and performance.

react-native-app-intro is a react native component implementing a parallax effect welcome page using base on react-native-swiper , similar to the one found in Google's app like Sheet, Drive, Docs...

Pros of react-native-app-intro

  • Specifically designed for app introductions and onboarding experiences
  • Simpler API for creating intro slides
  • Includes built-in pagination and skip/done buttons

Cons of react-native-app-intro

  • Less flexible for general-purpose carousel use cases
  • Limited customization options compared to react-native-snap-carousel
  • Less actively maintained (last update was several years ago)

Code Comparison

react-native-app-intro:

<AppIntro>
  <View style={[styles.slide,{ backgroundColor: '#fa931d' }]}>
    <Text>Page 1</Text>
  </View>
  <View style={[styles.slide,{ backgroundColor: '#a4b602' }]}>
    <Text>Page 2</Text>
  </View>
</AppIntro>

react-native-snap-carousel:

<Carousel
  data={entries}
  renderItem={({item, index}) => <MySlideComponent data={item} />}
  sliderWidth={sliderWidth}
  itemWidth={itemWidth}
/>

react-native-app-intro provides a more straightforward approach for creating intro slides, while react-native-snap-carousel offers greater flexibility and customization options for various carousel use cases. The code comparison shows that react-native-app-intro uses a simpler structure with predefined slide components, whereas react-native-snap-carousel requires more setup but allows for more dynamic content rendering.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

react-native-snap-carousel

platforms npm npm

github issues github closed issues Issue Stats



✨ Some great news for you, fellow plugin user!

💡 Head over there now to learn more about all the goodness that's coming your way.



Table of contents

  1. Showcase
  2. Usage
  3. Example
  4. Props, methods and getters
  5. Layouts and custom interpolations
  6. ParallaxImage component
  7. Pagination component
  8. Tips and tricks
  9. Known issues
  10. Important note regarding Android
  11. Important note regarding iOS
  12. Roadmap
  13. Credits

Showcase

:raised_hands: New feature: layouts

Do you want to find out more?

react-native-snap-carousel default layout react-native-snap-carousel tinder layout react-native-snap-carousel stack layout

Real-world examples

These are live apps we've created that make heavy use of the plugin. Don't be shy, share yours if you've done something awesome with it!

react-native-snap-carousel aix react-native-snap-carousel aix

react-native-snap-carousel react-native-snap-carousel react-native-snap-carousel


:handshake: Maintainers wanted

Hey there,

Creating and maintaining this plugin has been a fun ride that started in 2016. We thank you all for your appreciation and for making the most out of it! You've motivated us to spend countless hours improving the plugin, and made us happy to give back to the Open Source community.

Put simply, we love this project. However we currently aren't able to give it the love it deserves and the care it requires. If you have enough time and knowledge, and want to become a maintainer, please let us know.

💡 Just head there if you're interested.

We're not abandoning the ship, but we need more people to help us keep it alive and well!


Usage

$ npm install --save react-native-snap-carousel

If you're using Typescript you should also install type definitions:

$ npm install --save @types/react-native-snap-carousel
import Carousel from 'react-native-snap-carousel';

export class MyCarousel extends Component {

    _renderItem = ({item, index}) => {
        return (
            <View style={styles.slide}>
                <Text style={styles.title}>{ item.title }</Text>
            </View>
        );
    }

    render () {
        return (
            <Carousel
              ref={(c) => { this._carousel = c; }}
              data={this.state.entries}
              renderItem={this._renderItem}
              sliderWidth={sliderWidth}
              itemWidth={itemWidth}
            />
        );
    }
}

Example

Here are simple examples that can be edited in real time in your browser:

You can also find a more in-depth (read "complex") one in the /example folder.

react-native-snap-carousel

Props, methods and getters

In order to let you to create mighty carousels and to keep up with your requests, we add new features on a regular basis. Consequently, the list of available props has become really huge and deserves a documentation of its own.

:books: Documentation for "Props, methods and getters"

Layouts and custom interpolations

Built-in layouts

In version 3.6.0, we've added two new layouts on top of the original one: the first one is called 'stack' since it mimics a stack of cards, and the other one is called 'tinder' since it provides a Tinder-like animation.

You can choose between the three of them using the new prop layout and you can modify the default card offset in the 'stack' and 'tinder' layouts with prop layoutCardOffset.

react-native-snap-carousel default layout

<Carousel layout={'default'} />

react-native-snap-carousel stack layout ios react-native-snap-carousel stack layout android

<Carousel layout={'stack'} layoutCardOffset={`18`} />

react-native-snap-carousel tinder layout ios react-native-snap-carousel tinder layout android

<Carousel layout={'tinder'} layoutCardOffset={`9`} />

A few things worth noting:

  • As you can see, the effect had to be inverted on Android. This has to do with a really annoying Android-specific bug.
  • Even though the new layouts have been created with horizontal carousels in mind, they will also work with vertical ones \o/
  • :warning: You should NOT use stack or tinder layouts if you have a large data set to display. In order to avoid rendering issues, the carousel will use a ScrollView component rather than a FlatList one for those layouts (see prop useScrollView). The tradeof is that you won't benefit from any of FlatList's advanced optimizations. See this issue for workarounds; or you may want to implement your own custom interpolation.

Custom interpolations

On top of the new layouts, we've exposed the logic we used so that users can create their own awesome layouts! If you're interested, take a deep breath and dive into the dedicated documentation.

:books: Documentation for "Custom interpolations"

Here are a few examples of what can easily be achieved (you can explore the source code and try it live in the provided example):

react-native-snap-carousel custom layout react-native-snap-carousel custom layout react-native-snap-carousel custom layout

ParallaxImage component

Version 3.0.0 introduced a <ParallaxImage /> component, an image component aware of carousel's current scroll position and therefore able to display a nice parallax effect (powered by the native driver to ensure top-notch performance).

:books: Documentation for "ParallaxImage component"

react-native-snap-carousel parallax image

Pagination component

Starting with version 2.4.0, a customizable <Pagination /> component has been added. You can see below how it looks like with its default configuration.

:books: Documentation for "Pagination component"

react-native-snap-carousel pagination

Tips and tricks

We've gathered together all the useful tips and tricks. There is a bunch of them, which makes this section a must-read!

:books: Documentation for "Tips and tricks"

Known issues

Make sure to read about the known issues before opening a new one; you may find something useful.

:books: Documentation for "Known issues"

Important note regarding Android

react-native-snap-carousel android

Android's debug mode is a mess: timeouts regularly desynchronize and scroll events are fired with some lag, which completely alters the inner logic of the carousel. On Android, you will experience issues with carousel's behavior when JS Dev Mode is enabled, and you might have trouble with unreliable callbacks and loop mode when it isn't. This is unfortunate, but it's rooted in various flaws of ScrollView/FlatList's implementation and the miscellaneous workarounds we had to implement to compensate for it.

:warning: Therefore you should always check if the issue you experience also happens in a production environment. This is, sadly, the only way to test the real performance and behavior of the carousel.

For more information, you can read the following notes: "Android performance" and "Unreliable callbacks".

Important note regarding iOS

react-native-snap-carousel ios

:warning: When debugging with the iOS simulator, you're only one "Cmd + T" away from toggling "Slow Animations". If carousel's animations seem painfully slow, make sure that you haven't enabled this setting by mistake.

Roadmap

  • Add more examples
  • Base the plugin on a component less buggy than FlatList
  • Implement different layouts and allow using custom interpolations
  • Implement both FlatList and ScrollView handling
  • Add the ability to provide custom items animation
  • Implement 'loop' mode
  • Improve Android's behavior
  • Add parallax image component
  • Base the plugin on FlatList instead of ScrollView
  • Add alignment option
  • Add pagination component
  • Add vertical implementation
  • Handle device orientation event (see this note)
  • Add RTL support
  • Improve momemtum handling
  • Improve snap on Android
  • Handle passing 1 item only
  • Fix centering

Credits

Written by Benoît Delmaire (bd-arc) and Maxime Bertonnier (Exilz) at Meliorence.

NPM DownloadsLast 30 Days