Skip to content

Commit adfed51

Browse files
committed
Add getTopmostFullScreenRoute
1 parent 8a9fc5c commit adfed51

3 files changed

Lines changed: 32 additions & 20 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {navigationRef} from '@libs/Navigation/Navigation';
2+
import type {NavigationRoute, RootNavigatorParamList, State} from '@libs/Navigation/types';
3+
import NAVIGATORS from '@src/NAVIGATORS';
4+
5+
/**
6+
* Returns the active tab route of the topmost TAB_NAVIGATOR in the root navigation state.
7+
* Use this to determine which full-screen tab (Search, Inbox, etc.) is currently focused.
8+
*/
9+
function getTopmostFullScreenRoute(): NavigationRoute | undefined {
10+
const rootState = navigationRef.getRootState() as State<RootNavigatorParamList>;
11+
12+
if (!rootState) {
13+
return undefined;
14+
}
15+
16+
const topmostTabNavigatorRoute = rootState.routes.findLast((route) => route.name === NAVIGATORS.TAB_NAVIGATOR);
17+
if (!topmostTabNavigatorRoute?.state) {
18+
return undefined;
19+
}
20+
const index = topmostTabNavigatorRoute.state.index ?? 0;
21+
return topmostTabNavigatorRoute.state.routes?.at(index);
22+
}
23+
24+
export default getTopmostFullScreenRoute;
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
import {navigationRef} from '@libs/Navigation/Navigation';
2-
import type {RootNavigatorParamList, State} from '@libs/Navigation/types';
31
import NAVIGATORS from '@src/NAVIGATORS';
4-
import getActiveTabName from './getActiveTabName';
5-
import {isFullScreenName} from './isNavigatorName';
2+
import getTopmostFullScreenRoute from './getTopmostFullScreenRoute';
63

74
const isReportTopmostSplitNavigator = (): boolean => {
8-
const rootState = navigationRef.getRootState() as State<RootNavigatorParamList>;
9-
10-
if (!rootState) {
5+
const topmostFullScreenRoute = getTopmostFullScreenRoute();
6+
if (!topmostFullScreenRoute) {
117
return false;
128
}
13-
14-
const topmostFullScreenRoute = rootState.routes.findLast((route) => isFullScreenName(route.name));
15-
return getActiveTabName(topmostFullScreenRoute) === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR;
9+
return topmostFullScreenRoute.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR;
1610
};
1711

1812
export default isReportTopmostSplitNavigator;
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
import {navigationRef} from '@libs/Navigation/Navigation';
2-
import type {RootNavigatorParamList, State} from '@libs/Navigation/types';
31
import NAVIGATORS from '@src/NAVIGATORS';
4-
import getActiveTabName from './getActiveTabName';
5-
import {isFullScreenName} from './isNavigatorName';
2+
import getTopmostFullScreenRoute from './getTopmostFullScreenRoute';
63

74
const isSearchTopmostFullScreenRoute = (): boolean => {
8-
const rootState = navigationRef.getRootState() as State<RootNavigatorParamList>;
9-
10-
if (!rootState) {
5+
const topmostFullScreenRoute = getTopmostFullScreenRoute();
6+
if (!topmostFullScreenRoute) {
117
return false;
128
}
13-
14-
const topmostFullScreenRoute = rootState.routes.findLast((route) => isFullScreenName(route.name));
15-
return getActiveTabName(topmostFullScreenRoute) === NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR;
9+
return topmostFullScreenRoute.name === NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR;
1610
};
1711

1812
export default isSearchTopmostFullScreenRoute;

0 commit comments

Comments
 (0)