Giter Site home page Giter Site logo

zbtang / react-native-viewpager Goto Github PK

View Code? Open in Web Editor NEW
951.0 21.0 285.0 4.73 MB

ViewPager and Indicator component for react-native on both android and ios.

JavaScript 89.74% Objective-C 6.02% Python 2.24% Shell 0.19% Java 1.81%
react-native viewpager

react-native-viewpager's Introduction

React-Native-ViewPager

npm npm npm

ViewPager and Indicator component for react-native on both android and ios. ViewPager's props is the same as ViewPagerAndroid.

Features

  • unify <ViewPagerAndroid> and <ScrollView pagingEnabled={true}> to <ViewPager>, add offer same props as ViewPagerAndroid.
  • <IndicatorViewPager> component support render indicator
  • implement common indicator: DotIndicator, TitleIndicator and TabIndicator

Preview

download demo apk file

Build and run the demo

cd RNViewPagerDemo/
npm install
react-native run-ios

Component API

<ViewPager /> Component API

<IndicatorViewPager /> Component API

<PagerDotIndicator /> Component API

<PagerTabIndicator /> Component API

<PagerTitleIndicator /> Component API

Usage

Install from npm:

npm install --save rn-viewpager

Integrate into your app:

import {StyleSheet, View, Text} from 'react-native';
import React, {Component} from 'react';
import {PagerTabIndicator, IndicatorViewPager, PagerTitleIndicator, PagerDotIndicator} from 'rn-viewpager';

export default class ViewPagerPage extends Component {
    render() {
        return (
            <View style={{flex:1}}>
                <IndicatorViewPager
                    style={{height:200}}
                    indicator={this._renderDotIndicator()}
                >
                    <View style={{backgroundColor:'cadetblue'}}>
                        <Text>page one</Text>
                    </View>
                    <View style={{backgroundColor:'cornflowerblue'}}>
                        <Text>page two</Text>
                    </View>
                    <View style={{backgroundColor:'#1AA094'}}>
                        <Text>page three</Text>
                    </View>
                </IndicatorViewPager>

                <IndicatorViewPager
					style={{flex:1, paddingTop:20, backgroundColor:'white'}}
                    indicator={this._renderTitleIndicator()}
                >
                    <View style={{backgroundColor:'cadetblue'}}>
                        <Text>page one</Text>
                    </View>
                    <View style={{backgroundColor:'cornflowerblue'}}>
                        <Text>page two</Text>
                    </View>
                    <View style={{backgroundColor:'#1AA094'}}>
                        <Text>page three</Text>
                    </View>
                </IndicatorViewPager>
                
                <IndicatorViewPager
					style={{flex:1, paddingTop:20, backgroundColor:'white'}}
                    indicator={this._renderTabIndicator()}
                >
                    <View style={{backgroundColor:'cadetblue'}}>
                        <Text>page one</Text>
                    </View>
                    <View style={{backgroundColor:'cornflowerblue'}}>
                        <Text>page two</Text>
                    </View>
                    <View style={{backgroundColor:'#1AA094'}}>
                        <Text>page three</Text>
                    </View>
                </IndicatorViewPager>
            </View>
        );
    }

    _renderTitleIndicator() {
        return <PagerTitleIndicator titles={['one', 'two', 'three']} />;
    }

    _renderDotIndicator() {
        return <PagerDotIndicator pageCount={3} />;
    }
    
    _renderTabIndicator() {
        let tabs = [{
                text: 'Home',
                iconSource: require('../imgs/ic_tab_home_normal.png'),
                selectedIconSource: require('../imgs/ic_tab_home_click.png')
            },{
                text: 'Message',
                iconSource: require('../imgs/ic_tab_task_normal.png'),
                selectedIconSource: require('../imgs/ic_tab_task_click.png')
            },{
                text: 'Profile',
                iconSource: require('../imgs/ic_tab_my_normal.png'),
                selectedIconSource: require('../imgs/ic_tab_my_click.png')
        }];
        return <PagerTabIndicator tabs={tabs} />;
    }

}

Note

When use this lib in ListView header on android platform, please add removeClippedSubviews={false} prop to your ListView.

react-native-viewpager's People

Contributors

anangryant avatar asmh1989 avatar christianchown avatar developer239 avatar fabian-ahorner avatar imesong avatar jr-k avatar jsm avatar lsps9150414 avatar maxeh avatar ms88privat avatar ojcarcete avatar rizzomichaelg avatar yiitz avatar zbtang 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-viewpager's Issues

Full screen ViewPager

