callstack / react-native-pager-view

React Native wrapper for the Android ViewPager and iOS UIPageViewController.
MIT License
2.74k stars 419 forks source link

[iOS] go back gesture does not work #315

Closed KingAmo closed 2 years ago

KingAmo commented 3 years ago

Description

Go back gesture is blocked, bc all events are captured by viewpager, hence react navigation is not aware of any pan event.

image

Reproducible Demo

Go to basic example and try to use go back gesture

troZee commented 3 years ago

Together with @mikeqcp were trying to find any viable solution. Below I am providing a result of our investigation.

svenlombaert commented 3 years ago

Same issue when using react-native-navigation. I'm using https://github.com/satya164/react-native-tab-view and it indeed seems to capture all gestures, can't swipe to open side menu as well.

marcel-happyfloat commented 3 years ago

In my old version I did use react-native-best-viewpager and both worked well, not sure if the foundation is comparable, but maybe you can check it out.

But I had to disable the gesture of the navigator when I was on the next page, so I could go back the page instead of the navigator when I was swiping close to the edge.

alantoa commented 2 years ago

+1 Same issue when using react-native-navigation.

JoniVR commented 2 years ago

FYI, for react-navigation (and perhaps also react-native-navigation): downgrading react-native-tab-view to v2.16.0 seems to resolve the issue for now.

1061750360 commented 2 years ago

I have a temporary solution. When you want to go back, you should forbid react-native-pager-view,let it can not scroll. (My English is not good, so Please understand)

This is the code:

step 1: pagerView has three child, curTabIndex is current child index. So curTabIndex === 0 is the first child,And now you wan t to go back. And the evt.nativeEvent.pageX <= 50 is true(because IOS back gesture distance Approximately equal to 50).you forbid react-native-pager-view,let it can not scroll. Now you can use gesture to go back!

  const panResponder = useRef(
      PanResponder.create({
        onMoveShouldSetPanResponder: () => true,
        onPanResponderGrant: (evt, gestureState) => {
          if (evt.nativeEvent.pageX <= 50 && curTabIndex === 0) {
            pagerViewRef.current.setScrollEnabled(false)
          }
        },
        onPanResponderRelease: () => {
          pagerViewRef.current.setScrollEnabled(true)
        }
      })
  ).current;

step 2: and add panResponder to the root node

  return (
      <View style={{width:width,height:height,display:'flex'}} {...panResponder.panHandlers}>
      ......

step 3:

          <PagerView
              style={{flex:1,backgroundColor:"#fff"}}
              ref={pagerViewRef}
              keyboardDismissMode={'on-drag'}
              orientation="horizontal"
              transitionStyle="scroll"
              layoutDirection="ltr"
              onPageSelected={(e) => onPageSelected(e.nativeEvent.position)}
          >
troZee commented 2 years ago

https://github.com/callstack/react-native-pager-view/releases/tag/v5.4.19

itsramiel commented 2 years ago

@troZee does not seem to fix it. I still can not swipe back

ChrisYohann commented 2 years ago

Hi @troZee, I have the same issue as @ramiel1999 even in 5.4.24. Cannot swipe back and using a TabView inside StackNavigator