question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

web: useAnimatedGestureHandler not working

See original GitHub issue

Description

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

Screenshots

Steps To Reproduce

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
karol-bisztygacommented, Dec 9, 2020

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

2reactions
ElForasterocommented, Nov 28, 2020

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - web: useAnimatedGestureHandler not working -
Description. That is working on android, but on the web the gesture event is not called. Screenshots. Steps To Reproduce.
Read more >
React Native Gesture Handler Not Working On Android
Everything works fine when I launch the app on the web but on android I get no feedback. I used snack to text...
Read more >
useAnimatedGestureHandler | React Native Reanimated
This hook allows for defining worklet handlers that can serve in a process of handling gestures. Before you can use the hook, make...
Read more >
Events | React Native Reanimated
const eventHandler = useAnimatedGestureHandler({ ... PanGestureHandler not only reports down and up events (that we subscribed to with onStart and onEnd ...
Read more >
Reanimated 2 - new approach to creating animations in React ...
Working with the new API is quite a pleasure and a new hooks set is ... Reanimated 2 provides us with a hook...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found