react-native-snap-carousel
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/react-native-snap-carousel package

3.9.1 • Public • Published

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

🙌 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 archriss aix react-native-snap-carousel archriss aix

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


🤝 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.

📚 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/
  • ⚠️ 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.

📚 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).

📚 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.

📚 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!

📚 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.

📚 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.

⚠️ 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

⚠️ 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 Archriss.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.9.183,315latest
4.0.0-beta.625,261beta

Version History

VersionDownloads (Last 7 Days)Published
4.0.0-beta.625,261
4.0.0-beta.5202
3.9.183,315
4.0.0-beta.4109
4.0.0-beta.31
4.0.0-beta.21
4.0.0-beta.11
3.9.0119
3.8.4373
3.8.31
3.8.211
3.8.19
3.8.0195
3.7.51,554
3.7.410
3.7.3282
3.7.245
3.7.10
3.7.086
3.6.04
3.5.03
3.4.00
3.3.40
3.3.31
3.3.20
3.3.10
3.3.00
3.2.30
3.2.20
3.2.10
3.2.00
3.1.00
2.4.00
2.3.10
2.3.01
2.2.20
2.2.10
2.2.00
2.1.40
2.1.30
2.1.20
2.1.10
2.1.00
2.0.30
2.0.20
2.0.11
2.0.00
1.6.11,266
1.6.00
1.5.03
1.4.00
1.3.1734
1.3.00
1.2.10
1.2.00
1.1.00
1.0.00

Package Sidebar

Install

npm i react-native-snap-carousel

Weekly Downloads

113,589

Version

3.9.1

License

BSD-3-Clause

Unpacked Size

191 kB

Total Files

23

Last publish

Collaborators

  • bd-arc
  • exilz