From 118c19dcce2151446de3f32e1f08616412dafa06 Mon Sep 17 00:00:00 2001 From: Ashoat Tevosyan Date: Tue, 5 Jun 2018 03:58:14 +0700 Subject: [PATCH] [flow] Update NavigationActions and introduce StackActions and DrawerActions (#4345) --- examples/NavigationPlayground/.flowconfig | 6 +- examples/NavigationPlayground/package.json | 2 +- examples/NavigationPlayground/yarn.lock | 20 +-- flow/react-navigation.js | 179 +++++++++++++-------- 4 files changed, 122 insertions(+), 85 deletions(-) diff --git a/examples/NavigationPlayground/.flowconfig b/examples/NavigationPlayground/.flowconfig index f71dd12c03..e70a6fce21 100644 --- a/examples/NavigationPlayground/.flowconfig +++ b/examples/NavigationPlayground/.flowconfig @@ -55,8 +55,6 @@ module.system=haste emoji=true -experimental.strict_type_args=true - munge_underscores=true module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' @@ -77,7 +75,5 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]* suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError -unsafe.enable_getters_and_setters=true - [version] -^0.61.0 +^0.67.0 diff --git a/examples/NavigationPlayground/package.json b/examples/NavigationPlayground/package.json index f9b3fa0251..299d6efbb0 100644 --- a/examples/NavigationPlayground/package.json +++ b/examples/NavigationPlayground/package.json @@ -23,7 +23,7 @@ "devDependencies": { "babel-jest": "^22.4.1", "babel-plugin-transform-remove-console": "^6.9.0", - "flow-bin": "^0.61.0", + "flow-bin": "^0.67.0", "jest": "^22.1.3", "jest-expo": "^26.0.0", "react-native-scripts": "^1.5.0", diff --git a/examples/NavigationPlayground/yarn.lock b/examples/NavigationPlayground/yarn.lock index aea77dc091..5dafc48914 100644 --- a/examples/NavigationPlayground/yarn.lock +++ b/examples/NavigationPlayground/yarn.lock @@ -2868,9 +2868,9 @@ find-up@^2.0.0, find-up@^2.1.0: dependencies: locate-path "^2.0.0" -flow-bin@^0.61.0: - version "0.61.0" - resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.61.0.tgz#d0473a8c35dbbf4de573823f4932124397d32d35" +flow-bin@^0.67.0: + version "0.67.1" + resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.67.1.tgz#eabb7197cce870ac9442cfd04251c7ddc30377db" follow-redirects@^1.2.3: version "1.5.0" @@ -5648,9 +5648,9 @@ react-native-svg@6.2.2: lodash "^4.16.6" pegjs "^0.10.0" -react-native-tab-view@^0.0.74: - version "0.0.74" - resolved "https://registry.yarnpkg.com/react-native-tab-view/-/react-native-tab-view-0.0.74.tgz#62c0c882d9232b461ce181d440d683b4f99d1bd8" +react-native-tab-view@^0.0.77: + version "0.0.77" + resolved "https://registry.yarnpkg.com/react-native-tab-view/-/react-native-tab-view-0.0.77.tgz#11ceb8e7c23100d07e628dc151b57797524d00d4" dependencies: prop-types "^15.6.0" @@ -5738,11 +5738,11 @@ react-native@^0.55.0: xmldoc "^0.4.0" yargs "^9.0.0" -react-navigation-deprecated-tab-navigator@1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/react-navigation-deprecated-tab-navigator/-/react-navigation-deprecated-tab-navigator-1.2.0.tgz#e0d969c196dcd3a4a440770a7bd97fa058eb4aaf" +react-navigation-deprecated-tab-navigator@1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/react-navigation-deprecated-tab-navigator/-/react-navigation-deprecated-tab-navigator-1.3.0.tgz#015dcae1e977b984ca7e99245261c15439026bb7" dependencies: - react-native-tab-view "^0.0.74" + react-native-tab-view "^0.0.77" react-navigation-header-buttons@^0.0.4: version "0.0.4" diff --git a/flow/react-navigation.js b/flow/react-navigation.js index 3a3fd83fba..17813fe90d 100644 --- a/flow/react-navigation.js +++ b/flow/react-navigation.js @@ -69,6 +69,14 @@ declare module 'react-navigation' { [key: string]: mixed, }; + declare export type NavigationBackAction = {| + type: 'Navigation/BACK', + key?: ?string, + |}; + declare export type NavigationInitAction = {| + type: 'Navigation/INIT', + params?: NavigationParams, + |}; declare export type NavigationNavigateAction = {| type: 'Navigation/NAVIGATE', routeName: string, @@ -79,12 +87,6 @@ declare module 'react-navigation' { key?: string, |}; - - declare export type NavigationBackAction = {| - type: 'Navigation/BACK', - key?: ?string, - |}; - declare export type NavigationSetParamsAction = {| type: 'Navigation/SET_PARAMS', @@ -95,23 +97,28 @@ declare module 'react-navigation' { params: NavigationParams, |}; - declare export type NavigationInitAction = {| - type: 'Navigation/INIT', - params?: NavigationParams, + declare export type NavigationPopAction = {| + +type: 'Navigation/POP', + +n?: number, + +immediate?: boolean, + |}; + declare export type NavigationPopToTopAction = {| + +type: 'Navigation/POP_TO_TOP', + +immediate?: boolean, + |}; + declare export type NavigationPushAction = {| + +type: 'Navigation/PUSH', + +routeName: string, + +params?: NavigationParams, + +action?: NavigationNavigateAction, + +key?: string, |}; - declare export type NavigationResetAction = {| type: 'Navigation/RESET', index: number, key?: ?string, actions: Array, |}; - - declare export type NavigationUriAction = {| - type: 'Navigation/URI', - uri: string, - |}; - declare export type NavigationReplaceAction = {| +type: 'Navigation/REPLACE', +key: string, @@ -119,33 +126,38 @@ declare module 'react-navigation' { +params?: NavigationParams, +action?: NavigationNavigateAction, |}; - declare export type NavigationPopAction = {| - +type: 'Navigation/POP', - +n?: number, - +immediate?: boolean, + declare export type NavigationCompleteTransitionAction = {| + +type: 'Navigation/COMPLETE_TRANSITION', + +key?: string, |}; - declare export type NavigationPopToTopAction = {| - +type: 'Navigation/POP_TO_TOP', - +immediate?: boolean, + + declare export type NavigationOpenDrawerAction = {| + +type: 'Navigation/OPEN_DRAWER', + +key?: string, |}; - declare export type NavigationPushAction = {| - +type: 'Navigation/PUSH', - +routeName: string, - +params?: NavigationParams, - +action?: NavigationNavigateAction, + declare export type NavigationCloseDrawerAction = {| + +type: 'Navigation/CLOSE_DRAWER', + +key?: string, + |}; + declare export type NavigationToggleDrawerAction = {| + +type: 'Navigation/TOGGLE_DRAWER', +key?: string, |}; declare export type NavigationAction = + | NavigationBackAction | NavigationInitAction | NavigationNavigateAction - | NavigationReplaceAction + | NavigationSetParamsAction | NavigationPopAction | NavigationPopToTopAction | NavigationPushAction - | NavigationBackAction - | NavigationSetParamsAction - | NavigationResetAction; + | NavigationResetAction + | NavigationReplaceAction + | NavigationCompleteTransitionAction + | NavigationOpenDrawerAction + | NavigationCloseDrawerAction + | NavigationToggleDrawerAction; /** * NavigationState is a tree of routes for a single navigator, where each @@ -709,44 +721,73 @@ declare module 'react-navigation' { BACK: 'Navigation/BACK', INIT: 'Navigation/INIT', NAVIGATE: 'Navigation/NAVIGATE', - RESET: 'Navigation/RESET', SET_PARAMS: 'Navigation/SET_PARAMS', - URI: 'Navigation/URI', - back: { - (payload?: { key?: ?string }): NavigationBackAction, - toString: () => string, - }, - init: { - (payload?: { params?: NavigationParams }): NavigationInitAction, - toString: () => string, - }, - navigate: { - (payload: { - routeName: string, - params?: ?NavigationParams, - action?: ?NavigationNavigateAction, - }): NavigationNavigateAction, - toString: () => string, - }, - reset: { - (payload: { - index: number, - key?: ?string, - actions: Array, - }): NavigationResetAction, - toString: () => string, - }, - setParams: { - (payload: { - key: string, - params: NavigationParams, - }): NavigationSetParamsAction, - toString: () => string, - }, - uri: { - (payload: { uri: string }): NavigationUriAction, - toString: () => string, - }, + + back: (payload?: { key?: ?string }) => NavigationBackAction, + init: (payload?: { params?: NavigationParams }) => NavigationInitAction, + navigate: (payload: { + routeName: string, + params?: ?NavigationParams, + action?: ?NavigationNavigateAction, + key?: string, + }) => NavigationNavigateAction, + setParams: (payload: { + key: string, + params: NavigationParams, + }) => NavigationSetParamsAction, + }; + + declare export var StackActions: { + POP: 'Navigation/POP', + POP_TO_TOP: 'Navigation/POP_TO_TOP', + PUSH: 'Navigation/PUSH', + RESET: 'Navigation/RESET', + REPLACE: 'Navigation/REPLACE', + COMPLETE_TRANSITION: 'Navigation/COMPLETE_TRANSITION', + + pop: (payload: { + n?: number, + immediate?: boolean, + }) => NavigationPopAction, + popToTop: (payload: { + immediate?: boolean, + }) => NavigationPopToTopAction, + push: (payload: { + routeName: string, + params?: NavigationParams, + action?: NavigationNavigateAction, + key?: string, + }) => NavigationPushAction, + reset: (payload: { + index: number, + key?: ?string, + actions: Array, + }) => NavigationResetAction, + replace: (payload: { + key: string, + routeName: string, + params?: NavigationParams, + action?: NavigationNavigateAction, + }) => NavigationReplaceAction, + completeTransition: (payload: { + key?: string, + }) => NavigationCompleteTransitionAction, + }; + + declare export var DrawerActions: { + OPEN_DRAWER: 'Navigation/OPEN_DRAWER', + CLOSE_DRAWER: 'Navigation/CLOSE_DRAWER', + TOGGLE_DRAWER: 'Navigation/TOGGLE_DRAWER', + + openDrawer: (payload: { + key?: string, + }) => NavigationOpenDrawerAction, + closeDrawer: (payload: { + key?: string, + }) => NavigationCloseDrawerAction, + toggleDrawer: (payload: { + key?: string, + }) => NavigationToggleDrawerAction, }; declare type _DefaultActionCreators = {|