Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

fix: implement canGoBack for tab router #51

Merged
merged 1 commit into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/core/src/BaseRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ const BaseRouter = {
shouldActionChangeFocus(action: CommonAction) {
return action.type === 'NAVIGATE';
},

canGoBack() {
return false;
},
};

export default BaseRouter;
4 changes: 4 additions & 0 deletions packages/routers/src/TabRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ export default function TabRouter({
return action.type === 'NAVIGATE';
},

canGoBack(state) {
return router.getStateForAction(state, { type: 'GO_BACK' }) !== null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this gave me an idea. we don't actually need to implement this method in routers. we can instead do this to implement canGoBack:

canGoBack: () =>
        router.getStateForAction(getState(), BaseActions.goBack()) !== null ||
        (parentNavigationHelpers && parentNavigationHelpers.canGoBack()) ||
        false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk.

},

actionCreators: TabActions,
};

Expand Down