Export getNavigationActionCreators (#4258)

* Export getNavigationActionCreators

`react-navigation-redux-helpers` generally needs to duplicate whatever `createNavigationCreator` does. As of `react-navigation@2.0`, that includes using `getNavigationActionCreators` to construct the top-level `NavigationScreenProp`.

This PR isn't strictly needed, as it's possible to import from the file directly. But that's a brittle approach, and not particularly discoverable for anybody attempting to use a "non-stateful" navigator with their state management library of choice.

* Further refinements after writing the new helper

* Final refinement of NavigationScreenProp's relationship with _DefaultActionCreators

* Resolve merge conflicts
This commit is contained in:
Ashoat Tevosyan 2018-05-26 01:59:11 -04:00 committed by Brent Vatne
parent 1d2ce862c2
commit 1e7d8d55c3
3 changed files with 30 additions and 15 deletions

View File

@ -487,6 +487,10 @@ declare module 'react-navigation' {
};
declare export type NavigationScreenProp<+S> = {
...$ObjMap<
_DefaultActionCreators,
<Args>((...args: Args) => *) => (...args: Args) => boolean
>,
+state: S,
dispatch: NavigationDispatch,
addListener: (
@ -495,21 +499,6 @@ declare module 'react-navigation' {
) => NavigationEventSubscription,
getParam: (paramName: string, fallback?: any) => any,
isFocused: () => boolean,
// Shared action creators that exist for all routers
goBack: (routeKey?: ?string) => boolean,
navigate: (
routeName:
| string
| {
routeName: string,
params?: NavigationParams,
action?: NavigationNavigateAction,
key?: string,
},
params?: NavigationParams,
action?: NavigationNavigateAction
) => boolean,
setParams: (newParams: NavigationParams) => boolean,
// StackRouter action creators
pop?: (n?: number, params?: { immediate?: boolean }) => boolean,
popToTop?: (params?: { immediate?: boolean }) => boolean,
@ -760,6 +749,26 @@ declare module 'react-navigation' {
},
};
declare type _DefaultActionCreators = {|
goBack: (routeKey?: ?string) => NavigationBackAction,
navigate: (
routeName:
| string
| {
routeName: string,
params?: NavigationParams,
action?: NavigationNavigateAction,
key?: string,
},
params?: NavigationParams,
action?: NavigationNavigateAction
) => NavigationNavigateAction,
setParams: (newParams: NavigationParams) => NavigationSetParamsAction,
|};
declare export function getNavigationActionCreators(
route: NavigationRoute | NavigationState
): _DefaultActionCreators;
declare type _RouterProp<S: NavigationState, O: {}> = {
router: NavigationRouter<S, O>,
};

View File

@ -71,6 +71,9 @@ module.exports = {
get DrawerActions() {
return require('./routers/DrawerActions').default;
},
get getNavigationActionCreators() {
return require('./routers/getNavigationActionCreators').default;
},
// Routers
get StackRouter() {

View File

@ -24,6 +24,9 @@ module.exports = {
get DrawerActions() {
return require('./routers/DrawerActions').default;
},
get getNavigationActionCreators() {
return require('./routers/getNavigationActionCreators').default;
},
// Routers
get StackRouter() {