1 | import type { Route } from '@react-navigation/routers';
|
2 |
|
3 | import { CHILD_STATE } from './useRouteCache';
|
4 |
|
5 | export default function getFocusedRouteNameFromRoute(
|
6 | route: Partial<Route<string>>
|
7 | ): string | undefined {
|
8 |
|
9 | const state = route[CHILD_STATE] ?? route.state;
|
10 | const params = route.params as { screen?: unknown } | undefined;
|
11 |
|
12 | const routeName = state
|
13 | ?
|
14 | state.routes[
|
15 |
|
16 |
|
17 | state.index ??
|
18 | (typeof state.type === 'string' && state.type !== 'stack'
|
19 | ? 0
|
20 | : state.routes.length - 1)
|
21 | ].name
|
22 | :
|
23 | typeof params?.screen === 'string'
|
24 | ? params.screen
|
25 | : undefined;
|
26 |
|
27 | return routeName;
|
28 | }
|