From fae1f71fb3f3fcbf7ad8ffdb9e0f5f1a840bf660 Mon Sep 17 00:00:00 2001 From: Eric Vicenti Date: Mon, 5 Feb 2018 11:33:00 -0800 Subject: [PATCH] Key for completion action, to prevent eager didFocus (#3435) The completion action would previously change the isTransitioning of any state, but this will ensure that the completing navigator only marks its own state as isTransitioning:false. Now, even when transition completion happens immediately on the parent, the child focus event still waits for the child isTransitioning to go false. --- src/NavigationActions.js | 1 + src/navigators/StackNavigator.js | 2 +- src/routers/StackRouter.js | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/NavigationActions.js b/src/NavigationActions.js index 6724e9f7..453c46f2 100644 --- a/src/NavigationActions.js +++ b/src/NavigationActions.js @@ -92,6 +92,7 @@ const uri = createAction(URI, payload => ({ const completeTransition = createAction(COMPLETE_TRANSITION, payload => ({ type: COMPLETE_TRANSITION, + key: payload && payload.key, })); const mapDeprecatedNavigateAction = action => { diff --git a/src/navigators/StackNavigator.js b/src/navigators/StackNavigator.js index 7f2abb26..38273dec 100644 --- a/src/navigators/StackNavigator.js +++ b/src/navigators/StackNavigator.js @@ -44,7 +44,7 @@ export default (routeConfigMap, stackConfig = {}) => { onTransitionStart={onTransitionStart} onTransitionEnd={(lastTransition, transition) => { const { state, dispatch } = props.navigation; - dispatch(NavigationActions.completeTransition()); + dispatch(NavigationActions.completeTransition({ key: state.key })); onTransitionEnd && onTransitionEnd(); }} /> diff --git a/src/routers/StackRouter.js b/src/routers/StackRouter.js index b9b72396..088ede65 100644 --- a/src/routers/StackRouter.js +++ b/src/routers/StackRouter.js @@ -107,13 +107,13 @@ export default (routeConfigs, stackConfig = {}) => { childRouters[action.routeName] !== undefined ) { return { + key: 'StackRouterRoot', isTransitioning: false, index: 0, routes: [ { routeName: action.routeName, params: action.params, - type: undefined, key: `Init-${generateKey()}`, }, ], @@ -142,6 +142,7 @@ export default (routeConfigs, stackConfig = {}) => { }; // eslint-disable-next-line no-param-reassign state = { + key: 'StackRouterRoot', isTransitioning: false, index: 0, routes: [route], @@ -254,6 +255,7 @@ export default (routeConfigs, stackConfig = {}) => { if ( action.type === NavigationActions.COMPLETE_TRANSITION && + (action.key == null || action.key === state.key) && state.isTransitioning ) { return {