1.0.2 • Published 6 years ago

react-native-looped-carousel-improved v1.0.2

Weekly downloads
23
License
MIT
Repository
github
Last release
6 years ago

react-native-looped-carousel-improved

Simple and Powerful Carousel to React Native.

NPM version Dependency Status devDependency Status

Full-fledged "infinite" (or not) carousel for your react-native project. Supports iOS and Android.

Based on React Native by Facebook and extends of react-native-looped-carousel component.

Demo

npm.io

Install

npm install react-native-looped-carousel-improved --save

Documentation Props

NamepropTypedefault valuedescription
autoplaybooleantrueenables auto animations
delaynumber4000number in milliseconds between auto animations
currentPagenumber0allows you to set initial page
pageStylestylenullstyle for pages
contentContainerStylestylenullcontentContainerStyle for the scrollView
onAnimateNextPagefuncnullcallback that is called with 0-based Id of the current page
swipebooltruemotion control for Swipe
isLoopedbooltrueloop the slide
Pagination---------
pageInfobooleanfalseshows {currentPage} / {totalNumberOfPages} pill at the bottom
pageInfoBackgroundColorstring'rgba(0, 0, 0, 0.25)'background color for pageInfo
pageInfoBottomContainerStylestylenullstyle for the pageInfo container
pageInfoTextStylestylenullstyle for text in pageInfo
pageInfoTextSeparatorstring' / 'separator for {currentPage} and {totalNumberOfPages}
Bullets---------
bulletsboolfalsewether to show "bullets" at the bottom of the carousel
bulletStylestylenullstyle for each bullet
bulletsContainerStylestylenullstyle for the bullets container
chosenBulletStylestlyenullstyle for the selected bullet
Arrows---------
arrowsboolfalsewether to show navigation arrows for the carousel
arrowsStylestylenullstyle for navigation arrows
arrowsContainerStylestylenullstyle for the navigation arrows container
leftArrowTextstring / element'Left'label / icon for left navigation arrow
rightArrowTextstring / element'Right'label / icon for right navigation arrow
rightArrowStylestylenullstyle for the right arrow
leftArrowStylestylenullstyle for the left arrow

Usage

import React, { Component } from 'react';
import {
  Text,
  View,
  Dimensions,
} from 'react-native';
import Carousel from 'react-native-looped-carousel-improved';

const { width, height } = Dimensions.get('window');

export default class MyCarousel extends Component {

  constructor(props) {
    super(props);

    this.state = {
      size: { width, height },
    };
  }

  _onLayoutDidChange = (e) => {
    const layout = e.nativeEvent.layout;
    this.setState({ size: { width: layout.width, height: layout.height } });
  }

  render() {
    return (
      <View style={{ flex: 1 }} onLayout={this._onLayoutDidChange}>
        <Carousel
          delay={2000}
          style={this.state.size}
          autoplay
          pageInfo
          isLooped
          onAnimateNextPage={(p) => console.log(p)}
        >
          <View style={[{ backgroundColor: '#BADA55' }, this.state.size]}><Text>1</Text></View>
          <View style={[{ backgroundColor: 'red' }, this.state.size]}><Text>2</Text></View>
          <View style={[{ backgroundColor: 'blue' }, this.state.size]}><Text>3</Text></View>
        </Carousel>
      </View>
    );
  }
}

Contributing

  1. Fork it!

  2. Create your feature branch: git checkout -b my-new-feature

  3. Commit your changes: git commit -am 'Add some feature'

  4. Push to the branch: git push origin my-new-feature

  5. Submit a pull request :D

History

This project is a just improvement to this project.

Credits

All Credits to @phil-r to create react-native-looped-carousel.

License

MIT @ Felipe Sousa