我正嘗試在兩個屏幕之間使用反應本機導航https://reactnavigation.org/進行導航。它是由index.js
努力EnableNotification.js
,但它不是從EnableNotification.js
工作,CreateMessage.js
React本機導航無法正常工作
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>;
}
}
消息_您收到什麼樣的_error導航呢? 'index.js'中的導航堆棧的CreateMessage部分是什麼? – zvona
@zvona不,我在index.js中只定義了兩個不確定它是否正確https://pastebin.com/6uHrh0Re –
** CreateMessage **組件需要成爲導航堆棧的一部分,才能通過' this.props.navigator.navigate()'。什麼是創建消息組件顯示的「方向」?它與啓用通知並行還是更深入? –
zvona