Giter Club home page Giter Club logo

react-native-pages's Introduction

react-native-pages

npm license travis 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 -
onScrollStart Scroll start callback Function -
onScrollEnd Scroll end callback Function -
onHalfway Dominant page change 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

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

class Example extends Component {
  _renderPager = (options) => {
    let {
      rtl,
      pages,
      progress,
      horizontal,
      indicatorColor,
      indicatorOpacity,
      indicatorPosition,
    } = options;

    if ('none' === indicatorPosition) {
      return null;
    }

    return (
      <Indicator {...options} />
    );
  };

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

    return (
      <Pages {...props} renderPager={this._renderPager}>
        {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-2019 Alexander Nazarov. All rights reserved.

react-native-pages's People

Contributors

andrewmarmion avatar n4kz avatar sudoplz avatar syzer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-pages's Issues

unsupported top level event "topScroll" dispatched

hi guy.
i have an question. when i try to use "react-native-pages" in my project (react-native 0.50) i see a bug "unsupported top level event "topScroll" dispatched".
pls help me check this is bug from "react-native-pages" or from facebook?

and how can i fix it?

thanks

how to disable swipe ?

Hi, this is a nice library, however it would be great if it includes swipeEnabled={false} so that, instead of manually swipe one can use programmatically swiping

Looping?

I don't see any options for looping the pages. (4 -> 1 -> 2 -> 3 -> 4 -> 1...ad infinitum) Is this a possible feature? Here's hoping 👍

Fantastic work on this library, I tried 5 others and this one was the easiest drop-in and provided most flexibility!

🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥

🙃
Thanks-Dan

Bottom Indicators are overlapped with a bar in iPhoneX.

This library is very good one for creating swipeable pages. But, in iPhoneX the bottom indicators are being overlapped by the black bar of iPhoneX. I have fixed it in in src/components/indicator/index.js. I'm trying to push it to a separate branch and raise a pull request, but I'm facing with 403 error. I request you to provide the fix.

I have changed the view from this:

<View style={[styles.container, { flexDirection }, style]} {...props}> {dots} </View>

to this:

<View style={[styles.container, { flexDirection }, style]} {...props}> <SafeAreaView style={[{flexDirection}]}> {dots} </SafeAreaView> </View>

and imported SafeAreaView in react-native.

Add the possibility to set testID to create unit tests

In my project, we are writing unit tests for our components and screens and we got stuck for a while because this library doesn't accept the testID property for the main View.

I suggest to add the testID here:

return (
    <View style={[styles.container, containerStyle]} onLayout={this.onLayout} testID={this.props.testID}>
        {this.renderPages(props)}

        <Pager />
      </View>
    );

I think it would be great if you could add the ability to set a testID. If you want I can make the PR, I even tested it locally but I decided to go with a workaround, in case anyone else wants it, here is my current code:

<View testID={'pagesViewWrapperTestId'}>
   <Pages
    ...        
   </Pages>
</View>

And in my test I do:

const pagesViewWrapper = queryByTestId('pagesViewWrapperTestId');
expect(pagesViewWrapper).toBeTruthy();
const pagesView = pagesViewWrapper.children[0].children[0]; // this gets the view from Pages I want to add the testID to access directly to it
fireEvent(pagesView, 'layout', {
	  nativeEvent: { layout: { height: 100 } },
});

The last part is to trigger the onLayout function from the View, otherwise, it doesn't render the pages content.

onScrollEnd not trigged on android

hi

thanks for this component , it looks nice and easy
i notice that the onScrollEnd event not trigged always on android but it wrks fine in ios

Regards

Getting slow visible pages on first load

Hi there, thanks for making this libs. Please help me, I getting slow visible pages on first load. I just follow examples and then apply for my project. But on first enter to this Components, I getting the first pages is visbile have delay (about 1-2s). Am I wrong some where? Please let me know, thanks again,

How to use isDragging?

I cannot find the way to implement this function, I need to detect if the user is dragging the pager

scrollToPage doesn't work when animated = false

scrollToPage doesn't work when animated = false. That happens because of this:

requestAnimationFrame(() => {
        this.scrollToPage(Math.floor(this.progress), false);
});

After scrollToPage it calls scrollToPage second time and goes back to 0 page.

Quick hack to override this issue (hopefully we can see a fix next version and we don't need this dirty hack):

//Set scrollState to 1 before scrolling
pager.current.scrollState = 1;
pager.current.scrollToPage(0, false)

//Make scrollState to 0 zero after scroll will finish
setTimeout(() => {
      pager.current.scrollState = 0
}, 100)

Thanks!!!

Start Page

Is there a way to set a starting page? For example, if I have three different horizontal pages, but I want to start on the second one, how would I do this?

Thanks!

android onScrollEnd() not firing

Hey there!

great little component :)

i found this previous issue where people seem to say it has been resolved? #13

Do i need a certain RN/ R to make it work?

i seem to have the functionality that was before the fix which was it randomly fires the callback on scroll end

(im also testing on the android simulator not sure if this makes a difference)

ive even tried rolling back to 0.5.6 version with the same results :(

i also have a prop being updated via dispatch which show the body contents of the current 'active' page and nulls for the rest to increase performance when there is lots of pages in case this could have something todo with it.

edit. oh as i remember seeing it being a float conversion issue before i have 42 pages in my current senario

Android choppy/slow performance

Just curious, is there a reason performance is so choppy/slow on Android? Are there considerations to be aware of with Android? I even have JS Dev Mode turned off in the Dev Settings, and it's still almost unusable. iOS is buttery smooth btw.

How to disable manually swipe gesture ?

Hi, this is a nice library, however it would be great if it includes swipeEnabled={true} so that, instead of manually swipe one can use programmatically swiping

Nested pages

I would really like to be able to have nested pages and I am wondering if there is any way to do that. Thanks!

Programmatically moving to next/prev

Is there a way to programmatically trigger swiping? I'm using some other controls within the pager which swallow the swiping gesture (to do panning), so I'd want to navigate through the pager based on my own code. That would also cover scenarios such as slide shows...

Getting the current page index

There does not seem to be a clear method to understand what page is focused. Something along the lines of would be helpful:

<Pages onChange={index => this.setState({ index })} />

Let me know if I can help.

Vertical Scroll/Pagination on Layout changes results in wrong scroll position

How to reproduce:

Create a multi paged, vertical layout. When switching from landscape to portrait and vice versa, the scroll position would sometimes end up 'in the middle' so to speak.

Furthermore, if a layout change is triggered by say the keyboard (text input inside pager), it would also result in the wrong scroll position.

Vertical scroll in horizontal slider

Thanks. Nice lib. But...
Problems with vertical scroll in horizontal slider.
For example I want to put inside WebView component.
Vertical slider with images so slow.... almost not work. (Доделай плиз...и будет OK)

Android device 4.2.

didScrollToPage?

How do I know when page view was scrolled and another view got in focus?

Auto scroll

I'm not able to do automatic scrolling of pages. After some time I want to scroll next page automatically.

How can. I do?

Slider component on Page causes conflicting swipe behavior

Hi,

I put a react-native-slider component in a child page. I want to be able to use the slider but when I do, it causes the react-native-pages component to start swiping between pages. How can I get a page to not respond to swiping while over the actual slider component, but work anywhere else on the page?

Thanks!
Steve

Doesn't work with Reanimated

I've got a container of <Animated.ScrollView> and stack inside views and so on.., I tried plugging it with Pages and the only part that appears is the indicator (2 dots for 2 views)
I don't know where it overlaps however my clue is to it overrides onScroll function and something goes wrong there..

(For code reference)
<Animated.ScrollView onScroll={onScroll({ y })} showsVerticalScrollIndicator={false} scrollEventThrottle={1} > ... <Pages> <View/> <View/> </Pages> </Animated.ScrollView>

If any more info is required, I can provide. Nice plugin nevertheless

Inset Pager with overflow

Hey! 2 questions tonight :)

Product requires that our "pages" be slightly visible to indicate that one can swipe to the next page. I've experimented with containerStyle and a few other things to get the next page to be peeking, but can't seem to achieve this, it seems to always cut off where i've padded / added margin, even with 'overflow': 'visible'

Desired result:

image

Where those 'cards' are each child. You can see that the next page is bleeding into the current. I can achieve this with a horizontal scroll view, but the pages don't "LOCK" like I want them to.

Is this possible with your library do you think?

Thanks :)

-Dan

componentWillReceiveProps is deprecated

Warning when using React Native 0.60.5:

Warning: componentWillReceiveProps is deprecated and will be removed in the next major version. Use static getDerivedStateFromProps instead.

Indicator working randomly (Android)

Hi there

Lastest NPM package, RN 0.51 (Expo 24)
Galaxy S6, Android 7.0

First of all thanks for a very neat component! I just did a trial run and noticed some rather random behavior with the indicator - the counter sometimes moves, sometimes doesn't (more often, it doesn't update), while the actual swiping between the views isn't a problem. Here's my code:

render() {
    return (
        <View style={{flex: 1, backgroundColor: "black"}}>
            <Pages style={{flex: 1}}>
                <View style={{ flex: 1 }}>
                    <Text style={{color: "white"}}>Page 0</Text>
                </View>

                <View style={{ flex: 1 }}>
                    <Text style={{color: "white"}}>Page 1</Text>
                </View>

                <View style={{ flex: 1 }}>
                    <Text style={{color: "white"}}>Page 2xy</Text>
                </View>
            </Pages>
        </View>
    );
}

Here's the indicator after some scrolling back and forth. Showing the 3rd page with the indicator selecting the 2nd:

I only saw the (closed) issue about Android not rendering at all, but the random updates seem to be different.

ViewPropTypes Depricated - Invariant Violation Error

Upgrading to Expo 46/React-Native .69 gave me Invariant Violation: ViewPropTypes has been removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'.

Narrowed it down to Pages being the cause. App only runs when I comment out the Pages component.

keyboardDismissMode='on-drag' doesn't work

We want to dismiss the keyboard when scrolling to another page. It seems that setting the keyboardDismissMode prop to 'on-drag', for the ScrollView, doesn't do anything. Using onScrollEnd prop is not what we want, because we allow other components to focus after using the scrollToPage(page) method - onScrollEnd={() => Keyboard.dismiss()} results in unwanted behavior.
Edit: Using react-native 0.60.5

Scroll to Page ddoesn't trigger animation

ezgif-3-9fcb3dec8d

When using scrollToPage, animation (Animated, interpolate) does not work.

It's not clear in the gif above, but the first two instances (where the text 'Amount' animates from bottom to up) of page switch, it is done by swiping right and has an animation

On the second two instances, the page switch was done with scrollToPage and it doesn't trigger the animation

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.