React-native-reanimated: web: useAnimatedGestureHandler not working

Created on 2 Nov 2020  路  13Comments  路  Source: software-mansion/react-native-reanimated

Description

That is working on android, but on the web the gesture event is not called

Screenshots

Steps To Reproduce

1.

const gestureHandler = useAnimatedGestureHandler(
      {
        onStart: (_, ctx: any) => {
          //notCalled
        },
        onActive: (event, ctx) => {
          //notCalled
        },
        onEnd: (_) => {
          //notCalled
        },
      },
      [],
    );

Expected behavior

Actual behavior

Snack or minimal code example

Package versions

  • React: 17.0.1
  • React Native: 0.63.1
  • React Native Reanimated: 2.0.0-alpha.8
  • React Native Gesture Handler: 1.8.0
  • NodeJS: 12
馃彔 Reanimated2 馃悶 Bug 馃Лweb

Most helpful comment

@ElForastero thanks, I will reopen the issue and soon push the fix 馃檶

All 13 comments

Hi! Could you please provide reproducing repository?

In the repo, I added the gesture handler to blue box and logged into the event but nothings logged.
https://github.com/hosseinmd/test-reanimated2

Hey!
Indeed it does not work in your case, I think the problem might be that you haven't enabled reanimated's babel plugin as stated in the docs. The tool you're using apparently hides babel configuration.

So my guess is that you'd probably need to do yarn eject and then add it manually(I got an error doing yarn eject in my local environment but decided to not spend more time on this as it's unrelated - web works fine for other tools designed for creating RN app - check the playground).

I added the babel plugin in config-override.

The playground has packages versions that are not updated.
I update packages in this PR https://github.com/software-mansion-labs/reanimated-2-playground/pull/23
Now useAnimatedGestureHandler not working

The playground has packages versions that are not updated.
I update packages in this PR software-mansion-labs/reanimated-2-playground#23
Now useAnimatedGestureHandler not working

There's a known bug in RNGH and as the issue is still open I assume it's not been fixed by now. So for now please just leave react-native-web as it is(as well as react-dom - otherwise you'll end up with errors).

After doing the following changes in your repo, it works:

"react-dom": "^16.13.1",
"react-native-web": "^0.12.3",
"react-native-gesture-handler": "1.8.0",

Because of pressable and modal in react-native-web 0.14 we can't downgrade to 0.12. we need another solution.

I understand but this is a problem with RNGH, not reanimated.

The issue in RNGH was fixed, but handler still doesn't work on web.

@karol-bisztyga

Well, I finally made it working on both iOS and Web by manually defining handlers for PanGestureHandler.

useAnimatedGestureHandler works well in native but seems like does absolutely nothing in web environment. Spend a while trying to understand the source of the problem, but with no success.

  const y = useSharedValue(0);
  const startY = useSharedValue(0);

  const gestureHandler = ({ nativeEvent: e }) => {
    'worklet';
    if (e.state === State.ACTIVE) {
      console.log('active');
      y.value = startY.value + e.translationY;
    }
  };

  const gestureStateHandler = ({ nativeEvent: e }) => {
    'worklet';
    if (e.state === State.BEGAN) {
      console.log('began');
      startY.value = y.value;
    }

    if (e.state === State.END) {
      console.log('end');
      y.value = withSpring(0);
    }
  };

return (
<PanGestureHandler onHandlerStateChange={gestureStateHandler} onGestureEvent={gestureHandler}>
        <Animated.View style={[animatedStyle]} />
</PanGestureHandler>
)

"react": "16.13.1",
"react-native": "0.63.3",
"react-native-web": "^0.14.7"
"react-native-gesture-handler": "^1.9.0",
"react-native-reanimated": "^2.0.0-rc.0",

UPD:

It looks like the issue is because of this. WorkletEventHandler is being passed into RNGH instead of regular listener. 馃

image

@ElForastero thanks, I will reopen the issue and soon push the fix 馃檶

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wasim-abuzaher picture wasim-abuzaher  路  3Comments

alexfov picture alexfov  路  3Comments

WeTruck picture WeTruck  路  3Comments

nextriot picture nextriot  路  3Comments

robertgonzales picture robertgonzales  路  3Comments