我正在使用react-native
并尝试整合react-navigation
https://reactnavigation.org/docs/intro/进行导航。我在实施时遇到了一些困难。
**
* 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);
/**
* 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>;
}
}
答案 0 :(得分:6)
在EnableNotification.js
中,您可以导出EnableNotification
类而不使用默认值(这是一个命名导出)。
然后您在import EnableNotificationScreen from "./EnableNotification"
中使用index.android.js
导入它,这会导致错误。
你应该
a)导出默认的EnableNotification屏幕,即export default class EnableNotification extends Component
或
b)更改为import { EnableNotification } from "./EnableNotification"
详细了解导出类型here
答案 1 :(得分:0)
现在您正在注册Scheduled
组件。您应该做的是注册ScheduledApp
组件。
目前未使用ScheduledApp
,因此无法找到您导航到的EnableNotification
屏幕。
像这样注册您的应用:
AppRegistry.registerComponent("Scheduled", () => ScheduledApp);
我也经常做的是定义初始路线。你可以通过定义initialRouteName
来做到这一点:
const ScheduledApp = StackNavigator({
Splash: { screen: SplashScreen },
EnableNotification: { screen: EnableNotification }
}, {
initialRouteName: 'Splash'
});