Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-pagination

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-pagination

The best Pagination component for React Native.

  • 1.5.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
516
increased by53.57%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-pagination

The best Pagination component for React Native.

npm version npm version npm version npm version PR Stats Issue Stats Join the chat

React Native Pagination

Roadmap

see: ROADMAP.md

Horizontal

To try these out yourself its prudy easy, Just open examples/ios/*.xcodeproj in Xcode, then press Cmd + R; you may edit examples/index.ios.js for switch cases.

react-native-pagination horizontal robot react-native-pagination horizontal

Vertical

react-native-pagination vertical react-native-pagination lighttheme

Getting Started

Installation

  • Install react-native first
$ npm i react-native -g
$ yarn add react-native-pagination
$ cd ReactNativePaginationExample
$ yarn install #(or with npm "npm i react-native-pagination —save")
$ react-native run-ios
  • Initialization of a react-native project
$ react-native init myReactNativePaginationExample
$ cd myReactNativePaginationExample
$ yarn install #(or with npm "npm i && npm i react-native-pagination —save")
$ yarn add react-native-pagination
$ react-native link
$ react-native run-ios

Example

or clone the repo and play with the example project

$ git clone https://github.com/garrettmac/react-native-pagination
$ cd react-native-pagination/ReactNativePaginationExample
$ yarn install
$ react-native link
$ react-native run-ios

one liner

git clone https://github.com/garrettmac/react-native-pagination && cd react-native-pagination/ReactNativePaginationExample && yarn install && react-native link && react-native run-ios

Quick start with ReactNativePaginationExample.

Development

in your project

$ yarn add react-native-pagination
$ react-native link #this makes sure react-native-vector-icons load correctly
$ react-native run-ios

Basic Usage

  • In your myApp/index.ios.js, use:
import React, { Component } from 'react';
import {AppRegistry,StyleSheet,View,FlatList,} from 'react-native';
import ContactItem from './Pages/widgets/ContactItem'; // https://github.com/garrettmac/react-native-pagination/blob/master/ReactNativePaginationExample/Pages/widgets/ContactItem.js
import faker from 'faker';//assuming you have this.
import _ from 'lodash';
import Pagination,{Icon,Dot} from 'react-native-pagination';//{Icon,Dot} also available

//lets use faker to create mock data
let MockPersonList = new _.times(35,(i)=>{
  return {
    id:i,
    index:i,
    name:faker.name.findName(),
    avatar:faker.internet.avatar(),
    group:_.sample(["Family","Friend","Acquaintance","Other"]),
    email:faker.internet.email(),
  }
})

export default class ReactNativePaginationExample extends Component {
  constructor(props){
     super(props);
      this.state = {
        items: MockPersonList,
      };
    }
    //create each list item
  _renderItem = ({item}) => {
    return (<ContactItem index={item.id}
        onPressItem={this.onPressItem.bind(this)}
        name={item.name}
        avatar={item.avatar}
        description={item.email}
        tag={item.group}
        createTagColor
      />)
    };
    //pressed an item
  onPressItem = (item) => console.log("onPressItem:item ",item);

  //map to some od. We use the "id" attribute of each item in our list created in our MockPersonList
  _keyExtractor = (item, index) => item.id;

  // REQUIRED for ReactNativePagination to work correctly
  onViewableItemsChanged = ({ viewableItems, changed }) =>this.setState({viewableItems})

  render() {
    return (
      <View style={[s.container]}>
          <FlatList
            data={this.state.items}
            ref={r=>this.refs=r}//create refrence point to enable scrolling
            keyExtractor={this._keyExtractor}//map your keys to whatever unique ids the have (mine is a "id" prop)
            renderItem={this._renderItem}//render each item
            onViewableItemsChanged={this.onViewableItemsChanged.bind(this)}//need this
          />

          <Pagination
            // dotThemeLight //<--use with backgroundColor:"grey"
            listRef={this.refs}//to allow React Native Pagination to scroll to item when clicked  (so add "ref={r=>this.refs=r}" to your list)
            paginationVisibleItems={this.state.viewableItems}//needs to track what the user sees
            paginationItems={this.state.items}//pass the same list as data
            paginationItemPadSize={3} //num of items to pad above and below your visable items
          />
        </View>
      )
  }
};

const s = StyleSheet.create({
  container: {
    flex: 1,
    // backgroundColor:"grey",//<-- use with "dotThemeLight"
  },
});

AppRegistry.registerComponent('ReactNativePaginationExample', () => App);

Currently only supported for FlatList's

Properties

All properties took text editors auto completion into consideration and follow the basic structure [prefix][body][suffix ] where [component name ][component attribute][continued component attribute / component change] to provide users with the full list of options when working with prefix's without having to revisit the official docs.

Most Common Component Prefix Options:dot, startDot,endDot Most Common Component Body Options:Icon, Font,Style ,Color Most Common Component Suffix Options:Hide, Size,IconFamily ,or NotActive,Active Empty Resulting props like dotIconHide ,startDotIconHide, or startFontSize,endDotStyle ect.

Basic

Basic Props
PropDefaultTypeDescription
paginationItems[]arrayan array pagination Items
paginationVisibleItems[]arrayan array pagination visible items obtained by using React Native List Components onViewableItemsChanged callback function (see example)
dotThemeLightfalseboolif you pass in the dotThemeLight prop (setting it to true) the pagination dots swaps to a a light theme. By default they are dark.
horizontalfalsebooluse to alternate between horizontal and vertical (just like you do with your list component)
dotAnimationLayoutAnimation.Presets.easeInEaseOutAnimationdot Animation triggered when navigating
paginationStyle{}stylepagination Styles
pagingEnabledfalseboolEnable Paging. This is a prop that is also used in React Native List Components (like FlatList) that gives you that paging effect that stops the scroll on every new page.
hideEmptyDotsfalseboolHide Empty Dots Icons
paginationItemPadSize3numberpagination Item Pad Size
Basic Styles
PropDefaultTypeDescription
paginationStyle when horizontal{height, alignItems:"center" , justifyContent: 'space-between', position:"absolute", top:0, margin:0, bottom:0, right:0, bottom:0, padding:0, flex:1, }styledefault when horizontal
paginationStyle when not horizontal{width, alignItems:"center", justifyContent: 'space-between', position:"absolute", margin:0, bottom:10, left:0, right:0, padding:0, flex:1,}styledefault when not horizontal
textStyle{}style objectglobal style object. Tread lightly it may overlay if you plan to use my default Light/Dark Themes
dotStyle{}style objectaddition style to use for pagination dots
startDotStyle{}style objectaddition style to use for start dots
endDotStyle`{}style objectaddition style to use for end dots

this uses react-native-vector-icons [checkout here] (https://github.com/oblador/react-native-vector-icons)

Start/End Dots

Start/End Dot Basic Props
PropDefaultTypeDescription
startDotIconName (when horizontal)”chevron-left”icon nameIcon shown for dot at start of list
startDotIconName (when vertical)”chevron-up”icon nameIcon shown for dot at start of list
endDotIconName (when horizontal)”chevron-right”icon nameIcon shown for dot at start of list
endDotIconName (when vertical )”chevron-down”icon nameIcon shown for dot at start of list
startDotIconSize15numberend icon dot size
endDotIconSize15numberend icon dot size
startDotIconFamily / endDotIconFamilyMaterialCommunityIconsstring of font family nameFont Family for Icon. options: Entypo, EvilIcons, FontAwesome, Foundation, Ionicons, MaterialIcons, MaterialCommunityIcons, Octicons, Zocial, SimpleLineIcons (available in react-native-vector-icons package)
Start/End Dot Text
PropDefaultTypeDescription
startDotFontSize11numberstart Dot Font Size
endDotFontSize11numberend Dot Font Size

Pagination Dots

These are the list of dots that represent each item in your paginationItems

Pagination Dots Basic Props
PropDefaultTypeDescription
dotIconFamily”MaterialCommunityIcons”string of font family nameFont Family for Icon. options: Entypo, EvilIcons, FontAwesome, Foundation, Ionicons, MaterialIcons, MaterialCommunityIcons, Octicons, Zocial, SimpleLineIcons (available in react-native-vector-icons package)
dotIconNameEmpty”close”icon nameIcon Shown when pagination dot is Empty
dotIconNameActive”checkbox-blank-circle”icon nameIcon Shown when pagination dot is Active
dotIconNameNotActive”checkbox-blank-circle-outline”icon nameIcon Shown when pagination dot is Not Active
dotIconSizeActive15numbersize of pagination icon when active
dotIconSizeNotActive10numbersize of pagination iconwhen vertical
dotIconColorNotActive”rgba(0,0,0,.5)”colordot Icon Font Size when on page but Not Active
dotIconColorActive”rgba(0,0,0,.3)”colordot Icon Font Size when on page but Not Active
dotIconColorEmpty”rgba(0,0,0,.2)”colordot Icon Font Size when on page but Not Active

when using dotThemeLight

PropDefaultTypeDescription
dotIconColorNotActive”rgba(255,255,255,.4)”colordot Icon Font Size when on page but Not Active
dotIconColorActive”rgba(255,255,255,.5)”colordot Icon Font Size when on page but Not Active
dotIconColorEmpty”rgba(255,255,255,.2)”colordot Icon Font Size when on page but Not Active
Dot Text

by default it displays index+1, if you'd like display text add the paginationDotText property to each one of your items before passing it into the Pagination

Component. Example:

paginationItems=paginationItems.map(o=>{
   o.paginationDotText=o.name;
  return o
})
Pagination Dots
PropDefaultTypeDescription
dotFontSizeActive11numberdot Text Font Size when Active on page
dotFontSizeEmpty11numberdot Text Font Size when empty on page
dotFontSizeNotActive9numberdot Text Font Size when on page but Not Active
dotTextColorNotActive”rgba(0,0,0,.5)”colordot Text Color when Not Active
dotTextColorActive”rgba(0,0,0,.3)”colordot Text Color when Active
dotTextColorEmpty”rgba(0,0,0,.2)”colordot Text Color when Empty

when using dotThemeLight

PropDefaultTypeDescription
dotTextColorNotActive”rgba(255,255,255,.4)”colordot Text Color when Not Active
dotTextColorActive”rgba(255,255,255,.5)”colordot Text Color when Active
dotTextColorEmpty”rgba(255,255,255,.2)”colordot Text Color when Empty

Advanced Positioning

PropDefaultTypeDescription
dotSwapAxis (all pagination dots)/ startDotSwapAxis / endDotSwapAxisfalseboolkeeps the lists in the correct position (horizontal or vertical) by swaps how dots display
dotPositionSwap (all pagination dots)/startDotPositionSwap / endDotPositionSwapfalseboolSwaps the dots flexDirection default style property.

Wanna move anything to the left, right, top, or bottom of something? Then use dotSwapAxis in combination until you find the right mix startDotPositionSwap.

Visibility

PropDefaultTypeDescription
dotIconHide / startDotIconHide / endDotIconHidefalseboolhide the dots icon
dotIconHide / startDotIconHide / endDotIconHidefalseboolhide the dots icon
dotTextHide / startDotTextHide / endDotTextHidefalseboolhide the dots text
dotEmptyHidefalseboolhide the dots text

Methods

Method NameDescription
dotOnPress / startDotOnPress /endDotOnPressby default it will scroll to the pagination dot pressed (disableDotOnPressNavigation to turn off), if you'd like a callback you can pass in the dotOnPress callback function

Other

PropDefaultTypeDescription
debugModefalseboolshow console log results of list items

Components

ComponentsRequired ParamsOther ParamsDescription
PaginationpaginationItems,paginationVisibleItemssee abovemain pagination Component
Dot``see abovePagination Dot Component
IconnameiconFamily,size,colorsame as 'react-native-vector-icons' but with a iconFamily option

Issues

Feel free to contact me or create an issue

Keywords

FAQs

Package last updated on 24 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc