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

UseRef in android does not setPage if route changes (works in IOS)

Open AyoParadis opened this issue 1 year ago • 2 comments

Im using expo router v.3. I’m accessing the ref via my global state manager in another component (screen header). Everything works in IOS as expected, but in android if i replace the route, the ref becomes null immediately and the page stays on the current page.

const showDialog = () => {
    Alert.alert(
      'Hey Ayo!',
      'Are you sure you want to go back to home. You will loose all current progress.',
      [
        {
          text: 'Cancel',
          onPress: () => console.log('Cancel Pressed'),
          style: 'cancel'
        },
        {
          text: 'Go Home',
          onPress: () => {
            setCurrentMomentState({
              selectedDate: 'none',
              selectedMomentType: 'none'
            });
            (pagerViewRef.current as any).setPage(0);

            router.replace('/(protected)/(tabs)/home');
          }
        }
      ]
    );

Using a set-time around the set page call on android is a hacky solution.

AyoParadis avatar Mar 25 '24 00:03 AyoParadis

I have the same issue

Beat-YT avatar Apr 26 '24 17:04 Beat-YT

I have the same issue

For now the only workaround is using a setTimeout.

AyoParadis avatar Apr 26 '24 18:04 AyoParadis

Hey, please provide a reproduction repository.

MrRefactor avatar Nov 28 '24 06:11 MrRefactor

Or instead of using ref, please try using new usePagerView hook.

MrRefactor avatar Nov 30 '24 15:11 MrRefactor