如何获取我所在的页码?ViewPager 反应本机

cri*_*res 2 android android-viewpager viewpagerindicator react-native

我正在使用react-native-community的ViewPager来向下滚动我的页面,但是在捕获用户所在的页面时遇到了麻烦,在API中有一个 showPageIndicator: boolean 但仅适用于IOS,我想我们可以通过这个 bool 捕获 IOS 中的号码,有某种方法可以捕获该号码。

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

<ViewPager
            initialPage={0}
            orientation="horizontal"
            scrollEnabled
            onPageSelected={changePage}
>
Run Code Online (Sandbox Code Playgroud)

小智 14

您可以使用 OnPageSelected Prop 来获取位置。

<ViewPager
        initialPage={0}
        orientation="horizontal"
        scrollEnabled
        onPageSelected={e => {console.log("Current page index", e.nativeEvent.position)}}>
Run Code Online (Sandbox Code Playgroud)