mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-29 12:55:21 +08:00
Revert "StackRouter block actions while transitioning (#3469)"
This reverts commit 858a0d7a53.
This commit is contained in:
@@ -45,9 +45,6 @@ const navigate = createAction(NAVIGATE, payload => {
|
|||||||
if (payload.key) {
|
if (payload.key) {
|
||||||
action.key = payload.key;
|
action.key = payload.key;
|
||||||
}
|
}
|
||||||
if (payload.immediate) {
|
|
||||||
action.immediate = payload.immediate;
|
|
||||||
}
|
|
||||||
return action;
|
return action;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -73,9 +70,6 @@ const push = createAction(PUSH, payload => {
|
|||||||
if (payload.action) {
|
if (payload.action) {
|
||||||
action.action = payload.action;
|
action.action = payload.action;
|
||||||
}
|
}
|
||||||
if (payload.immediate) {
|
|
||||||
action.immediate = payload.immediate;
|
|
||||||
}
|
|
||||||
return action;
|
return action;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ describe('NavigationContainer', () => {
|
|||||||
// First dispatch
|
// First dispatch
|
||||||
expect(
|
expect(
|
||||||
navigationContainer.dispatch(
|
navigationContainer.dispatch(
|
||||||
NavigationActions.navigate({ routeName: 'bar', immediate: true })
|
NavigationActions.navigate({ routeName: 'bar' })
|
||||||
)
|
)
|
||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ describe('NavigationContainer', () => {
|
|||||||
// Second dispatch
|
// Second dispatch
|
||||||
expect(
|
expect(
|
||||||
navigationContainer.dispatch(
|
navigationContainer.dispatch(
|
||||||
NavigationActions.navigate({ routeName: 'baz', immediate: true })
|
NavigationActions.navigate({ routeName: 'baz' })
|
||||||
)
|
)
|
||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ describe('NavigationContainer', () => {
|
|||||||
// First dispatch
|
// First dispatch
|
||||||
expect(
|
expect(
|
||||||
navigationContainer.dispatch(
|
navigationContainer.dispatch(
|
||||||
NavigationActions.navigate({ routeName: 'bar', immediate: true })
|
NavigationActions.navigate({ routeName: 'bar' })
|
||||||
)
|
)
|
||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
|
|
||||||
@@ -157,28 +157,28 @@ describe('NavigationContainer', () => {
|
|||||||
// Second dispatch
|
// Second dispatch
|
||||||
expect(
|
expect(
|
||||||
navigationContainer.dispatch(
|
navigationContainer.dispatch(
|
||||||
NavigationActions.navigate({ routeName: 'baz', immediate: true })
|
NavigationActions.navigate({ routeName: 'baz' })
|
||||||
)
|
)
|
||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
|
|
||||||
// Third dispatch
|
// Third dispatch
|
||||||
expect(
|
expect(
|
||||||
navigationContainer.dispatch(
|
navigationContainer.dispatch(
|
||||||
NavigationActions.navigate({ routeName: 'car', immediate: true })
|
NavigationActions.navigate({ routeName: 'car' })
|
||||||
)
|
)
|
||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
|
|
||||||
// Fourth dispatch
|
// Fourth dispatch
|
||||||
expect(
|
expect(
|
||||||
navigationContainer.dispatch(
|
navigationContainer.dispatch(
|
||||||
NavigationActions.navigate({ routeName: 'dog', immediate: true })
|
NavigationActions.navigate({ routeName: 'dog' })
|
||||||
)
|
)
|
||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
|
|
||||||
// Fifth dispatch
|
// Fifth dispatch
|
||||||
expect(
|
expect(
|
||||||
navigationContainer.dispatch(
|
navigationContainer.dispatch(
|
||||||
NavigationActions.navigate({ routeName: 'elk', immediate: true })
|
NavigationActions.navigate({ routeName: 'elk' })
|
||||||
)
|
)
|
||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
|
|
||||||
|
|||||||
@@ -148,17 +148,6 @@ export default (routeConfigs, stackConfig = {}) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
action.type === NavigationActions.COMPLETE_TRANSITION &&
|
|
||||||
(action.key == null || action.key === state.key) &&
|
|
||||||
state.isTransitioning
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
isTransitioning: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if a child scene wants to handle the action as long as it is not a reset to the root stack
|
// Check if a child scene wants to handle the action as long as it is not a reset to the root stack
|
||||||
if (action.type !== NavigationActions.RESET || action.key !== null) {
|
if (action.type !== NavigationActions.RESET || action.key !== null) {
|
||||||
const keyIndex = action.key
|
const keyIndex = action.key
|
||||||
@@ -229,10 +218,6 @@ export default (routeConfigs, stackConfig = {}) => {
|
|||||||
behavesLikePushAction(action) &&
|
behavesLikePushAction(action) &&
|
||||||
childRouters[action.routeName] !== undefined
|
childRouters[action.routeName] !== undefined
|
||||||
) {
|
) {
|
||||||
if (state.isTransitioning) {
|
|
||||||
return { ...state };
|
|
||||||
}
|
|
||||||
|
|
||||||
const childRouter = childRouters[action.routeName];
|
const childRouter = childRouters[action.routeName];
|
||||||
let route;
|
let route;
|
||||||
|
|
||||||
@@ -305,6 +290,17 @@ export default (routeConfigs, stackConfig = {}) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
action.type === NavigationActions.COMPLETE_TRANSITION &&
|
||||||
|
(action.key == null || action.key === state.key) &&
|
||||||
|
state.isTransitioning
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isTransitioning: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Handle navigation to other child routers that are not yet pushed
|
// Handle navigation to other child routers that are not yet pushed
|
||||||
if (behavesLikePushAction(action)) {
|
if (behavesLikePushAction(action)) {
|
||||||
const childRouterNames = Object.keys(childRouters);
|
const childRouterNames = Object.keys(childRouters);
|
||||||
|
|||||||
@@ -493,23 +493,6 @@ describe('StackRouter', () => {
|
|||||||
expect(poppedImmediatelyState.isTransitioning).toBe(false);
|
expect(poppedImmediatelyState.isTransitioning).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Navigate does not happen while transitioning', () => {
|
|
||||||
const TestRouter = StackRouter({
|
|
||||||
foo: { screen: () => <div /> },
|
|
||||||
bar: { screen: () => <div /> },
|
|
||||||
});
|
|
||||||
const initState = {
|
|
||||||
...TestRouter.getStateForAction(NavigationActions.init()),
|
|
||||||
isTransitioning: true,
|
|
||||||
};
|
|
||||||
const pushedState = TestRouter.getStateForAction(
|
|
||||||
NavigationActions.navigate({ routeName: 'bar' }),
|
|
||||||
initState
|
|
||||||
);
|
|
||||||
expect(pushedState.index).toEqual(0);
|
|
||||||
expect(pushedState.routes.length).toEqual(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Navigate Pushes duplicate routeName', () => {
|
test('Navigate Pushes duplicate routeName', () => {
|
||||||
const TestRouter = StackRouter({
|
const TestRouter = StackRouter({
|
||||||
foo: { screen: () => <div /> },
|
foo: { screen: () => <div /> },
|
||||||
@@ -517,13 +500,13 @@ describe('StackRouter', () => {
|
|||||||
});
|
});
|
||||||
const initState = TestRouter.getStateForAction(NavigationActions.init());
|
const initState = TestRouter.getStateForAction(NavigationActions.init());
|
||||||
const pushedState = TestRouter.getStateForAction(
|
const pushedState = TestRouter.getStateForAction(
|
||||||
NavigationActions.navigate({ routeName: 'bar', immediate: true }),
|
NavigationActions.navigate({ routeName: 'bar' }),
|
||||||
initState
|
initState
|
||||||
);
|
);
|
||||||
expect(pushedState.index).toEqual(1);
|
expect(pushedState.index).toEqual(1);
|
||||||
expect(pushedState.routes[1].routeName).toEqual('bar');
|
expect(pushedState.routes[1].routeName).toEqual('bar');
|
||||||
const pushedTwiceState = TestRouter.getStateForAction(
|
const pushedTwiceState = TestRouter.getStateForAction(
|
||||||
NavigationActions.navigate({ routeName: 'bar', immediate: true }),
|
NavigationActions.navigate({ routeName: 'bar' }),
|
||||||
pushedState
|
pushedState
|
||||||
);
|
);
|
||||||
expect(pushedTwiceState.index).toEqual(2);
|
expect(pushedTwiceState.index).toEqual(2);
|
||||||
@@ -557,7 +540,7 @@ describe('StackRouter', () => {
|
|||||||
});
|
});
|
||||||
const initState = TestRouter.getStateForAction(NavigationActions.init());
|
const initState = TestRouter.getStateForAction(NavigationActions.init());
|
||||||
const pushedState = TestRouter.getStateForAction(
|
const pushedState = TestRouter.getStateForAction(
|
||||||
NavigationActions.push({ routeName: 'bar', immediate: true }),
|
NavigationActions.push({ routeName: 'bar' }),
|
||||||
initState
|
initState
|
||||||
);
|
);
|
||||||
expect(pushedState.index).toEqual(1);
|
expect(pushedState.index).toEqual(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user