react-native-pager-view
react-native-pager-view copied to clipboard
setPage is not working (Testing on Android)
pagerRef.current.setPage(next) using this to set the page. But then how to get active page.
from usePagerView activePage is not updating
I can confirm it's not working.
checking
It's now working. Version 6.8.1
Whoever is facing the same issue here is my workaround.
- Add
onPageSelectedcallback to theAnimatedPagerView. It returns theposition. - Declare the position as state and rely on position of
activePagethat 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>
any update
@MrRefactor
also having this after upgrading to new arch
Same issue after enabled new arch