Giter Club home page Giter Club logo

react-native-pages's Introduction

react-native-pages

npm license codeclimate

Easy to use page view component for React Native

example

Features

  • Easy to use
  • Consistent look and feel on iOS and Android
  • Landscape and portrait orientation support
  • Parallax and complex animation support
  • Animated page indicator
  • Configurable scroll direction
  • Configurable page indicator position, color and opacity
  • RTL support
  • Pure javascript implementation

Installation

npm install --save react-native-pages

Usage

import React, { Component } from 'react';
import { Pages } from 'react-native-pages';

class Example extends Component {
  render() {
    return (
      <Pages>
        <View style={{ flex: 1, backgroundColor: 'red' }} />
        <View style={{ flex: 1, backgroundColor: 'green' }} />
        <View style={{ flex: 1, backgroundColor: 'blue' }} />
      </Pages>
    );
  }
}

Properties

name description type default
horizontal Scroll direction Boolean true
rtl RTL mode for horizontal scroll Boolean false
startPage Start page Number 0
indicatorColor Page indicator color String rgb(255, 255, 255)
indicatorOpacity Page indicator opacity (inactive dots) Number 0.30
indicatorPosition Page indicator position String bottom
containerStyle Style for container view Object -
progress Animated.Value updated with progress Object -
onScrollEnd Scroll end callback Function -
renderPager Render pager callback Function -

Possible values for indicatorPosition are none, top, right, bottom and left

Methods

name description returns
scrollToPage Scroll to page with optional animation -
isDragging Returns whether the user has begun scrolling Boolean
isDecelerating Returns whether content is moving after scrolling Boolean

Replacing page indicator

class Example extends Component {
  renderPager({ pages, progress, indicatorPosition }) {
    if ('none' === indicatorPosition) {
      return null;
    }

    return (
      <MyIndicator pages={pages} progress={progress} position={indicatorPosition} />
    );
  }

  render() {
    let { children, ...props } = this.props;

    return (
      <Pages {...props} renderPager={this.renderPager.bind(this)}>
        {children}
      </Pages>
    );
  }
}

For implementation details take look at Indicator component

Parallax and other animations

All child components receive the following props

name description type
index Page index Number
pages Page count Number
progress Animated.Value with current progress Object

For usage example take look at example app source code

Example

git clone https://github.com/n4kz/react-native-pages
cd react-native-pages/example
npm install
npm run ios # or npm run android

Copyright and License

BSD License

Copyright 2017-2018 Alexander Nazarov. All rights reserved.

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.