【发布时间】:2017-07-12 14:04:18
【问题描述】:
我正在尝试使用此页面上的一些方法在我的 StackNavigator 中嵌套一个 DrawerNavigator:
https://github.com/react-community/react-navigation/issues/131
我的应用程序已加载,但标题栏中未显示任何内容。它应该有一个标题和一个图片,点击后会显示抽屉菜单。
如果有人得到这样的工作,你能帮忙吗?谢谢!
这是我的 app.js:
import Drawer from './DrawerMenu';
const diceRoller = StackNavigator({
Home: { screen: HomeScreen },
Drawer: { screen: Drawer }
});
AppRegistry.registerComponent('diceRoller', () => diceRoller);
export { diceRoller }
DrawerMenu.js:
import { DrawerNavigator } from 'react-navigation';
import { TouchableHighlight, Image } from 'react-native';
import MenuScreen from './MenuScreen';
import React from 'react';
const getDrawerItem = navigation => (
<TouchableHighlight>
<Image source={require('./images/menubars.png')} style={{width: 50, height: 50}} />
onPress={() => {
if (navigation.state.index === 0) {
navigation.navigate('DrawerOpen');
} else {
navigation.navigate('DrawerClose');
}
}}
</TouchableHighlight>
);
const getNavigationOptionsWithAction = (title, backgroundColor, color, headerLeft) => ({
title,
headerStyle: {
backgroundColor,
},
headerTitleStyle: {
color,
},
headerTintColor: color,
headerLeft,
});
const getDrawerConfig = (drawerWidth, drawerPosition) => ({
drawerWidth,
drawerPosition,
});
const Drawer = DrawerNavigator ({
MenuScreen: { screen: MenuScreen }
}, getDrawerConfig(300, 'left'));
Drawer.navigationOptions = ({ navigation }) => getNavigationOptionsWithAction('Menu', 'blue', 'white', getDrawerItem(navigation));
export default Drawer;
【问题讨论】:
标签: react-native react-native-android react-navigation