1

I just started working with React Native and I wanted to use React Navigator to go to a new Screen. I followed the documentation here but I keep running into a problem.

I have an App Navigator file below

import { createStackNavigator } from 'react-navigation';
import LandingPage from './src/components/LandingPages/LandingPage';

const AppNavigator = createStackNavigator({
  Home: { screen: LandingPage },
});

export default AppNavigator;

And my App.js file is

    /**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 * @lint-ignore-every XPLATJSCOPYRIGHT1
 */

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import AppNavigator from './AppNavigator';

type Props = {};
export default class App extends Component {
  render() {
    return (
   <AppNavigator/>

   );
  }
}

However, I get the error below.

null is not an object (evaluating 'RNGestureHandlerModule.State')

<unknown>
GestureHandler.js:55:37
loadModuleImplementation
require.js:321:6
<unknown>
Swipeable.js:11
loadModuleImplementation
require.js:321:6
<unknown>
index.js:1
loadModuleImplementation
require.js:321:6
<unknown>
StackViewLayout.js:19
loadModuleImplementation
require.js:321:6
<unknown>
StackView.js:4
loadModuleImplementation
require.js:321:6
<unknown>
createStackNavigator.js:3
loadModuleImplementation
require.js:321:6
createStackNavigator
index.js:9:18
createStackNavigator
react-navigation.js:107:45
<unknown>
AppNavigator.js:4:21
loadModuleImplementation
require.js:321:6
<unknown>
App.js:13
loadModuleImplementation
require.js:321:6
<unknown>
index.js:7
loadModuleImplementation
require.js:321:6
guardedLoadModule
require.js:199:45
global code
<unknown file>:0

I have also tried

  1. remove node_modules and package-lock.json
  2. npm install
  3. npm install --save react-navigation
  4. npm install --save react-native-gesture-handler
  5. react-native link

But I still get the same error. Anyone has any ideas ?

EDIT

It is happening in ios

EDIT

Package.json

    {
      "name": "AppName",
      "version": "0.0.1",
      "private": true,
      "scripts": {
      "start": "node node_modules/react-native/local-cli/cli.js start",
,     "test": "jest"
      },
     "dependencies": {
     "react": "16.6.3",
     "react-native": "0.58.4",
     "react-native-gesture-handler": "^1.0.15",
     "react-navigation": "^3.2.1"
   },
    "devDependencies": {
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "24.1.0",
    "jest": "24.1.0",
    "metro-react-native-babel-preset": "0.51.1",
    "react-test-renderer": "16.6.3"
   },
   "jest": {
   "preset": "react-native"
 }

}

Uma
  • 938
  • 1
  • 12
  • 28

4 Answers4

0

If it's in android then make sure to add those changes to MainActivity.java after you link the package check documentation

+ import com.facebook.react.ReactActivityDelegate;
+ import com.facebook.react.ReactRootView;
+ import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
.
.
.
+  @Override
+  protected ReactActivityDelegate createReactActivityDelegate() {
+    return new ReactActivityDelegate(this, getMainComponentName()) {
+      @Override
+      protected ReactRootView createRootView() {
+       return new RNGestureHandlerEnabledRootView(MainActivity.this);
+      }
+    };
+  }

That's usually the issue.

Rachid Rhafour
  • 436
  • 2
  • 9
0

For Andriod u have to make changes to MainActivity.java For ios Add this to your podfile:

pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler/ios'

You're good to go!

Akshay Mulgavkar
  • 1,727
  • 9
  • 22
0

I figured out what the problem was. I was not using the StackNavigator correctly and I did not have the GestureHandler installed and lined correctly.

I created a new project, copied my old files into it and changed the Navigator class as such and it began to work fine.

  import { createStackNavigator, createAppContainer } from 'react-navigation';
  import LandingPage from './components/LandingPage/LandingPage';
  import Login from './components/Login/Login';

 const stack = createStackNavigator({
     Landing: {
         screen: LandingPage,
          navigationOptions:{
             header: null,
         },
     },
     Login: {
         screen: Login,
     },

 });

 const App = createAppContainer(stack); <----- Key emphasis

 export default App;
Uma
  • 938
  • 1
  • 12
  • 28
0

The most common cause for this problem is not rebuilding the app. follow these steps

  1. close the metro builder terminal window
  2. run react-native run-ios again (or run-android in case you are facing the issue in android).

If this doesn't fixed your issue

  1. try deleting the app from device.
  2. run react-native run-ios again.

If you are on android and this issue still haven't fixed check if your MainActivity.java matches with the one provided in their installation instructions.

Haseeb A
  • 5,356
  • 1
  • 30
  • 34