Thanks for sharing this component! Right now setting flex:1 on the ViewPager doesn't make it fill the screen, seems like it needs a specific number. Would be great if it could handle that.

[iOS] onPageSelected doesn't get fired when scrolled too fast

Using IndicatorViewPager
If you scroll through before the page completely stops,
onPageSelected callback never gets fired.
On Android, this works as intended, where even if you scroll through fast no indexes are missed.

For instance, if you log the indexes in iOS it may show up as
1, 2, 5 where index 3 and 4 were scrolled before fully stopped.

versions:

"react": "15.4.2",
"react-native": "0.41.2",
"rn-viewpager": "^1.1.4",

Change page manually.

"You can call pager. setPage(selectedPageIndex) or pager.setPageWithoutAnimation(selectedPageIndex)" This is not working. I got this error: "undefined is not an object (evaluating 'this.viewPager.setPage')" .

This is the code:
`import React, { Component } from 'react';
import { View, TouchableWithoutFeedback } from 'react-native';
import { IndicatorViewPager } from 'rn-viewpager';
import { IntroOne, IntroTwo } from '@scenes/shared/Intros';

// Styles
import Styles from './styles';

export default class IntroPager extends Component {
constructor () {
super();
this.state = {page : 0};
}

render () {
return (

<IndicatorViewPager ref={viewPager => { this.viewPager = viewPager; }} style={Styles.IndicatorViewPagerStyle}>












);
}

updatePage (myPage) {
this.refs.viewPager.setPage(myPage);
}
}`

Prevent Vertical Drag

Hi I want to prevent vertical drag for pagerdotindicator. I am not sure where I can make that edit. Also there is some white space because of the indicator view pager. How can I remove that space?

大神,安卓闪退

bf35b014-d1b5-4993-8585-70074fa0d89b 少了 com.zubintang/com.zubintang.MainActivity目录啊
导致 安卓 闪退啊,

How to make an infinite loop on the last dot ?

Hi guys when i set autplayenable true, when the dots in the last page, and it goes back to first dot seems the view inside of the dots is like reversing back not doing it like infinite loop.
how can i make it like infinite loop ? Both for slide manually and autoplay the slider.. so when goes to last page when i swipe it to right it goes to first dot, same as autoplay enable..

Support for disabling scroll

I was investigating using this pager as a wizard. As such I dont want the user to be able to manually swipe to the next page until all the information is complete. Is there a way in which I can disable scroll?

Looking at the code it seems like its always enabled and no way to disable.

Thanks

Support for custom Icon

Currently it supports only Image as icon style in PageTabIndicator

Please add support for custom iconStyle as Icon instead of only Image. It will be flexible if prop type of iconStyle is View.

使用这个组件会报错 Encountered an error while persisting cache

你好, 使用组件会报如下这样的错误,不知道要如何解决。 react native 是 0.25, 谢谢。

transformed 543/544 (100%)[node-haste] Encountered an error while persisting cache:

