├── SCRN.gif
├── package.json
├── LICENSE
├── README.md
└── index.js
/SCRN.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kfbow/simple-carousel-react-native/HEAD/SCRN.gif
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "simple-carousel-react-native",
3 | "version": "1.0.1",
4 | "description": "A simple React Native carousel",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/kfbow/simple-carousel-react-native.git"
12 | },
13 | "author": "kfbow",
14 | "license": "MIT",
15 | "bugs": {
16 | "url": "https://github.com/kfbow/simple-carousel-react-native/issues"
17 | },
18 | "homepage": "https://github.com/kfbow/simple-carousel-react-native#readme"
19 | }
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Kolbe Bowring
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # simple-carousel-react-native
2 | A simple React Native carousel
3 |
4 | 
5 |
6 | ## Installation
7 | ```
8 | npm i simple-carousel-react-native --save
9 | ```
10 |
11 | ## How to use
12 | Import the module and each child will be a page in the carousel.
13 | ```
14 | import Carousel from 'simple-carousel-react-native';
15 |
16 |
17 |
18 |
19 | Page 1
20 |
21 |
22 |
23 |
24 |
25 | Page 2
26 |
27 |
28 |
29 |
30 |
31 | Page 3
32 |
33 |
34 |
35 | ```
36 |
37 | If you would like to define some of the props:
38 | ```
39 |
42 |
43 | Page 1
44 |
45 |
46 | ```
47 |
48 | ## API
49 | *(Type, Default)*
50 | * **backgroundColor** - (String, '#fff') - The background color of the parent ``.
51 | * **bubbleHeight** - (Number, 10) - The height of the bubble indicator.
52 | * **bubbleWidth** - (Number, 10) - The width of the bubble indicator.
53 | * **color** - (String, '#ffa500') - The color of the highlighted bubble indicator.
54 | * **dimmedColor** - (String, '#d3d3d3') - The color of the dimmed out bubble indicators.
55 | * **height** - (Number, 350) - The height of the carousel.
56 | * **showBubbles** - (Boolean, true) - Show the bubble indicators.
57 | * **showScroll** - (Boolean, false) - Show the native scroll bar.
58 | * **width** - (Number, 350) - The width of the carousel.
59 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /** @flow */
3 |
4 | import React, { Component } from 'react';
5 | import {
6 | ScrollView,
7 | View
8 | } from 'react-native';
9 |
10 | export default class Carousel extends Component {
11 | state: {
12 | offset: ?Number
13 | }
14 |
15 | constructor(props) {
16 | super(props);
17 |
18 | this.state = {
19 | offset: 0,
20 | }
21 | }
22 |
23 | renderBubbles = (width: Number) => {
24 | const {
25 | children,
26 | color = '#ffa500',
27 | dimmedColor = '#d3d3d3',
28 | bubbleWidth = 10,
29 | bubbleHeight = 10
30 | } = this.props;
31 |
32 | let bubbles = [];
33 |
34 | const emptyBubble = {
35 | width: bubbleWidth,
36 | height: bubbleHeight,
37 | backgroundColor: dimmedColor,
38 | borderRadius: 15,
39 | alignSelf: 'center',
40 | }
41 |
42 | const filledBubble = {
43 | width: bubbleWidth,
44 | height: bubbleHeight,
45 | backgroundColor: color,
46 | borderRadius: 15,
47 | alignSelf: 'center',
48 | }
49 |
50 | for (var i=0; i
53 | )
54 | }
55 |
56 | if (this.state.offset % width === 0) {
57 | bubbles.map((v) => {
58 | v.key == this.state.offset
59 | ? bubbles[v.key / width]
60 | =
61 | : null;
62 | })
63 | }
64 |
65 | return (
66 |
67 | { bubbles }
68 |
69 | )
70 | }
71 |
72 | render() {
73 | const {
74 | backgroundColor = '#fff',
75 | children,
76 | height = 350,
77 | showBubbles = true,
78 | showScroll = false,
79 | width = 350,
80 | } = this.props;
81 |
82 | let pages = [];
83 |
84 | for (var i=0; i
87 | { children[i] }
88 |
89 | )
90 | }
91 |
92 | return (
93 |
94 | {
99 | this.setState({offset: e.nativeEvent.contentOffset.x})
100 | }}
101 | style={{ width: width, height: height }}>
102 | { pages }
103 |
104 | { showBubbles ? this.renderBubbles(width) : null }
105 |
106 | )
107 | }
108 | }
109 |
--------------------------------------------------------------------------------