mirror of
https://github.com/status-im/react-navigation.git
synced 2025-02-24 09:08:15 +00:00
Don't forward back actions to inactive children of TabRouters (#2121)
This commit is contained in:
parent
a62ad18b31
commit
e0de8b4dce
@ -100,12 +100,12 @@ export default (routeConfigs, config = {}) => {
|
||||
let activeTabIndex = state.index;
|
||||
const isBackEligible =
|
||||
action.key == null || action.key === activeTabLastState.key;
|
||||
if (
|
||||
action.type === NavigationActions.BACK &&
|
||||
isBackEligible &&
|
||||
shouldBackNavigateToInitialRoute
|
||||
) {
|
||||
activeTabIndex = initialRouteIndex;
|
||||
if (action.type === NavigationActions.BACK) {
|
||||
if (isBackEligible && shouldBackNavigateToInitialRoute) {
|
||||
activeTabIndex = initialRouteIndex;
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
let didNavigate = false;
|
||||
if (action.type === NavigationActions.NAVIGATE) {
|
||||
|
@ -634,6 +634,69 @@ describe('TabRouter', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('Back actions are not propagated to inactive children', () => {
|
||||
const ScreenA = () => <div />;
|
||||
const ScreenB = () => <div />;
|
||||
const ScreenC = () => <div />;
|
||||
const InnerNavigator = () => <div />;
|
||||
InnerNavigator.router = TabRouter({
|
||||
a: { screen: ScreenA },
|
||||
b: { screen: ScreenB },
|
||||
});
|
||||
|
||||
const router = TabRouter(
|
||||
{
|
||||
inner: { screen: InnerNavigator },
|
||||
c: { screen: ScreenC },
|
||||
},
|
||||
{
|
||||
backBehavior: 'none',
|
||||
}
|
||||
);
|
||||
|
||||
const state0 = router.getStateForAction(INIT_ACTION);
|
||||
|
||||
const state1 = router.getStateForAction(
|
||||
{ type: NavigationActions.NAVIGATE, routeName: 'b' },
|
||||
state0
|
||||
);
|
||||
|
||||
const state2 = router.getStateForAction(
|
||||
{ type: NavigationActions.NAVIGATE, routeName: 'c' },
|
||||
state1
|
||||
);
|
||||
|
||||
const state3 = router.getStateForAction(
|
||||
{ type: NavigationActions.BACK },
|
||||
state2
|
||||
);
|
||||
|
||||
expect(state3).toEqual(state2);
|
||||
});
|
||||
|
||||
test('Back behavior initialRoute works', () => {
|
||||
const ScreenA = () => <div />;
|
||||
const ScreenB = () => <div />;
|
||||
const router = TabRouter({
|
||||
a: { screen: ScreenA },
|
||||
b: { screen: ScreenB },
|
||||
});
|
||||
|
||||
const state0 = router.getStateForAction(INIT_ACTION);
|
||||
|
||||
const state1 = router.getStateForAction(
|
||||
{ type: NavigationActions.NAVIGATE, routeName: 'b' },
|
||||
state0
|
||||
);
|
||||
|
||||
const state2 = router.getStateForAction(
|
||||
{ type: NavigationActions.BACK },
|
||||
state1
|
||||
);
|
||||
|
||||
expect(state2).toEqual(state0);
|
||||
});
|
||||
|
||||
test('Inner actions are only unpacked if the current tab matches', () => {
|
||||
const PlainScreen = () => <div />;
|
||||
const ScreenA = () => <div />;
|
||||
|
Loading…
x
Reference in New Issue
Block a user