UNPKG

1.29 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = getFocusedRouteNameFromRoute;
7
8var _useRouteCache = require("./useRouteCache");
9
10function getFocusedRouteNameFromRoute(route) {
11 var _route$CHILD_STATE, _state$index;
12
13 // @ts-expect-error: this isn't in type definitions coz we want this private
14 const state = (_route$CHILD_STATE = route[_useRouteCache.CHILD_STATE]) !== null && _route$CHILD_STATE !== void 0 ? _route$CHILD_STATE : route.state;
15 const params = route.params;
16 const routeName = state ? // Get the currently active route name in the nested navigator
17 state.routes[// If we have a partial state without index, for tab/drawer, first screen will be focused one, and last for stack
18 // The type property will only exist for rehydrated state and not for state from deep link
19 (_state$index = state.index) !== null && _state$index !== void 0 ? _state$index : typeof state.type === 'string' && state.type !== 'stack' ? 0 : state.routes.length - 1].name : // If state doesn't exist, we need to default to `screen` param if available
20 typeof (params === null || params === void 0 ? void 0 : params.screen) === 'string' ? params.screen : undefined;
21 return routeName;
22}
23//# sourceMappingURL=getFocusedRouteNameFromRoute.js.map
\No newline at end of file