5.0.11 • Published 3 years ago

@react-native-community/viewpager v5.0.11

Weekly downloads
58,517
License
MIT
Repository
github
Last release
3 years ago

react-native-viewpager

CircleCI branch npm package Lean Core Extracted License

This component allows the user to swipe left and right through pages of data. Under the hood it is using the native Android ViewPager and the iOS UIPageViewController implementations. See it in action!

Versions

3.x4.0.x, 4.1.x>= 4.2.x5.x
iOS supportDeprecatediOS supportiOS support
ViewPager1 supportDeprecatedReverted to 3.3.0ViewPager2 support

Getting started

yarn add @react-native-community/viewpager

Linking

>= 0.60

Autolinking will just do the job.

< 0.60

Mostly automatic

react-native link @react-native-community/viewpager

Manual linking

Follow the instructions in the React Native documentation to manually link the framework or link using Cocoapods by adding this to your Podfile:

pod 'react-native-viewpager', :path => '../node_modules/@react-native-community/viewpager'

android/settings.gradle

include ':@react-native-community_viewpager'
project(':@react-native-community_viewpager').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/viewpager/android')

android/app/build.gradle

dependencies {
   ...
   implementation project(':@react-native-community_viewpager')
}

android/app/src/main/.../MainApplication.java

On top, where imports are:

import com.reactnativecommunity.viewpager.RNCViewPagerPackage;

Add the RNCViewPagerPackage class to your list of exported packages.

@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
    new MainReactPackage(),
    new RNCViewPagerPackage()
  );
}

Usage

import React from 'react';
import {StyleSheet, View, Text} from 'react-native';
import ViewPager from '@react-native-community/viewpager';

const MyPager = () => {
  return (
    <ViewPager style={styles.viewPager} initialPage={0}>
      <View key="1">
        <Text>First page</Text>
      </View>
      <View key="2">
        <Text>Second page</Text>
      </View>
    </ViewPager>
  );
};

const styles = StyleSheet.create({
  viewPager: {
    flex: 1,
  },
});

Attention: Note that you can only use View components as children of ViewPager (cf. folder /example) . For Android if View has own children, set prop collapsable to false https://reactnative.dev/docs/view#collapsable, otherwise react-native might remove those children views and and it's children will be rendered as separate pages

Advanced usage

For advanced usage please take a look into our example project

API

PropDescriptionPlatform
initialPageIndex of initial page that should be selectedboth
scrollEnabled: booleanShould viewpager scroll, when scroll enabledboth
onPageScroll: (e: PageScrollEvent) => voidExecuted when transitioning between pages (ether because the animation for the requested page has changed or when the user is swiping/dragging between pages)both
onPageScrollStateChanged: (e: PageScrollStateChangedEvent) => voidFunction called when the page scrolling state has changedboth
onPageSelected: (e: PageSelectedEvent) => voidThis callback will be called once the ViewPager finishes navigating to the selected pageboth
pageMargin: numberBlank space to be shown between pagesboth
keyboardDismissMode: ('none' / 'on-drag')Determines whether the keyboard gets dismissed in response to a dragboth
orientation: OrientationSet horizontal or vertical scrolling orientation (it does not work dynamically)both
transitionStyle: TransitionStyleUse scroll or curl to change transition style (it does not work dynamically)iOS
showPageIndicator: booleanShows the dots indicator at the bottom of the viewiOS
overScrollMode: OverScollModeUsed to override default value of overScroll mode. Can be auto, always or never. Defaults to autoAndroid
offscreenPageLimit: numberSet the number of pages that should be retained to either side of the currently visible page(s). Pages beyond this limit will be recreated from the adapter when needed. Defaults to RecyclerView's caching strategy. The given value must either be larger than 0.Android
overdrag: booleanAllows for overscrolling after reaching the end or very beginning or pagesiOS

Development workflow

To get started with the project, run yarn bootstrap in the root directory to install the required dependencies.

yarn bootstrap

While developing, you can run the example to check your changes

cd example
yarn android
yarn ios

Before sending a pull rquest, make sure your code passes TypeScript and ESLint. Run the following to verify:

yarn typescript
yarn lint

To fix formatting errors, run the following:

yarn lint --fix

Preview

Android

horizontalvertical

iOS

