【发布时间】:2017-04-25 15:07:01
【问题描述】:
我正在尝试使用 react-native 导航 https://reactnavigation.org/ 在两个屏幕之间导航。它从index.js 到EnableNotification.js 工作,但从EnableNotification.js 到CreateMessage.js 不工作
EnableNotification.js
/**
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from "react";
import { View, Text, Image, Button, StyleSheet } from "react-native";
import { StackNavigator } from "react-navigation";
import styles from "./Styles";
import * as strings from "./Strings";
import CreateMessage from "./CreateMessage";
export default class EnableNotificationScreen extends Component {
render() {
const { navigate } = this.props.navigation;
return (
<View style={styles.container}>
<Image source={require("./img/enable_notification.png")} />
<Text style={styles.textStyle}> {strings.enable_notification} </Text>
<View style={{ width: 240, marginTop: 30 }}>
<Button
title="ENABLE NOTIFICATION"
color="#FE434C"
onPress={() => navigate("CreateMessage")}
style={{ borderRadius: 40 }}
/>
</View>
<Text
style={{
textAlign: "center",
marginTop: 10
}}
>
NOT NOW
</Text>
</View>
);
}
}
const ScheduledApp = StackNavigator({
CreateMessage: {
screen: CreateMessage,
navigationOptions: {
header: {
visible: false
}
}
}
});
CreateMessage.js
import React, { Component } from "react";
import { View, Text, Image, Button, StyleSheet } from "react-native";
export default class CreateMessage extends Component {
render() {
return <View><Text>Hello World!</Text></View>;
}
}
【问题讨论】:
-
您收到什么样的错误消息? CreateMessage 是
index.js中导航堆栈的一部分吗? -
@zvona 不我在 index.js 中只定义了两个 不确定是否正确pastebin.com/6uHrh0Re
-
CreateMessage 组件需要成为导航堆栈的一部分才能通过
this.props.navigator.navigate(<name>)导航到那里。 Create Message 组件显示的“方向”是什么?它是与启用通知并行还是深入堆栈?
标签: android react-native react-native-navigation