Gathering detailed insights and metrics for @brandingbrand/react-native-pager-view
Gathering detailed insights and metrics for @brandingbrand/react-native-pager-view
Gathering detailed insights and metrics for @brandingbrand/react-native-pager-view
Gathering detailed insights and metrics for @brandingbrand/react-native-pager-view
npm install @brandingbrand/react-native-pager-view
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2,764 Stars
587 Commits
422 Forks
24 Watching
19 Branches
153 Contributors
Updated on 29 Nov 2024
TypeScript (52.04%)
Kotlin (17.63%)
Objective-C (15.53%)
Objective-C++ (9.32%)
Ruby (1.54%)
C++ (1.54%)
JavaScript (1.3%)
Makefile (0.59%)
Shell (0.51%)
Cumulative downloads
Total Downloads
Last day
-30.1%
58
Compared to previous day
Last week
43.2%
338
Compared to previous week
Last month
-21.5%
1,303
Compared to previous month
Last year
14,271.9%
13,797
Compared to previous year
2
21
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!
4.x | 5.x and above |
---|---|
iOS | iOS support |
ViewPager1 | ViewPager2 |
In version 6.x support for transitionStyle
property has been dropped. More information here.
"@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
Bun:
bun add react-native-pager-view
Yarn:
yarn add react-native-pager-view
Autolinking will just do the job.
react-native link react-native-pager-view
Follow the instructions in the React Native documentation to manually link the framework or link using Cocoapods by adding this to your Podfile
:
1pod 'react-native-pager-view', :path => '../node_modules/react-native-pager-view'
android/settings.gradle
1include ':react-native-pager-view' 2project(':react-native-pager-view').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-pager-view/android')
android/app/build.gradle
1dependencies { 2 ... 3 implementation project(':react-native-pager-view') 4}
android/app/src/main/.../MainApplication.java
On top, where imports are:
Add import com.reactnativepagerview.PagerViewPackage;
Add the PagerViewPackage
class to your list of exported packages.
1@Override 2protected List<ReactPackage> getPackages() { 3 return Arrays.<ReactPackage>asList( 4 new MainReactPackage(), 5 new PagerViewPackage() 6 ); 7}
1import React from 'react'; 2import { StyleSheet, View, Text } from 'react-native'; 3import PagerView from 'react-native-pager-view'; 4 5const MyPager = () => { 6 return ( 7 <PagerView style={styles.pagerView} initialPage={0}> 8 <View key="1"> 9 <Text>First page</Text> 10 </View> 11 <View key="2"> 12 <Text>Second page</Text> 13 </View> 14 </PagerView> 15 ); 16}; 17 18const styles = StyleSheet.create({ 19 pagerView: { 20 flex: 1, 21 }, 22});
Attention: Note that you can only use View
components as children of PagerView
(cf. folder /example)
. For Android if View
has own children, set prop collapsable
to false https://reactnative.dev/docs/view#collapsable-android, otherwise react-native might remove those children views and and its children will be rendered as separate pages
For advanced usage please take a look into our example project
Prop | Description | Platform |
---|---|---|
initialPage | Index of initial page that should be selected | both |
scrollEnabled: boolean | Should pager view scroll, when scroll enabled | both |
onPageScroll: (e: PageScrollEvent) => 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 |
onPageScrollStateChanged: (e: PageScrollStateChangedEvent) => void | Function called when the page scrolling state has changed | both |
onPageSelected: (e: PageSelectedEvent) => void | This callback will be called once the ViewPager finishes navigating to the selected page | both |
pageMargin: number | Blank space to be shown between pages | both |
keyboardDismissMode: ('none' / 'on-drag') | Determines whether the keyboard gets dismissed in response to a drag | both |
orientation: Orientation | Set horizontal or vertical scrolling orientation (it does not work dynamically) | both |
overScrollMode: OverScrollMode | Used to override default value of overScroll mode. Can be auto , always or never . Defaults to auto | Android |
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 |
overdrag: boolean | Allows for overscrolling after reaching the end or very beginning or pages. Defaults to false | iOS |
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 |
Method | Description | Platform |
---|---|---|
setPage(index: number) | Function to scroll to a specific page in the PagerView. Invalid index is ignored. | both |
setPageWithoutAnimation(index: number) | Function to scroll to a specific page in the PagerView. Invalid index is ignored. | both |
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 |
See the contributing guide to learn how to contribute to the repository and the development workflow.
flex:1
does not work for child views, please use width: '100%', height: '100%'
instead
[iOS]: In case of UIViewControllerHierarchyInconsistency
error, please use below fix:
requestAnimationFrame(() => refPagerView.current?.setPage(index));
horizontal | vertical |
---|---|
horizontal | vertical |
---|---|
An example can be found here
To attach reanimated handler with onPageScroll
follow the below steps.
1// 1. Define the handler 2function usePageScrollHandler(handlers, dependencies) { 3 const { context, doDependenciesDiffer } = useHandler(handlers, dependencies); 4 const subscribeForEvents = ['onPageScroll']; 5 6 return useEvent( 7 (event) => { 8 'worklet'; 9 const { onPageScroll } = handlers; 10 if (onPageScroll && event.eventName.endsWith('onPageScroll')) { 11 onPageScroll(event, context); 12 } 13 }, 14 subscribeForEvents, 15 doDependenciesDiffer 16 ); 17} 18 19// 2. Attach the event handler 20import PagerView from 'react-native-pager-view'; 21import Animated from 'react-native-reanimated'; 22const AnimatedPagerView = Animated.createAnimatedComponent(PagerView); 23 24const pageScrollHandler = usePageScrollHandler({ 25 onPageScroll: (e) => { 26 'worklet'; 27 offset.value = e.offset; 28 console.log(e.offset, e.position); 29 }, 30}); 31 32<AnimatedPagerView onPageScroll={pageScrollHandler} />;
The usePagerView
hook is a convenient way to manage the state and control the behavior of the <PagerView />
component. It provides functions and variables to interact with the pager, such as navigating between pages and enabling/disabling scrolling.
Below is an example of how to use the usePager hook:
1export function PagerHookExample() { 2 const { AnimatedPagerView, ref, ...rest } = usePagerView({ pagesAmount: 10 }); 3 4 return ( 5 <SafeAreaView style={styles.container}> 6 <AnimatedPagerView 7 testID="pager-view" 8 ref={ref} 9 style={styles.PagerView} 10 initialPage={0} 11 layoutDirection="ltr" 12 overdrag={rest.overdragEnabled} 13 scrollEnabled={rest.scrollEnabled} 14 onPageScroll={rest.onPageScroll} 15 onPageSelected={rest.onPageSelected} 16 onPageScrollStateChanged={rest.onPageScrollStateChanged} 17 pageMargin={10} 18 orientation="horizontal" 19 > 20 {useMemo( 21 () => 22 rest.pages.map((_, index) => ( 23 <View 24 testID="pager-view-content" 25 key={index} 26 style={{ 27 flex: 1, 28 backgroundColor: '#fdc08e', 29 alignItems: 'center', 30 padding: 20, 31 }} 32 collapsable={false} 33 > 34 <LikeCount /> 35 <Text testID={`pageNumber${index}`}> 36 {`page number ${index}`} 37 </Text> 38 </View> 39 )), 40 [rest.pages] 41 )} 42 </AnimatedPagerView> 43 <NavigationPanel {...rest} /> 44 </SafeAreaView> 45 ); 46}
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.
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.
The 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.
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
24 commit(s) and 13 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
binaries present in source code
Details
Reason
Found 19/28 approved changesets -- score normalized to 6
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More