我使用DrawerNavigator
,我有3頁:Router page
,mainScreen
和photos page
,
我maked頭導航欄區域,我用這<TouchableHighlight onPress={() => this.props.navigation.navigate('DrawerOpen')}>
打開抽屜菜單在mainScreen中,也用於照片頁面,菜單在mainScreen中可以,但是當我在照片頁面中點擊<TouchableHighlight onPress={() => this.props.navigation.navigate('DrawerOpen')}>
時,出現此錯誤:
我該如何解決這個問題?入門未定義不是對象評估_this.props.navigation
我的照片頁:
import React from 'react';
import { Button, ScrollView, View, Text, StyleSheet, TouchableHighlight } from 'react-native';
import { DrawerNavigator } from 'react-navigation';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import Icon from 'react-native-vector-icons/FontAwesome'
const MyNavScreen = ({ navigation }) => (
<View>
<View style={styles.containerNavbar}>
<TouchableHighlight onPress={() => this.props.navigation.navigate('DrawerOpen')}>
<Icon name="bars" size={30} color="#fff" />
</TouchableHighlight>
<Text style={styles.navbarTitle}>Photos</Text>
</View>
<ScrollView>
<View><Text>photo</Text></View>
<Button onPress={() => navigation.goBack(null)} title="Go back" />
</ScrollView>
</View>
);
const MyPhotosHomeScreen = ({ navigation }) => (
<MyNavScreen navigation={navigation} />
);
MyPhotosHomeScreen.navigationOptions = {
title: 'Photos',
drawerIcon: ({ tintColor }) => (
<MaterialIcons
name="photo"
size={24}
style={{ color: tintColor }}
/>
),
};
export default MyPhotosHomeScreen;
mainScreen:
export default class MainScreen extends React.Component {
static navigationOptions = {
drawerLabel: 'Home',
drawerIcon: ({ tintColor }) => (
<MaterialIcons
name="home"
size={24}
style={{ color: tintColor }}
/>
)
};
render() {
return (
<View>
<View style={styles.containerNavbar}>
<TouchableHighlight onPress={() => this.props.navigation.navigate('DrawerOpen')}>
<Icon name="bars" size={30} color="#fff" />
</TouchableHighlight>
<Text style={styles.navbarTitle}>mainScreen</Text>
</View>
<View>
<View style={styles.containerFooter}>
<Text style={styles.footerTitle}>Footer</Text>
</View>
</View>
</View>
)
}
}
嗯,我認爲這很明顯,你不包括照片頁面中的所有內容。請使用這兩個文件中的所有代碼更新您的代碼,以便查看缺少的內容。 – wuno
這是我的所有代碼,沒有我的風格,我從' '傳遞了我的照片頁面,我可以在照片頁面看到照片文字和後退按鈕,但是如果您需要? –