{"id":13679304,"url":"https://github.com/callstack/react-native-pager-view","last_synced_at":"2025-05-14T09:06:23.080Z","repository":{"id":37369577,"uuid":"169435703","full_name":"callstack/react-native-pager-view","owner":"callstack","description":"React Native wrapper for the Android ViewPager and iOS UIPageViewController.","archived":false,"fork":false,"pushed_at":"2025-04-22T16:48:34.000Z","size":39653,"stargazers_count":2959,"open_issues_count":144,"forks_count":445,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-05-14T09:03:46.976Z","etag":null,"topics":["android","hacktoberfest","ios","react-native"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/callstack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-02-06T16:17:45.000Z","updated_at":"2025-05-14T06:10:23.000Z","dependencies_parsed_at":"2023-10-14T17:13:58.078Z","dependency_job_id":"4912363a-e453-457f-bd0a-57f32c89e107","html_url":"https://github.com/callstack/react-native-pager-view","commit_stats":{"total_commits":540,"total_committers":137,"mean_commits":"3.9416058394160585","dds":0.8962962962962963,"last_synced_commit":"e1a677b832a12a7260ae1dd23c90cbff2008d784"},"previous_names":["callstack/react-native-viewpager","react-native-community/react-native-viewpager"],"tags_count":126,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/callstack%2Freact-native-pager-view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/callstack%2Freact-native-pager-view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/callstack%2Freact-native-pager-view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/callstack%2Freact-native-pager-view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/callstack","download_url":"https://codeload.github.com/callstack/react-native-pager-view/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254110374,"owners_count":22016391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","hacktoberfest","ios","react-native"],"created_at":"2024-08-02T13:01:04.088Z","updated_at":"2025-05-14T09:06:23.054Z","avatar_url":"https://github.com/callstack.png","language":"TypeScript","readme":"# react-native-pager-view \u003cimg src=\"img/viewpager-logo.png\" alt=\"ViewPager\" width=\"24\" height=\"24\"\u003e\n\n[![npm package](https://badge.fury.io/js/react-native-pager-view.svg)](https://badge.fury.io/js/react-native-pager-view)\n[![Lean Core Extracted](https://img.shields.io/badge/Lean%20Core-Extracted-brightgreen.svg)](https://github.com/facebook/react-native/issues/23313)\n[![License](https://img.shields.io/github/license/callstack/react-native-pager-view?color=blue)](https://github.com/callstack/react-native-pager-view/blob/master/LICENSE)\n\n[![Lint](https://github.com/callstack/react-native-pager-view/actions/workflows/main.yml/badge.svg)](https://github.com/callstack/react-native-pager-view/actions/workflows/main.yml)\n[![iOS Build](https://github.com/callstack/react-native-pager-view/actions/workflows/ios.yml/badge.svg)](https://github.com/callstack/react-native-pager-view/actions/workflows/ios.yml)\n[![Android Build](https://github.com/callstack/react-native-pager-view/actions/workflows/android.yml/badge.svg)](https://github.com/callstack/react-native-pager-view/actions/workflows/android.yml)\n\nThis component allows the user to swipe left and right through pages of data. Under the hood it is using the native [Android ViewPager](https://developer.android.com/jetpack/androidx/releases/viewpager2) and the [iOS UIPageViewController](https://developer.apple.com/documentation/uikit/uipageviewcontroller) implementations. [See it in action!](https://github.com/callstack/react-native-pager-view#preview)\n\n\u003cbr/\u003e\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"img/vp-carousel.gif\" alt=\"ViewPager\" width=\"300\"\u003e\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\n## Versions\n\n| 4.x        | 5.x and above |\n| ---------- | ------------- |\n| iOS        | iOS support   |\n| ViewPager1 | ViewPager2    |\n\n## Migration\n\nIn version **6.x** support for `transitionStyle` property has been dropped. More information [here](https://github.com/callstack/react-native-pager-view/blob/master/MIGRATION.md).\n\n`\"@react-native-community/viewpager\"` library has been changed to `react-native-pager-view`. Here you can find more information, how to migrate pager view to the latest [version](https://github.com/callstack/react-native-pager-view/blob/master/MIGRATION.md)\n\n## Getting started\nBun: \n\n`bun add react-native-pager-view`\n\nYarn:\n\n `yarn add react-native-pager-view`\n\n## Linking\n\n### \u003e= 0.60\n\nAutolinking will just do the job.\n\n### \u003c 0.60\n\n#### Mostly automatic\n\n`react-native link react-native-pager-view`\n\n#### Manual linking\n\n\u003cdetails\u003e\n\u003csummary\u003eManually link the library on iOS\u003c/summary\u003e\n\u003c/br\u003e\n\nFollow the [instructions in the React Native documentation](https://facebook.github.io/react-native/img/linking-libraries-ios#manual-linking) to manually link the framework or link using [Cocoapods](https://cocoapods.org) by adding this to your `Podfile`:\n\n```ruby\npod 'react-native-pager-view', :path =\u003e '../node_modules/react-native-pager-view'\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eManually link the library on Android\u003c/summary\u003e\n\u003c/br\u003e\nMake the following changes:\n\n#### `android/settings.gradle`\n\n```groovy\ninclude ':react-native-pager-view'\nproject(':react-native-pager-view').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-pager-view/android')\n```\n\n#### `android/app/build.gradle`\n\n```groovy\ndependencies {\n   ...\n   implementation project(':react-native-pager-view')\n}\n```\n\n#### `android/app/src/main/.../MainApplication.java`\n\nOn top, where imports are:\n\nAdd `import com.reactnativepagerview.PagerViewPackage;`\n\nAdd the `PagerViewPackage` class to your list of exported packages.\n\n```java\n@Override\nprotected List\u003cReactPackage\u003e getPackages() {\n  return Arrays.\u003cReactPackage\u003easList(\n    new MainReactPackage(),\n    new PagerViewPackage()\n  );\n}\n```\n\n\u003c/details\u003e\n\n## Usage\n\n```js\nimport React from 'react';\nimport { StyleSheet, View, Text } from 'react-native';\nimport PagerView from 'react-native-pager-view';\n\nconst MyPager = () =\u003e {\n  return (\n    \u003cPagerView style={styles.pagerView} initialPage={0}\u003e\n      \u003cView key=\"1\"\u003e\n        \u003cText\u003eFirst page\u003c/Text\u003e\n      \u003c/View\u003e\n      \u003cView key=\"2\"\u003e\n        \u003cText\u003eSecond page\u003c/Text\u003e\n      \u003c/View\u003e\n    \u003c/PagerView\u003e\n  );\n};\n\nconst styles = StyleSheet.create({\n  pagerView: {\n    flex: 1,\n  },\n});\n```\n\n**Attention:** Note that you can only use `View` components as children of `PagerView` (cf. folder _/example_)\n. For Android if `View` has own children, set prop `collapsable` to false \u003chttps://reactnative.dev/docs/view#collapsable-android\u003e, otherwise react-native might remove those children views and and its children will be rendered as separate pages\n\n## Advanced usage\n\nFor advanced usage please take a look into our [example project](https://github.com/callstack/react-native-pager-view/blob/master/example/src/BasicPagerViewExample.tsx)\n\n## API\n\n| Prop                                                                 |                                                                                                                             Description                                                                                                                             | Platform |\n| -------------------------------------------------------------------- | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------: |\n| `initialPage`                                                        |                                                                                                            Index of initial page that should be selected                                                                                                            |   both   |\n| `scrollEnabled: boolean`                                             |                                                                                                            Should pager view scroll, when scroll enabled                                                                                                            |   both   |\n| `onPageScroll: (e: PageScrollEvent) =\u003e void`                         |                                                    Executed when transitioning between pages (ether because the animation for the requested page has changed or when the user is swiping/dragging between pages)                                                    |   both   |\n| `onPageScrollStateChanged: (e: PageScrollStateChangedEvent) =\u003e void` |                                                                                                      Function called when the page scrolling state has changed                                                                                                      |   both   |\n| `onPageSelected: (e: PageSelectedEvent) =\u003e void`                     |                                                                                      This callback will be called once the ViewPager finishes navigating to the selected page                                                                                       |   both   |\n| `pageMargin: number`                                                 |                                                                                                                Blank space to be shown between pages                                                                                                                |   both   |\n| `keyboardDismissMode: ('none' / 'on-drag')`                          |                                                                                                Determines whether the keyboard gets dismissed in response to a drag                                                                                                 |   both   |\n| `orientation: Orientation`                                           |                                                                                       Set `horizontal` or `vertical` scrolling orientation (it does **not** work dynamically)                                                                                       |   both   |\n| `overScrollMode: OverScrollMode`                                     |                                                                              Used to override default value of overScroll mode. Can be `auto`, `always` or `never`. Defaults to `auto`                                                                              | Android  |\n| `offscreenPageLimit: number`                                         | Set 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  |\n| `overdrag: boolean`                                                  |                                                                                   Allows for overscrolling after reaching the end or very beginning or pages. Defaults to `false`                                                                                   |   iOS    |\n| `layoutDirection: ('ltr' / 'rtl' / 'locale')`                        |                                                      Specifies layout direction. Use `ltr` or `rtl` to set explicitly or `locale` to deduce from the default language script of a locale. Defaults to `locale`                                                      |   both   |\n\n| Method                                     |                                                                                                         Description                                                                                                          | Platform |\n| ------------------------------------------ | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------: |\n| `setPage(index: number)`                   |                                                                      Function to scroll to a specific page in the PagerView. Invalid index is ignored.                                                                       |   both   |\n| `setPageWithoutAnimation(index: number)`   |                                                                      Function to scroll to a specific page in the PagerView. Invalid index is ignored.                                                                       |   both   |\n| `setScrollEnabled(scrollEnabled: boolean)` | A helper function to enable/disable scroll imperatively. The recommended way is using the scrollEnabled prop, however, there might be a case where a imperative solution is more useful (e.g. for not blocking an animation) |   both   |\n\n## Contributing\n\nSee the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.\n\n## Known Issues\n\n- `flex:1` does not work for child views, please use `width: '100%', height: '100%'` [instead](https://github.com/callstack/react-native-pager-view/issues/186#issuecomment-675320732)\n\n- [iOS]: In case of `UIViewControllerHierarchyInconsistency` error, please use below fix:\n\n```\nrequestAnimationFrame(() =\u003e refPagerView.current?.setPage(index));\n```\n\n## Preview\n\n### Android\n\n|                            horizontal                             |                                  vertical                                  |\n| :---------------------------------------------------------------: | :------------------------------------------------------------------------: |\n| \u003cimg src=\"img/android-viewpager.gif\" alt=\"ViewPager\" width=\"325\"\u003e | \u003cimg src=\"img/android-viewpager-vertical.gif\" alt=\"ViewPager\" width=\"325\"\u003e |\n\n### iOS\n\n|                              horizontal                              |                                vertical                                |\n| :------------------------------------------------------------------: | :--------------------------------------------------------------------: |\n| \u003cimg src=\"img/ios-viewpager-scroll.gif\" alt=\"ViewPager\" width=\"325\"\u003e | \u003cimg src=\"img/ios-viewpager-vertical.gif\" alt=\"ViewPager\" width=\"325\"\u003e |\n\n## Reanimated onPageScroll handler\n\nAn example can be found [here](https://github.com/callstack/react-native-pager-view/blob/master/example/src/ReanimatedOnPageScrollExample.tsx)\n\n#### Instructions\n\nTo attach reanimated handler with `onPageScroll` follow the below steps.\n\n```jsx\n// 1. Define the handler\nfunction usePageScrollHandler(handlers, dependencies) {\n  const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);\n  const subscribeForEvents = ['onPageScroll'];\n\n  return useEvent(\n    (event) =\u003e {\n      'worklet';\n      const { onPageScroll } = handlers;\n      if (onPageScroll \u0026\u0026 event.eventName.endsWith('onPageScroll')) {\n        onPageScroll(event, context);\n      }\n    },\n    subscribeForEvents,\n    doDependenciesDiffer\n  );\n}\n\n// 2. Attach the event handler\nimport PagerView from 'react-native-pager-view';\nimport Animated from 'react-native-reanimated';\nconst AnimatedPagerView = Animated.createAnimatedComponent(PagerView);\n\nconst pageScrollHandler = usePageScrollHandler({\n  onPageScroll: (e) =\u003e {\n    'worklet';\n    offset.value = e.offset;\n    console.log(e.offset, e.position);\n  },\n});\n\n\u003cAnimatedPagerView onPageScroll={pageScrollHandler} /\u003e;\n```\n\n## usePagerView Hook Usage\nThe `usePagerView` hook is a convenient way to manage the state and control the behavior of the `\u003cPagerView /\u003e` component. It provides functions and variables to interact with the pager, such as navigating between pages and enabling/disabling scrolling.\n\nBelow is an example of how to use the usePager hook:\n\n```jsx\nexport function PagerHookExample() {\n  const { AnimatedPagerView, ref, ...rest } = usePagerView({ pagesAmount: 10 });\n  \n  return (\n    \u003cSafeAreaView style={styles.container}\u003e\n      \u003cAnimatedPagerView\n        testID=\"pager-view\"\n        ref={ref}\n        style={styles.PagerView}\n        initialPage={0}\n        layoutDirection=\"ltr\"\n        overdrag={rest.overdragEnabled}\n        scrollEnabled={rest.scrollEnabled}\n        onPageScroll={rest.onPageScroll}\n        onPageSelected={rest.onPageSelected}\n        onPageScrollStateChanged={rest.onPageScrollStateChanged}\n        pageMargin={10}\n        orientation=\"horizontal\"\n      \u003e\n        {useMemo(\n          () =\u003e\n            rest.pages.map((_, index) =\u003e (\n              \u003cView\n                testID=\"pager-view-content\"\n                key={index}\n                style={{\n                  flex: 1,\n                  backgroundColor: '#fdc08e',\n                  alignItems: 'center',\n                  padding: 20,\n                }}\n                collapsable={false}\n              \u003e\n                \u003cLikeCount /\u003e\n                \u003cText testID={`pageNumber${index}`}\u003e\n                  {`page number ${index}`}\n                \u003c/Text\u003e\n              \u003c/View\u003e\n            )),\n          [rest.pages]\n        )}\n      \u003c/AnimatedPagerView\u003e\n      \u003cNavigationPanel {...rest} /\u003e\n    \u003c/SafeAreaView\u003e\n  );\n}\n```\n### How the Example Works:\n\n- **Pager View Setup**: The `AnimatedPagerView` component wraps `PagerView` in React Native's animation capabilities. It accepts multiple props from the `usePager` hook, such as `overdragEnabled`, `scrollEnabled`, `onPageScroll`, `onPageSelected`, and others to manage pager behavior.\n\n- **Rendering Pages**: The pages are dynamically generated using the `rest.pages` array (initialized by `usePager`). The `useMemo` hook ensures the pages are only recomputed when necessary for performance reasons.\n\n### Conclusion\n\nThe `usePager` hook makes it easy to handle pagination with dynamic views. This example demonstrates how to set up a simple paginated interface where users can scroll through pages, interact with page elements, and control the pager with external navigation.\n\n\n## License\n\nMIT\n","funding_links":[],"categories":["Uncategorized","TypeScript"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcallstack%2Freact-native-pager-view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcallstack%2Freact-native-pager-view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcallstack%2Freact-native-pager-view/lists"}