React-native-gesture-handler: Unhandled JS Exception: undefined is not an object (evaluating 'RNGestureHandlerModule.State')

Created on 24 Jan 2019  路  7Comments  路  Source: software-mansion/react-native-gesture-handler

When my project displayed this error, I ran the console command as recommended
npm install --save react-navigation
npm install --save react-native-gesture-handler
react-native link react-native-gesture-handler
But my mistake didn't go away, and then I used the pod method
pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler/ios'
But unfortunately, my program still shows this error, so I can do nothing and ask my friend for help

Android

Most helpful comment

I'm seeing the same problem. I've been able to set it up properly with iOS using pods, however with Android it throws this error.

I have to manually link so here's what I have setup:

app/build.gradle:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation "com.facebook.react:react-native:$rootProject.ext.reactNative"
    // From node_modules
    implementation 'com.amazonaws:aws-android-sdk-cognito:2.10.0'
    implementation 'com.amazonaws:aws-android-sdk-cognitoauth:2.10.0@aar'
    implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.10.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.jakewharton.timber:timber:4.7.0'
    implementation 'com.android.support:support-media-compat:28.0.0'
    implementation 'com.android.support:customtabs:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation project(':react-native-gesture-handler')
}

Then settings.gradle:

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

include: ':app'

Lastly MainActivity.java:

import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

public class MainActivity extends ReactActivity {
    @Override
    protected ReactActivityDelegate createReactActivityDelegate() {
        return new ReactActivityDelegate(this, "myawesomeproject") {
            @Override
            protected ReactRootView createRootView() {
                // This is required for react-navigation
                return new RNGestureHandlerEnabledRootView(MainActivity.this);
            }
        };
    }
}

EDIT. This now works after I added the last step to manually linking the project.
Updated MainApplication.java:

import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;

public class MainApplication extends Application implements ReactApplication, INotificationsApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
             // Other dependencies here
              new RNGestureHandlerPackage()
      );
    }
}

Some instructions that pertain to this: https://reactnavigation.org/docs/en/getting-started.html

All 7 comments

Have the same issue in the latest version "^1.0.14"

Cannot read property 'State' of undefined in 'GestureHandler.js'

the module NativeModules.RNGestureHandlerModule is unrecognised

it seems the linking to the native code not working well

Excuse me. How to solve this problem

I'm seeing the same problem. I've been able to set it up properly with iOS using pods, however with Android it throws this error.

I have to manually link so here's what I have setup:

app/build.gradle:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation "com.facebook.react:react-native:$rootProject.ext.reactNative"
    // From node_modules
    implementation 'com.amazonaws:aws-android-sdk-cognito:2.10.0'
    implementation 'com.amazonaws:aws-android-sdk-cognitoauth:2.10.0@aar'
    implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.10.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.jakewharton.timber:timber:4.7.0'
    implementation 'com.android.support:support-media-compat:28.0.0'
    implementation 'com.android.support:customtabs:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation project(':react-native-gesture-handler')
}

Then settings.gradle:

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

include: ':app'

Lastly MainActivity.java:

import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

public class MainActivity extends ReactActivity {
    @Override
    protected ReactActivityDelegate createReactActivityDelegate() {
        return new ReactActivityDelegate(this, "myawesomeproject") {
            @Override
            protected ReactRootView createRootView() {
                // This is required for react-navigation
                return new RNGestureHandlerEnabledRootView(MainActivity.this);
            }
        };
    }
}

EDIT. This now works after I added the last step to manually linking the project.
Updated MainApplication.java:

import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;

public class MainApplication extends Application implements ReactApplication, INotificationsApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
             // Other dependencies here
              new RNGestureHandlerPackage()
      );
    }
}

Some instructions that pertain to this: https://reactnavigation.org/docs/en/getting-started.html

Same issue on iOS :/

Same issue on iOS :/

Follow this steps by Facebook. Steps 1-2 Manual Linking worked for me.

I am facing the same issue in ios ..anyone found the solution

Manual linking should resolve this problem. If that not a case please reply with repo containing repro example.

Was this page helpful?
0 / 5 - 0 ratings