horizontal - scrollhorizontal - curl
vertical - scrollvertical - curl
react-native-circularviewpager@tantei/react-native-scrollable-tab-view@snooper/coreframework-reactnative-component-libpbfintechfz@igen/react-native-scrollable-tab-viewlenme_component_librarymomo-component-kitsddt-react-native@infinitebrahmanuniverse/nolb-_react-n@everything-registry/sub-chunk-765poket-app-testrn-slickrn-dqgbuisavecomponentssave-mobile-componentsstatefullapicjslibrary@smuxx/react-native-scrollable-tab-viewreact-native-scroll-tab-viewreact-native-scrollable-tab-view-haidaireact-native-scrollable-tab-view-jszhreact-native-scrollable-tab-view-none-prop-typesreact-native-scrollable-tab-view-tsreact-native-scrollable-tab-viewreact-native-scrollable-tab-view-fgreact-native-scrollable-tab-view-fixedreact-native-scrollable-tab-view-twicereact-native-scrollable-tab-view-zzlyreact-native-scrollable-tabs-hybridreact-native-pager-carouselreact-native-slick-sliderreact-native-slim-galleryreact-native-tabview-exreact-native-swipe-renderreact-native-template-umbappsamplereact-native-swiper-fix-viewpagerreact-native-swiper-ajustedreact-native-tab-scrollreact-native-tab-scrollablereact-native-template-cprntemplatereact-native-top-tab-view@newbanker/react-native-scrollable-tab-viewreact-native-base-typescript-hungtruongreact-native-best-viewpagerreact-native-carouselreact-native-diaozhao-commonreact-native-diablo-uireact-native-circular-viewpagerreact-native-foocaa-librariesreact-native-gizwits-scrollable-tab-view@momo-platform/component-kitsreact-native-fluidsreact-native-liveplayerreact-native-mint-componentsreact-native-mscrollable-tabviewreact-native-igen-scrollable-tab-view@mftechio/react-native-scrollable-tab-view@react-native-matcha/components@react-native-mint/components@react-native-diy/tabview@sconnelley/react-native-top-tab-view@tungnc3/rn-scrollable-tabviewrn-rncviewpagerrishabh-edfora-libraryrn-view-pager-emern-viewpager-handyrn-viewpager-lbscrollable-tab-lmdi@shankarmorwal/rn-viewpagerzjeen-react-native-rn-scrollable-tab-viewtab-bar-primetenvine-scrollable-tab-viewzy-react-native-scrollable-tab-view@staltz/rn-viewpageredfora-common-libraryerfan-tab-header-viewfixed-react-native-scrollable-tab-viewfansapp-react-native-scrollable-tab-viewlanao-app-scrollable-tab-viewmy-rn-viewpager@eliakimtoluan/react-native-scrollable-tab-view@emadfanaian/react-native-scrollable-tab-view@eohjsc/react-native-personal-health@eohjsc/react-native-smart-parkingldq-react-native-scrollable-tab-view@dooboo-ui/native-pinch-zoom-slider-modal@dooboo-ui/pinch-zoom-slider-modal@crossinfo/react-native-scrollable-tab-viewcprntemplatekk-mobile-components-rnkk-mobile-components-rn-testcrm_componentsclwy-react-native-scrollable-tab-view@ezviz/ys-rn-pub-mini@hinh-eoh/test_publishpalette-mobilepacken-rnunicom-taro@whir-react-native/componentsantu-rn-scrollable-tab-view
5.0.10

3 years ago

5.0.11

3 years ago

5.0.9

3 years ago

5.0.8

3 years ago

4.2.4

3 years ago

5.0.6

3 years ago

4.2.3

3 years ago

5.0.7

3 years ago

4.2.2

3 years ago

5.0.5

3 years ago

5.0.4

3 years ago

5.0.3

3 years ago

4.2.1

3 years ago

5.0.2

3 years ago

4.2.0

4 years ago

4.1.7

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.1.6

4 years ago

4.1.5

4 years ago

3.3.1

4 years ago

4.1.4

4 years ago

4.1.3

4 years ago

4.1.2

4 years ago

4.1.1

4 years ago

4.1.0

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.3.0

4 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.0

4 years ago

2.0.2

4 years ago

2.0.1

5 years ago

2.0.0

5 years ago

2.0.0-rc.1

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago