我将 DrawerNavigator 用于 React-Native,并在 Drawer 内使用以下 CustomDrawerContentComponent ...
const uiTheme = {
palette: {
primaryColor: COLOR.blue500,
},
toolbar: {
container: {
height: 80,
},
},
};
const propTypes = {
navigation: PropTypes.shape({
goBack: PropTypes.func.isRequired,
}).isRequired,
};
const CustomDrawerContentComponent = props => (
<Container>
<Toolbar
leftElement="arrow-back"
onLeftElementPress={() => this.props.navigation.goBack()}
centerElement="Menu"
/>
<View>
<Drawer.Header>
<Drawer.Header.Account
avatar={<Avatar text="K" />}
footer={{
dense: true,
centerElement: {
primaryText: 'Account',
secondaryText: 'xxxx@yahoo.com',
},
rightElement: 'arrow-drop-down',
}}
/>
</Drawer.Header>
<DrawerItems {...props} />
</View>
</Container>
);
const MainRoot = DrawerNavigator(
{
Login: {
path: '/login',
screen: Login,
},
Profile: {
path: '/profile',
screen: Profile,
},
Settings: {
path: '/settings',
screen: Settings,
},
},
{
initialRouteName: 'Settings',
contentOptions: {
activeTintColor: '#2089b0',
activeBackgroundColor: 'transparent',
inactiveTintColor: '#000000',
inactiveBackgroundColor: 'transparent',
labelStyle: {
fontSize: 18,
marginLeft: 0,
fontFamily: 'sans-serif-thin',
},
},
drawerWidth: SCREEN_WIDTH * 0.8,
contentComponent: CustomDrawerContentComponent,
drawerOpenRoute: 'DrawerOpen',
drawerCloseRoute: 'DrawerClose',
drawerToggleRoute: 'DrawerToggle',
}
);
export default class AppContainer extends Component {
render() {
return (
<ThemeContext.Provider value={getTheme(uiTheme)}>
<MainRoot />
</ThemeContext.Provider>
);
}
}
Expo.registerRootComponent(AppContainer);
我想要做的是将工具栏的元素定位到底部......
这是怎么做到的..?(对不起,React-Native 相对较新......)
此外,代码 onLeftElementPress={() => this.props.navigation.goBack()} 为 this.props.navigation 返回 null。
是否需要传递一些东西..?
谢谢。