1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.SingleNavigatorContext = void 0;
|
7 | exports.default = EnsureSingleNavigator;
|
8 |
|
9 | var React = _interopRequireWildcard(require("react"));
|
10 |
|
11 | function _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); }
|
12 |
|
13 | function _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; }
|
14 |
|
15 | const MULTIPLE_NAVIGATOR_ERROR = `Another navigator is already registered for this container. You likely have multiple navigators under a single "NavigationContainer" or "Screen". Make sure each navigator is under a separate "Screen" container. See https://reactnavigation.org/docs/nesting-navigators for a guide on nesting.`;
|
16 | const SingleNavigatorContext = React.createContext(undefined);
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | exports.SingleNavigatorContext = SingleNavigatorContext;
|
22 |
|
23 | function EnsureSingleNavigator(_ref) {
|
24 | let {
|
25 | children
|
26 | } = _ref;
|
27 | const navigatorKeyRef = React.useRef();
|
28 | const value = React.useMemo(() => ({
|
29 | register(key) {
|
30 | const currentKey = navigatorKeyRef.current;
|
31 |
|
32 | if (currentKey !== undefined && key !== currentKey) {
|
33 | throw new Error(MULTIPLE_NAVIGATOR_ERROR);
|
34 | }
|
35 |
|
36 | navigatorKeyRef.current = key;
|
37 | },
|
38 |
|
39 | unregister(key) {
|
40 | const currentKey = navigatorKeyRef.current;
|
41 |
|
42 | if (key !== currentKey) {
|
43 | return;
|
44 | }
|
45 |
|
46 | navigatorKeyRef.current = undefined;
|
47 | }
|
48 |
|
49 | }), []);
|
50 | return React.createElement(SingleNavigatorContext.Provider, {
|
51 | value: value
|
52 | }, children);
|
53 | }
|
54 |
|
\ | No newline at end of file |