如何解决模块“应用程序”无法找到'react-native'应用程序

时间:2018-05-21 12:12:22

标签: react-native react-native-android react-native-navigation

我很反应原生,我正在按照教程尝试浏览列表和详细信息页面。

我创建了一个Initial项目,它在最初运行的根目录中有App.js. 我创建了自己的app文件夹,其中包含'config'和'screens'文件夹以及index.js。 我的项目结构如下所示。

enter image description here

我删除了App.js文件,因为我没有运行它,但我希望'Feeds.js'运行。 这是我的主要内容 index.js

 import { AppRegistry } from 'react-native';
 import App from './app/index';
 AppRegistry.registerComponent('DemoNavList', () => App);

应用程序/ index.js

import React, {Component} from 'react';
import {Root, Tabs} from './config/router';

class App extends Component{
   render(){
    return <Root/>;
   }
}

export default App;

应用程序/配置/ router.js

    import React from 'react';
import { TabNavigator, StackNavigator } from 'react-navigation';
import { Icon } from 'react-native-elements';

import Feed from '../screens/Feed';
import Settings from '../screens/Settings';
import UserDetail from '../screens/UserDetail';
import Me from '../screens/Me';

export const FeedStack = StackNavigator({
  Feed: {
    screen: Feed,
    navigationOptions: {
      title: 'Feed',
    },
  },
  Details: {
    screen: UserDetail,
    navigationOptions: ({ navigation }) => ({
      title: `${navigation.state.params.name.first.toUpperCase()} ${navigation.state.params.name.last.toUpperCase()}`,
    }),
  },
});

export const Tabs = TabNavigator({
  Feed: {
    screen: FeedStack,
    navigationOptions: {
      tabBarLabel: 'Feed',
      tabBarIcon: ({ tintColor }) => <Icon name="list" size={35} color={tintColor} />,
    },
  },
  Me: {
    screen: Me,
    navigationOptions: {
      tabBarLabel: 'Me',
      tabBarIcon: ({ tintColor }) => <Icon name="account-circle" size={35} color={tintColor} />
    },
  },
});

export const SettingsStack = StackNavigator({
  Settings: {
    screen: Settings,
    navigationOptions: {
      title: 'Settings',
    },
  },
});

export const Root = StackNavigator({
  Tabs: {
    screen: Tabs,
  },
  Settings: {
    screen: SettingsStack,
  },
}, {
  mode: 'modal',
  headerMode: 'none',
});

我从https://github.com/spencercarli/getting-started-react-navigation

下载了代码

这是错误截图

enter image description here

如果你可以指导我做错的地方,那将会非常有帮助。 谢谢 [R

1 个答案:

答案 0 :(得分:1)

AppRegistry.registerComponent(appKey, componentProvider)中的 appKey 应该与您的react-native项目的名称匹配。如果它被改变,它可能会导致这样的问题。尝试更改&#39; DemoNavList&#39; to&#39; FirstLookReactNavigation&#39;在你提到的git存储库中给出。

或者您应该尝试将您的反应原生应用的主文件夹重命名为&#39; DemoNavList&#39;