React Native

React Native常用第三方框架之导航react-navi

2017-12-18  本文已影响0人  代码森林中的一只猫

(三).DrawerNavigator


const DrawerNav = DrawerNavigator({

Home: { screen: MainScreen },

Bill: { screen: MainScreen1 },

Me: { screen: MainScreen1 },
},
{

drawerWidth: 200, // 抽屉宽

drawerPosition: 'right', // 抽屉在左边还是右边

// contentComponent: CustomDrawerContentComponent, // 自定义抽屉组件

contentOptions: {

initialRouteName: 'Home', // 默认页面组件

activeTintColor: 'white', // 选中文字颜色

activeBackgroundColor: '#ff8500', // 选中背景颜色

inactiveTintColor: '#666', // 未选中文字颜色

inactiveBackgroundColor: '#fff', // 未选中背景颜色
}

开启:this.props.navigation.navigate('DrawerOpen'); // open drawer

关闭:this.props.navigation.navigate('DrawerClose'); // close drawer

navigationOptions主要有以下参数:

Demo

const App = DrawerNavigator({
"首页" : {screen : MainView },
"设置页面" : {screen : SettingPage },
MinePage : {screen : MinePage },
}, {
drawerWidth : width / 4 * 3,
drawerPosition : 'left',
contentOptions : {
initialRouteName : 'MainView',
activeItemKey : 'Notifications',
labelStyle : {
height : 20,
},
activeTintColor : 'white',
activeBackgroundColor : '#ff8500',
inactiveTintColor : '#666',
inactiveBackgroundColor : '#fff',
style : {
marginVertical : 0,
},
},

contentComponent : props => {
return (
<ScrollView>
<View>
<View style={{backgroundColor: '#ffff' }}>
<TouchableOpacity
onPress={() => {
props.navigation.navigate('MinePage');
}}>
<Text style={styles.titleMsg}>个人照片</Text>
<Image source={require('./../icons/one.png')} style={styles.img}/>
</TouchableOpacity>
</View>
<DrawerItems {...props} />
</View>
</ScrollView>
)
},
},
);

双侧栏的架构


const TabPageDrawer = DrawerNavigator({
'MY JOBS': {screen: HomePageStack},
'Reset Password': {screen: ResetPassword},
}, {
drawerWidth: screen.width / 4 * 3,
drawerPosition: 'left',
contentOptions: {
initialRouteName: HomePageStack,
activeItemKey: 'Notifications',
labelStyle: {
height: 20,
},
activeTintColor: '#666',
activeBackgroundColor: 'transparent',
inactiveTintColor: '#666',
inactiveBackgroundColor: 'transparent',
style: {
marginVertical: 0,
marginTop: 40
},
backBehavior: 'none',
},

contentComponent: props => {

return (
<View style={styles.container1}>
<ListItem/>
<DrawerItems {...props} />
<Button
containerStyle={styles.containerButtonStyle}
style={{fontSize: px2dp(20), color: 'white'}}
onPress={
}>
LOGOUT
</Button>
<View style={styles.versionContainer}>
<Text style={styles.version}>1.0.1</Text>
</View>
</View>
)
},
},
);

const HomePageStack = StackNavigator({
TabHomePage: {
screen: QDPAllStatusJobs,
navigationOptions: commonNavigationOptions(),
},

{
transitionConfig: TransitionConfiguration,
headerMode: 'screen', // 导航栏的显示模式, screen: 有渐变透明效果, float: 无透明效果, none: 隐藏导航栏
}
);

侧栏用DrawerNavigator里嵌套StackNavigator
右边侧栏用的框架

import Drawer from 'react-native-drawer-menu';
上一篇 下一篇

猜你喜欢

热点阅读