1 | function _extends() { _extends = Object.assign || 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({
|
29 | theme = DefaultTheme,
|
30 | linking,
|
31 | fallback = null,
|
32 | documentTitle,
|
33 | onReady,
|
34 | ...rest
|
35 | }, ref) {
|
36 | const isLinkingEnabled = linking ? linking.enabled !== false : false;
|
37 |
|
38 | if (linking !== null && linking !== void 0 && linking.config) {
|
39 | validatePathConfig(linking.config);
|
40 | }
|
41 |
|
42 | const refContainer = React.useRef(null);
|
43 | useBackButton(refContainer);
|
44 | useDocumentTitle(refContainer, documentTitle);
|
45 | const {
|
46 | getInitialState
|
47 | } = useLinking(refContainer, {
|
48 | independent: rest.independent,
|
49 | enabled: isLinkingEnabled,
|
50 | prefixes: [],
|
51 | ...linking
|
52 | });
|
53 |
|
54 |
|
55 | React.useEffect(() => {
|
56 | if (refContainer.current) {
|
57 | REACT_NAVIGATION_DEVTOOLS.set(refContainer.current, {
|
58 | get linking() {
|
59 | var _linking$prefixes, _linking$getStateFrom, _linking$getPathFromS, _linking$getActionFro;
|
60 |
|
61 | return { ...linking,
|
62 | enabled: isLinkingEnabled,
|
63 | prefixes: (_linking$prefixes = linking === null || linking === void 0 ? void 0 : linking.prefixes) !== null && _linking$prefixes !== void 0 ? _linking$prefixes : [],
|
64 | getStateFromPath: (_linking$getStateFrom = linking === null || linking === void 0 ? void 0 : linking.getStateFromPath) !== null && _linking$getStateFrom !== void 0 ? _linking$getStateFrom : getStateFromPath,
|
65 | getPathFromState: (_linking$getPathFromS = linking === null || linking === void 0 ? void 0 : linking.getPathFromState) !== null && _linking$getPathFromS !== void 0 ? _linking$getPathFromS : getPathFromState,
|
66 | getActionFromState: (_linking$getActionFro = linking === null || linking === void 0 ? void 0 : linking.getActionFromState) !== null && _linking$getActionFro !== void 0 ? _linking$getActionFro : getActionFromState
|
67 | };
|
68 | }
|
69 |
|
70 | });
|
71 | }
|
72 | });
|
73 | const [isResolved, initialState] = useThenable(getInitialState);
|
74 | React.useImperativeHandle(ref, () => refContainer.current);
|
75 | const linkingContext = React.useMemo(() => ({
|
76 | options: linking
|
77 | }), [linking]);
|
78 | const isReady = rest.initialState != null || !isLinkingEnabled || isResolved;
|
79 | const onReadyRef = React.useRef(onReady);
|
80 | React.useEffect(() => {
|
81 | onReadyRef.current = onReady;
|
82 | });
|
83 | React.useEffect(() => {
|
84 | if (isReady) {
|
85 | var _onReadyRef$current;
|
86 |
|
87 | (_onReadyRef$current = onReadyRef.current) === null || _onReadyRef$current === void 0 ? void 0 : _onReadyRef$current.call(onReadyRef);
|
88 | }
|
89 | }, [isReady]);
|
90 |
|
91 | if (!isReady) {
|
92 |
|
93 |
|
94 | return fallback;
|
95 | }
|
96 |
|
97 | return React.createElement(LinkingContext.Provider, {
|
98 | value: linkingContext
|
99 | }, React.createElement(ThemeProvider, {
|
100 | value: theme
|
101 | }, React.createElement(BaseNavigationContainer, _extends({}, rest, {
|
102 | initialState: rest.initialState == null ? initialState : rest.initialState,
|
103 | ref: refContainer
|
104 | }))));
|
105 | }
|
106 |
|
107 | const NavigationContainer = React.forwardRef(NavigationContainerInner);
|
108 | export default NavigationContainer;
|
109 |
|
\ | No newline at end of file |