-
Notifications
You must be signed in to change notification settings - Fork 41
feat: make NAVIGATE and JUMP_TO to support key and name of the route #16
Conversation
Codecov Report
@@ Coverage Diff @@
## master #16 +/- ##
=========================================
- Coverage 94.88% 94.09% -0.8%
=========================================
Files 14 14
Lines 215 220 +5
Branches 44 49 +5
=========================================
+ Hits 204 207 +3
- Misses 9 11 +2
Partials 2 2
Continue to review full report at Codecov.
|
@@ -151,25 +151,38 @@ const StackRouter: Router<CommonAction | Action> = { | |||
}); | |||
|
|||
case 'NAVIGATE': | |||
if (state.routeNames.includes(action.payload.name)) { | |||
if ( | |||
action.payload.key || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also check if the key
exists in the stack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do it line 180
src/__tests__/index.test.tsx
Outdated
@@ -60,6 +60,76 @@ it('initializes state for a navigator on navigation', () => { | |||
}); | |||
}); | |||
|
|||
it('throws if NAVIGATE dispatched with both key and name', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move these to a separate file
(target.hasOwnProperty('key') && target.hasOwnProperty('name')) || | ||
(!target.hasOwnProperty('key') && !target.hasOwnProperty('name')) | ||
) { | ||
throw new Error( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of throwing in the action creator, we can throw in the router. Then it'll also prevent someone from calling dispatch
directly with incorrect stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. We don't want anyone to dispatch NAVIGATE
directly. If yes, risk included. I don't want to copy this error to every new and existing navigators.
src/BaseActions.tsx
Outdated
@@ -19,8 +19,20 @@ export function goBack(): Action { | |||
return { type: 'GO_BACK' }; | |||
} | |||
|
|||
export function navigate(name: string, params?: object): Action { | |||
return { type: 'NAVIGATE', payload: { name, params } }; | |||
export function navigate(target: TargetForAction, params?: object): Action { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to change the types in the NavigationProp
object in types.tsx
example/TabNavigator.tsx
Outdated
@@ -171,8 +181,20 @@ const TabRouter: Router<Action | CommonAction> = { | |||
}, | |||
|
|||
actionCreators: { | |||
jumpTo(name: string, params?: object) { | |||
return { type: 'JUMP_TO', payload: { name, params } }; | |||
jumpTo(target: TargetForAction, params?: object) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to change types for the TabNavigationProp
type above
src/types.tsx
Outdated
@@ -2,6 +2,8 @@ import * as BaseActions from './BaseActions'; | |||
|
|||
export type CommonAction = BaseActions.Action; | |||
|
|||
export type TargetForAction = string | { name: string } | { key: string }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call it TargetRoute
?
Closes #16 When the statusbar is not translucent, the view resizes when the keyboard is shown on Android. The tab bar stays above the keyboard. This PR makes the tab bar hide automatically when the keyboard is shown. The behaviour is enabled by default and can be disabled with `keyboardHidesTabBar: false` in `tabBarOptions`
Closes #16 When the statusbar is not translucent, the view resizes when the keyboard is shown on Android. The tab bar stays above the keyboard. This PR makes the tab bar hide automatically when the keyboard is shown. The behaviour is enabled by default and can be disabled with `keyboardHidesTabBar: false` in `tabBarOptions`
No description provided.