UNPKG

7.08 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _core = require("@react-navigation/core");
9
10var React = _interopRequireWildcard(require("react"));
11
12var _LinkingContext = _interopRequireDefault(require("./LinkingContext"));
13
14var _DefaultTheme = _interopRequireDefault(require("./theming/DefaultTheme"));
15
16var _ThemeProvider = _interopRequireDefault(require("./theming/ThemeProvider"));
17
18var _useBackButton = _interopRequireDefault(require("./useBackButton"));
19
20var _useDocumentTitle = _interopRequireDefault(require("./useDocumentTitle"));
21
22var _useLinking = _interopRequireDefault(require("./useLinking"));
23
24var _useThenable = _interopRequireDefault(require("./useThenable"));
25
26function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
28function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
30function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
32function _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); }
33
34global.REACT_NAVIGATION_DEVTOOLS = new WeakMap();
35
36/**
37 * Container component which holds the navigation state designed for React Native apps.
38 * This should be rendered at the root wrapping the whole app.
39 *
40 * @param props.initialState Initial state object for the navigation tree. When deep link handling is enabled, this will override deep links when specified. Make sure that you don't specify an `initialState` when there's a deep link (`Linking.getInitialURL()`).
41 * @param props.onReady Callback which is called after the navigation tree mounts.
42 * @param props.onStateChange Callback which is called with the latest navigation state when it changes.
43 * @param props.theme Theme object for the navigators.
44 * @param props.linking Options for deep linking. Deep link handling is enabled when this prop is provided, unless `linking.enabled` is `false`.
45 * @param props.fallback Fallback component to render until we have finished getting initial state when linking is enabled. Defaults to `null`.
46 * @param props.documentTitle Options to configure the document title on Web. Updating document title is handled by default unless `documentTitle.enabled` is `false`.
47 * @param props.children Child elements to render the content.
48 * @param props.ref Ref object which refers to the navigation object containing helper methods.
49 */
50function NavigationContainerInner(_ref, ref) {
51 let {
52 theme = _DefaultTheme.default,
53 linking,
54 fallback = null,
55 documentTitle,
56 onReady,
57 ...rest
58 } = _ref;
59 const isLinkingEnabled = linking ? linking.enabled !== false : false;
60
61 if (linking !== null && linking !== void 0 && linking.config) {
62 (0, _core.validatePathConfig)(linking.config);
63 }
64
65 const refContainer = React.useRef(null);
66 (0, _useBackButton.default)(refContainer);
67 (0, _useDocumentTitle.default)(refContainer, documentTitle);
68 const {
69 getInitialState
70 } = (0, _useLinking.default)(refContainer, {
71 independent: rest.independent,
72 enabled: isLinkingEnabled,
73 prefixes: [],
74 ...linking
75 }); // Add additional linking related info to the ref
76 // This will be used by the devtools
77
78 React.useEffect(() => {
79 if (refContainer.current) {
80 REACT_NAVIGATION_DEVTOOLS.set(refContainer.current, {
81 get linking() {
82 var _linking$prefixes, _linking$getStateFrom, _linking$getPathFromS, _linking$getActionFro;
83
84 return { ...linking,
85 enabled: isLinkingEnabled,
86 prefixes: (_linking$prefixes = linking === null || linking === void 0 ? void 0 : linking.prefixes) !== null && _linking$prefixes !== void 0 ? _linking$prefixes : [],
87 getStateFromPath: (_linking$getStateFrom = linking === null || linking === void 0 ? void 0 : linking.getStateFromPath) !== null && _linking$getStateFrom !== void 0 ? _linking$getStateFrom : _core.getStateFromPath,
88 getPathFromState: (_linking$getPathFromS = linking === null || linking === void 0 ? void 0 : linking.getPathFromState) !== null && _linking$getPathFromS !== void 0 ? _linking$getPathFromS : _core.getPathFromState,
89 getActionFromState: (_linking$getActionFro = linking === null || linking === void 0 ? void 0 : linking.getActionFromState) !== null && _linking$getActionFro !== void 0 ? _linking$getActionFro : _core.getActionFromState
90 };
91 }
92
93 });
94 }
95 });
96 const [isResolved, initialState] = (0, _useThenable.default)(getInitialState);
97 React.useImperativeHandle(ref, () => refContainer.current);
98 const linkingContext = React.useMemo(() => ({
99 options: linking
100 }), [linking]);
101 const isReady = rest.initialState != null || !isLinkingEnabled || isResolved;
102 const onReadyRef = React.useRef(onReady);
103 React.useEffect(() => {
104 onReadyRef.current = onReady;
105 });
106 React.useEffect(() => {
107 if (isReady) {
108 var _onReadyRef$current;
109
110 (_onReadyRef$current = onReadyRef.current) === null || _onReadyRef$current === void 0 ? void 0 : _onReadyRef$current.call(onReadyRef);
111 }
112 }, [isReady]);
113
114 if (!isReady) {
115 // This is temporary until we have Suspense for data-fetching
116 // Then the fallback will be handled by a parent `Suspense` component
117 return fallback;
118 }
119
120 return /*#__PURE__*/React.createElement(_LinkingContext.default.Provider, {
121 value: linkingContext
122 }, /*#__PURE__*/React.createElement(_ThemeProvider.default, {
123 value: theme
124 }, /*#__PURE__*/React.createElement(_core.BaseNavigationContainer, _extends({}, rest, {
125 initialState: rest.initialState == null ? initialState : rest.initialState,
126 ref: refContainer
127 }))));
128}
129
130const NavigationContainer = /*#__PURE__*/React.forwardRef(NavigationContainerInner);
131var _default = NavigationContainer;
132exports.default = _default;
133//# sourceMappingURL=NavigationContainer.js.map
\No newline at end of file