1 | function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
2 |
|
3 | import { BaseNavigationContainer, getActionFromState, getPathFromState, getStateFromPath, validatePathConfig } from '@react-navigation/core';
|
4 | import * as React from 'react';
|
5 | import LinkingContext from './LinkingContext';
|
6 | import DefaultTheme from './theming/DefaultTheme';
|
7 | import ThemeProvider from './theming/ThemeProvider';
|
8 | import useBackButton from './useBackButton';
|
9 | import useDocumentTitle from './useDocumentTitle';
|
10 | import useLinking from './useLinking';
|
11 | import useThenable from './useThenable';
|
12 | global.REACT_NAVIGATION_DEVTOOLS = new WeakMap();
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | function NavigationContainerInner(_ref, ref) {
|
29 | let {
|
30 | theme = DefaultTheme,
|
31 | linking,
|
32 | fallback = null,
|
33 | documentTitle,
|
34 | onReady,
|
35 | ...rest
|
36 | } = _ref;
|
37 | const isLinkingEnabled = linking ? linking.enabled !== false : false;
|
38 |
|
39 | if (linking !== null && linking !== void 0 && linking.config) {
|
40 | validatePathConfig(linking.config);
|
41 | }
|
42 |
|
43 | const refContainer = React.useRef(null);
|
44 | useBackButton(refContainer);
|
45 | useDocumentTitle(refContainer, documentTitle);
|
46 | const {
|
47 | getInitialState
|
48 | } = useLinking(refContainer, {
|
49 | independent: rest.independent,
|
50 | enabled: isLinkingEnabled,
|
51 | prefixes: [],
|
52 | ...linking
|
53 | });
|
54 |
|
55 |
|
56 | React.useEffect(() => {
|
57 | if (refContainer.current) {
|
58 | REACT_NAVIGATION_DEVTOOLS.set(refContainer.current, {
|
59 | get linking() {
|
60 | var _linking$prefixes, _linking$getStateFrom, _linking$getPathFromS, _linking$getActionFro;
|
61 |
|
62 | return { ...linking,
|
63 | enabled: isLinkingEnabled,
|
64 | prefixes: (_linking$prefixes = linking === null || linking === void 0 ? void 0 : linking.prefixes) !== null && _linking$prefixes !== void 0 ? _linking$prefixes : [],
|
65 | getStateFromPath: (_linking$getStateFrom = linking === null || linking === void 0 ? void 0 : linking.getStateFromPath) !== null && _linking$getStateFrom !== void 0 ? _linking$getStateFrom : getStateFromPath,
|
66 | getPathFromState: (_linking$getPathFromS = linking === null || linking === void 0 ? void 0 : linking.getPathFromState) !== null && _linking$getPathFromS !== void 0 ? _linking$getPathFromS : getPathFromState,
|
67 | getActionFromState: (_linking$getActionFro = linking === null || linking === void 0 ? void 0 : linking.getActionFromState) !== null && _linking$getActionFro !== void 0 ? _linking$getActionFro : getActionFromState
|
68 | };
|
69 | }
|
70 |
|
71 | });
|
72 | }
|
73 | });
|
74 | const [isResolved, initialState] = useThenable(getInitialState);
|
75 | React.useImperativeHandle(ref, () => refContainer.current);
|
76 | const linkingContext = React.useMemo(() => ({
|
77 | options: linking
|
78 | }), [linking]);
|
79 | const isReady = rest.initialState != null || !isLinkingEnabled || isResolved;
|
80 | const onReadyRef = React.useRef(onReady);
|
81 | React.useEffect(() => {
|
82 | onReadyRef.current = onReady;
|
83 | });
|
84 | React.useEffect(() => {
|
85 | if (isReady) {
|
86 | var _onReadyRef$current;
|
87 |
|
88 | (_onReadyRef$current = onReadyRef.current) === null || _onReadyRef$current === void 0 ? void 0 : _onReadyRef$current.call(onReadyRef);
|
89 | }
|
90 | }, [isReady]);
|
91 |
|
92 | if (!isReady) {
|
93 |
|
94 |
|
95 | return fallback;
|
96 | }
|
97 |
|
98 | return React.createElement(LinkingContext.Provider, {
|
99 | value: linkingContext
|
100 | }, React.createElement(ThemeProvider, {
|
101 | value: theme
|
102 | }, React.createElement(BaseNavigationContainer, _extends({}, rest, {
|
103 | initialState: rest.initialState == null ? initialState : rest.initialState,
|
104 | ref: refContainer
|
105 | }))));
|
106 | }
|
107 |
|
108 | const NavigationContainer = React.forwardRef(NavigationContainerInner);
|
109 | export default NavigationContainer;
|
110 |
|
\ | No newline at end of file |