我使用react-native创建了一个带有sidemenu的页面,并使用react-navigation进行路由 . 我想禁用通过左侧滑动侧手势出现的侧面菜单屏幕 .
export const StackNav = StackNavigator(
{
Login: {
screen: Login,
navigationOptions: {
headerMode: "none",
header: null
}
},
Signup: {
screen: Signup,
navigationOptions: {
headerMode: "none",
header: null
}
},
},
{
initialRouteName: "Login"
}
);
//for admin login, run campaign
const TabNav1 = TabNavigator(
{
SelectCarriers: {
screen: SelectCarriers,
navigationOptions: {
tabBarLabel: "Select Carriers"
}
},
ErrorRecords: {
screen: ErrorRecords,
navigationOptions: {
tabBarLabel: "Error Records"
}
}
},
{
tabBarPosition: "top",
tabBarOptions: {
labelStyle: {
fontWeight: "bold"
}
}
}
);
//for Notification page or carrier login
const TabNav = TabNavigator(
{
Notification: {
screen: Notification,
navigationOptions: {
tabBarLabel: "Notification"
}
},
NotificationHistory: {
screen: NotificationHistory,
navigationOptions: {
tabBarLabel: "Notification History"
}
}
},
{
tabBarPosition: "bottom"
}
);
const TabNavStack = StackNavigator({
Main: {
screen: TabNav,
navigationOptions: ({ navigation }) => ({
headerTitle: "Notification"
})
}
});
const sidemenuNav = StackNavigator({
Dashboard: {
screen: Dashboard,
navigationOptions: ({ navigation }) => ({
headerLeft: (
<TouchableOpacity onPress={() => navigation.toggleDrawer()}>
<Text style={{ paddingLeft: 15 }}>
<Icon name="navicon" style={{ fontSize: 25 }} />
</Text>
</TouchableOpacity>
)
})
},
ViewRanking: {
screen: ViewRanking,
navigationOptions: ({ navigation }) => ({
title: "View Ranking"
})
},
SelectCarriers: {
screen: SelectCarriers,
navigationOptions: ({ navigation }) => ({
headerTitle: "SELECT CARRIER"
})
},
RunCampaign : {
screen: RunCampaign,
navigationOptions: ({navigation}) =>({
title: "RUN"
})
},
SelectedCampaign : {
screen: SelectedCampaign,
navigationOptions: ({navigation}) => ({
title: "SELECTED CAMPAIGN",
})
},
ChangePassword: {
screen: ChangePassword,
navigationOptions: {
title: 'Change Password'
}
},
EmailAnalytics: {
screen: EmailAnalytics,
navigationOptions: {
title: 'Email Analytics'
}
},
ViewCampaignHistory: {
screen: ViewCampaignHistory,
navigationOptions: {
title: 'View Campaign History'
}
},
CheckResponse: {
screen: CheckResponse,
navigationOptions: {
title: 'CHECK RESPONSE'
}
},
CampaignResult: {
screen: CampaignResult,
navigationOptions: {
title: 'CAMPAIGN RESULT'
}
},
});
const DrawerNav = DrawerNavigator(
{
Item1: {
screen: sidemenuNav
}
},
{
contentComponent: SideMenu,
drawerWidth: Dimensions.get("window").width - 120
}
);
export const PrimaryNav = StackNavigator(
{
StackNav: { screen: StackNav },
TabNavStack: { screen: TabNavStack },
DrawerNav: { screen: DrawerNav }
},
{
// Default config for all screens
headerMode: "none",
initialRouteName: "StackNav"
}
);
所以,在sidemenuNav中,我想为ViewRanking,SelectCarriers禁用侧抽屉....
我尝试了 drawerLockMode
导航选项,但没有奏效 .
我提到了一些问题,但没有用 .
在建议答案后将其标记为重复或投票否决
1 回答
drawerLockMode
是您要找的选项 . Doc(No drawerLockedMode)并且有三种类型选项 . Doc
解锁(默认),意味着抽屉将响应(打开/关闭)触摸手势 .
锁定关闭,意味着抽屉将保持关闭状态而不响应手势 .
锁定打开,意味着抽屉将保持打开状态而不响应手势 . 抽屉仍然可以通过编程方式打开和关闭(openDrawer / closeDrawer) .
因此,在
sidemenuNav
的navigationOptions中添加条件语句 . Doc这是我测试过的代码 .
添加
我完全测试了你的屏幕架构师并检查它是否运行良好 .
我不确定你的代码有什么问题,但是使用最近的反应导航和推荐方法
createSomeNavigator
而不是弃用DrawerNavigator
,StackNavigator
等等 . 祝好运 .