1 | import type { NavigationState, ParamListBase } from '@react-navigation/routers';
|
2 | import * as React from 'react';
|
3 |
|
4 | import CurrentRenderContext from './CurrentRenderContext';
|
5 | import type {
|
6 | Descriptor,
|
7 | NavigationHelpers,
|
8 | NavigationProp,
|
9 | RouteProp,
|
10 | } from './types';
|
11 |
|
12 | type Options = {
|
13 | state: NavigationState;
|
14 | navigation: NavigationHelpers<ParamListBase>;
|
15 | descriptors: Record<
|
16 | string,
|
17 | Descriptor<object, NavigationProp<ParamListBase>, RouteProp<ParamListBase>>
|
18 | >;
|
19 | };
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | export default function useCurrentRender({
|
26 | state,
|
27 | navigation,
|
28 | descriptors,
|
29 | }: Options) {
|
30 | const current = React.useContext(CurrentRenderContext);
|
31 |
|
32 | if (current && navigation.isFocused()) {
|
33 | current.options = descriptors[state.routes[state.index].key].options;
|
34 | }
|
35 | }
|