Swiper/carousel component for React Native with previews, multiple layouts, parallax images, performant handling of huge numbers of items, and more. Compatible with Android & iOS.
npm install react-native-snap-carousel!platforms





-----
-----
-----
-----
1. Showcase
1. Usage
1. Example
1. Props, methods and getters
1. Layouts and custom interpolations
1. ParallaxImage component
1. Pagination component
1. Tips and tricks
1. Known issues
1. Important note regarding Android
1. Important note regarding iOS
1. Roadmap
1. Credits
!react-native-snap-carousel default layout
!react-native-snap-carousel tinder layout
!react-native-snap-carousel stack layout
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
---
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.
We're not abandoning the ship, but we need more people to help us keep it alive and well!
---
``bash`
$ npm install --save react-native-snap-carousel
If you're using Typescript you should also install type definitions:
`bash`
$ npm install --save @types/react-native-snap-carousel
`javascript
import Carousel from 'react-native-snap-carousel';
export class MyCarousel extends Component {
_renderItem = ({item, index}) => {
return (
);
}
render () {
return (
data={this.state.entries}
renderItem={this._renderItem}
sliderWidth={sliderWidth}
itemWidth={itemWidth}
/>
);
}
}
`
Here are simple examples that can be edited in real time in your browser:
- https://snack.expo.io/@vitkor/carousel-simple-example
- https://snack.expo.io/@bd-arc/react-native-snap-carousel-%7C-example-with-custom-interpolations
You can also find a more in-depth (read "complex") one in the /example folder.
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.
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
`javascript`
!react-native-snap-carousel stack layout ios
!react-native-snap-carousel stack layout android
`javascript} />`
!react-native-snap-carousel tinder layout ios
!react-native-snap-carousel tinder layout android
`javascript} />`
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.
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.
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
componentVersion 3.0.0 introduced a 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).
!react-native-snap-carousel parallax image
componentStarting with version 2.4.0, a customizable component has been added. You can see below how it looks like with its default configuration.
!react-native-snap-carousel pagination
We've gathered together all the useful tips and tricks. There is a bunch of them, which makes this section a must-read!
Make sure to read about the known issues before opening a new one; you may find something useful.
!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".
!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.
- [ ] Add more examples
- [ ] Base the plugin on a component less buggy than FlatListFlatList
- [X] Implement different layouts and allow using custom interpolations
- [X] Implement both and ScrollView handlingFlatList
- [X] Add the ability to provide custom items animation
- [X] Implement 'loop' mode
- [X] Improve Android's behavior
- [x] Add parallax image component
- [x] Base the plugin on instead of ScrollView`
- [x] Add alignment option
- [x] Add pagination component
- [x] Add vertical implementation
- [x] Handle device orientation event (see this note)
- [x] Add RTL support
- [x] Improve momemtum handling
- [x] Improve snap on Android
- [x] Handle passing 1 item only
- [x] Fix centering
Written by Benoît Delmaire (bd-arc) and Maxime Bertonnier (Exilz) at
Archriss.