0.3.2 • Published 5 years ago

react-native-viewpager-carousel v0.3.2

Weekly downloads
96
License
MIT
Repository
github
Last release
5 years ago

React Native Viewpager Carousel

npm version dependencie status dev-dependency status npm npm travis build

Contribution

Feel free to make a pull request. I'm happy about every contribution.

Examples

You can find example implementations for all use cases of this library in the repo react-native-viewpager-carousel-example-app. The example project is also linked as git submodule in this project.

Installation

yarn add react-native-viewpager-carousel

or

npm install --save react-native-viewpager-carousel

Preview

preview

ViewPager

The <ViewPager /> is the base component of the library. Till now it acts like a simple view-carousel:

import { ViewPager } from 'react-native-viewpager-carousel'

class ExampleCarousel extends PureComponent {

    constructor() {
        this.data = [
            { title: 'title 1' },
            { title: 'title 2' },
            { title: 'title 3' },
        ]
    }
    
    _renderPage = ({data}) => {
        return ( <Text>{item.title}</Text> )
    }

    render() {
        return (
            <ViewPager
                data={this.data}
                renderPage={this._renderPage}
            />
        )
    }
}

API

prop namedata typedefaultfunctionality
containerStylestyle{}the component is wrapped into a <View />. Styles to this <View /> can be assigned through this property
contentContainerStylestyle{}posibility to set styles to the content container (the entire scrollable area)
dataarray[]a data array of objects
devbooleanfalsedraws a black line around the pages and tabs for debugging
lazyrenderbooleanfalselazyrender renders the active page only when its in the viewport
lazyrenderThresholdnumber1determines how many threshold left and right the current visible page sould be rendered if lazyrender={true}
renderAsCarouselbooleantruerenders the as endless carousel
thresholdPagesnumber1number of pages left and right of the scrollable content (sneak preview)
pageWidthnumber{{screen width of device}}width of page
initialPageobject{}key value pair of initial page: e. g. data={key:'page-a'}, {key:'page-b'} & initialPage={{key:'page-b}}
scrollEnabledbooleantruedecleares wether the ViewPager sould be able to scroll by user or not
firePageChangeIfPassedScreenCenterbooleanfalsetoggle's if onPageChange sould already be called when the dragged page passed half of the screen
pageingEnabledbooleantrue
experimentalMirroringbooleanfalsetoggles the mirroring of the scrollposition of the threshold views - more information here
showNativeScrollIndicatorbooleanfalsenative ScrollView indicator is disabled by default
renderPagefunction() => {}render callback for content page
onPageChangefunction() => {}callback when the page changes -> retuns the current pageNumber as first argument
onScrollfunction() => {}callback when the content area scrolls

TabbedPager

In addition to the <ViewPager /> the <TabbedPager /> component provides an additional renderFunction for Tabs above the content view. The following pseudo-code shows the basic usage with an <Image /> as content and a <Text /> as tab.

import { TabbedPager } from 'react-native-viewpager-carousel'

class ExampleCarousel extends PureComponent {

    constructor() {
        this.data = [
            { title: 'title 1', url: 'http://...' },
            { title: 'title 2', url: 'http://...' },
            { title: 'title 3', url: 'http://...' },
        ]
    }
    
    _renderTab = ({data}) => {
        return ( <Text>{data.title}</Text> )
    }
    
    _renderPage = ({data}) => {
        return ( <Image source={{uri: data.url}} /> )
    }

    render() {
        return (
            <ViewPager
                data={this.data}
                renderTab={this._renderTab}
                renderPage={this._renderPage}
            />
        )
    }
}

API

prop namedata typedefaultfunctionality
dataarray[]a data array of objects
devbooleanfalsedraws a black line around the pages and tabs for debugging
fullScreenbooleantruedraws the in full screen mode (flex 1)
lazyrenderbooleanfalselazyrender renders the active page only when its in the viewport
lazyrenderThresholdnumber1determines how many threshold left and right the current visible page sould be rendered if lazyrender={true}
renderAsCarouselbooleantruerenders the as endless carousel
tabContainerPositionstring'top'could be 'top' || 'bottom' - places the tab container on top of the viewpager or on the bottom side
scrollTabsEnabledbooleanfalse
firePageChangeIfPassedScreenCenterbooleanfalsetoggle's if onPageChange sould already be called when the dragged page passed half of the screen
staticTabWidthnumber{{screen width of device / 2}}
initialPageobject{}key value pair of initial page: e. g. data={key:'page-a'}, {key:'page-b'} & initialPage={{key:'page-b}}
showTabIndicatorbooleantruetoggles the tab indicator
tabIndicatorColorstring'transparent'changes the color of the tab indicator
tabIndicatorHeightnumber2height of tab indicator
tabsVisiblebooleantrueindicates if tabs should be visible or not
DividerComponentanynullrenders a given Component between the tabs and the content area
renderPagefunction() => {}render callback for content page
renderTabfunction() => {}render callback for the tab
onPageChangefunction() => {}callback when the page changes -> retuns the current pageNumber as first argument
experimentalMirroringbooleanfalsetoggles the mirroring of the scrollposition of the threshold views - more information here
0.3.2

5 years ago

0.3.1

5 years ago

0.2.12

6 years ago

0.2.10

6 years ago

0.2.9

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.13-rc.3

7 years ago

0.1.13-rc.2

7 years ago

0.1.13-rc.1

7 years ago

0.1.12

7 years ago

0.1.12-rc.1

7 years ago

0.1.11

7 years ago

0.1.11-rc.3

7 years ago

0.1.11-rc.2

7 years ago

0.1.11-rc.1

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7-rc.4

7 years ago

0.1.7-rc.3

7 years ago

0.1.7-rc.2

7 years ago

0.1.7-rc.1

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago