Swiper component for React Native featuring previews, multiple layouts, parallax images, performant handling of huge numbers of items, and RTL support. Compatible with Android & iOS.
✨ Do you want an even better plugin? Vote for React Native's feature requests to let the Facebook team know what they need to improve!
⚠️ Before submitting a new issue, make sure to read the guidelines and then to fill out the issue template!
- Showcase
- Usage
- Props, methods and getters
- Important note regarding Android
- Layouts and custom interpolations
ParallaxImage
componentPagination
component- Example
- Tips and tricks
- Known issues
- Roadmap
- Credits
This app is available on Android and iOS. It uses version 3.2.0 of the plugin, with FlatList
's implementation and parallax images.
You can try the app live on Android and iOS. It currently uses version 1.4.0 of the plugin. Be aware that sliders' layouts will break on RTL devices since support was added in version 2.1.0 (see #38).
Please note that we do not plan on Open-Sourcing the code of our showcase app. Still, we've put together an example for you to play with, and you can find some insight about our map implementation in this comment. The folks at codedaily.io have created a great tutorial about implementing a similar feature. Go check it out!
$ npm install --save 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}
/>
);
}
}
You can find the dedicated documentation here.
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.
For more information, you can read the following notes: "Android performance" and "Unreliable callbacks".
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
.
<Carousel layout={'default'} />
<Carousel layout={'stack'} layoutCardOffset={`18`} />
<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/
📖 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 see 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):
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.
You can find the documentation for this component here.
Starting with version 2.4.0
, a customizable <Pagination />
component has been added. This is how it looks like with its default configuration:
You can find the documentation for this component here.
You can find the following example in the /example
folder.
All the useful tips and tricks have been gathered here - 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.
- Add more examples
- Handle different items' width/height
- Implement different layouts and allow using custom interpolations
- Implement both
FlatList
andScrollView
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 ofScrollView
- 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
Written by Benoît Delmaire (bd-arc) and Maxime Bertonnier (Exilz) at Archriss.