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

onPageSelected is triggering with e.nativeEvent.position==0 after leaving tabview

Open phazei opened this issue 1 year ago • 7 comments

Environment

Android V15 only, iOS not affected

React Native 0.74.5 "react-native-pager-view": "~6.4.1", "react-native-tab-view": "~3.5.2", "@react-navigation/stack": "~6.4.1", "@react-navigation/material-top-tabs": "~6.6.14",

Description

I'm using @react-navigation/material-top-tabs. When I navigate to a view that's not part of the tab navigator, but still in a stack, it triggers a _onPageSelected originating from react-native-pager-view that causes the navigation to navigate away from the current view and to the first tab of the pager. Note, it might be triggering _onPageScrollStateChanged also? The RN debugger is finicky and sometimes it was one or the other.

A detailed description is provided here with some debugging.

Reproducible Demo

https://snack.expo.dev/@phazei/react-native-material-tab-bug?platform=android

On android, click the second tab, then click the link on the second tab and you can see it blink to the hello screen, and then be forced back to tab 1.

This was the minimal example, but in production, it actually lets it get to the hello screen, but then clicking another navigation link that's a sibling to hello, forces it back to tab 1. It's caused by the same _onPageSelected or _onPageScrollStateChanged.

phazei avatar Oct 31 '24 19:10 phazei

Hi! I am also looking for a fix or a workaround to this problem, but for the react-native-pager-view v7.0.0-rc.0.

Denys-Kozak-Paidy avatar Nov 19 '24 21:11 Denys-Kozak-Paidy

Hey, looking into that.

Hi! I am also looking for a fix or a workaround to this problem, but for the react-native-pager-view v7.0.0-rc.0.

We wont support version 7 anymore.

MrRefactor avatar Nov 29 '24 11:11 MrRefactor

Hi, any news on this issue ?

toutiii avatar Dec 24 '24 16:12 toutiii

Hi, any news on this issue ? 😊

ppmdatix avatar Feb 10 '25 15:02 ppmdatix

Hi there. Do you have any idea when this issue will be resolved? :-)

tonsnoei avatar Feb 13 '25 15:02 tonsnoei

you may try the code following ` const scrolledRef = useRef(false);

const handlePageSelected = useCallback(() => { if (!scrolledRef.current) return; scrolledRef.current = false; // your operation });

return ( <PagerView onPageSelected={handlePageSelected} onPageScroll={() => { scrolledRef.current = true; }}

); `

just filter it by watching page scroll

Mr-633 avatar Sep 30 '25 08:09 Mr-633

const scrolledRef = useRef(false);

const handlePageSelected = useCallback(() => {
if (!scrolledRef.current) return;
scrolledRef.current = false;
// your operation
});

return (
<PagerView
onPageSelected={handlePageSelected}
onPageScroll={() => {
scrolledRef.current = true;
}}

);

Mr-633 avatar Sep 30 '25 08:09 Mr-633