【发布时间】:2017-12-26 20:10:02
【问题描述】:
我正在使用 DrawerNavigator,我有 3 页:Router page、mainScreen 和 photos page,
我制作了一个标题导航栏区域,我使用这个<TouchableHighlight onPress={() => this.props.navigation.navigate('DrawerOpen')}>在mainScreen中打开抽屉菜单并将其用于照片页面,mainScreen中的菜单正常,但是当我在照片页面中单击<TouchableHighlight onPress={() => this.props.navigation.navigate('DrawerOpen')}>时,我收到了这个错误:
我该如何解决?
我的照片页面:
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;
主屏幕:
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>
)
}
}
【问题讨论】:
-
嗯,我认为很明显您没有在照片页面中包含所有内容。请使用这两个文件中的所有代码更新您的代码,以便我们查看缺少的内容。
-
这是我的所有代码,没有我的风格,我从 `
` 传递了我的照片页面,我可以在照片页面中看到照片文本和后退按钮,但我如果需要,应该添加我的路由器页面吗? -
我也遇到了同样的问题我
import { useNavigation } from '@react-navigation/native';const navigation = useNavigation();这对我有帮助。
标签: react-native react-navigation