Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch the number of the page that i'm in? ViewPager React Native

I'm using ViewPager by react-native-community to scroll down my page, but I'm having trouble when catching the page that the user is in, in the API there is a showPageIndicator: boolean but only for IOS, i figure we can catch the number in the IOS by this bool there is some way i can catch the number.

https://github.com/react-native-community/react-native-viewpager

<ViewPager
            initialPage={0}
            orientation="horizontal"
            scrollEnabled
            onPageSelected={changePage}
>
like image 569
cristiano soares Avatar asked Nov 24 '25 03:11

cristiano soares


1 Answers

You can use OnPageSelected Prop to get position.

<ViewPager
        initialPage={0}
        orientation="horizontal"
        scrollEnabled
        onPageSelected={e => {console.log("Current page index", e.nativeEvent.position)}}>
like image 183
Shoaib Ahmed Avatar answered Nov 25 '25 17:11

Shoaib Ahmed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!