From 966ecb53baf14a4a7ed68bd448c348defc1e752e Mon Sep 17 00:00:00 2001 From: Eric Vicenti Date: Thu, 25 Jan 2018 00:13:28 -0800 Subject: [PATCH] Navigation Event Subscriptions (#3345) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add fbemitter, keep flow passing * Begin support for event emitter - Adds emitter to navigation prop - Emits top level onAction event - stub getChildEventSubscriber for child events * Support navigationState.isNavigating * Focus and blur events starting to work - Navigation completion action wired up - Event chaining logic built in getChildEventSubscriber - Renamed onAction evt to ‘action’ * Wrap up events progress and testing * Rename to isTransitioning and COMPLETE_TRANSITION * rm accidental dependency * Suppoert event payload type --- .../examples/NavigationPlayground/.flowconfig | 81 -------- .../NavigationPlayground/js/SimpleStack.js | 123 +++++++++--- .../NavigationPlayground/js/SimpleTabs.js | 33 +++- .../examples/NavigationPlayground/yarn.lock | 13 +- packages/react-navigation/package.json | 3 +- packages/react-navigation/prettier.config.js | 4 + .../react-navigation/src/NavigationActions.js | 7 + .../__tests__/NavigationStateUtils-test.js | 53 +++++- .../__tests__/addNavigationHelpers-test.js | 8 + .../src/createNavigationContainer.js | 33 +++- .../src/getChildEventSubscriber.js | 154 +++++++++++++++ .../src/navigators/StackNavigator.js | 7 +- .../__snapshots__/StackNavigator-test.js.snap | 4 + .../src/routers/StackRouter.js | 23 ++- .../react-navigation/src/routers/TabRouter.js | 1 + .../src/routers/__tests__/Routers-test.js | 31 ++- .../src/routers/__tests__/StackRouter-test.js | 178 +++++++++++++++--- .../src/routers/__tests__/TabRouter-test.js | 34 ++++ .../__tests__/createConfigGetter-test.js | 64 ++++++- .../src/routers/createConfigGetter.js | 5 + .../src/views/CardStack/CardStack.js | 5 + .../src/views/Drawer/DrawerView.js | 12 +- .../src/views/Transitioner.js | 8 + .../__tests__/NavigationScenesReducer-test.js | 11 ++ .../src/views/__tests__/TabView-test.js | 5 + .../__snapshots__/TabView-test.js.snap | 1 + .../src/withCachedChildNavigation.js | 5 + packages/react-navigation/yarn.lock | 8 +- 28 files changed, 734 insertions(+), 180 deletions(-) delete mode 100644 packages/react-navigation/examples/NavigationPlayground/.flowconfig create mode 100644 packages/react-navigation/prettier.config.js create mode 100644 packages/react-navigation/src/getChildEventSubscriber.js diff --git a/packages/react-navigation/examples/NavigationPlayground/.flowconfig b/packages/react-navigation/examples/NavigationPlayground/.flowconfig deleted file mode 100644 index 171bb5bd..00000000 --- a/packages/react-navigation/examples/NavigationPlayground/.flowconfig +++ /dev/null @@ -1,81 +0,0 @@ -[ignore] -; We fork some components by platform -.*/*[.]android.js - -; Ignore "BUCK" generated dirs -/\.buckd/ - -; Ignore unexpected extra "@providesModule" -.*/node_modules/.*/node_modules/fbjs/.* - -; Ignore duplicate module providers -; For RN Apps installed via npm, "Libraries" folder is inside -; "node_modules/react-native" but in the source repo it is in the root -.*/Libraries/react-native/React.js - -; Ignore polyfills -.*/Libraries/polyfills/.* - -.*/react-navigation/node_modules/.* - -; Additional create-react-native-app ignores - -; Ignore duplicate module providers -.*/node_modules/fbemitter/lib/* - -; Ignore misbehaving dev-dependencies -.*/node_modules/xdl/build/* -.*/node_modules/reqwest/tests/* - -; Ignore missing expo-sdk dependencies (temporarily) -; https://github.com/expo/expo/issues/162 -.*/node_modules/expo/src/* - -; Ignore react-native-fbads dependency of the expo sdk -.*/node_modules/react-native-fbads/* - -.*/react-navigation/lib-rn/.* -.*/react-navigation/lib/.* - -.*/react-navigation/examples/ReduxExample/.* -.*/react-navigation/website/.* - -; This package is required by Expo and causes Flow errors -.*/node_modules/react-native-gesture-handler/.* - -[include] - -[libs] -node_modules/react-native/Libraries/react-native/react-native-interface.js -node_modules/react-native/flow/ - -[options] -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' -module.file_ext=.js -module.file_ext=.jsx -module.file_ext=.json -module.file_ext=.native.js - -suppress_type=$FlowIssue -suppress_type=$FlowFixMe -suppress_type=$FlowFixMeProps -suppress_type=$FlowFixMeState -suppress_type=$FixMe - -suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) -suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ -suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy -suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError - -unsafe.enable_getters_and_setters=true - -[version] -^0.56.0 diff --git a/packages/react-navigation/examples/NavigationPlayground/js/SimpleStack.js b/packages/react-navigation/examples/NavigationPlayground/js/SimpleStack.js index c8047fe3..53e92100 100644 --- a/packages/react-navigation/examples/NavigationPlayground/js/SimpleStack.js +++ b/packages/react-navigation/examples/NavigationPlayground/js/SimpleStack.js @@ -7,38 +7,101 @@ import { Button, ScrollView, StatusBar } from 'react-native'; import { StackNavigator, SafeAreaView } from 'react-navigation'; import SampleText from './SampleText'; -const MyNavScreen = ({ navigation, banner }) => ( - - {banner} -