Route'EnableNotification'应声明一个屏幕

N S*_*rma 2 android reactjs react-native react-navigation

我正在努力react-native并尝试整合react-navigation https://reactnavigation.org/docs/intro/进行导航.我在实施时遇到了一些困难.

index.android.js

**
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from "react";
import {
  AppRegistry,
  Image,
  View,
  Text,
  Button,
  StyleSheet
} from "react-native";
import { StackNavigator } from "react-navigation";
import EnableNotificationScreen from "./EnableNotification";

class SplashScreen extends Component {
  render() {
    console.disableYellowBox = true;
    const { navigate } = this.props.navigation;
    return (
      <View style={styles.container}>
        <Image source={require("./img/talk_people.png")} />
        <Text style={{ fontSize: 22, textAlign: "center" }}>
          Never forget to stay in touch with the people that matter to you.
        </Text>
        <View style={{ width: 240, marginTop: 30 }}>
          <Button
            title="CONTINUE"
            color="#FE434C"
            onPress={() => navigate("EnableNotification")}
          />
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    backgroundColor: "#FFFFFF",
    alignItems: "center",
    justifyContent: "center",
    padding: 16,
    flex: 1,
    flexDirection: "column"
  }
});

const ScheduledApp = StackNavigator(
  {
    Splash: { screen: SplashScreen },
    EnableNotification: { screen: EnableNotificationScreen }
  },
  {
    initialRouteName: "Splash"
  }
);

AppRegistry.registerComponent("Scheduled", () => ScheduledApp);
Run Code Online (Sandbox Code Playgroud)

EnableNotification.js

/**
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from "react";
import { View, Text } from "react-native";

export class EnableNotification extends Component {
  render() {
    return <View><Text>Enable Notification</Text></View>;
  }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

alp*_*pha 6

EnableNotification.js你的导出你的EnableNotification类没有默认(这是一个命名导出).

然后你import EnableNotificationScreen from "./EnableNotification"在你的导入它index.android.js,这导致错误.

你应该

a)导出默认的EnableNotification屏幕,即export default class EnableNotification extends Component

b)改为 import { EnableNotification } from "./EnableNotification"

这里阅读更多关于出口类型的信息