1 | import * as React from 'react';
|
2 | 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.`;
|
3 | export const SingleNavigatorContext = React.createContext(undefined);
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export default function EnsureSingleNavigator(_ref) {
|
9 | let {
|
10 | children
|
11 | } = _ref;
|
12 | const navigatorKeyRef = React.useRef();
|
13 | const value = React.useMemo(() => ({
|
14 | register(key) {
|
15 | const currentKey = navigatorKeyRef.current;
|
16 |
|
17 | if (currentKey !== undefined && key !== currentKey) {
|
18 | throw new Error(MULTIPLE_NAVIGATOR_ERROR);
|
19 | }
|
20 |
|
21 | navigatorKeyRef.current = key;
|
22 | },
|
23 |
|
24 | unregister(key) {
|
25 | const currentKey = navigatorKeyRef.current;
|
26 |
|
27 | if (key !== currentKey) {
|
28 | return;
|
29 | }
|
30 |
|
31 | navigatorKeyRef.current = undefined;
|
32 | }
|
33 |
|
34 | }), []);
|
35 | return React.createElement(SingleNavigatorContext.Provider, {
|
36 | value: value
|
37 | }, children);
|
38 | }
|
39 |
|
\ | No newline at end of file |