使用本机导航时,带有RnGestureHandler的未定义对象

时间:2018-11-21 20:27:44

标签: react-native react-navigation-stack

我正在尝试在尚未使用它的现有应用中实现本机导航。

我正在关注this答案。

由于我已经有一个应用程序设置,因此我需要略微调整他的程序。我的切入点:

//index.js
import {AppRegistry} from 'react-native';
import {createAppContainer, createStackNavigator} from 'react-navigation';
import {name as appName} from './app.json';
import {Config} from './navigation/config'
import App2 from "./navigation/App2";
import BarCodeReader from "./navigation/BarCodeReader";

export const AppNavigator = StackNavigator(Config.navigation);

//I've also tried this instead, similar error:
//export const AppNavigator = createStackNavigator(Config.navigation);

AppRegistry.registerComponent('appName', ()=>AppNavigator);

根据我运行手机时出现的红色死亡屏幕,AppNavigator ....行似乎是导致错误的行。那是我的代码的最后一行在死亡的红色屏幕上提到。

我的路线:

//config.js
import App2 from './App2'
import BarCodeReader from './BarCodeReader'

export const Config = {
  navigation: {
    App2: {
      screen: App2
    },
    BarCodeReader: {
      screen: BarCodeReader
    }
  }
};

我要加载的替代页面(例如,app2-我只是想尽量使其简单以隔离错误,而没有让我的实际代码导致意外错误...)

//app2.js
import React, {Component} from 'react';
import {Text, View} from 'react-native';

export default class App2 extends Component {
  constructor(props){
    super(props);
  }

  render() {
      return (
        <View>
          <Text>          Showing stuff from app2
          </Text>
        </View>);
  }
}

运行它时,在控制台上(网络风暴),我得到:

D/ReactNative( 1044): CatalystInstanceImpl.runJSBundle()
D/ReactNative( 1044): ReactInstanceManager.setupReactContext()
D/ReactNative( 1044): CatalystInstanceImpl.initialize()
D/ReactNative( 1044): ReactInstanceManager.attachRootViewToInstance()
W/ReactNativeJS( 1044): Require cycle: node_modules/react-native-gesture-handler/index.js -> node_modules/react-native-gesture-handler/Swipeable.js -> node_modules/react-native-gesture-handler/index.js
W/ReactNativeJS( 1044): 
W/ReactNativeJS( 1044): Require cycles are allowed, but can result in 

uninitialized values. Consider refactoring to remove the need for a cycle.
W/ReactNativeJS( 1044): Require cycle: node_modules/react-native-gesture-handler/index.js -> node_modules/react-native-gesture-handler/DrawerLayout.js -> node_modules/react-native-gesture-handler/index.js
W/ReactNativeJS( 1044): 
W/ReactNativeJS( 1044): Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
E/ReactNativeJS( 1044): undefined is not an object (evaluating 'RNGestureHandlerModule.State')
E/ReactNativeJS( 1044): Module AppRegistry is not a registered callable module (calling runApplication)

是因为它在谈论周期吗?如果有什么问题呢?如果没有,我的问题是什么?

1 个答案:

答案 0 :(得分:0)

这可能会有所帮助:

我遇到了一个问题-

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

解决我问题的解决方法是降级反应导航版本。

就我而言,我从^3.0.4^2.18.0