From 30166c52cb34a2f30fffbfcb19158756ca105cf0 Mon Sep 17 00:00:00 2001 From: Eric Vicenti Date: Thu, 10 Mar 2016 11:16:01 -0800 Subject: [PATCH] NavigationExperimental: Avoid double push on double-tap in UIExplorer Reviewed By: javache Differential Revision: D3033918 fb-gh-sync-id: 9085db138754f1aa557f0190456529e5e71ac27b shipit-source-id: 9085db138754f1aa557f0190456529e5e71ac27b --- Examples/UIExplorer/UIExplorerNavigationReducer.js | 6 +++++- .../Reducer/NavigationStackReducer.js | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Examples/UIExplorer/UIExplorerNavigationReducer.js b/Examples/UIExplorer/UIExplorerNavigationReducer.js index 77a09adf451..854e5b36eed 100644 --- a/Examples/UIExplorer/UIExplorerNavigationReducer.js +++ b/Examples/UIExplorer/UIExplorerNavigationReducer.js @@ -36,8 +36,12 @@ export type UIExplorerNavigationState = { }; const UIExplorerStackReducer = StackReducer({ - getPushedReducerForAction: (action) => { + getPushedReducerForAction: (action, lastState) => { if (action.type === 'UIExplorerExampleAction' && UIExplorerList.Modules[action.openExample]) { + if (lastState.children.find(child => child.key === action.openExample)) { + // The example is already open, we should avoid pushing examples twice + return null; + } return (state) => state || {key: action.openExample}; } return null; diff --git a/Libraries/NavigationExperimental/Reducer/NavigationStackReducer.js b/Libraries/NavigationExperimental/Reducer/NavigationStackReducer.js index f27df30fb04..520d788b866 100644 --- a/Libraries/NavigationExperimental/Reducer/NavigationStackReducer.js +++ b/Libraries/NavigationExperimental/Reducer/NavigationStackReducer.js @@ -29,7 +29,7 @@ export type NavigationStackReducerAction = BackAction | { export type ReducerForStateHandler = (state: NavigationState) => NavigationReducer; -export type PushedReducerForActionHandler = (action: any) => ?NavigationReducer; +export type PushedReducerForActionHandler = (action: any, lastState: NavigationParentState) => ?NavigationReducer; export type StackReducerConfig = { /* @@ -93,7 +93,7 @@ function NavigationStackReducer({initialState, getReducerForState, getPushedRedu }; } - const subReducerToPush = getPushedReducerForAction(action); + const subReducerToPush = getPushedReducerForAction(action, lastParentState); if (subReducerToPush) { return NavigationStateUtils.push( lastParentState,