我對react-native很新,我一直在嘗試導航。 我有4個組件類,每個都在它自己的.js文件中。 App.js導入stackNavigator。 Movies.js導入另一個名爲MoviePopup.js的組件。 MoviePopup.js有一個按鈕,我想點擊打開一個確認屏幕(Confirmation.js)並傳遞一個隨機代碼。將堆棧導航器與導入的組件相結合React-native
裏面App.js我設置了stackNavigator如下:
const TicketsApp = StackNavigator({
Movies: { screen: MoviesList },
Confirmation: { screen: Confirmation },
});
應用導航以及電影頁面。 電影裏面我寫了一個funtion bookTicket()如下:
bookTicket =() => {
if (!this.state.chosenTime) {
Alert.alert('Book Movie Error', 'Please select show time');
} else {
this.closeMovie();//close popup
//I am supposed to navigate to comfirmation window here
//and pass a booking code as a prop to the confirmation window
//What code should I use here to make my navigation work
}
}
我無法瀏覽該點導航到確認頁面。
<TouchableHighlight
underlayColor="#9575CD"
style={styles.buttonContainer}
onPress={onBook} >
<Text style={styles.button}>Book My Tickets</Text>
</TouchableHighlight>
我需要幫助寫在了bookTicket功能:bookTicket()函數爲道具,以Moviepopup.js爲「onBook」功能如下傳遞,並呼籲按鈕的內部Moviepopup.js的onPress方法導航才能正常工作。
謝謝得到了我失蹤。 –