Swiper component for React Native. Supersede react-native-swiper
npm install react-native-swiper2
!logo
Based on react-native-swiper, which was the best Swiper component for React Native.
However for some reason, react-native-swiper didn't update for long time, and can not run on recent react native versions.
So I forked this react-native-swiper2, and would maintain it as long as I could.
PRs or Issues are deeply welcomed.
- [v2.0.7]
+ correct onPageChange index.
- [v2.0.6]
+ support RN 0.25+. (@xirc).
- [v2.0.5]
+ add scrollTo for android. (@LeeChSien).
- [v2.0.4]
+ fix scrollTo warning.
- [v2.0.3]
+ support pagination on android.
- [v2.0.2]
+ add simple support for android.
- [v2.0.1]
+ fix the dimensions module error.
+ fix the keys warning when render dots.
- [v1.3.0]
+ 8d6d75c inject state in ScrollResponders (@thanks @smothers).
- [v1.2.2]
+ 890c0ce ensure onMomentumScrollEnd synchronous update index.
- [v1.2.0]
+ 838b24c Re-design a loop model for avoid img flickering.
+ 9cb91c5 fixes #7 onMomentumScrollEnd lost event param. (thanks @smothers)
- [v1.1.1]
+ 21f0b00 fixes #6 a define-propType error. (thanks @benjamingeorge)
- [v1.1.0]
+ 44ec630 fixes #4 onMoementumScrollEnd gets overridden. (thanks @subpublicanders)
+ 5de06a7 New prop: renderPagination. (thanks @aksonov)
- [v1.0.4]
+ 21cb373 fixes #2 Solve the problem of installation. (thanks @jamwaffles)
- [v1.0.3]
+ 0f796f3 fixes #1 Two 'horizontal' in propTypes. (thanks @MacyzZ)
> Try these cases by yourself very easy, Just open examples/swiper.xcodeproj with Xcode, then press Cmd + R; you may edit examples/index.ios.js for switch cases.




- Installation
- Basic Usage
- Properties
+ Basic
+ Custom basic style & content
+ Pagination
+ Autoplay
+ Control buttons
+ Props of Children
+ Basic props of
+ Supported ScrollResponder
- Examples
- Development
``bash`
$ npm i react-native-swiper2 --save
- Install react-native-cli first
`bash`
$ npm i react-native-cli -g
- Initialization of a react-native project
`bash`
$ react-native init myproject
- Then, edit myproject/index.ios.js, like this:
`jsx
var Swiper = require('react-native-swiper2')
// es6
// import Swiper from 'react-native-swiper2'
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
} = React;
var styles = StyleSheet.create({
wrapper: {
},
slide1: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#9DD6EB',
},
slide2: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#97CAE5',
},
slide3: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#92BBD9',
},
text: {
color: '#fff',
fontSize: 30,
fontWeight: 'bold',
}
})
var swiper = React.createClass({
render: function() {
return (
)
}
})
AppRegistry.registerComponent('swiper', () => swiper)
`
#### Basic
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| horizontal | true | bool | If true, the scroll view's children are arranged horizontally in a row instead of vertically in a column. |bool
| loop | true | | Set to true to enable continuous loop mode. |number
| index | 0 | | Index number of initial slide. |bool
| showsButtons | false | | Set to true make control buttons visible. |bool
| autoplay | false | | Set to true enable auto play mode. |
#### Custom basic style & content
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| width | - | number | If no specify default enable fullscreen mode by flex: 1. |number
| height | - | | If no specify default fullscreen mode by flex: 1. |style
| style | {...} | | See default style in source. |
#### Pagination
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| showsPagination | true | bool | Set to true make pagination visible. |style
| paginationStyle | {...} | | Custom styles will merge with the default styles. |function
| renderPagination | - | | Complete control how to render pagination with three params (index, total, context) ref to this.state.index / this.state.total / this, For example: show numbers instead of dots. |
| dot | | element | Allow custom the dot element. |
| activeDot | | element | Allow custom the active-dot element. |
#### Autoplay
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| autoplay | true | bool | Set to true enable auto play mode. |number
| autoplayTimeout | 2.5 | | Delay between auto play transitions (in second). |bool
| autoplayDirection | true | | Cycle direction control. |
#### Control buttons
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| showsButtons | true | bool | Set to true make control buttons visible. |{backgroundColor: 'transparent', flexDirection: 'row', position: 'absolute', top: 0, left: 0, flex: 1, paddingHorizontal: 10, paddingVertical: 10, justifyContent: 'space-between', alignItems: 'center'}
| buttonWrapperStyle | | style | Custom styles. |
| nextButton | | element | Allow custom the next button. |
| prevButton | | element | Allow custom the prev button. |
#### Props of Children
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| style | {...} | style | Custom styles will merge with the default styles. |element
| title | { | If this parameter is not specified, will not render the title. |
#### Basic props of
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| horizontal | true | bool | If true, the scroll view's children are arranged horizontally in a row instead of vertically in a column. |bool
| pagingEnabled | true | | If true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for horizontal pagination. |bool
| showsHorizontalScrollIndicator | false | | Set to true if you want to show horizontal scroll bar. |bool
| showsVerticalScrollIndicator | false | | Set to true if you want to show vertical scroll bar. |bool
| bounces | false | | If true, the scroll view bounces when it reaches the end of the content if the content is larger then the scroll view along the axis of the scroll direction. If false, it disables all bouncing even if the alwaysBounce* props are true. |bool
| scrollsToTop | false | | If true, the scroll view scrolls to top when the status bar is tapped. |bool
| removeClippedSubviews | true | | If true, offscreen child views (whose overflow value is hidden) are removed from their native backing superview when offscreen. This canimprove scrolling performance on long lists. |bool
| automaticallyAdjustContentInsets | false | | Set to true if you need adjust content insets automation. |
> @see: http://facebook.github.io/react-native/docs/scrollview.html
#### Supported ScrollResponder
| Prop | Params | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| onMomentumScrollBegin | e / state / context | function | When animation begins after letting up |e
| onMomentumScrollEnd | / state / context | function | Makes no sense why this occurs first during bounce |e
| onTouchStartCapture | / state / context | function | Immediately after onMomentumScrollEnd |e
| onTouchStart | / state / context | function | Same, but bubble phase |e
| onTouchEnd | / state / context | function | You could hold the touch start for a long time |e
| onResponderRelease | / state / context | function | When lifting up - you could pause forever before * lifting |
> Note: each ScrollResponder be injected with two params: state and context, you can get state and context(ref to swiper's this) from params, for example:
`jsx`
var swiper = React.createClass({
_onMomentumScrollEnd: function (e, state, context) {
console.log(state, context.state)
},
render: function() {
return (
...
)
}
})
> More ScrollResponder info, see: https://github.com/facebook/react-native/blob/master/Libraries/Components/ScrollResponder.js
@TODO, see code in examples first.
`bash``
$ npm start
- @leecade The main author of the original version .
Feel free to create an issue
> Inspired by nolimits4web/Swiper & Design material from Dribbble & made with ♥.