UNPKG

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