0

我正在尝试在一个(尚未)使用它的现有应用程序中实现 react-native 导航。

我正在关注这个答案。

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

//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>);
  }
}

当我运行它时,在控制台(webstorm)上我得到:

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)

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

4

1 回答 1

0

这可能会有所帮助:

我遇到了一个问题-

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

解决我的问题的解决方法是降级react-navigation 版本。

就我而言,我从^3.0.4^2.18.0

于 2018-12-08T08:43:24.010 回答