SyntaxError: D:/test/index.js: Unexpected token (121:6)
119 | _renderDotIndicator()
120 | {

121 | return (
| ^
122 | <PagerDotIndicator
123 | pageCount={3}
124 | />

viewpager 的位置问题

viewpager 属性中有个 pageMargin: 0,我怎么把这个取出来另外在给它设值。
我在首页中是实用妈个 pageMargin:0,但是我在使用position TitileIndicatior位置后,把view pager给遮住了TitileIndicatior高度的一半,我是使用 view pager中的pageMargin来调整还是有什么其他的办法。

removeClippedSubviews={false} not working

The fix is not working. I am using this as a ListView Header and have set the removeClippedSubviews prop to false, but the pager still not showing. only the dotindicator is showing.

Change a page programmatically.

Hi!

Is it possible to programmatically change the page.
I want to change the page when a button is pressed.

Thanks in advance.

can not scroll the page when the content exceeds the width of the screen

i have image. when my screen on landscape, screen can not scroll. while adding image becomes wide.

this is my code

const { width, height } = Dimensions.get('window')

const styles = {
image: {
width:null,

alignSelf: 'stretch',
flex: 1

}
}

import {PagerTabIndicator, IndicatorViewPager, PagerTitleIndicator, PagerDotIndicator} from 'rn-viewpager';

export default class ViewPagerPage extends Component {
render() {

    var _scrollView: ScrollView;

    return (
        <View style={{flex:1}}>
            <IndicatorViewPager
                style={{flex:1}}
                indicator={this._renderDotIndicator()}
            >
                <View style={{backgroundColor:'cadetblue'}}>
                    <Text>page one</Text>
                </View>
                <View style={{backgroundColor:'cornflowerblue', flex:1}}>
                    <ScrollView
                      pagingEnabled = {true}
                    >
                    <Image style={styles.image} source={require('./img/2.jpg')} /> // **<-- this is my question**
                    </ScrollView>
                </View>
                <View style={{backgroundColor:'#1AA094'}}>
                    <Text>page three</Text>
                </View>
            </IndicatorViewPager>


        </View>
    );
}


_renderDotIndicator() {
    return <PagerDotIndicator pageCount={3} />;
}

}

Android: ViewPager loses scroll anchors

Hi,

if you are using an IndicatorViewPager in combination with a navigator (in my case react-native-navigation), the ViewPager loses the scroll anchors. To be more specific: lets say the view pager is our root view. When you now push a view on the navigator and pop it again, the view pager is scrolling contiously. This only occurs on android.

Does anyone have an idea here?

Regards,
Malte

[iOS] onPageSelected firing twice

Using IndicatorViewPager in iOS
onPageSelected callback is firing twice every page view.

versions

"rn-viewpager": "^1.1.4",
"react": "15.4.2",
"react-native": "0.41.2",

pagingEnabled for android is supported since 0.28

Assuming this was the original reason to create this package, it looks like pagingEnabled/horizontal is supported in Android now

<ScrollView pagingEnabled={true}>

Is the main reason to use this library for paging controls? Why use ViewPagerAndroid at all? That would be a helpful addition to the docs.

Problems when used inside a ListView

<ListView
        renderHeader = {this.starter}
        dataSource={this.state.dataSource2}
...etc
/>
...
starter()
{
    return (
        <View style = {{flex: 1}}>
            <ProfileCard/>
            <IndicatorViewPager style={{height: height/2.75}}>
                <View>
                    <TelcoMainCard/>
                </View>
                <View>
                    <TelcoPlanSingle/>
                </View>
                <View>
                    <ServicesCardMain/>
                </View>
                <View>
                    <MyDeviceCard/>
                </View>
            </IndicatorViewPager>
        </View>
    );
},

This is some of the extracted code from one of my files.
(1) The IndicatorViewPager shows nothing until i change the size of another component at runtime (there is a button on the screen that changes a box's height, in the listview. The button and the box are not within IndicatorViewPager).

(2)Also, if i scroll down too much in the listView's rendered items and then come up to the IndicatorViewPager, it stops acting like View Pager and works like a normal ScrollView, until i click that button again.

More info: The box's size changes by changing the height of another view using the state.
e.g.
height: this.state.boxHeight and then i change the height using setState.
The box is ProfileCard in the code i pasted above.

是否支持IndicatorViewPager嵌套,目前测试显示有问题

 render() {
        return (
            <Animated.View style={{flex: 1}}>



            <IndicatorViewPager
            style={{flex: 1}}
            indicator={this._renderTabIndicator()}
            onPageScroll={this._onPageScroll.bind(this)}
            initialPage={0}
            >

            <View>
            <IndicatorViewPager
            style={{flex: 1}}
            indicator={this._renderIndicator()}
            onPageScroll={this._onNormalPageScroll.bind(this)}
            >

             <View>
            <Text>page 1</Text>
            </View>

            <View>
            <Text>page 2</Text>
            </View>

            <View>
            <Text>page 3</Text>
            </View>

            <View>
            <Text>page 4</Text>
            </View>

            </IndicatorViewPager>
            </View>




            <View style={{backgroundColor:'cornflowerblue'}}>
            <Text>page two</Text>
            </View>

            <View style={{backgroundColor:'#1AA094'}}>
            <Text>page three</Text>
            </View>

            </IndicatorViewPager>
            </Animated.View>
            );
}

外层为tab,内层为nod,内层不用View包裹时,
滑动时,底部的position不对,第一个ViewPager中的小圆点不显示;

如果用View包裹里面的IndicatorViewPager后,里面的viewpager中内容无法显示,只显示4个小圆点。

Manually swiping pages does not work on Android

Swiping the pages manually (for example in the demo app, but also in my own projects) results in the error:

Cannot read property 'onPageSelected' of undefined

Object._onPageSelectedOnAndroid [as onPageSelected]
    ...ViewPager.js:72:23
ViewPagerAndroid._this_.onPageSelected
    ...ViewPagerAndroid.android.js:201:17

Otherwise the demo code works great with the automatic scrolling, the tab switching and the bottom tab bar. It is just the manual swiping which does not work.

I have tried to pass onPageSelected() function into props but was unable to get that working.

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.