Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Exilz committed Oct 5, 2016
0 parents commit 6bee158
Show file tree
Hide file tree
Showing 4 changed files with 448 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"parser" : "babel-eslint",
"extends" : [
"standard",
"standard-react"
],
"env" : {
"browser" : true
},
"globals": {
"__DEV__": false
},
"rules": {
"indent": [2, 4],
"generator-star-spacing": 0,
"react/jsx-indent": [0, 4],
"jsx-indent-props": [0, 4],
"react/jsx-curly-spacing": [0, "never"],
"react/jsx-boolean-value": [0, "never"],
"semi" : [2, "always"],
"operator-linebreak": [2, "after"],
"no-warning-comments": [1, { "terms": ["todo", "fixme", "xxx"], "location": "start" }]
}
}
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# react-native-snap-carousel
Simple carousel component with snapping effect on Android & iOS for React Native

![react-native-snap-carousel](https://zippy.gfycat.com/BoringBasicKiskadee.gif)
![react-native-snap-carousel](https://zippy.gfycat.com/IncompatibleVengefulBasenji.gif)

## Usage

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

```
import Carousel from 'react-native-snap-carousel';
_renderItem (data, index) {
return (
...
);
}
render () {
<Carousel
ref={'carousel'}
items={this.state.entries}
renderItem={this._renderItem}
sliderWidth={sliderWidth}
itemWidth={itemWidth}
itemHorizontalMargin={itemHorizontalMargin}
slideStyle={styles.slide} />
}
```

## Props

In addition of these props, you can provide any prop from [ScrollView](https://facebook.github.io/react-native/docs/scrollview.html) since it's using it both on Android & iOS.

Prop | Description | Type | Default
------ | ------ | ------ | ------
items | Array of items to loop on | Array | Required
sliderWidth | The width in pixels of your slider | Number | Required
itemWidth | Width in pixels of your items | Number | Required
itemHorizontalMargin | Width in pixels of the horizontal margin between your elements | Number | Required
renderItem | Function returning a react element. The entry data is the 1st parameter, its index is the 2nd | Function | Required
slideStyle | Style of each item's container | Number | Required
swipeThreshold | Delta x when swiping to trigger the snap | Number | `20`
animationFunc | Animated animation to use. Provide the name of the method | String | `Timing`
animationOptions | Animation options to be merged with the default ones. Can be used w/ animationFunc | Object | `{ easing: Easing.elastic(1) }`
firstItem | Index of the first item to display | Number | `0`
autoplay | Trigger autoplay on mount | Boolean | `false`
autoplayInterval | Delay in ms until navigating to the next item | `3000`
autoplayDelay | Deay before enabling autoplay on startup & after releasing the touch | Number | `5000`
enableSnap | If enabled, releasing the touch will scroll to the center of the nearest/active item | Number | `true`
snapOnAndroid | Snapping on android is kinda choppy, especially when swiping quickly so you can disable it | Boolean | `false`

## Methods

* `startAutoplay (instantly = false)` Start the autoplay manually
* `stopAutoplay ()` Stop the autoplay manually
* `snapToItem (index, animated = true)` Snap to an item manually

## TODO :

- [ ] Improve snap on Android
- [ ] Fix centering since it's a little off
- [ ] Handle passing 1 item only
- [ ] Handle changing props on-the-fly
- [ ] Handle device orientation event
- [ ] Add Vertical implementation
Loading

0 comments on commit 6bee158

Please sign in to comment.