UNPKG

7.03 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 || 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({
51 theme = _DefaultTheme.default,
52 linking,
53 fallback = null,
54 documentTitle,
55 onReady,
56 ...rest
57}, ref) {
58 const isLinkingEnabled = linking ? linking.enabled !== false : false;
59
60 if (linking !== null && linking !== void 0 && linking.config) {
61 (0, _core.validatePathConfig)(linking.config);
62 }
63
64 const refContainer = React.useRef(null);
65 (0, _useBackButton.default)(refContainer);
66 (0, _useDocumentTitle.default)(refContainer, documentTitle);
67 const {
68 getInitialState
69 } = (0, _useLinking.default)(refContainer, {
70 independent: rest.independent,
71 enabled: isLinkingEnabled,
72 prefixes: [],
73 ...linking
74 }); // Add additional linking related info to the ref
75 // This will be used by the devtools
76
77 React.useEffect(() => {
78 if (refContainer.current) {
79 REACT_NAVIGATION_DEVTOOLS.set(refContainer.current, {
80 get linking() {
81 var _linking$prefixes, _linking$getStateFrom, _linking$getPathFromS, _linking$getActionFro;
82
83 return { ...linking,
84 enabled: isLinkingEnabled,
85 prefixes: (_linking$prefixes = linking === null || linking === void 0 ? void 0 : linking.prefixes) !== null && _linking$prefixes !== void 0 ? _linking$prefixes : [],
86 getStateFromPath: (_linking$getStateFrom = linking === null || linking === void 0 ? void 0 : linking.getStateFromPath) !== null && _linking$getStateFrom !== void 0 ? _linking$getStateFrom : _core.getStateFromPath,
87 getPathFromState: (_linking$getPathFromS = linking === null || linking === void 0 ? void 0 : linking.getPathFromState) !== null && _linking$getPathFromS !== void 0 ? _linking$getPathFromS : _core.getPathFromState,
88 getActionFromState: (_linking$getActionFro = linking === null || linking === void 0 ? void 0 : linking.getActionFromState) !== null && _linking$getActionFro !== void 0 ? _linking$getActionFro : _core.getActionFromState
89 };
90 }
91
92 });
93 }
94 });
95 const [isResolved, initialState] = (0, _useThenable.default)(getInitialState);
96 React.useImperativeHandle(ref, () => refContainer.current);
97 const linkingContext = React.useMemo(() => ({
98 options: linking
99 }), [linking]);
100 const isReady = rest.initialState != null || !isLinkingEnabled || isResolved;
101 const onReadyRef = React.useRef(onReady);
102 React.useEffect(() => {
103 onReadyRef.current = onReady;
104 });
105 React.useEffect(() => {
106 if (isReady) {
107 var _onReadyRef$current;
108
109 (_onReadyRef$current = onReadyRef.current) === null || _onReadyRef$current === void 0 ? void 0 : _onReadyRef$current.call(onReadyRef);
110 }
111 }, [isReady]);
112
113 if (!isReady) {
114 // This is temporary until we have Suspense for data-fetching
115 // Then the fallback will be handled by a parent `Suspense` component
116 return fallback;
117 }
118
119 return /*#__PURE__*/React.createElement(_LinkingContext.default.Provider, {
120 value: linkingContext
121 }, /*#__PURE__*/React.createElement(_ThemeProvider.default, {
122 value: theme
123 }, /*#__PURE__*/React.createElement(_core.BaseNavigationContainer, _extends({}, rest, {
124 initialState: rest.initialState == null ? initialState : rest.initialState,
125 ref: refContainer
126 }))));
127}
128
129const NavigationContainer = /*#__PURE__*/React.forwardRef(NavigationContainerInner);
130var _default = NavigationContainer;
131exports.default = _default;
132//# sourceMappingURL=NavigationContainer.js.map
\No newline at end of file