Repository navigation
Description
Environment
React native 73 with react-native-pager-view version 6.2.0 required by react-native-tab-view.
iOS 17 or 18
Description
I’m using the react-native-gesture-handler/PanGestureHandler and react-native/Animated.View to have a swipeable card where, when doing a left swipe, it shows a button under the card at the right. After upgrading to react-native-pager-view version 6.2.0 on iOS, the behaviour started failing. When doing horizontal swipes on my card, the event.nativeEvent.velocityX was always 0 from the onHandlerStateChange of the PanGestureHandler, so I was not able to recognize the left-right swipe.
This PR sounds related to that failure. Using a patch, I removed the gestureRecognizer, and it fixed my issue. I’m not sure I fully understand the why, though since I’m no iOS pro. I also observed that only a press seems possible, no swipe
Reproducible Demo
Used lib
"react-native": "0.73.9"
"react-native-reanimated": "3.16.6",
"react-native-screens": "3.35.0",
"react-native-pager-view": "6.2.0",
"react-native-tab-view": "3.1.1",
Snippet:
const minDist = 40;
const activeOffsetX: [number, number] = [-minDist, minDist];
const onHandlerStateChange = (event: PanGestureHandlerStateChangeEvent) => {
console.log('event.nativeEvent.velocityX', event.nativeEvent.velocityX);
};
const topLayerAnimatedStyle = [{ zIndex: 1 }, { transform: [{ translateX }] }];
const onGestureEvent = (event: PanGestureHandlerGestureEvent) => {
dragX.setValue(event.nativeEvent.translationX + offsetX);
};
return (
<>
<PanGestureHandler
activeOffsetX={activeOffsetX}
onGestureEvent={onGestureEvent}
onHandlerStateChange={onHandlerStateChange}
>
<Animated.View style={topLayerAnimatedStyle}>{children}</Animated.View>
</PanGestureHandler>
</>
);With my patch or on version 6.1.4 my output is:
LOG event.nativeEvent.velocityX 0
LOG event.nativeEvent.velocityX -1002.9360699191757
LOG event.nativeEvent.velocityX -245.47632455384255
LOG event.nativeEvent.velocityX 0
LOG event.nativeEvent.velocityX -1249.3361543957585
LOG event.nativeEvent.velocityX -63.76235796194474
LOG event.nativeEvent.velocityX 0
LOG event.nativeEvent.velocityX -2644.1441499830335
LOG event.nativeEvent.velocityX -16.774982503172016
LOG event.nativeEvent.velocityX 0
LOG event.nativeEvent.velocityX -581.1156704515844
LOG event.nativeEvent.velocityX -20.014514665633452
LOG event.nativeEvent.velocityX 0
LOG event.nativeEvent.velocityX -1642.6676575322836
LOG event.nativeEvent.velocityX -36.247993423507644
LOG event.nativeEvent.velocityX 0
LOG event.nativeEvent.velocityX 2148.9406521571445
LOG event.nativeEvent.velocityX 820.4758208075385
LOG event.nativeEvent.velocityX 0
LOG event.nativeEvent.velocityX -977.1913252058387
LOG event.nativeEvent.velocityX -117.93175092593243
After upgrading to 6.2.0 or without my patch, I have the below output, and the swipe does not work; only the press seems to occur, explaining why I have less output than above.
LOG event.nativeEvent.velocityX 0
LOG event.nativeEvent.velocityX 0
LOG event.nativeEvent.velocityX 0
LOG event.nativeEvent.velocityX 0
LOG event.nativeEvent.velocityX 0
LOG event.nativeEvent.velocityX 0
Note: I tried upgrading to "react-native-tab-view": "4.0.5", but it did not fix the issue!
Activity
[-]`event.nativeEvent.velocityX` of `react-native-gesture-handler/PanGestureHandler` is always 0[/-][+]`velocityX` of `PanGestureHandler` is always 0[/+]dprevost-LMI commentedon Feb 21, 2025
The patch I used:
[-]`velocityX` of `PanGestureHandler` is always 0[/-][+]`velocityX` of `PanGestureHandler` is always 0 because of `gestureRecognizer`[/+][-]`velocityX` of `PanGestureHandler` is always 0 because of `gestureRecognizer`[/-][+]`velocityX` of `PanGestureHandler` is always 0 because of `gestureRecognizer` on iOS[/+][-]`velocityX` of `PanGestureHandler` is always 0 because of `gestureRecognizer` on iOS[/-][+](iOS) `velocityX` of `PanGestureHandler` is always 0 because of `gestureRecognizer`[/+]dprevost-LMI commentedon Feb 22, 2025
By searching a bit more, the PR mentioned seems to have spilled a lot of ink:
So it would be appreciated if this issue could be looked into and maybe have a little push in merging #933?
Meanwhile, for others, using the above patch or this smaller patch will indeed unblock you!
Update: I tried the smaller patch, and it works, but only in my first tab and not in other tabs! So, I revert the PR completely
marsakt commentedon Mar 27, 2025
Small update from my side, I wanted to use / create the patch for the latest version:
package.json:
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
"react-native-pager-view": "6.7.0",
following content has to be stored in \patches\react-native-pager-view+6.7.0.patch
it works for me, I have nested react native pager views and scrolling works for both of them.
But I would like to ask you if somebody can create / finish / merge PR which will fix this problem on iOS
Thank you very much !!!
MrRefactor commentedon Apr 30, 2025
I will be looking into that
MrRefactor commentedon May 30, 2025
Closing, released 6.8.1 with a fix for this
dprevost-LMI commentedon Jun 5, 2025
I have just upgraded, and that fixed my issue. Thank you!