NavigationExperimental: Avoid double push on double-tap in UIExplorer

Reviewed By: javache

Differential Revision: D3033918

fb-gh-sync-id: 9085db138754f1aa557f0190456529e5e71ac27b
shipit-source-id: 9085db138754f1aa557f0190456529e5e71ac27b
This commit is contained in:
Eric Vicenti 2016-03-10 11:16:01 -08:00 committed by Facebook Github Bot 1
parent c304364af4
commit 30166c52cb
2 changed files with 7 additions and 3 deletions

View File

@ -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;

View File

@ -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,