1 | import * as React from 'react';
|
2 | import NavigationBuilderContext from './NavigationBuilderContext';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export default function useOnRouteFocus(_ref) {
|
10 | let {
|
11 | router,
|
12 | getState,
|
13 | key: sourceRouteKey,
|
14 | setState
|
15 | } = _ref;
|
16 | const {
|
17 | onRouteFocus: onRouteFocusParent
|
18 | } = React.useContext(NavigationBuilderContext);
|
19 | return React.useCallback(key => {
|
20 | const state = getState();
|
21 | const result = router.getStateForRouteFocus(state, key);
|
22 |
|
23 | if (result !== state) {
|
24 | setState(result);
|
25 | }
|
26 |
|
27 | if (onRouteFocusParent !== undefined && sourceRouteKey !== undefined) {
|
28 | onRouteFocusParent(sourceRouteKey);
|
29 | }
|
30 | }, [getState, onRouteFocusParent, router, setState, sourceRouteKey]);
|
31 | }
|
32 |
|
\ | No newline at end of file |