Skip to content

(iOS) velocityX of PanGestureHandler is always 0 because of gestureRecognizer #972

Closed
@dprevost-LMI

Description

@dprevost-LMI

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions