ksh*_*way 3 javascript android ios react-native react-navigation
我有一个应用程序需要能够使用两个抽屉导航器,一个在标题的左侧和右侧。
我现在可以用滑动手势打开两个抽屉,但是我需要能够以编程方式打开它。我发现该navigation.openDrawer()功能仅适用于其中一个抽屉,而不适用于另一个,因为它只能使用我的抽屉导航器中的一个导航道具(以先到者为准)。
以下是我的渲染功能:
const LeftStack = createStackNavigator(
{
LeftDrawerStack
},
{
navigationOptions: ({navigation}) => ({
headerLeft: (
<TouchableOpacity onPress={() => navigation.openDrawer()}>
<Icon style={{marginLeft: 10}} name='menu'/>
</TouchableOpacity>
)
})
}
);
const RightStack = createStackNavigator(
{
RightDrawerStack
},
{
navigationOptions: ({navigation}) => ({
headerRight: (
<TouchableOpacity onPress={() => navigation.openDrawer()}>
<Icon style={{marginRight: 10}} name='ios-bulb'/>
</TouchableOpacity>
)
})
}
);
export const RouteStack = createStackNavigator(
{
screen: LoginScreen,
navigationOptions: ({navigation}) => ({
header: null
}),
LeftStack,
RightStack
}
);Run Code Online (Sandbox Code Playgroud)
这是我的抽屉路线:
export const LeftDrawerStack = createDrawerNavigator(
{
Dashboard: {
screen: DashboardScreen
},
History: {
screen: HistoryScreen
},
Privacy: {
screen: PrivacyPolicyScreen
},
TermsAndConditions: {
screen: TermsAndConditionsScreen
}
}, {
initialRouteName: 'Dashboard',
contentComponent: LeftDrawerScreen
}
);
export const RightDrawerStack = createDrawerNavigator(
{
LeftDrawerStack,
Settings: {
screen: SettingsScreen
}
}, {
drawerPosition: 'right',
contentComponent: RightDrawerScreen
}
);Run Code Online (Sandbox Code Playgroud)
这是到目前为止我的导航的图片,但是两个汉堡包菜单都在右侧打开相同的菜单,而不是在各自的两侧打开一个菜单。
我可能会遗漏一些部分,但如果我忘记了,我一定会发布更多信息!
我能够通过以下设置来做到这一点(尝试将您的结构更改为这样):
const LeftDrawer = createDrawerNavigator(
{
LeftDrawer: MyStackNavigator,
},
{
getCustomActionCreators: (route, stateKey) => { return { toggleLeftDrawer: () => DrawerActions.toggleDrawer({ key: stateKey }) }; },
drawerPosition: 'left',
contentComponent: MyLeftDrawer
}
);
const RightDrawer = createDrawerNavigator(
{
Drawer: LeftDrawer,
},
{
getCustomActionCreators: (route, stateKey) => { return { toggleRightDrawer: () => DrawerActions.toggleDrawer({ key: stateKey }) }; },
drawerPosition: 'right',
contentComponent: MyRightDrawer
}
);
export const RootNavigator = createStackNavigator(
{
Login: Login,
Home: RightDrawer
},
{
initialRouteName: 'Login',
navigationOptions: { header: null, gesturesEnabled: false }
}
);
Run Code Online (Sandbox Code Playgroud)
关键是 getCustomActionCreators。它可以让你从任何屏幕调用函数中MyStackNavigator是这样的:this.props.navigation.toggleLeftDrawer();。
| 归档时间: |
|
| 查看次数: |
6231 次 |
| 最近记录: |