13 thoughts on “undefined is not an object (evaluating ‘RNGestureHandlerModule.State’)

  1. I had a similar issue. I’m using CocoaPods instead of react-native link.

    Add this to your podfile:

    pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler/ios'
    
  2. Hi i solved it now what i did was is to create a new RN project using react-native init nameOfYourProject and install the following:

    npm install --save react-native-gesture-handler
    react-native link react-native-gesture-handler
    

    and edit my MainActivity and MainApplication:

    android\app\src\main\java\com\nameOfYourProject\MainActivity.java

    package com.mlguide; // make sure you change it to your project's name, mine is com.mlguide 
    
    import com.facebook.react.ReactActivity;
    import com.facebook.react.ReactActivityDelegate;
    import com.facebook.react.ReactRootView;
    import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
    
    public class MainActivity extends ReactActivity {
    
        /**
         * Returns the name of the main component registered from JavaScript.
         * This is used to schedule rendering of the component.
         */
        @Override
        protected String getMainComponentName() {
            return "mlguide"; // this one too
        }
    
        @Override
        protected ReactActivityDelegate createReactActivityDelegate() {
          return new ReactActivityDelegate(this, getMainComponentName()) {
            @Override
            protected ReactRootView createRootView() {
                return new RNGestureHandlerEnabledRootView(MainActivity.this);
          }
        };
      }
    }
    
    

    android\app\src\main\java\com\nameOfYourProject\MainApplication.java

    package com.mlguide; // change it
    
    import android.app.Application;
    
    import com.facebook.react.ReactApplication;
    import com.oblador.vectoricons.VectorIconsPackage; // Remove this, this another library i use for my project
    import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
    import com.facebook.react.ReactNativeHost;
    import com.facebook.react.ReactPackage;
    import com.facebook.react.shell.MainReactPackage;
    import com.facebook.soloader.SoLoader;
    
    import java.util.Arrays;
    import java.util.List;
    
    public class MainApplication extends Application implements ReactApplication {
    
      private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
          return BuildConfig.DEBUG;
        }
    
        @Override
        protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
                new VectorIconsPackage(), // This one too
                new RNGestureHandlerPackage()
          );
        }
    
        @Override
        protected String getJSMainModuleName() {
          return "index";
        }
      };
    
      @Override
      public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
      }
    
      @Override
      public void onCreate() {
        super.onCreate();
        SoLoader.init(this, /* native exopackage */ false);
      }
    }
    
    
  3. @kmagiera Lots of people integrate React Native into an existing project instead of starting from scratch. This often means using CocoaPods instead of react-native link. Some instructions for this use case would probably help immensely, especially since the Podfile isn’t in the root directory.

  4. I was also getting the same issue. What I did was delete the app from my iPhone simulator and then go to Hardware -> Erase all content & settings. After that I reinstalled the app and everything worked fine after that 🙂

  5. I solved it by adding RNGestureHandlerPackage() to the ReactInstanceManagerBuilder‘s list of packages, manually. @kmagiera Is this something that can be added in the documentation, particularly, for the cases when developer is adding react-native to the existing native android apps? I am happy to help.

  6. Change pod path for RNGestureHandler to ../node_modules/react-native-gesture-handler, @MIyulong

    pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler'
  7. I had the same problem in iOS, solved by manual installation:

    • open node_modules/react-native-gesture-handler/ios/
    • finder will show up
    • drag the dir RNGestureHandler.xcodeproj to Libraries in the top of Xcode
    • select only reference and create group if the dialog shows up
    • follow @cmcaboy
      #205 (comment)

    I think it is helpful if this alternative procedure is written in the document of Getting Started > Installation section.

    image 2018-12-26 13-11-05

  8. If you are using react-link to link your dependencies:
    1/ open your ios Podfile and delete all yout linked dependencies: pod ‘xxxxxxx’, :path => ‘../node_modules/xxxxx’
    2/ Close Xcode
    3/ In your /ios folder run “pod update”
    4/ In your project source run “react-native link”
    5/ Open Xcode and Clean Build Folder from Xcode Menu -> Product
    6/ Run your application from Xcode
    7/ Link manually the dependency “react-native-gesture-handler” into your Xcode Project following steps in documentation: https://facebook.github.io/react-native/docs/linking-libraries-ios
    8/ Now run your application from Xcode, you should be fine.

  9. I was able to fix this by following @acro5piano‘s recommendation, but I had to also add libRNGestureHandler.a to General -> Linked Frameworks and Libraries section.

    More or less, I had to manually link. react-native link did not work for my project.

  10. I was having same problem in Android Emulator
    Here’s what I did

    • Deleted node_modules

    • npm install (or yarn install if you’re using yarn)

    • npm install --save react-navigation (or for yarn yarn add react-navigation)

    • npm install --save react-native-gesture-handler (yarn: yarn add react-native-gesture-handler)

    • Open YourApp > android > app > build.gradle
      into dependencies block add the following line

    implementation project(':react-native-gesture-handler')

    • Open YourApp > android > settings.gradle
      add following lines

    include ':react-native-gesture-handler'
    project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')

  11. This will solve the problem make sure you run npm install after adding the lib in react project
    pod ‘RNGestureHandler’, :path => ‘../node_modules/react-native-gesture-handler’