From 1e7d8d55c3dabbbbe1f54a49929fe71207f447a9 Mon Sep 17 00:00:00 2001 From: Ashoat Tevosyan Date: Sat, 26 May 2018 01:59:11 -0400 Subject: [PATCH] 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 --- flow/react-navigation.js | 39 +++++++++++++++++++++++-------------- src/react-navigation.js | 3 +++ src/react-navigation.web.js | 3 +++ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/flow/react-navigation.js b/flow/react-navigation.js index 3910321..3a3fd83 100644 --- a/flow/react-navigation.js +++ b/flow/react-navigation.js @@ -487,6 +487,10 @@ declare module 'react-navigation' { }; declare export type NavigationScreenProp<+S> = { + ...$ObjMap< + _DefaultActionCreators, + ((...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 = { router: NavigationRouter, }; diff --git a/src/react-navigation.js b/src/react-navigation.js index 6ac714c..b62a363 100644 --- a/src/react-navigation.js +++ b/src/react-navigation.js @@ -71,6 +71,9 @@ module.exports = { get DrawerActions() { return require('./routers/DrawerActions').default; }, + get getNavigationActionCreators() { + return require('./routers/getNavigationActionCreators').default; + }, // Routers get StackRouter() { diff --git a/src/react-navigation.web.js b/src/react-navigation.web.js index d4daaf6..ddf9002 100644 --- a/src/react-navigation.web.js +++ b/src/react-navigation.web.js @@ -24,6 +24,9 @@ module.exports = { get DrawerActions() { return require('./routers/DrawerActions').default; }, + get getNavigationActionCreators() { + return require('./routers/getNavigationActionCreators').default; + }, // Routers get StackRouter() {