react-native-pager-view icon indicating copy to clipboard operation
react-native-pager-view copied to clipboard

setPage is not working (Testing on Android)

Open rishabh-arch opened this issue 9 months ago • 7 comments

pagerRef.current.setPage(next) using this to set the page. But then how to get active page. from usePagerView activePage is not updating

rishabh-arch avatar Apr 16 '25 20:04 rishabh-arch

I can confirm it's not working.

diegolmello avatar Apr 17 '25 18:04 diegolmello

checking

MrRefactor avatar Apr 30 '25 08:04 MrRefactor

It's now working. Version 6.8.1

Whoever is facing the same issue here is my workaround.

  1. Add onPageSelected callback to the AnimatedPagerView. It returns the position.
  2. Declare the position as state and rely on position of activePage that is not updated for some reason.
const [position, setPosition] = useState(0)

const onPrevious = useCallback(() => setPage(position - 1), [position, setPage])
const onNext = useCallback(() => setPage(position + 1), [setPage, position])


  <AnimatedPagerView
       testID='pager-view'
       ref={ref}
       style={styles.container}
       initialPage={0}
       overdrag={false}
       scrollEnabled={false}
       pageMargin={0}
       orientation='horizontal'
       onPageSelected={({ nativeEvent: { position } }) => {
         setPosition(position)
       }}
     >
       {renderScreens}
     </AnimatedPagerView>

mitaxe avatar Jun 09 '25 16:06 mitaxe

any update

saadlatif75 avatar Jun 18 '25 16:06 saadlatif75

@MrRefactor

saadlatif75 avatar Jun 19 '25 05:06 saadlatif75

also having this after upgrading to new arch

mikebouwmans avatar Jun 25 '25 13:06 mikebouwmans

Same issue after enabled new arch

KestasVenslauskas avatar Aug 12 '25 16:08 KestasVenslauskas