StackNavigator 标题未在最简单的示例中显示

StackNavigator title not showing in simplest example

我刚刚开始 React Native 开发,安装了 Expo,创建了一个应用程序(有效),安装了 react-navigation 并使用 https://reactnavigation.org/docs/intro/ 中的示例尝试了第一个 StackNavigator 示例。我在命令行中 运行 npm run ios,并使用 Nuclide IDE。所有这些对我来说都是全新的。

问题是,在 运行 示例中,iOS 模拟器中的屏幕显示如下:

而不是显示带有 'Welcome' 的标题栏。

作为初学者,我不知道从哪里开始。这是我的 package.json:

{
  "name": "rnproject",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-preset-flow": "^6.23.0",
    "flow-bin": "0.42.0",
    "jest-expo": "~1.0.1",
    "react-native-scripts": "0.0.30",
    "react-test-renderer": "16.0.0-alpha.6"
  },
  "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
  "scripts": {
    "start": "react-native-scripts start",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "node node_modules/jest/bin/jest.js --watch"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "expo": "^17.0.0",
    "react": "16.0.0-alpha.6",
    "react-native": "^0.44.0",
    "react-navigation": "^1.0.0-beta.11"
  }
}

有一个包含以下内容的 app.json 文件:

{
  "expo": {
    "sdkVersion": "17.0.0"
  }
} 

我还添加了 flow,这在示例代码中没有引发任何错误,但在 react-navigation 包中引发了 115 个错误。他们中的大多数看起来像:identifier 'expect', could not resolve name.

最后我找到了答案here: To use the examples on reactnavigation.org in Expo XDE, you have to make some changes. Here are the changes necessary for the first example:

import Expo from 'expo';  // <--- include this line
import React from 'react';
import {
  AppRegistry,   // <- remove this line
  Text,
} from 'react-native';
import { StackNavigator } from 'react-navigation';

class HomeScreen extends React.Component {
  static navigationOptions = {
    title: 'Welcome',
  };
  render() {
    return <Text>Hello, Navigation!</Text>;
  }
}

const SimpleApp = StackNavigator({
  Home: { screen: HomeScreen },
});

// change the following line:
AppRegistry.registerComponent('SimpleApp', () => SimpleApp);
// into:
Expo.registerRootComponent(SimpleApp);