Giter Club home page Giter Club logo

react-native-anchor-carousel's Introduction

react-native-anchor-carousel


Build Status

A simple swipeable carousel for React Native which anchor two side of list..

Installation

Install the dependency.

$ npm install react-native-anchor-carousel 
$ yarn add react-native-anchor-carousel 

Example

Expo snack demo here


full example here **Hook Component version:

import React, {useRef} from 'react';
import Carousel from 'react-native-anchor-carousel';
const carouselRef = useRef(null);
<View style={styles.carouselContainer}>
     <Carousel  style={styles.carousel}
                data={data}
                renderItem={this.renderItem}
                itemWidth={200}
                containerWidth={width - 20} 
                separatorWidth={0}
                ref={carouselRef}
	            //pagingEnable={false}
	            //minScrollDistance={20}
            />
</View>
  renderItem = ({item, index}) => {
        const {backgroundColor} = item;
        return (
            <TouchableOpacity style={[styles.item, {backgroundColor}]}
                              onPress={() => { carouselRef.current.scrollToIndex(index); }}>
                 .......
            </TouchableOpacity>)
    };
 
	const styles = StyleSheet.create({ 
		....
		carouselContainer: {
		    height:200  
		},
	    	carousel: {
	            flex:1
		} 
	})

**Traditional component version:

import Carousel from 'react-native-anchor-carousel';
<View style={styles.carouselContainer}>
     <Carousel  style={styles.carousel}
                data={data}
                renderItem={this.renderItem}
                itemWidth={200}
                containerWidth={width - 20} 
                separatorWidth={0}
                ref={(c) => {
                    this._carousel = c;
                }}
	            //pagingEnable={false}
	            //minScrollDistance={20}
            />
</View>
  renderItem = ({item, index}) => {
        const {backgroundColor} = item;
        return (
            <TouchableOpacity style={[styles.item, {backgroundColor}]}
                              onPress={() => {
                                  this._carousel.scrollToIndex(index);
                              }}>
                 .......
            </TouchableOpacity>)
    };
 
	const styles = StyleSheet.create({ 
		....
		carouselContainer: {
		    height:200  
		},
	    	carousel: {
	            flex:1
		} 
	})

Usages

This component currently just support only carousel for horizontal side carousel From version 2.2.0, It is now supported Flatlist props From version 3.0.0 Change scroll behavior of previous versions

Props Description Type Default Required
data Array of data for rendering Array [] Yes
renderItems take each item from data and renders it. Function receives one agrument {item,index} and must return as React.Element Function () => {} Yes
initialIndex Initial starting focused item of list Number 0 No
onScrollEnd Fired while scrollview end of scrolling Function ()=> {} No
pagingEnable Enable or disable autor scroll to closest item Boolean False No
containerWidth Width of the carousel container box number Screen width Yes
itemWidth Width of each item in carousel Number 90% of screen width Yes
separatorWidth Width of separator in carousel (cause it only support horizontal side at the present time) Number 10 No
inActiveScale Value of the scale effect applied to inactive item Number 0.85 No
inActiveOpacity Value of the opacity effect applied to inactive item Number 0.8 No
style Style of the carousel container box View style {} No
itemContainerStyle Style for each carousel container item View style {} No
minScrollDistance Minimum distance when scrolling to move to the next item Number 25 No

References from

This library is written after taking reference from react-native-snap-carousel

Development

Welcome everybody to contribute ! Hope this simple carousel can help somebody for fast develope react-native app!

Todos

  • Cover vertical side carousel

License

MIT

Free Software, Hell Yeah!

react-native-anchor-carousel's People

Contributors

namlehoangdev avatar vitorandrietta avatar

Forkers

giugrilli

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.