'Expo GestureHandler isn't firing any events

i've seen alot of people having the same problem but sadly without any solutions . I'm using expo with react native gesture handler, i have added "react-native-reanimated/plugin" in babel.config.js but still not getting any response.

Here is my code: babel.config.js

module.exports = function (api) {
  api.cache(true);
  return {
    presets: ["babel-preset-expo"],
    plugins: ["react-native-reanimated/plugin"],
  };
};

App.js

import { PanGestureHandler } from "react-native-gesture-handler";
import "react-native-gesture-handler";
import Animated, {
  useAnimatedGestureHandler,
  useAnimatedStyle,
  useSharedValue,
} from "react-native-reanimated";

import { StyleSheet, View } from "react-native";

const SIZE = 100.0;

export default function App() {
  const translateX = useSharedValue(0);
  const panGestureEvent = useAnimatedGestureHandler({
    onStart: (event) => {
      console.log("starting...");
    },
    onActive: (event) => {
      // translateX.value = event.translationX;
      console.log(event.translationX);
    },
    onEnd: (event) => {},
  });

  const rStyle = useAnimatedStyle(() => {
    return {
      transform: [{ translateX: translateX.value }],
    };
  });

  return (
    <View style={styles.container}>
      <PanGestureHandler onGestureEvent={panGestureEvent}>
        <Animated.View style={[styles.square, rStyle]} />
      </PanGestureHandler>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
  square: {
    width: SIZE,
    height: SIZE,
    backgroundColor: "dodgerblue",
    borderRadius: 15,
  },
});

i didn't do anything smart, simple and easy code, yet not getting any response.

package.json

{
  "name": "a",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "expo": "~44.0.0",
    "expo-status-bar": "~1.2.0",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-native": "0.64.3",
    "react-native-web": "0.17.1",
    "react-native-gesture-handler": "~2.1.0",
    "react-native-reanimated": "^2.3.1"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
  "private": true
}


Solution 1:[1]

On Android you need to wrap everything with GestureHandlerRootView.

So do this below

import {
    GestureHandlerRootView,
} from 'react-native-gesture-handler';

then

<GestureHandlerRootView style={{ flex: 1 }}>
    <View style={styles.container}>
        <PanGestureHandler onGestureEvent={panGestureEvent}>
            <Animated.View style={[styles.square, rStyle]} />
        </PanGestureHandler>
    </View>
</GestureHandlerRootView>

Related documentation: https://docs.swmansion.com/react-native-gesture-handler/docs/installation#js

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Soullivaneuh