diff --git a/src/nav/__tests__/navSelectors-test.js b/src/nav/__tests__/navActions-test.js similarity index 79% rename from src/nav/__tests__/navSelectors-test.js rename to src/nav/__tests__/navActions-test.js index 9075bb41df4..955cbe75e48 100644 --- a/src/nav/__tests__/navSelectors-test.js +++ b/src/nav/__tests__/navActions-test.js @@ -1,10 +1,10 @@ /* @flow strict-local */ import deepFreeze from 'deep-freeze'; -import { getSameRoutesCount } from '../navSelectors'; +import { navigateBack } from '../navActions'; import * as NavigationService from '../NavigationService'; -describe('getSameRoutesCount', () => { +describe('navigateBack', () => { test('if no routes the count of same routes is 0', () => { // $FlowFixMe[cannot-write] Make Flow understand about mocking. NavigationService.getState = jest.fn().mockReturnValue( @@ -13,9 +13,9 @@ describe('getSameRoutesCount', () => { }), ); - const count = getSameRoutesCount(); + const action = navigateBack(); - expect(count).toEqual(0); + expect(action.payload.count).toEqual(0); }); test('if last route differs from routes the count of same routes is 0', () => { @@ -26,9 +26,9 @@ describe('getSameRoutesCount', () => { }), ); - const count = getSameRoutesCount(); + const action = navigateBack(); - expect(count).toEqual(1); + expect(action.payload.count).toEqual(1); }); test('if several of the routes are the same ignore the params and return their count', () => { @@ -45,8 +45,8 @@ describe('getSameRoutesCount', () => { }), ); - const count = getSameRoutesCount(); + const action = navigateBack(); - expect(count).toEqual(3); + expect(action.payload.count).toEqual(3); }); }); diff --git a/src/nav/navActions.js b/src/nav/navActions.js index 49a45728629..22d79032a6e 100644 --- a/src/nav/navActions.js +++ b/src/nav/navActions.js @@ -6,11 +6,22 @@ import { type GenericNavigationAction, } from '@react-navigation/native'; +import * as NavigationService from './NavigationService'; import type { Message, Narrow, SharedData, UserId } from '../types'; import type { ApiResponseServerSettings } from '../api/settings/getServerSettings'; -import { getSameRoutesCount } from '../selectors'; -export const navigateBack = (): PopAction => StackActions.pop(getSameRoutesCount()); +export const navigateBack = (): PopAction => { + const routes = NavigationService.getState().routes; + let i = routes.length - 1; + while (i >= 0) { + if (routes[i].name !== routes[routes.length - 1].name) { + break; + } + i--; + } + const sameRoutesCount = routes.length - i - 1; + return StackActions.pop(sameRoutesCount); +}; /* * "Reset" actions, to explicitly prohibit back navigation. diff --git a/src/nav/navSelectors.js b/src/nav/navSelectors.js deleted file mode 100644 index 899b23fbd39..00000000000 --- a/src/nav/navSelectors.js +++ /dev/null @@ -1,14 +0,0 @@ -/* @flow strict-local */ -import * as NavigationService from './NavigationService'; - -export const getSameRoutesCount = () => { - const routes = NavigationService.getState().routes; - let i = routes.length - 1; - while (i >= 0) { - if (routes[i].name !== routes[routes.length - 1].name) { - break; - } - i--; - } - return routes.length - i - 1; -}; diff --git a/src/selectors.js b/src/selectors.js index 66a0cd62aa9..c5c57d90aa9 100644 --- a/src/selectors.js +++ b/src/selectors.js @@ -7,7 +7,6 @@ export * from './chat/fetchingSelectors'; export * from './directSelectors'; export * from './emoji/emojiSelectors'; export * from './message/messageSelectors'; -export * from './nav/navSelectors'; export * from './subscriptions/subscriptionSelectors'; export * from './topics/topicSelectors'; export * from './typing/typingSelectors';