Skip to content

Commit

Permalink
Key for completion action, to prevent eager didFocus (react-navigatio…
Browse files Browse the repository at this point in the history
…n#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.
  • Loading branch information
ericvicenti authored and sourcecode911 committed Mar 9, 2020
1 parent 3747d9f commit 1da29ae
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/NavigationActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion src/navigators/StackNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}}
/>
Expand Down
4 changes: 3 additions & 1 deletion src/routers/StackRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`,
},
],
Expand Down Expand Up @@ -142,6 +142,7 @@ export default (routeConfigs, stackConfig = {}) => {
};
// eslint-disable-next-line no-param-reassign
state = {
key: 'StackRouterRoot',
isTransitioning: false,
index: 0,
routes: [route],
Expand Down Expand Up @@ -254,6 +255,7 @@ export default (routeConfigs, stackConfig = {}) => {

if (
action.type === NavigationActions.COMPLETE_TRANSITION &&
(action.key == null || action.key === state.key) &&
state.isTransitioning
) {
return {
Expand Down

0 comments on commit 1da29ae

Please sign in to comment.