mirror of
https://github.com/status-im/react-navigation.git
synced 2025-02-24 17:18:09 +00:00
drawer router key (#3925)
This commit is contained in:
parent
6cde6e2558
commit
f70a25a6a8
@ -18,9 +18,9 @@ export default (routeConfigs, config = {}) => {
|
||||
|
||||
getActionCreators(route, navStateKey) {
|
||||
return {
|
||||
openDrawer: () => ({ type: DrawerActions.OPEN_DRAWER }),
|
||||
closeDrawer: () => ({ type: DrawerActions.CLOSE_DRAWER }),
|
||||
toggleDrawer: () => ({ type: DrawerActions.TOGGLE_DRAWER }),
|
||||
openDrawer: () => DrawerActions.openDrawer({ key: navStateKey }),
|
||||
closeDrawer: () => DrawerActions.closeDrawer({ key: navStateKey }),
|
||||
toggleDrawer: () => DrawerActions.toggleDrawer({ key: navStateKey }),
|
||||
...switchRouter.getActionCreators(route, navStateKey),
|
||||
};
|
||||
},
|
||||
@ -31,20 +31,31 @@ export default (routeConfigs, config = {}) => {
|
||||
isDrawerOpen: false,
|
||||
};
|
||||
|
||||
// Handle explicit drawer actions
|
||||
if (state.isDrawerOpen && action.type === DrawerActions.CLOSE_DRAWER) {
|
||||
const isRouterTargeted = action.key == null || action.key === state.key;
|
||||
|
||||
if (
|
||||
isRouterTargeted &&
|
||||
action.type === DrawerActions.CLOSE_DRAWER &&
|
||||
state.isDrawerOpen
|
||||
) {
|
||||
return {
|
||||
...state,
|
||||
isDrawerOpen: false,
|
||||
};
|
||||
}
|
||||
if (!state.isDrawerOpen && action.type === DrawerActions.OPEN_DRAWER) {
|
||||
|
||||
if (
|
||||
isRouterTargeted &&
|
||||
action.type === DrawerActions.OPEN_DRAWER &&
|
||||
!state.isDrawerOpen
|
||||
) {
|
||||
return {
|
||||
...state,
|
||||
isDrawerOpen: true,
|
||||
};
|
||||
}
|
||||
if (action.type === DrawerActions.TOGGLE_DRAWER) {
|
||||
|
||||
if (isRouterTargeted && action.type === DrawerActions.TOGGLE_DRAWER) {
|
||||
return {
|
||||
...state,
|
||||
isDrawerOpen: !state.isDrawerOpen,
|
||||
|
@ -70,4 +70,24 @@ describe('DrawerRouter', () => {
|
||||
);
|
||||
expect(state4.isDrawerOpen).toEqual(true);
|
||||
});
|
||||
|
||||
test('Drawer opens closes with key targeted', () => {
|
||||
const ScreenA = () => <div />;
|
||||
const ScreenB = () => <div />;
|
||||
const router = DrawerRouter({
|
||||
Foo: { screen: ScreenA },
|
||||
Bar: { screen: ScreenB },
|
||||
});
|
||||
const state = router.getStateForAction(INIT_ACTION);
|
||||
const state2 = router.getStateForAction(
|
||||
{ type: DrawerActions.OPEN_DRAWER, key: 'wrong' },
|
||||
state
|
||||
);
|
||||
expect(state2.isDrawerOpen).toEqual(false);
|
||||
const state3 = router.getStateForAction(
|
||||
{ type: DrawerActions.OPEN_DRAWER, key: state.key },
|
||||
state2
|
||||
);
|
||||
expect(state3.isDrawerOpen).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user