@react-navigation/core 6.2.0 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +17 -11
  2. package/lib/commonjs/PreventRemoveContext.js +17 -0
  3. package/lib/commonjs/PreventRemoveContext.js.map +1 -0
  4. package/lib/commonjs/PreventRemoveProvider.js +114 -0
  5. package/lib/commonjs/PreventRemoveProvider.js.map +1 -0
  6. package/lib/commonjs/getStateFromPath.js +1 -1
  7. package/lib/commonjs/getStateFromPath.js.map +1 -1
  8. package/lib/commonjs/index.js +36 -0
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/types.js.map +1 -1
  11. package/lib/commonjs/useChildListeners.js +6 -3
  12. package/lib/commonjs/useChildListeners.js.map +1 -1
  13. package/lib/commonjs/useComponent.js +22 -12
  14. package/lib/commonjs/useComponent.js.map +1 -1
  15. package/lib/commonjs/useEventEmitter.js +13 -3
  16. package/lib/commonjs/useEventEmitter.js.map +1 -1
  17. package/lib/commonjs/useFocusEffect.js +1 -1
  18. package/lib/commonjs/useFocusEffect.js.map +1 -1
  19. package/lib/commonjs/useKeyedChildListeners.js +4 -2
  20. package/lib/commonjs/useKeyedChildListeners.js.map +1 -1
  21. package/lib/commonjs/useNavigationBuilder.js +4 -2
  22. package/lib/commonjs/useNavigationBuilder.js.map +1 -1
  23. package/lib/commonjs/useNavigationHelpers.js +0 -4
  24. package/lib/commonjs/useNavigationHelpers.js.map +1 -1
  25. package/lib/commonjs/usePreventRemove.js +59 -0
  26. package/lib/commonjs/usePreventRemove.js.map +1 -0
  27. package/lib/commonjs/usePreventRemoveContext.js +27 -0
  28. package/lib/commonjs/usePreventRemoveContext.js.map +1 -0
  29. package/lib/module/PreventRemoveContext.js +9 -0
  30. package/lib/module/PreventRemoveContext.js.map +1 -0
  31. package/lib/module/PreventRemoveProvider.js +96 -0
  32. package/lib/module/PreventRemoveProvider.js.map +1 -0
  33. package/lib/module/getStateFromPath.js +1 -1
  34. package/lib/module/getStateFromPath.js.map +1 -1
  35. package/lib/module/index.js +4 -0
  36. package/lib/module/index.js.map +1 -1
  37. package/lib/module/types.js.map +1 -1
  38. package/lib/module/useChildListeners.js +6 -3
  39. package/lib/module/useChildListeners.js.map +1 -1
  40. package/lib/module/useComponent.js +23 -12
  41. package/lib/module/useComponent.js.map +1 -1
  42. package/lib/module/useEventEmitter.js +13 -3
  43. package/lib/module/useEventEmitter.js.map +1 -1
  44. package/lib/module/useFocusEffect.js +1 -1
  45. package/lib/module/useFocusEffect.js.map +1 -1
  46. package/lib/module/useKeyedChildListeners.js +4 -2
  47. package/lib/module/useKeyedChildListeners.js.map +1 -1
  48. package/lib/module/useNavigationBuilder.js +3 -2
  49. package/lib/module/useNavigationBuilder.js.map +1 -1
  50. package/lib/module/useNavigationHelpers.js +0 -4
  51. package/lib/module/useNavigationHelpers.js.map +1 -1
  52. package/lib/module/usePreventRemove.js +41 -0
  53. package/lib/module/usePreventRemove.js.map +1 -0
  54. package/lib/module/usePreventRemoveContext.js +12 -0
  55. package/lib/module/usePreventRemoveContext.js.map +1 -0
  56. package/lib/typescript/src/NavigationBuilderContext.d.ts +1 -1
  57. package/lib/typescript/src/PreventRemoveContext.d.ts +13 -0
  58. package/lib/typescript/src/PreventRemoveProvider.d.ts +9 -0
  59. package/lib/typescript/src/index.d.ts +4 -0
  60. package/lib/typescript/src/types.d.ts +10 -6
  61. package/lib/typescript/src/useComponent.d.ts +5 -1
  62. package/lib/typescript/src/useDescriptors.d.ts +3 -3
  63. package/lib/typescript/src/useNavigationBuilder.d.ts +9 -7
  64. package/lib/typescript/src/useNavigationHelpers.d.ts +3 -3
  65. package/lib/typescript/src/usePreventRemove.d.ts +12 -0
  66. package/lib/typescript/src/usePreventRemoveContext.d.ts +4 -0
  67. package/package.json +10 -9
  68. package/src/PreventRemoveContext.tsx +21 -0
  69. package/src/PreventRemoveProvider.tsx +126 -0
  70. package/src/getStateFromPath.tsx +4 -1
  71. package/src/index.tsx +4 -0
  72. package/src/types.tsx +39 -14
  73. package/src/useChildListeners.tsx +5 -3
  74. package/src/useComponent.tsx +19 -12
  75. package/src/useEventEmitter.tsx +14 -3
  76. package/src/useFocusEffect.tsx +1 -1
  77. package/src/useKeyedChildListeners.tsx +8 -4
  78. package/src/useNavigationBuilder.tsx +6 -3
  79. package/src/useNavigationHelpers.tsx +0 -6
  80. package/src/usePreventRemove.tsx +51 -0
  81. package/src/usePreventRemoveContext.tsx +15 -0
@@ -11,26 +11,36 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
11
11
 
12
12
  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; }
13
13
 
14
- function _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); }
15
-
16
- function useComponent(Component, props) {
17
- const propsRef = React.useRef(props); // Normally refs shouldn't be mutated in render
14
+ const NavigationContent = _ref => {
15
+ let {
16
+ render,
17
+ children
18
+ } = _ref;
19
+ return render(children);
20
+ };
21
+
22
+ function useComponent(render) {
23
+ const renderRef = React.useRef(render); // Normally refs shouldn't be mutated in render
18
24
  // But we return a component which will be rendered
19
25
  // So it's just for immediate consumption
20
26
 
21
- propsRef.current = props;
27
+ renderRef.current = render;
22
28
  React.useEffect(() => {
23
- propsRef.current = null;
29
+ renderRef.current = null;
24
30
  });
25
- return React.useRef(rest => {
26
- const props = propsRef.current;
31
+ return React.useRef(_ref2 => {
32
+ let {
33
+ children
34
+ } = _ref2;
35
+ const render = renderRef.current;
27
36
 
28
- if (props === null) {
37
+ if (render === null) {
29
38
  throw new Error('The returned component must be rendered in the same render phase as the hook.');
30
- } // @ts-expect-error: the props should be fine here
31
-
39
+ }
32
40
 
33
- return /*#__PURE__*/React.createElement(Component, _extends({}, props, rest));
41
+ return /*#__PURE__*/React.createElement(NavigationContent, {
42
+ render: render
43
+ }, children);
34
44
  }).current;
35
45
  }
36
46
  //# sourceMappingURL=useComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["useComponent.tsx"],"names":["useComponent","Component","props","propsRef","React","useRef","current","useEffect","rest","Error"],"mappings":";;;;;;;AAAA;;;;;;;;AAEe,SAASA,YAAT,CAGbC,SAHa,EAGCC,KAHD,EAGW;AACxB,QAAMC,QAAQ,GAAGC,KAAK,CAACC,MAAN,CAAuBH,KAAvB,CAAjB,CADwB,CAGxB;AACA;AACA;;AACAC,EAAAA,QAAQ,CAACG,OAAT,GAAmBJ,KAAnB;AAEAE,EAAAA,KAAK,CAACG,SAAN,CAAgB,MAAM;AACpBJ,IAAAA,QAAQ,CAACG,OAAT,GAAmB,IAAnB;AACD,GAFD;AAIA,SAAOF,KAAK,CAACC,MAAN,CAAcG,IAAD,IAAkD;AACpE,UAAMN,KAAK,GAAGC,QAAQ,CAACG,OAAvB;;AAEA,QAAIJ,KAAK,KAAK,IAAd,EAAoB;AAClB,YAAM,IAAIO,KAAJ,CACJ,+EADI,CAAN;AAGD,KAPmE,CASpE;;;AACA,wBAAO,oBAAC,SAAD,eAAeP,KAAf,EAA0BM,IAA1B,EAAP;AACD,GAXM,EAWJF,OAXH;AAYD","sourcesContent":["import * as React from 'react';\n\nexport default function useComponent<\n T extends React.ComponentType<any>,\n P extends {}\n>(Component: T, props: P) {\n const propsRef = React.useRef<P | null>(props);\n\n // Normally refs shouldn't be mutated in render\n // But we return a component which will be rendered\n // So it's just for immediate consumption\n propsRef.current = props;\n\n React.useEffect(() => {\n propsRef.current = null;\n });\n\n return React.useRef((rest: Omit<React.ComponentProps<T>, keyof P>) => {\n const props = propsRef.current;\n\n if (props === null) {\n throw new Error(\n 'The returned component must be rendered in the same render phase as the hook.'\n );\n }\n\n // @ts-expect-error: the props should be fine here\n return <Component {...props} {...rest} />;\n }).current;\n}\n"]}
1
+ {"version":3,"sources":["useComponent.tsx"],"names":["NavigationContent","render","children","useComponent","renderRef","React","useRef","current","useEffect","Error"],"mappings":";;;;;;;AAAA;;;;;;AASA,MAAMA,iBAAiB,GAAG,QAAiC;AAAA,MAAhC;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAAgC;AACzD,SAAOD,MAAM,CAACC,QAAD,CAAb;AACD,CAFD;;AAIe,SAASC,YAAT,CAAsBF,MAAtB,EAAsC;AACnD,QAAMG,SAAS,GAAGC,KAAK,CAACC,MAAN,CAA4BL,MAA5B,CAAlB,CADmD,CAGnD;AACA;AACA;;AACAG,EAAAA,SAAS,CAACG,OAAV,GAAoBN,MAApB;AAEAI,EAAAA,KAAK,CAACG,SAAN,CAAgB,MAAM;AACpBJ,IAAAA,SAAS,CAACG,OAAV,GAAoB,IAApB;AACD,GAFD;AAIA,SAAOF,KAAK,CAACC,MAAN,CAAa,SAAiD;AAAA,QAAhD;AAAEJ,MAAAA;AAAF,KAAgD;AACnE,UAAMD,MAAM,GAAGG,SAAS,CAACG,OAAzB;;AAEA,QAAIN,MAAM,KAAK,IAAf,EAAqB;AACnB,YAAM,IAAIQ,KAAJ,CACJ,+EADI,CAAN;AAGD;;AAED,wBAAO,oBAAC,iBAAD;AAAmB,MAAA,MAAM,EAAER;AAA3B,OAAoCC,QAApC,CAAP;AACD,GAVM,EAUJK,OAVH;AAWD","sourcesContent":["import * as React from 'react';\n\ntype Render = (children: React.ReactNode) => JSX.Element;\n\ntype Props = {\n render: Render;\n children: React.ReactNode;\n};\n\nconst NavigationContent = ({ render, children }: Props) => {\n return render(children);\n};\n\nexport default function useComponent(render: Render) {\n const renderRef = React.useRef<Render | null>(render);\n\n // Normally refs shouldn't be mutated in render\n // But we return a component which will be rendered\n // So it's just for immediate consumption\n renderRef.current = render;\n\n React.useEffect(() => {\n renderRef.current = null;\n });\n\n return React.useRef(({ children }: { children: React.ReactNode }) => {\n const render = renderRef.current;\n\n if (render === null) {\n throw new Error(\n 'The returned component must be rendered in the same render phase as the hook.'\n );\n }\n\n return <NavigationContent render={render}>{children}</NavigationContent>;\n }).current;\n}\n"]}
@@ -19,7 +19,7 @@ function useEventEmitter(listen) {
19
19
  React.useEffect(() => {
20
20
  listenRef.current = listen;
21
21
  });
22
- const listeners = React.useRef({});
22
+ const listeners = React.useRef(Object.create(null));
23
23
  const create = React.useCallback(target => {
24
24
  const removeListener = (type, callback) => {
25
25
  const callbacks = listeners.current[type] ? listeners.current[type][target] : undefined;
@@ -29,14 +29,24 @@ function useEventEmitter(listen) {
29
29
  }
30
30
 
31
31
  const index = callbacks.indexOf(callback);
32
- callbacks.splice(index, 1);
32
+
33
+ if (index > -1) {
34
+ callbacks.splice(index, 1);
35
+ }
33
36
  };
34
37
 
35
38
  const addListener = (type, callback) => {
36
39
  listeners.current[type] = listeners.current[type] || {};
37
40
  listeners.current[type][target] = listeners.current[type][target] || [];
38
41
  listeners.current[type][target].push(callback);
39
- return () => removeListener(type, callback);
42
+ let removed = false;
43
+ return () => {
44
+ // Prevent removing other listeners when unsubscribing same listener multiple times
45
+ if (!removed) {
46
+ removed = true;
47
+ removeListener(type, callback);
48
+ }
49
+ };
40
50
  };
41
51
 
42
52
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["useEventEmitter.tsx"],"names":["useEventEmitter","listen","listenRef","React","useRef","useEffect","current","listeners","create","useCallback","target","removeListener","type","callback","callbacks","undefined","index","indexOf","splice","addListener","push","emit","data","canPreventDefault","items","slice","concat","Object","keys","map","t","filter","cb","i","self","lastIndexOf","event","defineProperty","enumerable","get","defaultPrevented","defineProperties","preventDefault","value","forEach","useMemo"],"mappings":";;;;;;;AAAA;;;;;;AAWA;AACA;AACA;AACe,SAASA,eAAT,CACbC,MADa,EAEc;AAC3B,QAAMC,SAAS,GAAGC,KAAK,CAACC,MAAN,CAAaH,MAAb,CAAlB;AAEAE,EAAAA,KAAK,CAACE,SAAN,CAAgB,MAAM;AACpBH,IAAAA,SAAS,CAACI,OAAV,GAAoBL,MAApB;AACD,GAFD;AAIA,QAAMM,SAAS,GAAGJ,KAAK,CAACC,MAAN,CAAwD,EAAxD,CAAlB;AAEA,QAAMI,MAAM,GAAGL,KAAK,CAACM,WAAN,CAAmBC,MAAD,IAAoB;AACnD,UAAMC,cAAc,GAAG,CAACC,IAAD,EAAeC,QAAf,KAAiD;AACtE,YAAMC,SAAS,GAAGP,SAAS,CAACD,OAAV,CAAkBM,IAAlB,IACdL,SAAS,CAACD,OAAV,CAAkBM,IAAlB,EAAwBF,MAAxB,CADc,GAEdK,SAFJ;;AAIA,UAAI,CAACD,SAAL,EAAgB;AACd;AACD;;AAED,YAAME,KAAK,GAAGF,SAAS,CAACG,OAAV,CAAkBJ,QAAlB,CAAd;AAEAC,MAAAA,SAAS,CAACI,MAAV,CAAiBF,KAAjB,EAAwB,CAAxB;AACD,KAZD;;AAcA,UAAMG,WAAW,GAAG,CAACP,IAAD,EAAeC,QAAf,KAAiD;AACnEN,MAAAA,SAAS,CAACD,OAAV,CAAkBM,IAAlB,IAA0BL,SAAS,CAACD,OAAV,CAAkBM,IAAlB,KAA2B,EAArD;AACAL,MAAAA,SAAS,CAACD,OAAV,CAAkBM,IAAlB,EAAwBF,MAAxB,IAAkCH,SAAS,CAACD,OAAV,CAAkBM,IAAlB,EAAwBF,MAAxB,KAAmC,EAArE;AACAH,MAAAA,SAAS,CAACD,OAAV,CAAkBM,IAAlB,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nCE,QAAAA,UAAU,EAAE,IADuB;;AAEnCC,QAAAA,GAAG,GAAG;AACJ,iBAAOjB,IAAP;AACD;;AAJkC,OAArC;AAMD;;AAED,QAAIC,iBAAJ,EAAuB;AACrB,UAAIiB,gBAAgB,GAAG,KAAvB;AAEAb,MAAAA,MAAM,CAACc,gBAAP,CAAwBL,KAAxB,EAA+B;AAC7BI,QAAAA,gBAAgB,EAAE;AAChBF,UAAAA,UAAU,EAAE,IADI;;AAEhBC,UAAAA,GAAG,GAAG;AACJ,mBAAOC,gBAAP;AACD;;AAJe,SADW;AAO7BE,QAAAA,cAAc,EAAE;AACdJ,UAAAA,UAAU,EAAE,IADE;;AAEdK,UAAAA,KAAK,GAAG;AACNH,YAAAA,gBAAgB,GAAG,IAAnB;AACD;;AAJa;AAPa,OAA/B;AAcD;;AAED,0BAAAtC,SAAS,CAACI,OAAV,+EAAAJ,SAAS,EAAWkC,KAAX,CAAT;AAEAtB,IAAAA,SAAS,SAAT,IAAAA,SAAS,WAAT,YAAAA,SAAS,CAAE8B,OAAX,CAAoBZ,EAAD,IAAQA,EAAE,CAACI,KAAD,CAA7B;AAEA,WAAOA,KAAP;AACD,GAtEU,EAuEX,EAvEW,CAAb;AA0EA,SAAOjC,KAAK,CAAC0C,OAAN,CAAc,OAAO;AAAErC,IAAAA,MAAF;AAAUa,IAAAA;AAAV,GAAP,CAAd,EAAwC,CAACb,MAAD,EAASa,IAAT,CAAxC,CAAP;AACD","sourcesContent":["import * as React from 'react';\n\nimport type { EventArg, EventConsumer, EventEmitter } from './types';\n\nexport type NavigationEventEmitter<T extends Record<string, any>> =\n EventEmitter<T> & {\n create: (target: string) => EventConsumer<T>;\n };\n\ntype Listeners = ((e: any) => void)[];\n\n/**\n * Hook to manage the event system used by the navigator to notify screens of various events.\n */\nexport default function useEventEmitter<T extends Record<string, any>>(\n listen?: (e: any) => void\n): NavigationEventEmitter<T> {\n const listenRef = React.useRef(listen);\n\n React.useEffect(() => {\n listenRef.current = listen;\n });\n\n const listeners = React.useRef<Record<string, Record<string, Listeners>>>({});\n\n const create = React.useCallback((target: string) => {\n const removeListener = (type: string, callback: (data: any) => void) => {\n const callbacks = listeners.current[type]\n ? listeners.current[type][target]\n : undefined;\n\n if (!callbacks) {\n return;\n }\n\n const index = callbacks.indexOf(callback);\n\n callbacks.splice(index, 1);\n };\n\n const addListener = (type: string, callback: (data: any) => void) => {\n listeners.current[type] = listeners.current[type] || {};\n listeners.current[type][target] = listeners.current[type][target] || [];\n listeners.current[type][target].push(callback);\n\n return () => removeListener(type, callback);\n };\n\n return {\n addListener,\n removeListener,\n };\n }, []);\n\n const emit = React.useCallback(\n ({\n type,\n data,\n target,\n canPreventDefault,\n }: {\n type: string;\n data?: any;\n target?: string;\n canPreventDefault?: boolean;\n }) => {\n const items = listeners.current[type] || {};\n\n // Copy the current list of callbacks in case they are mutated during execution\n const callbacks =\n target !== undefined\n ? items[target]?.slice()\n : ([] as Listeners)\n .concat(...Object.keys(items).map((t) => items[t]))\n .filter((cb, i, self) => self.lastIndexOf(cb) === i);\n\n const event: EventArg<any, any, any> = {\n get type() {\n return type;\n },\n };\n\n if (target !== undefined) {\n Object.defineProperty(event, 'target', {\n enumerable: true,\n get() {\n return target;\n },\n });\n }\n\n if (data !== undefined) {\n Object.defineProperty(event, 'data', {\n enumerable: true,\n get() {\n return data;\n },\n });\n }\n\n if (canPreventDefault) {\n let defaultPrevented = false;\n\n Object.defineProperties(event, {\n defaultPrevented: {\n enumerable: true,\n get() {\n return defaultPrevented;\n },\n },\n preventDefault: {\n enumerable: true,\n value() {\n defaultPrevented = true;\n },\n },\n });\n }\n\n listenRef.current?.(event);\n\n callbacks?.forEach((cb) => cb(event));\n\n return event as any;\n },\n []\n );\n\n return React.useMemo(() => ({ create, emit }), [create, emit]);\n}\n"]}
1
+ {"version":3,"sources":["useEventEmitter.tsx"],"names":["useEventEmitter","listen","listenRef","React","useRef","useEffect","current","listeners","Object","create","useCallback","target","removeListener","type","callback","callbacks","undefined","index","indexOf","splice","addListener","push","removed","emit","data","canPreventDefault","items","slice","concat","keys","map","t","filter","cb","i","self","lastIndexOf","event","defineProperty","enumerable","get","defaultPrevented","defineProperties","preventDefault","value","forEach","useMemo"],"mappings":";;;;;;;AAAA;;;;;;AAWA;AACA;AACA;AACe,SAASA,eAAT,CACbC,MADa,EAEc;AAC3B,QAAMC,SAAS,GAAGC,KAAK,CAACC,MAAN,CAAaH,MAAb,CAAlB;AAEAE,EAAAA,KAAK,CAACE,SAAN,CAAgB,MAAM;AACpBH,IAAAA,SAAS,CAACI,OAAV,GAAoBL,MAApB;AACD,GAFD;AAIA,QAAMM,SAAS,GAAGJ,KAAK,CAACC,MAAN,CAChBI,MAAM,CAACC,MAAP,CAAc,IAAd,CADgB,CAAlB;AAIA,QAAMA,MAAM,GAAGN,KAAK,CAACO,WAAN,CAAmBC,MAAD,IAAoB;AACnD,UAAMC,cAAc,GAAG,CAACC,IAAD,EAAeC,QAAf,KAAiD;AACtE,YAAMC,SAAS,GAAGR,SAAS,CAACD,OAAV,CAAkBO,IAAlB,IACdN,SAAS,CAACD,OAAV,CAAkBO,IAAlB,EAAwBF,MAAxB,CADc,GAEdK,SAFJ;;AAIA,UAAI,CAACD,SAAL,EAAgB;AACd;AACD;;AAED,YAAME,KAAK,GAAGF,SAAS,CAACG,OAAV,CAAkBJ,QAAlB,CAAd;;AAEA,UAAIG,KAAK,GAAG,CAAC,CAAb,EAAgB;AACdF,QAAAA,SAAS,CAACI,MAAV,CAAiBF,KAAjB,EAAwB,CAAxB;AACD;AACF,KAdD;;AAgBA,UAAMG,WAAW,GAAG,CAACP,IAAD,EAAeC,QAAf,KAAiD;AACnEP,MAAAA,SAAS,CAACD,OAAV,CAAkBO,IAAlB,IAA0BN,SAAS,CAACD,OAAV,CAAkBO,IAAlB,KAA2B,EAArD;AACAN,MAAAA,SAAS,CAACD,OAAV,CAAkBO,IAAlB,EAAwBF,MAAxB,IAAkCJ,SAAS,CAACD,OAAV,CAAkBO,IAA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UAAU,EAAE,IADyB;;AAErCC,QAAAA,GAAG,GAAG;AACJ,iBAAO7B,MAAP;AACD;;AAJoC,OAAvC;AAMD;;AAED,QAAIa,IAAI,KAAKR,SAAb,EAAwB;AACtBR,MAAAA,MAAM,CAAC8B,cAAP,CAAsBD,KAAtB,EAA6B,MAA7B,EAAqC;AACnCE,QAAAA,UAAU,EAAE,IADuB;;AAEnCC,QAAAA,GAAG,GAAG;AACJ,iBAAOhB,IAAP;AACD;;AAJkC,OAArC;AAMD;;AAED,QAAIC,iBAAJ,EAAuB;AACrB,UAAIgB,gBAAgB,GAAG,KAAvB;AAEAjC,MAAAA,MAAM,CAACkC,gBAAP,CAAwBL,KAAxB,EAA+B;AAC7BI,QAAAA,gBAAgB,EAAE;AAChBF,UAAAA,UAAU,EAAE,IADI;;AAEhBC,UAAAA,GAAG,GAAG;AACJ,mBAAOC,gBAAP;AACD;;AAJe,SADW;AAO7BE,QAAAA,cAAc,EAAE;AACdJ,UAAAA,UAAU,EAAE,IADE;;AAEdK,UAAAA,KAAK,GAAG;AACNH,YAAAA,gBAAgB,GAAG,IAAnB;AACD;;AAJa;AAPa,OAA/B;AAcD;;AAED,0BAAAvC,SAAS,CAACI,OAAV,+EAAAJ,SAAS,EAAWmC,KAAX,CAAT;AAEAtB,IAAAA,SAAS,SAAT,IAAAA,SAAS,WAAT,YAAAA,SAAS,CAAE8B,OAAX,CAAoBZ,EAAD,IAAQA,EAAE,CAACI,KAAD,CAA7B;AAEA,WAAOA,KAAP;AACD,GAtEU,EAuEX,EAvEW,CAAb;AA0EA,SAAOlC,KAAK,CAAC2C,OAAN,CAAc,OAAO;AAAErC,IAAAA,MAAF;AAAUc,IAAAA;AAAV,GAAP,CAAd,EAAwC,CAACd,MAAD,EAASc,IAAT,CAAxC,CAAP;AACD","sourcesContent":["import * as React from 'react';\n\nimport type { EventArg, EventConsumer, EventEmitter } from './types';\n\nexport type NavigationEventEmitter<T extends Record<string, any>> =\n EventEmitter<T> & {\n create: (target: string) => EventConsumer<T>;\n };\n\ntype Listeners = ((e: any) => void)[];\n\n/**\n * Hook to manage the event system used by the navigator to notify screens of various events.\n */\nexport default function useEventEmitter<T extends Record<string, any>>(\n listen?: (e: any) => void\n): NavigationEventEmitter<T> {\n const listenRef = React.useRef(listen);\n\n React.useEffect(() => {\n listenRef.current = listen;\n });\n\n const listeners = React.useRef<Record<string, Record<string, Listeners>>>(\n Object.create(null)\n );\n\n const create = React.useCallback((target: string) => {\n const removeListener = (type: string, callback: (data: any) => void) => {\n const callbacks = listeners.current[type]\n ? listeners.current[type][target]\n : undefined;\n\n if (!callbacks) {\n return;\n }\n\n const index = callbacks.indexOf(callback);\n\n if (index > -1) {\n callbacks.splice(index, 1);\n }\n };\n\n const addListener = (type: string, callback: (data: any) => void) => {\n listeners.current[type] = listeners.current[type] || {};\n listeners.current[type][target] = listeners.current[type][target] || [];\n listeners.current[type][target].push(callback);\n\n let removed = false;\n return () => {\n // Prevent removing other listeners when unsubscribing same listener multiple times\n if (!removed) {\n removed = true;\n removeListener(type, callback);\n }\n };\n };\n\n return {\n addListener,\n removeListener,\n };\n }, []);\n\n const emit = React.useCallback(\n ({\n type,\n data,\n target,\n canPreventDefault,\n }: {\n type: string;\n data?: any;\n target?: string;\n canPreventDefault?: boolean;\n }) => {\n const items = listeners.current[type] || {};\n\n // Copy the current list of callbacks in case they are mutated during execution\n const callbacks =\n target !== undefined\n ? items[target]?.slice()\n : ([] as Listeners)\n .concat(...Object.keys(items).map((t) => items[t]))\n .filter((cb, i, self) => self.lastIndexOf(cb) === i);\n\n const event: EventArg<any, any, any> = {\n get type() {\n return type;\n },\n };\n\n if (target !== undefined) {\n Object.defineProperty(event, 'target', {\n enumerable: true,\n get() {\n return target;\n },\n });\n }\n\n if (data !== undefined) {\n Object.defineProperty(event, 'data', {\n enumerable: true,\n get() {\n return data;\n },\n });\n }\n\n if (canPreventDefault) {\n let defaultPrevented = false;\n\n Object.defineProperties(event, {\n defaultPrevented: {\n enumerable: true,\n get() {\n return defaultPrevented;\n },\n },\n preventDefault: {\n enumerable: true,\n value() {\n defaultPrevented = true;\n },\n },\n });\n }\n\n listenRef.current?.(event);\n\n callbacks?.forEach((cb) => cb(event));\n\n return event as any;\n },\n []\n );\n\n return React.useMemo(() => ({ create, emit }), [create, emit]);\n}\n"]}
@@ -47,7 +47,7 @@ function useFocusEffect(effect) {
47
47
  if (destroy === null) {
48
48
  message += " You returned 'null'. If your effect does not require clean-up, return 'undefined' (or nothing).";
49
49
  } else if (typeof destroy.then === 'function') {
50
- message += "\n\nIt looks like you wrote 'useFocusEffect(async () => ...)' or returned a Promise. " + 'Instead, write the async function inside your effect ' + 'and call it immediately:\n\n' + 'useFocusEffect(\n' + ' React.useCallback() => {\n' + ' async function fetchData() {\n' + ' // You can await here\n' + ' const response = await MyAPI.getData(someId);\n' + ' // ...\n' + ' }\n\n' + ' fetchData();\n' + ' }, [someId])\n' + ');\n\n' + 'See usage guide: https://reactnavigation.org/docs/use-focus-effect';
50
+ message += "\n\nIt looks like you wrote 'useFocusEffect(async () => ...)' or returned a Promise. " + 'Instead, write the async function inside your effect ' + 'and call it immediately:\n\n' + 'useFocusEffect(\n' + ' React.useCallback(() => {\n' + ' async function fetchData() {\n' + ' // You can await here\n' + ' const response = await MyAPI.getData(someId);\n' + ' // ...\n' + ' }\n\n' + ' fetchData();\n' + ' }, [someId])\n' + ');\n\n' + 'See usage guide: https://reactnavigation.org/docs/use-focus-effect';
51
51
  } else {
52
52
  message += ` You returned '${JSON.stringify(destroy)}'.`;
53
53
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["useFocusEffect.tsx"],"names":["useFocusEffect","effect","navigation","arguments","undefined","message","console","error","React","useEffect","isFocused","cleanup","callback","destroy","process","env","NODE_ENV","then","JSON","stringify","unsubscribeFocus","addListener","unsubscribeBlur"],"mappings":";;;;;;;AAAA;;AAEA;;;;;;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAwBC,MAAxB,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,QAAQ,EAAlB;AACAF,MAAAA,SAAS,GAAG,IAAZ;AACD;;AAED,UAAMU,gBAAgB,GAAGlB,UAAU,CAACmB,WAAX,CAAuB,OAAvB,EAAgC,MAAM;AAC7D;AACA;AACA,UAAIX,SAAJ,EAAe;AACb;AACD;;AAED,UAAIC,OAAO,KAAKP,SAAhB,EAA2B;AACzBO,QAAAA,OAAO;AACR;;AAEDA,MAAAA,OAAO,GAAGC,QAAQ,EAAlB;AACAF,MAAAA,SAAS,GAAG,IAAZ;AACD,KAbwB,CAAzB;AAeA,UAAMY,eAAe,GAAGpB,UAAU,CAACmB,WAAX,CAAuB,MAAvB,EAA+B,MAAM;AAC3D,UAAIV,OAAO,KAAKP,SAAhB,EAA2B;AACzBO,QAAAA,OAAO;AACR;;AAEDA,MAAAA,OAAO,GAAGP,SAAV;AACAM,MAAAA,SAAS,GAAG,KAAZ;AACD,KAPuB,CAAxB;AASA,WAAO,MAAM;AACX,UAAIC,OAAO,KAAKP,SAAhB,EAA2B;AACzBO,QAAAA,OAAO;AACR;;AAEDS,MAAAA,gBAAgB;AAChBE,MAAAA,eAAe;AAChB,KAPD;AAQD,GAhFD,EAgFG,CAACrB,MAAD,EAASC,UAAT,CAhFH;AAiFD","sourcesContent":["import * as React from 'react';\n\nimport useNavigation from './useNavigation';\n\ntype EffectCallback = () => undefined | void | (() => void);\n\n/**\n * Hook to run an effect in a focused screen, similar to `React.useEffect`.\n * This can be used to perform side-effects such as fetching data or subscribing to events.\n * The passed callback should be wrapped in `React.useCallback` to avoid running the effect too often.\n *\n * @param callback Memoized callback containing the effect, should optionally return a cleanup function.\n */\nexport default function useFocusEffect(effect: EffectCallback) {\n const navigation = useNavigation();\n\n if (arguments[1] !== undefined) {\n const message =\n \"You passed a second argument to 'useFocusEffect', but it only accepts one argument. \" +\n \"If you want to pass a dependency array, you can use 'React.useCallback':\\n\\n\" +\n 'useFocusEffect(\\n' +\n ' React.useCallback(() => {\\n' +\n ' // Your code here\\n' +\n ' }, [depA, depB])\\n' +\n ');\\n\\n' +\n 'See usage guide: https://reactnavigation.org/docs/use-focus-effect';\n\n console.error(message);\n }\n\n React.useEffect(() => {\n let isFocused = false;\n let cleanup: undefined | void | (() => void);\n\n const callback = () => {\n const destroy = effect();\n\n if (destroy === undefined || typeof destroy === 'function') {\n return destroy;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n let message =\n 'An effect function must not return anything besides a function, which is used for clean-up.';\n\n if (destroy === null) {\n message +=\n \" You returned 'null'. If your effect does not require clean-up, return 'undefined' (or nothing).\";\n } else if (typeof (destroy as any).then === 'function') {\n message +=\n \"\\n\\nIt looks like you wrote 'useFocusEffect(async () => ...)' or returned a Promise. \" +\n 'Instead, write the async function inside your effect ' +\n 'and call it immediately:\\n\\n' +\n 'useFocusEffect(\\n' +\n ' React.useCallback() => {\\n' +\n ' async function fetchData() {\\n' +\n ' // You can await here\\n' +\n ' const response = await MyAPI.getData(someId);\\n' +\n ' // ...\\n' +\n ' }\\n\\n' +\n ' fetchData();\\n' +\n ' }, [someId])\\n' +\n ');\\n\\n' +\n 'See usage guide: https://reactnavigation.org/docs/use-focus-effect';\n } else {\n message += ` You returned '${JSON.stringify(destroy)}'.`;\n }\n\n console.error(message);\n }\n };\n\n // We need to run the effect on intial render/dep changes if the screen is focused\n if (navigation.isFocused()) {\n cleanup = callback();\n isFocused = true;\n }\n\n const unsubscribeFocus = navigation.addListener('focus', () => {\n // If callback was already called for focus, avoid calling it again\n // The focus event may also fire on intial render, so we guard against runing the effect twice\n if (isFocused) {\n return;\n }\n\n if (cleanup !== undefined) {\n cleanup();\n }\n\n cleanup = callback();\n isFocused = true;\n });\n\n const unsubscribeBlur = navigation.addListener('blur', () => {\n if (cleanup !== undefined) {\n cleanup();\n }\n\n cleanup = undefined;\n isFocused = false;\n });\n\n return () => {\n if (cleanup !== undefined) {\n cleanup();\n }\n\n unsubscribeFocus();\n unsubscribeBlur();\n };\n }, [effect, navigation]);\n}\n"]}
1
+ {"version":3,"sources":["useFocusEffect.tsx"],"names":["useFocusEffect","effect","navigation","arguments","undefined","message","console","error","React","useEffect","isFocused","cleanup","callback","destroy","process","env","NODE_ENV","then","JSON","stringify","unsubscribeFocus","addListener","unsubscribeBlur"],"mappings":";;;;;;;AAAA;;AAEA;;;;;;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAwBC,MAAxB,EAAgD;AAC7D,QAAMC,UAAU,GAAG,6BAAnB;;AAEA,MAAIC,SAAS,CAAC,CAAD,CAAT,KAAiBC,SAArB,EAAgC;AAC9B,UAAMC,OAAO,GACX,yFACA,8EADA,GAEA,mBAFA,GAGA,+BAHA,GAIA,yBAJA,GAKA,sBALA,GAMA,QANA,GAOA,oEARF;AAUAC,IAAAA,OAAO,CAACC,KAAR,CAAcF,OAAd;AACD;;AAEDG,EAAAA,KAAK,CAACC,SAAN,CAAgB,MAAM;AACpB,QAAIC,SAAS,GAAG,KAAhB;AACA,QAAIC,OAAJ;;AAEA,UAAMC,QAAQ,GAAG,MAAM;AACrB,YAAMC,OAAO,GAAGZ,MAAM,EAAtB;;AAEA,UAAIY,OAAO,KAAKT,SAAZ,IAAyB,OAAOS,OAAP,KAAmB,UAAhD,EAA4D;AAC1D,eAAOA,OAAP;AACD;;AAED,UAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,YAAIX,OAAO,GACT,6FADF;;AAGA,YAAIQ,OAAO,KAAK,IAAhB,EAAsB;AACpBR,UAAAA,OAAO,IACL,kGADF;AAED,SAHD,MAGO,IAAI,OAAQQ,OAAD,CAAiBI,IAAxB,KAAiC,UAArC,EAAiD;AACtDZ,UAAAA,OAAO,IACL,0FACA,uDADA,GAEA,8BAFA,GAGA,mBAHA,GAIA,+BAJA,GAKA,oCALA,GAMA,+BANA,GAOA,uDAPA,GAQA,gBARA,GASA,WATA,GAUA,oBAVA,GAWA,kBAXA,GAYA,QAZA,GAaA,oEAdF;AAeD,SAhBM,MAgBA;AACLA,UAAAA,OAAO,IAAK,kBAAiBa,IAAI,CAACC,SAAL,CAAeN,OAAf,CAAwB,IAArD;AACD;;AAEDP,QAAAA,OAAO,CAACC,KAAR,CAAcF,OAAd;AACD;AACF,KApCD,CAJoB,CA0CpB;;;AACA,QAAIH,UAAU,CAACQ,SAAX,EAAJ,EAA4B;AAC1BC,MAAAA,OAAO,GAAGC,QAAQ,EAAlB;AACAF,MAAAA,SAAS,GAAG,IAAZ;AACD;;AAED,UAAMU,gBAAgB,GAAGlB,UAAU,CAACmB,WAAX,CAAuB,OAAvB,EAAgC,MAAM;AAC7D;AACA;AACA,UAAIX,SAAJ,EAAe;AACb;AACD;;AAED,UAAIC,OAAO,KAAKP,SAAhB,EAA2B;AACzBO,QAAAA,OAAO;AACR;;AAEDA,MAAAA,OAAO,GAAGC,QAAQ,EAAlB;AACAF,MAAAA,SAAS,GAAG,IAAZ;AACD,KAbwB,CAAzB;AAeA,UAAMY,eAAe,GAAGpB,UAAU,CAACmB,WAAX,CAAuB,MAAvB,EAA+B,MAAM;AAC3D,UAAIV,OAAO,KAAKP,SAAhB,EAA2B;AACzBO,QAAAA,OAAO;AACR;;AAEDA,MAAAA,OAAO,GAAGP,SAAV;AACAM,MAAAA,SAAS,GAAG,KAAZ;AACD,KAPuB,CAAxB;AASA,WAAO,MAAM;AACX,UAAIC,OAAO,KAAKP,SAAhB,EAA2B;AACzBO,QAAAA,OAAO;AACR;;AAEDS,MAAAA,gBAAgB;AAChBE,MAAAA,eAAe;AAChB,KAPD;AAQD,GAhFD,EAgFG,CAACrB,MAAD,EAASC,UAAT,CAhFH;AAiFD","sourcesContent":["import * as React from 'react';\n\nimport useNavigation from './useNavigation';\n\ntype EffectCallback = () => undefined | void | (() => void);\n\n/**\n * Hook to run an effect in a focused screen, similar to `React.useEffect`.\n * This can be used to perform side-effects such as fetching data or subscribing to events.\n * The passed callback should be wrapped in `React.useCallback` to avoid running the effect too often.\n *\n * @param callback Memoized callback containing the effect, should optionally return a cleanup function.\n */\nexport default function useFocusEffect(effect: EffectCallback) {\n const navigation = useNavigation();\n\n if (arguments[1] !== undefined) {\n const message =\n \"You passed a second argument to 'useFocusEffect', but it only accepts one argument. \" +\n \"If you want to pass a dependency array, you can use 'React.useCallback':\\n\\n\" +\n 'useFocusEffect(\\n' +\n ' React.useCallback(() => {\\n' +\n ' // Your code here\\n' +\n ' }, [depA, depB])\\n' +\n ');\\n\\n' +\n 'See usage guide: https://reactnavigation.org/docs/use-focus-effect';\n\n console.error(message);\n }\n\n React.useEffect(() => {\n let isFocused = false;\n let cleanup: undefined | void | (() => void);\n\n const callback = () => {\n const destroy = effect();\n\n if (destroy === undefined || typeof destroy === 'function') {\n return destroy;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n let message =\n 'An effect function must not return anything besides a function, which is used for clean-up.';\n\n if (destroy === null) {\n message +=\n \" You returned 'null'. If your effect does not require clean-up, return 'undefined' (or nothing).\";\n } else if (typeof (destroy as any).then === 'function') {\n message +=\n \"\\n\\nIt looks like you wrote 'useFocusEffect(async () => ...)' or returned a Promise. \" +\n 'Instead, write the async function inside your effect ' +\n 'and call it immediately:\\n\\n' +\n 'useFocusEffect(\\n' +\n ' React.useCallback(() => {\\n' +\n ' async function fetchData() {\\n' +\n ' // You can await here\\n' +\n ' const response = await MyAPI.getData(someId);\\n' +\n ' // ...\\n' +\n ' }\\n\\n' +\n ' fetchData();\\n' +\n ' }, [someId])\\n' +\n ');\\n\\n' +\n 'See usage guide: https://reactnavigation.org/docs/use-focus-effect';\n } else {\n message += ` You returned '${JSON.stringify(destroy)}'.`;\n }\n\n console.error(message);\n }\n };\n\n // We need to run the effect on intial render/dep changes if the screen is focused\n if (navigation.isFocused()) {\n cleanup = callback();\n isFocused = true;\n }\n\n const unsubscribeFocus = navigation.addListener('focus', () => {\n // If callback was already called for focus, avoid calling it again\n // The focus event may also fire on intial render, so we guard against runing the effect twice\n if (isFocused) {\n return;\n }\n\n if (cleanup !== undefined) {\n cleanup();\n }\n\n cleanup = callback();\n isFocused = true;\n });\n\n const unsubscribeBlur = navigation.addListener('blur', () => {\n if (cleanup !== undefined) {\n cleanup();\n }\n\n cleanup = undefined;\n isFocused = false;\n });\n\n return () => {\n if (cleanup !== undefined) {\n cleanup();\n }\n\n unsubscribeFocus();\n unsubscribeBlur();\n };\n }, [effect, navigation]);\n}\n"]}
@@ -17,13 +17,15 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
17
17
  function useKeyedChildListeners() {
18
18
  const {
19
19
  current: keyedListeners
20
- } = React.useRef({
20
+ } = React.useRef(Object.assign(Object.create(null), {
21
21
  getState: {},
22
22
  beforeRemove: {}
23
- });
23
+ }));
24
24
  const addKeyedListener = React.useCallback((type, key, listener) => {
25
+ // @ts-expect-error: according to ref stated above you can use `key` to index type
25
26
  keyedListeners[type][key] = listener;
26
27
  return () => {
28
+ // @ts-expect-error: according to ref stated above you can use `key` to index type
27
29
  keyedListeners[type][key] = undefined;
28
30
  };
29
31
  }, [keyedListeners]);
@@ -1 +1 @@
1
- {"version":3,"sources":["useKeyedChildListeners.tsx"],"names":["useKeyedChildListeners","current","keyedListeners","React","useRef","getState","beforeRemove","addKeyedListener","useCallback","type","key","listener","undefined"],"mappings":";;;;;;;AAAA;;;;;;AAIA;AACA;AACA;AACe,SAASA,sBAAT,GAAkC;AAC/C,QAAM;AAAEC,IAAAA,OAAO,EAAEC;AAAX,MAA8BC,KAAK,CAACC,MAAN,CAKjC;AACDC,IAAAA,QAAQ,EAAE,EADT;AAEDC,IAAAA,YAAY,EAAE;AAFb,GALiC,CAApC;AAUA,QAAMC,gBAAgB,GAAGJ,KAAK,CAACK,WAAN,CACvB,CACEC,IADF,EAEEC,GAFF,EAGEC,QAHF,KAIK;AACHT,IAAAA,cAAc,CAACO,IAAD,CAAd,CAAqBC,GAArB,IAA4BC,QAA5B;AAEA,WAAO,MAAM;AACXT,MAAAA,cAAc,CAACO,IAAD,CAAd,CAAqBC,GAArB,IAA4BE,SAA5B;AACD,KAFD;AAGD,GAXsB,EAYvB,CAACV,cAAD,CAZuB,CAAzB;AAeA,SAAO;AACLA,IAAAA,cADK;AAELK,IAAAA;AAFK,GAAP;AAID","sourcesContent":["import * as React from 'react';\n\nimport type { KeyedListenerMap } from './NavigationBuilderContext';\n\n/**\n * Hook which lets child navigators add getters to be called for obtaining rehydrated state.\n */\nexport default function useKeyedChildListeners() {\n const { current: keyedListeners } = React.useRef<{\n [K in keyof KeyedListenerMap]: Record<\n string,\n KeyedListenerMap[K] | undefined\n >;\n }>({\n getState: {},\n beforeRemove: {},\n });\n\n const addKeyedListener = React.useCallback(\n <T extends keyof KeyedListenerMap>(\n type: T,\n key: string,\n listener: KeyedListenerMap[T]\n ) => {\n keyedListeners[type][key] = listener;\n\n return () => {\n keyedListeners[type][key] = undefined;\n };\n },\n [keyedListeners]\n );\n\n return {\n keyedListeners,\n addKeyedListener,\n };\n}\n"]}
1
+ {"version":3,"sources":["useKeyedChildListeners.tsx"],"names":["useKeyedChildListeners","current","keyedListeners","React","useRef","Object","assign","create","getState","beforeRemove","addKeyedListener","useCallback","type","key","listener","undefined"],"mappings":";;;;;;;AAAA;;;;;;AAIA;AACA;AACA;AACe,SAASA,sBAAT,GAAkC;AAC/C,QAAM;AAAEC,IAAAA,OAAO,EAAEC;AAAX,MAA8BC,KAAK,CAACC,MAAN,CAMlCC,MAAM,CAACC,MAAP,CAAcD,MAAM,CAACE,MAAP,CAAc,IAAd,CAAd,EAAmC;AACjCC,IAAAA,QAAQ,EAAE,EADuB;AAEjCC,IAAAA,YAAY,EAAE;AAFmB,GAAnC,CANkC,CAApC;AAYA,QAAMC,gBAAgB,GAAGP,KAAK,CAACQ,WAAN,CACvB,CACEC,IADF,EAEEC,GAFF,EAGEC,QAHF,KAIK;AACH;AACAZ,IAAAA,cAAc,CAACU,IAAD,CAAd,CAAqBC,GAArB,IAA4BC,QAA5B;AAEA,WAAO,MAAM;AACX;AACAZ,MAAAA,cAAc,CAACU,IAAD,CAAd,CAAqBC,GAArB,IAA4BE,SAA5B;AACD,KAHD;AAID,GAbsB,EAcvB,CAACb,cAAD,CAduB,CAAzB;AAiBA,SAAO;AACLA,IAAAA,cADK;AAELQ,IAAAA;AAFK,GAAP;AAID","sourcesContent":["import * as React from 'react';\n\nimport type { KeyedListenerMap } from './NavigationBuilderContext';\n\n/**\n * Hook which lets child navigators add getters to be called for obtaining rehydrated state.\n */\nexport default function useKeyedChildListeners() {\n const { current: keyedListeners } = React.useRef<{\n [K in keyof KeyedListenerMap]: Record<\n string,\n KeyedListenerMap[K] | undefined\n >;\n }>(\n Object.assign(Object.create(null), {\n getState: {},\n beforeRemove: {},\n })\n );\n\n const addKeyedListener = React.useCallback(\n <T extends keyof KeyedListenerMap>(\n type: T,\n key: string,\n listener: KeyedListenerMap[T]\n ) => {\n // @ts-expect-error: according to ref stated above you can use `key` to index type\n keyedListeners[type][key] = listener;\n\n return () => {\n // @ts-expect-error: according to ref stated above you can use `key` to index type\n keyedListeners[type][key] = undefined;\n };\n },\n [keyedListeners]\n );\n\n return {\n keyedListeners,\n addKeyedListener,\n };\n}\n"]}
@@ -23,6 +23,8 @@ var _NavigationRouteContext = _interopRequireDefault(require("./NavigationRouteC
23
23
 
24
24
  var _NavigationStateContext = _interopRequireDefault(require("./NavigationStateContext"));
25
25
 
26
+ var _PreventRemoveProvider = _interopRequireDefault(require("./PreventRemoveProvider"));
27
+
26
28
  var _Screen = _interopRequireDefault(require("./Screen"));
27
29
 
28
30
  var _types = require("./types");
@@ -499,9 +501,9 @@ function useNavigationBuilder(createRouter, options) {
499
501
  navigation,
500
502
  descriptors
501
503
  });
502
- const NavigationContent = (0, _useComponent.default)(_NavigationHelpersContext.default.Provider, {
504
+ const NavigationContent = (0, _useComponent.default)(children => /*#__PURE__*/React.createElement(_NavigationHelpersContext.default.Provider, {
503
505
  value: navigation
504
- });
506
+ }, /*#__PURE__*/React.createElement(_PreventRemoveProvider.default, null, children)));
505
507
  return {
506
508
  state,
507
509
  navigation,
@@ -1 +1 @@
1
- {"version":3,"sources":["useNavigationBuilder.tsx"],"names":["PrivateValueStore","isValidKey","key","undefined","getRouteConfigsFromChildren","children","groupKey","groupOptions","configs","React","Children","toArray","reduce","acc","child","isValidElement","type","Screen","props","navigationKey","Error","JSON","stringify","name","push","keys","options","Fragment","Group","screenOptions","String","process","env","NODE_ENV","forEach","config","component","getComponent","console","warn","test","useNavigationBuilder","createRouter","navigatorKey","route","useContext","NavigationRouteContext","screenListeners","rest","current","router","useRef","params","state","initial","screen","initialRouteName","routeConfigs","screens","routeNames","map","routeKeyList","curr","join","routeParamList","initialParams","routeGetIdList","Object","assign","getId","length","isStateValid","useCallback","isStateInitialized","stale","currentState","getState","getCurrentState","setState","setCurrentState","setKey","getKey","getIsInitial","NavigationStateContext","stateCleanedUp","cleanUpState","initializedState","isFirstStateInitialization","useMemo","initialRouteParamList","initialParamsFromParams","getInitialState","getRehydratedState","previousRouteKeyListRef","useEffect","previousRouteKeyList","nextState","getStateForRouteNamesChange","routeKeyChanges","filter","hasOwnProperty","previousNestedParamsRef","previousParams","action","CommonActions","reset","navigate","path","updatedState","getStateForAction","shouldUpdate","setTimeout","initializedStateRef","emitter","e","target","routes","find","index","navigation","descriptors","listeners","concat","cb","i","self","lastIndexOf","listener","emit","data","childListeners","addListener","keyedListeners","addKeyedListener","onAction","actionListeners","beforeRemoveListeners","beforeRemove","routerConfigOptions","onRouteFocus","id","focusedListeners","focus","getStateListeners","defaultScreenOptions","NavigationContent","NavigationHelpersContext","Provider","value"],"mappings":";;;;;;;AAAA;;AAYA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA;AACA;AACAA;;AAOA,MAAMC,UAAU,GAAIC,GAAD,IACjBA,GAAG,KAAKC,SAAR,IAAsB,OAAOD,GAAP,KAA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,QANA;AAOA1D,IAAAA,QAPA;AAQAE,IAAAA,QARA;AASA6D,IAAAA,YATA;AAUAR,IAAAA,WAVA;AAWAE,IAAAA,gBAXA;AAYAnF,IAAAA,MAZA;AAaA;AACA+D,IAAAA;AAdA,GALkB,CAApB;AAsBA,iCAAiB;AACf5D,IAAAA,KADe;AAEfkE,IAAAA,UAFe;AAGfC,IAAAA;AAHe,GAAjB;AAMA,QAAMyB,iBAAiB,GAAG,2BAAaC,kCAAyBC,QAAtC,EAAgD;AACxEC,IAAAA,KAAK,EAAE7B;AADiE,GAAhD,CAA1B;AAIA,SAAO;AACLlE,IAAAA,KADK;AAELkE,IAAAA,UAFK;AAGLC,IAAAA,WAHK;AAILyB,IAAAA;AAJK,GAAP;AAMD","sourcesContent":["import {\n CommonActions,\n DefaultRouterOptions,\n NavigationAction,\n NavigationState,\n ParamListBase,\n PartialState,\n Route,\n Router,\n RouterConfigOptions,\n RouterFactory,\n} from '@react-navigation/routers';\nimport * as React from 'react';\nimport { isValidElementType } from 'react-is';\n\nimport Group from './Group';\nimport isArrayEqual from './isArrayEqual';\nimport isRecordEqual from './isRecordEqual';\nimport NavigationHelpersContext from './NavigationHelpersContext';\nimport NavigationRouteContext from './NavigationRouteContext';\nimport NavigationStateContext from './NavigationStateContext';\nimport Screen from './Screen';\nimport {\n DefaultNavigatorOptions,\n EventMapBase,\n EventMapCore,\n NavigatorScreenParams,\n PrivateValueStore,\n RouteConfig,\n} from './types';\nimport useChildListeners from './useChildListeners';\nimport useComponent from './useComponent';\nimport useCurrentRender from './useCurrentRender';\nimport useDescriptors, { ScreenConfigWithParent } from './useDescriptors';\nimport useEventEmitter from './useEventEmitter';\nimport useFocusedListenersChildrenAdapter from './useFocusedListenersChildrenAdapter';\nimport useFocusEvents from './useFocusEvents';\nimport useKeyedChildListeners from './useKeyedChildListeners';\nimport useNavigationHelpers from './useNavigationHelpers';\nimport useOnAction from './useOnAction';\nimport useOnGetState from './useOnGetState';\nimport useOnRouteFocus from './useOnRouteFocus';\nimport useRegisterNavigator from './useRegisterNavigator';\nimport useScheduleUpdate from './useScheduleUpdate';\n\n// This is to make TypeScript compiler happy\n// eslint-disable-next-line babel/no-unused-expressions\nPrivateValueStore;\n\ntype NavigatorRoute<State extends NavigationState> = {\n key: string;\n params?: NavigatorScreenParams<ParamListBase, State>;\n};\n\nconst isValidKey = (key: unknown) =>\n key === undefined || (typeof key === 'string' && key !== '');\n\n/**\n * Extract route config object from React children elements.\n *\n * @param children React Elements to extract the config from.\n */\nconst getRouteConfigsFromChildren = <\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n>(\n children: React.ReactNode,\n groupKey?: string,\n groupOptions?: ScreenConfigWithParent<\n State,\n ScreenOptions,\n EventMap\n >['options']\n) => {\n const configs = React.Children.toArray(children).reduce<\n ScreenConfigWithParent<State, ScreenOptions, EventMap>[]\n >((acc, child) => {\n if (React.isValidElement(child)) {\n if (child.type === Screen) {\n // We can only extract the config from `Screen` elements\n // If something else was rendered, it's probably a bug\n\n if (!isValidKey(child.props.navigationKey)) {\n throw new Error(\n `Got an invalid 'navigationKey' prop (${JSON.stringify(\n child.props.navigationKey\n )}) for the screen '${\n child.props.name\n }'. It must be a non-empty string or 'undefined'.`\n );\n }\n\n acc.push({\n keys: [groupKey, child.props.navigationKey],\n options: groupOptions,\n props: child.props as RouteConfig<\n ParamListBase,\n string,\n State,\n ScreenOptions,\n EventMap\n >,\n });\n return acc;\n }\n\n if (child.type === React.Fragment || child.type === Group) {\n if (!isValidKey(child.props.navigationKey)) {\n throw new Error(\n `Got an invalid 'navigationKey' prop (${JSON.stringify(\n child.props.navigationKey\n )}) for the group. It must be a non-empty string or 'undefined'.`\n );\n }\n\n // When we encounter a fragment or group, we need to dive into its children to extract the configs\n // This is handy to conditionally define a group of screens\n acc.push(\n ...getRouteConfigsFromChildren<State, ScreenOptions, EventMap>(\n child.props.children,\n child.props.navigationKey,\n child.type !== Group\n ? groupOptions\n : groupOptions != null\n ? [...groupOptions, child.props.screenOptions]\n : [child.props.screenOptions]\n )\n );\n return acc;\n }\n }\n\n throw new Error(\n `A navigator can only contain 'Screen', 'Group' or 'React.Fragment' as its direct children (found ${\n React.isValidElement(child)\n ? `'${\n typeof child.type === 'string' ? child.type : child.type?.name\n }'${\n child.props?.name ? ` for the screen '${child.props.name}'` : ''\n }`\n : typeof child === 'object'\n ? JSON.stringify(child)\n : `'${String(child)}'`\n }). To render this component in the navigator, pass it in the 'component' prop to 'Screen'.`\n );\n }, []);\n\n if (process.env.NODE_ENV !== 'production') {\n configs.forEach((config) => {\n const { name, children, component, getComponent } = config.props;\n\n if (typeof name !== 'string' || !name) {\n throw new Error(\n `Got an invalid name (${JSON.stringify(\n name\n )}) for the screen. It must be a non-empty string.`\n );\n }\n\n if (\n children != null ||\n component !== undefined ||\n getComponent !== undefined\n ) {\n if (children != null && component !== undefined) {\n throw new Error(\n `Got both 'component' and 'children' props for the screen '${name}'. You must pass only one of them.`\n );\n }\n\n if (children != null && getComponent !== undefined) {\n throw new Error(\n `Got both 'getComponent' and 'children' props for the screen '${name}'. You must pass only one of them.`\n );\n }\n\n if (component !== undefined && getComponent !== undefined) {\n throw new Error(\n `Got both 'component' and 'getComponent' props for the screen '${name}'. You must pass only one of them.`\n );\n }\n\n if (children != null && typeof children !== 'function') {\n throw new Error(\n `Got an invalid value for 'children' prop for the screen '${name}'. It must be a function returning a React Element.`\n );\n }\n\n if (component !== undefined && !isValidElementType(component)) {\n throw new Error(\n `Got an invalid value for 'component' prop for the screen '${name}'. It must be a valid React Component.`\n );\n }\n\n if (getComponent !== undefined && typeof getComponent !== 'function') {\n throw new Error(\n `Got an invalid value for 'getComponent' prop for the screen '${name}'. It must be a function returning a React Component.`\n );\n }\n\n if (typeof component === 'function') {\n if (component.name === 'component') {\n // Inline anonymous functions passed in the `component` prop will have the name of the prop\n // It's relatively safe to assume that it's not a component since it should also have PascalCase name\n // We won't catch all scenarios here, but this should catch a good chunk of incorrect use.\n console.warn(\n `Looks like you're passing an inline function for 'component' prop for the screen '${name}' (e.g. component={() => <SomeComponent />}). Passing an inline function will cause the component state to be lost on re-render and cause perf issues since it's re-created every render. You can pass the function as children to 'Screen' instead to achieve the desired behaviour.`\n );\n } else if (/^[a-z]/.test(component.name)) {\n console.warn(\n `Got a component with the name '${component.name}' for the screen '${name}'. React Components must start with an uppercase letter. If you're passing a regular function and not a component, pass it as children to 'Screen' instead. Otherwise capitalize your component's name.`\n );\n }\n }\n } else {\n throw new Error(\n `Couldn't find a 'component', 'getComponent' or 'children' prop for the screen '${name}'. This can happen if you passed 'undefined'. You likely forgot to export your component from the file it's defined in, or mixed up default import and named import when importing.`\n );\n }\n });\n }\n\n return configs;\n};\n\n/**\n * Hook for building navigators.\n *\n * @param createRouter Factory method which returns router object.\n * @param options Options object containing `children` and additional options for the router.\n * @returns An object containing `state`, `navigation`, `descriptors` objects.\n */\nexport default function useNavigationBuilder<\n State extends NavigationState,\n RouterOptions extends DefaultRouterOptions,\n ActionHelpers extends Record<string, () => void>,\n ScreenOptions extends {},\n EventMap extends Record<string, any>\n>(\n createRouter: RouterFactory<State, any, RouterOptions>,\n options: DefaultNavigatorOptions<\n ParamListBase,\n State,\n ScreenOptions,\n EventMap\n > &\n RouterOptions\n) {\n const navigatorKey = useRegisterNavigator();\n\n const route = React.useContext(NavigationRouteContext) as\n | NavigatorRoute<State>\n | undefined;\n\n const { children, screenListeners, ...rest } = options;\n const { current: router } = React.useRef<Router<State, any>>(\n createRouter({\n ...(rest as unknown as RouterOptions),\n ...(route?.params &&\n route.params.state == null &&\n route.params.initial !== false &&\n typeof route.params.screen === 'string'\n ? { initialRouteName: route.params.screen }\n : null),\n })\n );\n\n const routeConfigs = getRouteConfigsFromChildren<\n State,\n ScreenOptions,\n EventMap\n >(children);\n\n const screens = routeConfigs.reduce<\n Record<string, ScreenConfigWithParent<State, ScreenOptions, EventMap>>\n >((acc, config) => {\n if (config.props.name in acc) {\n throw new Error(\n `A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named '${config.props.name}')`\n );\n }\n\n acc[config.props.name] = config;\n return acc;\n }, {});\n\n const routeNames = routeConfigs.map((config) => config.props.name);\n const routeKeyList = routeNames.reduce<Record<string, React.Key | undefined>>(\n (acc, curr) => {\n acc[curr] = screens[curr].keys.map((key) => key ?? '').join(':');\n return acc;\n },\n {}\n );\n const routeParamList = routeNames.reduce<Record<string, object | undefined>>(\n (acc, curr) => {\n const { initialParams } = screens[curr].props;\n acc[curr] = initialParams;\n return acc;\n },\n {}\n );\n const routeGetIdList = routeNames.reduce<\n RouterConfigOptions['routeGetIdList']\n >(\n (acc, curr) =>\n Object.assign(acc, {\n [curr]: screens[curr].props.getId,\n }),\n {}\n );\n\n if (!routeNames.length) {\n throw new Error(\n \"Couldn't find any screens for the navigator. Have you defined any screens as its children?\"\n );\n }\n\n const isStateValid = React.useCallback(\n (state) => state.type === undefined || state.type === router.type,\n [router.type]\n );\n\n const isStateInitialized = React.useCallback(\n (state) =>\n state !== undefined && state.stale === false && isStateValid(state),\n [isStateValid]\n );\n\n const {\n state: currentState,\n getState: getCurrentState,\n setState: setCurrentState,\n setKey,\n getKey,\n getIsInitial,\n } = React.useContext(NavigationStateContext);\n\n const stateCleanedUp = React.useRef(false);\n\n const cleanUpState = React.useCallback(() => {\n setCurrentState(undefined);\n stateCleanedUp.current = true;\n }, [setCurrentState]);\n\n const setState = React.useCallback(\n (state: NavigationState | PartialState<NavigationState> | undefined) => {\n if (stateCleanedUp.current) {\n // State might have been already cleaned up due to unmount\n // We do not want to expose API allowing to override this\n // This would lead to old data preservation on main navigator unmount\n return;\n }\n setCurrentState(state);\n },\n [setCurrentState]\n );\n\n const [initializedState, isFirstStateInitialization] = React.useMemo(() => {\n const initialRouteParamList = routeNames.reduce<\n Record<string, object | undefined>\n >((acc, curr) => {\n const { initialParams } = screens[curr].props;\n const initialParamsFromParams =\n route?.params?.state == null &&\n route?.params?.initial !== false &&\n route?.params?.screen === curr\n ? route.params.params\n : undefined;\n\n acc[curr] =\n initialParams !== undefined || initialParamsFromParams !== undefined\n ? {\n ...initialParams,\n ...initialParamsFromParams,\n }\n : undefined;\n\n return acc;\n }, {});\n\n // If the current state isn't initialized on first render, we initialize it\n // We also need to re-initialize it if the state passed from parent was changed (maybe due to reset)\n // Otherwise assume that the state was provided as initial state\n // So we need to rehydrate it to make it usable\n if (\n (currentState === undefined || !isStateValid(currentState)) &&\n route?.params?.state == null\n ) {\n return [\n router.getInitialState({\n routeNames,\n routeParamList: initialRouteParamList,\n routeGetIdList,\n }),\n true,\n ];\n } else {\n return [\n router.getRehydratedState(\n route?.params?.state ?? (currentState as PartialState<State>),\n {\n routeNames,\n routeParamList: initialRouteParamList,\n routeGetIdList,\n }\n ),\n false,\n ];\n }\n // We explicitly don't include routeNames, route.params etc. in the dep list\n // below. We want to avoid forcing a new state to be calculated in those cases\n // Instead, we handle changes to these in the nextState code below. Note\n // that some changes to routeConfigs are explicitly ignored, such as changes\n // to initialParams\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [currentState, router, isStateValid]);\n\n const previousRouteKeyListRef = React.useRef(routeKeyList);\n\n React.useEffect(() => {\n previousRouteKeyListRef.current = routeKeyList;\n });\n\n const previousRouteKeyList = previousRouteKeyListRef.current;\n\n let state =\n // If the state isn't initialized, or stale, use the state we initialized instead\n // The state won't update until there's a change needed in the state we have initalized locally\n // So it'll be `undefined` or stale until the first navigation event happens\n isStateInitialized(currentState)\n ? (currentState as State)\n : (initializedState as State);\n\n let nextState: State = state;\n\n if (\n !isArrayEqual(state.routeNames, routeNames) ||\n !isRecordEqual(routeKeyList, previousRouteKeyList)\n ) {\n // When the list of route names change, the router should handle it to remove invalid routes\n nextState = router.getStateForRouteNamesChange(state, {\n routeNames,\n routeParamList,\n routeGetIdList,\n routeKeyChanges: Object.keys(routeKeyList).filter(\n (name) =>\n previousRouteKeyList.hasOwnProperty(name) &&\n routeKeyList[name] !== previousRouteKeyList[name]\n ),\n });\n }\n\n const previousNestedParamsRef = React.useRef(route?.params);\n\n React.useEffect(() => {\n previousNestedParamsRef.current = route?.params;\n }, [route?.params]);\n\n if (route?.params) {\n const previousParams = previousNestedParamsRef.current;\n\n let action: CommonActions.Action | undefined;\n\n if (\n typeof route.params.state === 'object' &&\n route.params.state != null &&\n route.params !== previousParams\n ) {\n // If the route was updated with new state, we should reset to it\n action = CommonActions.reset(route.params.state);\n } else if (\n typeof route.params.screen === 'string' &&\n ((route.params.initial === false && isFirstStateInitialization) ||\n route.params !== previousParams)\n ) {\n // If the route was updated with new screen name and/or params, we should navigate there\n action = CommonActions.navigate({\n name: route.params.screen,\n params: route.params.params,\n path: route.params.path,\n });\n }\n\n // The update should be limited to current navigator only, so we call the router manually\n const updatedState = action\n ? router.getStateForAction(nextState, action, {\n routeNames,\n routeParamList,\n routeGetIdList,\n })\n : null;\n\n nextState =\n updatedState !== null\n ? router.getRehydratedState(updatedState, {\n routeNames,\n routeParamList,\n routeGetIdList,\n })\n : nextState;\n }\n\n const shouldUpdate = state !== nextState;\n\n useScheduleUpdate(() => {\n if (shouldUpdate) {\n // If the state needs to be updated, we'll schedule an update\n setState(nextState);\n }\n });\n\n // The up-to-date state will come in next render, but we don't need to wait for it\n // We can't use the outdated state since the screens have changed, which will cause error due to mismatched config\n // So we override the state object we return to use the latest state as soon as possible\n state = nextState;\n\n React.useEffect(() => {\n setKey(navigatorKey);\n\n if (!getIsInitial()) {\n // If it's not initial render, we need to update the state\n // This will make sure that our container gets notifier of state changes due to new mounts\n // This is necessary for proper screen tracking, URL updates etc.\n setState(nextState);\n }\n\n return () => {\n // We need to clean up state for this navigator on unmount\n // We do it in a timeout because we need to detect if another navigator mounted in the meantime\n // For example, if another navigator has started rendering, we should skip cleanup\n // Otherwise, our cleanup step will cleanup state for the other navigator and re-initialize it\n setTimeout(() => {\n if (getCurrentState() !== undefined && getKey() === navigatorKey) {\n cleanUpState();\n }\n }, 0);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // We initialize this ref here to avoid a new getState getting initialized\n // whenever initializedState changes. We want getState to have access to the\n // latest initializedState, but don't need it to change when that happens\n const initializedStateRef = React.useRef<State>();\n initializedStateRef.current = initializedState;\n\n const getState = React.useCallback((): State => {\n const currentState = getCurrentState();\n\n return isStateInitialized(currentState)\n ? (currentState as State)\n : (initializedStateRef.current as State);\n }, [getCurrentState, isStateInitialized]);\n\n const emitter = useEventEmitter<EventMapCore<State>>((e) => {\n let routeNames = [];\n\n let route: Route<string> | undefined;\n\n if (e.target) {\n route = state.routes.find((route) => route.key === e.target);\n\n if (route?.name) {\n routeNames.push(route.name);\n }\n } else {\n route = state.routes[state.index];\n routeNames.push(\n ...Object.keys(screens).filter((name) => route?.name === name)\n );\n }\n\n if (route == null) {\n return;\n }\n\n const navigation = descriptors[route.key].navigation;\n\n const listeners = ([] as (((e: any) => void) | undefined)[])\n .concat(\n // Get an array of listeners for all screens + common listeners on navigator\n ...[\n screenListeners,\n ...routeNames.map((name) => {\n const { listeners } = screens[name].props;\n return listeners;\n }),\n ].map((listeners) => {\n const map =\n typeof listeners === 'function'\n ? listeners({ route: route as any, navigation })\n : listeners;\n\n return map\n ? Object.keys(map)\n .filter((type) => type === e.type)\n .map((type) => map?.[type])\n : undefined;\n })\n )\n // We don't want same listener to be called multiple times for same event\n // So we remove any duplicate functions from the array\n .filter((cb, i, self) => cb && self.lastIndexOf(cb) === i);\n\n listeners.forEach((listener) => listener?.(e));\n });\n\n useFocusEvents({ state, emitter });\n\n React.useEffect(() => {\n emitter.emit({ type: 'state', data: { state } });\n }, [emitter, state]);\n\n const { listeners: childListeners, addListener } = useChildListeners();\n\n const { keyedListeners, addKeyedListener } = useKeyedChildListeners();\n\n const onAction = useOnAction({\n router,\n getState,\n setState,\n key: route?.key,\n actionListeners: childListeners.action,\n beforeRemoveListeners: keyedListeners.beforeRemove,\n routerConfigOptions: {\n routeNames,\n routeParamList,\n routeGetIdList,\n },\n emitter,\n });\n\n const onRouteFocus = useOnRouteFocus({\n router,\n key: route?.key,\n getState,\n setState,\n });\n\n const navigation = useNavigationHelpers<\n State,\n ActionHelpers,\n NavigationAction,\n EventMap\n >({\n id: options.id,\n onAction,\n getState,\n emitter,\n router,\n });\n\n useFocusedListenersChildrenAdapter({\n navigation,\n focusedListeners: childListeners.focus,\n });\n\n useOnGetState({\n getState,\n getStateListeners: keyedListeners.getState,\n });\n\n const descriptors = useDescriptors<\n State,\n ActionHelpers,\n ScreenOptions,\n EventMap\n >({\n state,\n screens,\n navigation,\n screenOptions: options.screenOptions,\n defaultScreenOptions: options.defaultScreenOptions,\n onAction,\n getState,\n setState,\n onRouteFocus,\n addListener,\n addKeyedListener,\n router,\n // @ts-expect-error: this should have both core and custom events, but too much work right now\n emitter,\n });\n\n useCurrentRender({\n state,\n navigation,\n descriptors,\n });\n\n const NavigationContent = useComponent(NavigationHelpersContext.Provider, {\n value: navigation,\n });\n\n return {\n state,\n navigation,\n descriptors,\n NavigationContent,\n };\n}\n"]}
1
+ {"version":3,"sources":["useNavigationBuilder.tsx"],"names":["PrivateValueStore","isValidKey","key","undefined","getRouteConfigsFromChildren","children","groupKey","groupOptions","configs","React","Children","toArray","reduce","acc","child","isValidElement","type","Screen","props","navigationKey","Error","JSON","stringify","name","push","keys","options","Fragment","Group","screenOptions","String","process","env","NODE_ENV","forEach","config","component","getComponent","console","warn","test","useNavigationBuilder","createRouter","navigatorKey","route","useContext","NavigationRouteContext","screenListeners","rest","current","router","useRef","params","state","initial","screen","initialRouteName","routeConfigs","screens","routeNames","map","routeKeyList","curr","join","routeParamList","initialParams","routeGetIdList","Object","assign","getId","length","isStateValid","useCallback","isStateInitialized","stale","currentState","getState","getCurrentState","setState","setCurrentState","setKey","getKey","getIsInitial","NavigationStateContext","stateCleanedUp","cleanUpState","initializedState","isFirstStateInitialization","useMemo","initialRouteParamList","initialParamsFromParams","getInitialState","getRehydratedState","previousRouteKeyListRef","useEffect","previousRouteKeyList","nextState","getStateForRouteNamesChange","routeKeyChanges","filter","hasOwnProperty","previousNestedParamsRef","previousParams","action","CommonActions","reset","navigate","path","updatedState","getStateForAction","shouldUpdate","setTimeout","initializedStateRef","emitter","e","target","routes","find","index","navigation","descriptors","listeners","concat","cb","i","self","lastIndexOf","listener","emit","data","childListeners","addListener","keyedListeners","addKeyedListener","onAction","actionListeners","beforeRemoveListeners","beforeRemove","routerConfigOptions","onRouteFocus","id","focusedListeners","focus","getStateListeners","defaultScreenOptions","NavigationContent"],"mappings":";;;;;;;AAAA;;AAYA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA;AACA;AACAA;;AAOA,MAAMC,UAAU,GAAIC,GAAD,IACjBA,GAAG,KAAKC,SAAR,IAAsB,OAAOD,GAAP,KAAe,QAAf,IAA2BA,GAAG,KAAK,EAD3D;AAGA;AACA;AACA;AACA;AACA;;;AACA,MAAME,2BAA2B,GAAG,CAKlCC,QALkC,EAMlCC,QANkC,EAOlCC,YAPkC,KAY/B;AACH,QAAMC,OAAO,GAAGC,KAAK,CAACC,QAAN,CAAeC,OAAf,CAAuBN,QAAvB,EAAiCO,MAAjC,CAEd,CAACC,GAAD,EAAMC,KAAN,KAAgB;AAAA;;AAChB,sBAAIL,KAAK,CAACM,cAAN,CAAqBD,KAArB,CAAJ,EAAiC;AAC/B,UAAIA,KAAK,CAACE,IAAN,KAAeC,eAAnB,EAA2B;AACzB;AACA;AAEA,YAAI,CAAChB,UAAU,CAACa,KAAK,CAACI,KAAN,CAAYC,aAAb,CAAf,EAA4C;AAC1C,gBAAM,IAAIC,KAAJ,CACH,wCAAuCC,IAAI,CAACC,SAAL,CACtCR,KAAK,CAACI,KAAN,CAAYC,aAD0B,CAEtC,qBACAL,KAAK,CAACI,KAAN,CAAYK,IACb,kDALG,CAAN;AAOD;;AAEDV,QAAAA,GAAG,CAACW,IAAJ,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U,GAAG,mCAKjB;AACAqB,IAAAA,EAAE,EAAElH,OAAO,CAACkH,EADZ;AAEAN,IAAAA,QAFA;AAGA1D,IAAAA,QAHA;AAIAqC,IAAAA,OAJA;AAKA/D,IAAAA;AALA,GALiB,CAAnB;AAaA,mDAAmC;AACjCqE,IAAAA,UADiC;AAEjCsB,IAAAA,gBAAgB,EAAEX,cAAc,CAACY;AAFA,GAAnC;AAKA,8BAAc;AACZlE,IAAAA,QADY;AAEZmE,IAAAA,iBAAiB,EAAEX,cAAc,CAACxD;AAFtB,GAAd;AAKA,QAAM4C,WAAW,GAAG,6BAKlB;AACAnE,IAAAA,KADA;AAEAK,IAAAA,OAFA;AAGA6D,IAAAA,UAHA;AAIA1F,IAAAA,aAAa,EAAEH,OAAO,CAACG,aAJvB;AAKAmH,IAAAA,oBAAoB,EAAEtH,OAAO,CAACsH,oBAL9B;AAMAV,IAAAA,QANA;AAOA1D,IAAAA,QAPA;AAQAE,IAAAA,QARA;AASA6D,IAAAA,YATA;AAUAR,IAAAA,WAVA;AAWAE,IAAAA,gBAXA;AAYAnF,IAAAA,MAZA;AAaA;AACA+D,IAAAA;AAdA,GALkB,CAApB;AAsBA,iCAAiB;AACf5D,IAAAA,KADe;AAEfkE,IAAAA,UAFe;AAGfC,IAAAA;AAHe,GAAjB;AAMA,QAAMyB,iBAAiB,GAAG,2BAAc5I,QAAD,iBACrC,oBAAC,iCAAD,CAA0B,QAA1B;AAAmC,IAAA,KAAK,EAAEkH;AAA1C,kBACE,oBAAC,8BAAD,QAAwBlH,QAAxB,CADF,CADwB,CAA1B;AAMA,SAAO;AACLgD,IAAAA,KADK;AAELkE,IAAAA,UAFK;AAGLC,IAAAA,WAHK;AAILyB,IAAAA;AAJK,GAAP;AAMD","sourcesContent":["import {\n CommonActions,\n DefaultRouterOptions,\n NavigationAction,\n NavigationState,\n ParamListBase,\n PartialState,\n Route,\n Router,\n RouterConfigOptions,\n RouterFactory,\n} from '@react-navigation/routers';\nimport * as React from 'react';\nimport { isValidElementType } from 'react-is';\n\nimport Group from './Group';\nimport isArrayEqual from './isArrayEqual';\nimport isRecordEqual from './isRecordEqual';\nimport NavigationHelpersContext from './NavigationHelpersContext';\nimport NavigationRouteContext from './NavigationRouteContext';\nimport NavigationStateContext from './NavigationStateContext';\nimport PreventRemoveProvider from './PreventRemoveProvider';\nimport Screen from './Screen';\nimport {\n DefaultNavigatorOptions,\n EventMapBase,\n EventMapCore,\n NavigatorScreenParams,\n PrivateValueStore,\n RouteConfig,\n} from './types';\nimport useChildListeners from './useChildListeners';\nimport useComponent from './useComponent';\nimport useCurrentRender from './useCurrentRender';\nimport useDescriptors, { ScreenConfigWithParent } from './useDescriptors';\nimport useEventEmitter from './useEventEmitter';\nimport useFocusedListenersChildrenAdapter from './useFocusedListenersChildrenAdapter';\nimport useFocusEvents from './useFocusEvents';\nimport useKeyedChildListeners from './useKeyedChildListeners';\nimport useNavigationHelpers from './useNavigationHelpers';\nimport useOnAction from './useOnAction';\nimport useOnGetState from './useOnGetState';\nimport useOnRouteFocus from './useOnRouteFocus';\nimport useRegisterNavigator from './useRegisterNavigator';\nimport useScheduleUpdate from './useScheduleUpdate';\n\n// This is to make TypeScript compiler happy\n// eslint-disable-next-line babel/no-unused-expressions\nPrivateValueStore;\n\ntype NavigatorRoute<State extends NavigationState> = {\n key: string;\n params?: NavigatorScreenParams<ParamListBase, State>;\n};\n\nconst isValidKey = (key: unknown) =>\n key === undefined || (typeof key === 'string' && key !== '');\n\n/**\n * Extract route config object from React children elements.\n *\n * @param children React Elements to extract the config from.\n */\nconst getRouteConfigsFromChildren = <\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n>(\n children: React.ReactNode,\n groupKey?: string,\n groupOptions?: ScreenConfigWithParent<\n State,\n ScreenOptions,\n EventMap\n >['options']\n) => {\n const configs = React.Children.toArray(children).reduce<\n ScreenConfigWithParent<State, ScreenOptions, EventMap>[]\n >((acc, child) => {\n if (React.isValidElement(child)) {\n if (child.type === Screen) {\n // We can only extract the config from `Screen` elements\n // If something else was rendered, it's probably a bug\n\n if (!isValidKey(child.props.navigationKey)) {\n throw new Error(\n `Got an invalid 'navigationKey' prop (${JSON.stringify(\n child.props.navigationKey\n )}) for the screen '${\n child.props.name\n }'. It must be a non-empty string or 'undefined'.`\n );\n }\n\n acc.push({\n keys: [groupKey, child.props.navigationKey],\n options: groupOptions,\n props: child.props as RouteConfig<\n ParamListBase,\n string,\n State,\n ScreenOptions,\n EventMap\n >,\n });\n return acc;\n }\n\n if (child.type === React.Fragment || child.type === Group) {\n if (!isValidKey(child.props.navigationKey)) {\n throw new Error(\n `Got an invalid 'navigationKey' prop (${JSON.stringify(\n child.props.navigationKey\n )}) for the group. It must be a non-empty string or 'undefined'.`\n );\n }\n\n // When we encounter a fragment or group, we need to dive into its children to extract the configs\n // This is handy to conditionally define a group of screens\n acc.push(\n ...getRouteConfigsFromChildren<State, ScreenOptions, EventMap>(\n child.props.children,\n child.props.navigationKey,\n child.type !== Group\n ? groupOptions\n : groupOptions != null\n ? [...groupOptions, child.props.screenOptions]\n : [child.props.screenOptions]\n )\n );\n return acc;\n }\n }\n\n throw new Error(\n `A navigator can only contain 'Screen', 'Group' or 'React.Fragment' as its direct children (found ${\n React.isValidElement(child)\n ? `'${\n typeof child.type === 'string' ? child.type : child.type?.name\n }'${\n child.props?.name ? ` for the screen '${child.props.name}'` : ''\n }`\n : typeof child === 'object'\n ? JSON.stringify(child)\n : `'${String(child)}'`\n }). To render this component in the navigator, pass it in the 'component' prop to 'Screen'.`\n );\n }, []);\n\n if (process.env.NODE_ENV !== 'production') {\n configs.forEach((config) => {\n const { name, children, component, getComponent } = config.props;\n\n if (typeof name !== 'string' || !name) {\n throw new Error(\n `Got an invalid name (${JSON.stringify(\n name\n )}) for the screen. It must be a non-empty string.`\n );\n }\n\n if (\n children != null ||\n component !== undefined ||\n getComponent !== undefined\n ) {\n if (children != null && component !== undefined) {\n throw new Error(\n `Got both 'component' and 'children' props for the screen '${name}'. You must pass only one of them.`\n );\n }\n\n if (children != null && getComponent !== undefined) {\n throw new Error(\n `Got both 'getComponent' and 'children' props for the screen '${name}'. You must pass only one of them.`\n );\n }\n\n if (component !== undefined && getComponent !== undefined) {\n throw new Error(\n `Got both 'component' and 'getComponent' props for the screen '${name}'. You must pass only one of them.`\n );\n }\n\n if (children != null && typeof children !== 'function') {\n throw new Error(\n `Got an invalid value for 'children' prop for the screen '${name}'. It must be a function returning a React Element.`\n );\n }\n\n if (component !== undefined && !isValidElementType(component)) {\n throw new Error(\n `Got an invalid value for 'component' prop for the screen '${name}'. It must be a valid React Component.`\n );\n }\n\n if (getComponent !== undefined && typeof getComponent !== 'function') {\n throw new Error(\n `Got an invalid value for 'getComponent' prop for the screen '${name}'. It must be a function returning a React Component.`\n );\n }\n\n if (typeof component === 'function') {\n if (component.name === 'component') {\n // Inline anonymous functions passed in the `component` prop will have the name of the prop\n // It's relatively safe to assume that it's not a component since it should also have PascalCase name\n // We won't catch all scenarios here, but this should catch a good chunk of incorrect use.\n console.warn(\n `Looks like you're passing an inline function for 'component' prop for the screen '${name}' (e.g. component={() => <SomeComponent />}). Passing an inline function will cause the component state to be lost on re-render and cause perf issues since it's re-created every render. You can pass the function as children to 'Screen' instead to achieve the desired behaviour.`\n );\n } else if (/^[a-z]/.test(component.name)) {\n console.warn(\n `Got a component with the name '${component.name}' for the screen '${name}'. React Components must start with an uppercase letter. If you're passing a regular function and not a component, pass it as children to 'Screen' instead. Otherwise capitalize your component's name.`\n );\n }\n }\n } else {\n throw new Error(\n `Couldn't find a 'component', 'getComponent' or 'children' prop for the screen '${name}'. This can happen if you passed 'undefined'. You likely forgot to export your component from the file it's defined in, or mixed up default import and named import when importing.`\n );\n }\n });\n }\n\n return configs;\n};\n\n/**\n * Hook for building navigators.\n *\n * @param createRouter Factory method which returns router object.\n * @param options Options object containing `children` and additional options for the router.\n * @returns An object containing `state`, `navigation`, `descriptors` objects.\n */\nexport default function useNavigationBuilder<\n State extends NavigationState,\n RouterOptions extends DefaultRouterOptions,\n ActionHelpers extends Record<string, () => void>,\n ScreenOptions extends {},\n EventMap extends Record<string, any>\n>(\n createRouter: RouterFactory<State, any, RouterOptions>,\n options: DefaultNavigatorOptions<\n ParamListBase,\n State,\n ScreenOptions,\n EventMap\n > &\n RouterOptions\n) {\n const navigatorKey = useRegisterNavigator();\n\n const route = React.useContext(NavigationRouteContext) as\n | NavigatorRoute<State>\n | undefined;\n\n const { children, screenListeners, ...rest } = options;\n const { current: router } = React.useRef<Router<State, any>>(\n createRouter({\n ...(rest as unknown as RouterOptions),\n ...(route?.params &&\n route.params.state == null &&\n route.params.initial !== false &&\n typeof route.params.screen === 'string'\n ? { initialRouteName: route.params.screen }\n : null),\n })\n );\n\n const routeConfigs = getRouteConfigsFromChildren<\n State,\n ScreenOptions,\n EventMap\n >(children);\n\n const screens = routeConfigs.reduce<\n Record<string, ScreenConfigWithParent<State, ScreenOptions, EventMap>>\n >((acc, config) => {\n if (config.props.name in acc) {\n throw new Error(\n `A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named '${config.props.name}')`\n );\n }\n\n acc[config.props.name] = config;\n return acc;\n }, {});\n\n const routeNames = routeConfigs.map((config) => config.props.name);\n const routeKeyList = routeNames.reduce<Record<string, React.Key | undefined>>(\n (acc, curr) => {\n acc[curr] = screens[curr].keys.map((key) => key ?? '').join(':');\n return acc;\n },\n {}\n );\n const routeParamList = routeNames.reduce<Record<string, object | undefined>>(\n (acc, curr) => {\n const { initialParams } = screens[curr].props;\n acc[curr] = initialParams;\n return acc;\n },\n {}\n );\n const routeGetIdList = routeNames.reduce<\n RouterConfigOptions['routeGetIdList']\n >(\n (acc, curr) =>\n Object.assign(acc, {\n [curr]: screens[curr].props.getId,\n }),\n {}\n );\n\n if (!routeNames.length) {\n throw new Error(\n \"Couldn't find any screens for the navigator. Have you defined any screens as its children?\"\n );\n }\n\n const isStateValid = React.useCallback(\n (state) => state.type === undefined || state.type === router.type,\n [router.type]\n );\n\n const isStateInitialized = React.useCallback(\n (state) =>\n state !== undefined && state.stale === false && isStateValid(state),\n [isStateValid]\n );\n\n const {\n state: currentState,\n getState: getCurrentState,\n setState: setCurrentState,\n setKey,\n getKey,\n getIsInitial,\n } = React.useContext(NavigationStateContext);\n\n const stateCleanedUp = React.useRef(false);\n\n const cleanUpState = React.useCallback(() => {\n setCurrentState(undefined);\n stateCleanedUp.current = true;\n }, [setCurrentState]);\n\n const setState = React.useCallback(\n (state: NavigationState | PartialState<NavigationState> | undefined) => {\n if (stateCleanedUp.current) {\n // State might have been already cleaned up due to unmount\n // We do not want to expose API allowing to override this\n // This would lead to old data preservation on main navigator unmount\n return;\n }\n setCurrentState(state);\n },\n [setCurrentState]\n );\n\n const [initializedState, isFirstStateInitialization] = React.useMemo(() => {\n const initialRouteParamList = routeNames.reduce<\n Record<string, object | undefined>\n >((acc, curr) => {\n const { initialParams } = screens[curr].props;\n const initialParamsFromParams =\n route?.params?.state == null &&\n route?.params?.initial !== false &&\n route?.params?.screen === curr\n ? route.params.params\n : undefined;\n\n acc[curr] =\n initialParams !== undefined || initialParamsFromParams !== undefined\n ? {\n ...initialParams,\n ...initialParamsFromParams,\n }\n : undefined;\n\n return acc;\n }, {});\n\n // If the current state isn't initialized on first render, we initialize it\n // We also need to re-initialize it if the state passed from parent was changed (maybe due to reset)\n // Otherwise assume that the state was provided as initial state\n // So we need to rehydrate it to make it usable\n if (\n (currentState === undefined || !isStateValid(currentState)) &&\n route?.params?.state == null\n ) {\n return [\n router.getInitialState({\n routeNames,\n routeParamList: initialRouteParamList,\n routeGetIdList,\n }),\n true,\n ];\n } else {\n return [\n router.getRehydratedState(\n route?.params?.state ?? (currentState as PartialState<State>),\n {\n routeNames,\n routeParamList: initialRouteParamList,\n routeGetIdList,\n }\n ),\n false,\n ];\n }\n // We explicitly don't include routeNames, route.params etc. in the dep list\n // below. We want to avoid forcing a new state to be calculated in those cases\n // Instead, we handle changes to these in the nextState code below. Note\n // that some changes to routeConfigs are explicitly ignored, such as changes\n // to initialParams\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [currentState, router, isStateValid]);\n\n const previousRouteKeyListRef = React.useRef(routeKeyList);\n\n React.useEffect(() => {\n previousRouteKeyListRef.current = routeKeyList;\n });\n\n const previousRouteKeyList = previousRouteKeyListRef.current;\n\n let state =\n // If the state isn't initialized, or stale, use the state we initialized instead\n // The state won't update until there's a change needed in the state we have initalized locally\n // So it'll be `undefined` or stale until the first navigation event happens\n isStateInitialized(currentState)\n ? (currentState as State)\n : (initializedState as State);\n\n let nextState: State = state;\n\n if (\n !isArrayEqual(state.routeNames, routeNames) ||\n !isRecordEqual(routeKeyList, previousRouteKeyList)\n ) {\n // When the list of route names change, the router should handle it to remove invalid routes\n nextState = router.getStateForRouteNamesChange(state, {\n routeNames,\n routeParamList,\n routeGetIdList,\n routeKeyChanges: Object.keys(routeKeyList).filter(\n (name) =>\n previousRouteKeyList.hasOwnProperty(name) &&\n routeKeyList[name] !== previousRouteKeyList[name]\n ),\n });\n }\n\n const previousNestedParamsRef = React.useRef(route?.params);\n\n React.useEffect(() => {\n previousNestedParamsRef.current = route?.params;\n }, [route?.params]);\n\n if (route?.params) {\n const previousParams = previousNestedParamsRef.current;\n\n let action: CommonActions.Action | undefined;\n\n if (\n typeof route.params.state === 'object' &&\n route.params.state != null &&\n route.params !== previousParams\n ) {\n // If the route was updated with new state, we should reset to it\n action = CommonActions.reset(route.params.state);\n } else if (\n typeof route.params.screen === 'string' &&\n ((route.params.initial === false && isFirstStateInitialization) ||\n route.params !== previousParams)\n ) {\n // If the route was updated with new screen name and/or params, we should navigate there\n action = CommonActions.navigate({\n name: route.params.screen,\n params: route.params.params,\n path: route.params.path,\n });\n }\n\n // The update should be limited to current navigator only, so we call the router manually\n const updatedState = action\n ? router.getStateForAction(nextState, action, {\n routeNames,\n routeParamList,\n routeGetIdList,\n })\n : null;\n\n nextState =\n updatedState !== null\n ? router.getRehydratedState(updatedState, {\n routeNames,\n routeParamList,\n routeGetIdList,\n })\n : nextState;\n }\n\n const shouldUpdate = state !== nextState;\n\n useScheduleUpdate(() => {\n if (shouldUpdate) {\n // If the state needs to be updated, we'll schedule an update\n setState(nextState);\n }\n });\n\n // The up-to-date state will come in next render, but we don't need to wait for it\n // We can't use the outdated state since the screens have changed, which will cause error due to mismatched config\n // So we override the state object we return to use the latest state as soon as possible\n state = nextState;\n\n React.useEffect(() => {\n setKey(navigatorKey);\n\n if (!getIsInitial()) {\n // If it's not initial render, we need to update the state\n // This will make sure that our container gets notifier of state changes due to new mounts\n // This is necessary for proper screen tracking, URL updates etc.\n setState(nextState);\n }\n\n return () => {\n // We need to clean up state for this navigator on unmount\n // We do it in a timeout because we need to detect if another navigator mounted in the meantime\n // For example, if another navigator has started rendering, we should skip cleanup\n // Otherwise, our cleanup step will cleanup state for the other navigator and re-initialize it\n setTimeout(() => {\n if (getCurrentState() !== undefined && getKey() === navigatorKey) {\n cleanUpState();\n }\n }, 0);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // We initialize this ref here to avoid a new getState getting initialized\n // whenever initializedState changes. We want getState to have access to the\n // latest initializedState, but don't need it to change when that happens\n const initializedStateRef = React.useRef<State>();\n initializedStateRef.current = initializedState;\n\n const getState = React.useCallback((): State => {\n const currentState = getCurrentState();\n\n return isStateInitialized(currentState)\n ? (currentState as State)\n : (initializedStateRef.current as State);\n }, [getCurrentState, isStateInitialized]);\n\n const emitter = useEventEmitter<EventMapCore<State>>((e) => {\n let routeNames = [];\n\n let route: Route<string> | undefined;\n\n if (e.target) {\n route = state.routes.find((route) => route.key === e.target);\n\n if (route?.name) {\n routeNames.push(route.name);\n }\n } else {\n route = state.routes[state.index];\n routeNames.push(\n ...Object.keys(screens).filter((name) => route?.name === name)\n );\n }\n\n if (route == null) {\n return;\n }\n\n const navigation = descriptors[route.key].navigation;\n\n const listeners = ([] as (((e: any) => void) | undefined)[])\n .concat(\n // Get an array of listeners for all screens + common listeners on navigator\n ...[\n screenListeners,\n ...routeNames.map((name) => {\n const { listeners } = screens[name].props;\n return listeners;\n }),\n ].map((listeners) => {\n const map =\n typeof listeners === 'function'\n ? listeners({ route: route as any, navigation })\n : listeners;\n\n return map\n ? Object.keys(map)\n .filter((type) => type === e.type)\n .map((type) => map?.[type])\n : undefined;\n })\n )\n // We don't want same listener to be called multiple times for same event\n // So we remove any duplicate functions from the array\n .filter((cb, i, self) => cb && self.lastIndexOf(cb) === i);\n\n listeners.forEach((listener) => listener?.(e));\n });\n\n useFocusEvents({ state, emitter });\n\n React.useEffect(() => {\n emitter.emit({ type: 'state', data: { state } });\n }, [emitter, state]);\n\n const { listeners: childListeners, addListener } = useChildListeners();\n\n const { keyedListeners, addKeyedListener } = useKeyedChildListeners();\n\n const onAction = useOnAction({\n router,\n getState,\n setState,\n key: route?.key,\n actionListeners: childListeners.action,\n beforeRemoveListeners: keyedListeners.beforeRemove,\n routerConfigOptions: {\n routeNames,\n routeParamList,\n routeGetIdList,\n },\n emitter,\n });\n\n const onRouteFocus = useOnRouteFocus({\n router,\n key: route?.key,\n getState,\n setState,\n });\n\n const navigation = useNavigationHelpers<\n State,\n ActionHelpers,\n NavigationAction,\n EventMap\n >({\n id: options.id,\n onAction,\n getState,\n emitter,\n router,\n });\n\n useFocusedListenersChildrenAdapter({\n navigation,\n focusedListeners: childListeners.focus,\n });\n\n useOnGetState({\n getState,\n getStateListeners: keyedListeners.getState,\n });\n\n const descriptors = useDescriptors<\n State,\n ActionHelpers,\n ScreenOptions,\n EventMap\n >({\n state,\n screens,\n navigation,\n screenOptions: options.screenOptions,\n defaultScreenOptions: options.defaultScreenOptions,\n onAction,\n getState,\n setState,\n onRouteFocus,\n addListener,\n addKeyedListener,\n router,\n // @ts-expect-error: this should have both core and custom events, but too much work right now\n emitter,\n });\n\n useCurrentRender({\n state,\n navigation,\n descriptors,\n });\n\n const NavigationContent = useComponent((children: React.ReactNode) => (\n <NavigationHelpersContext.Provider value={navigation}>\n <PreventRemoveProvider>{children}</PreventRemoveProvider>\n </NavigationHelpersContext.Provider>\n ));\n\n return {\n state,\n navigation,\n descriptors,\n NavigationContent,\n };\n}\n"]}
@@ -82,10 +82,6 @@ function useNavigationHelpers(_ref) {
82
82
  current = current.getParent();
83
83
  }
84
84
 
85
- if (current == null) {
86
- throw new Error(`Couldn't find a parent navigator with the ID "${id}". Is this navigator nested under another navigator with this ID?`);
87
- }
88
-
89
85
  return current;
90
86
  }
91
87
 
@@ -1 +1 @@
1
- {"version":3,"sources":["useNavigationHelpers.tsx"],"names":["PrivateValueStore","useNavigationHelpers","id","navigatorId","onAction","getState","emitter","router","onUnhandledAction","React","useContext","UnhandledActionContext","parentNavigationHelpers","NavigationContext","useMemo","dispatch","op","action","handled","actions","actionCreators","CommonActions","helpers","Object","keys","reduce","acc","name","navigationHelpers","emit","isFocused","canGoBack","state","getStateForAction","goBack","routeNames","routeParamList","routeGetIdList","getId","getParent","undefined","current","Error"],"mappings":";;;;;;;AAAA;;AAOA;;AAEA;;AACA;;AACA;;;;;;;;AAGA;AACA;AACAA;;AAUA;AACA;AACA;AACA;AACe,SAASC,oBAAT,OAWY;AAAA,MANzB;AACAC,IAAAA,EAAE,EAAEC,WADJ;AAEAC,IAAAA,QAFA;AAGAC,IAAAA,QAHA;AAIAC,IAAAA,OAJA;AAKAC,IAAAA;AALA,GAMyB;AACzB,QAAMC,iBAAiB,GAAGC,KAAK,CAACC,UAAN,CAAiBC,+BAAjB,CAA1B;AACA,QAAMC,uBAAuB,GAAGH,KAAK,CAACC,UAAN,CAAiBG,0BAAjB,CAAhC;AAEA,SAAOJ,KAAK,CAACK,OAAN,CAAc,MAAM;AACzB,UAAMC,QAAQ,GAAIC,EAAD,IAA6C;AAC5D,YAAMC,MAAM,GAAG,OAAOD,EAAP,KAAc,UAAd,GAA2BA,EAAE,CAACX,QAAQ,EAAT,CAA7B,GAA4CW,EAA3D;AAEA,YAAME,OAAO,GAAGd,QAAQ,CAACa,MAAD,CAAxB;;AAEA,UAAI,CAACC,OA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EAAsB;AACpB,cAAIC,OAAO,GAAGb,iBAAd;;AAEA,iBAAOa,OAAO,IAAIvC,EAAE,KAAKuC,OAAO,CAACH,KAAR,EAAzB,EAA0C;AACxCG,YAAAA,OAAO,GAAGA,OAAO,CAACF,SAAR,EAAV;AACD;;AAED,cAAIE,OAAO,IAAI,IAAf,EAAqB;AACnB,kBAAM,IAAIC,KAAJ,CACH,iDAAgDxC,EAAG,mEADhD,CAAN;AAGD;;AAED,iBAAOuC,OAAP;AACD;;AAED,eAAO7B,uBAAP;AACD,OAxCuB;AAyCxBP,MAAAA;AAzCwB,KAA1B;AA4CA,WAAOuB,iBAAP;AACD,GAnEM,EAmEJ,CACDzB,WADC,EAEDG,OAAO,CAACuB,IAFP,EAGDxB,QAHC,EAIDD,QAJC,EAKDI,iBALC,EAMDI,uBANC,EAODL,MAPC,CAnEI,CAAP;AA4ED","sourcesContent":["import {\n CommonActions,\n NavigationAction,\n NavigationState,\n ParamListBase,\n Router,\n} from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport NavigationContext from './NavigationContext';\nimport { NavigationHelpers, PrivateValueStore } from './types';\nimport UnhandledActionContext from './UnhandledActionContext';\nimport type { NavigationEventEmitter } from './useEventEmitter';\n\n// This is to make TypeScript compiler happy\n// eslint-disable-next-line babel/no-unused-expressions\nPrivateValueStore;\n\ntype Options<State extends NavigationState, Action extends NavigationAction> = {\n id: string | undefined;\n onAction: (action: NavigationAction) => boolean;\n getState: () => State;\n emitter: NavigationEventEmitter<any>;\n router: Router<State, Action>;\n};\n\n/**\n * Navigation object with helper methods to be used by a navigator.\n * This object includes methods for common actions as well as methods the parent screen's navigation object.\n */\nexport default function useNavigationHelpers<\n State extends NavigationState,\n ActionHelpers extends Record<string, () => void>,\n Action extends NavigationAction,\n EventMap extends Record<string, any>\n>({\n id: navigatorId,\n onAction,\n getState,\n emitter,\n router,\n}: Options<State, Action>) {\n const onUnhandledAction = React.useContext(UnhandledActionContext);\n const parentNavigationHelpers = React.useContext(NavigationContext);\n\n return React.useMemo(() => {\n const dispatch = (op: Action | ((state: State) => Action)) => {\n const action = typeof op === 'function' ? op(getState()) : op;\n\n const handled = onAction(action);\n\n if (!handled) {\n onUnhandledAction?.(action);\n }\n };\n\n const actions = {\n ...router.actionCreators,\n ...CommonActions,\n };\n\n const helpers = Object.keys(actions).reduce((acc, name) => {\n // @ts-expect-error: name is a valid key, but TypeScript is dumb\n acc[name] = (...args: any) => dispatch(actions[name](...args));\n return acc;\n }, {} as ActionHelpers);\n\n const navigationHelpers = {\n ...parentNavigationHelpers,\n ...helpers,\n dispatch,\n emit: emitter.emit,\n isFocused: parentNavigationHelpers\n ? parentNavigationHelpers.isFocused\n : () => true,\n canGoBack: () => {\n const state = getState();\n\n return (\n router.getStateForAction(state, CommonActions.goBack() as Action, {\n routeNames: state.routeNames,\n routeParamList: {},\n routeGetIdList: {},\n }) !== null ||\n parentNavigationHelpers?.canGoBack() ||\n false\n );\n },\n getId: () => navigatorId,\n getParent: (id?: string) => {\n if (id !== undefined) {\n let current = navigationHelpers;\n\n while (current && id !== current.getId()) {\n current = current.getParent();\n }\n\n if (current == null) {\n throw new Error(\n `Couldn't find a parent navigator with the ID \"${id}\". Is this navigator nested under another navigator with this ID?`\n );\n }\n\n return current;\n }\n\n return parentNavigationHelpers;\n },\n getState,\n } as NavigationHelpers<ParamListBase, EventMap> & ActionHelpers;\n\n return navigationHelpers;\n }, [\n navigatorId,\n emitter.emit,\n getState,\n onAction,\n onUnhandledAction,\n parentNavigationHelpers,\n router,\n ]);\n}\n"]}
1
+ {"version":3,"sources":["useNavigationHelpers.tsx"],"names":["PrivateValueStore","useNavigationHelpers","id","navigatorId","onAction","getState","emitter","router","onUnhandledAction","React","useContext","UnhandledActionContext","parentNavigationHelpers","NavigationContext","useMemo","dispatch","op","action","handled","actions","actionCreators","CommonActions","helpers","Object","keys","reduce","acc","name","navigationHelpers","emit","isFocused","canGoBack","state","getStateForAction","goBack","routeNames","routeParamList","routeGetIdList","getId","getParent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;AAGxBP,MAAAA,QAHwB;AAIxBc,MAAAA,IAAI,EAAEvB,OAAO,CAACuB,IAJU;AAKxBC,MAAAA,SAAS,EAAElB,uBAAuB,GAC9BA,uBAAuB,CAACkB,SADM,GAE9B,MAAM,IAPc;AAQxBC,MAAAA,SAAS,EAAE,MAAM;AACf,cAAMC,KAAK,GAAG3B,QAAQ,EAAtB;AAEA,eACEE,MAAM,CAAC0B,iBAAP,CAAyBD,KAAzB,EAAgCX,uBAAca,MAAd,EAAhC,EAAkE;AAChEC,UAAAA,UAAU,EAAEH,KAAK,CAACG,UAD8C;AAEhEC,UAAAA,cAAc,EAAE,EAFgD;AAGhEC,UAAAA,cAAc,EAAE;AAHgD,SAAlE,MAIO,IAJP,KAKAzB,uBALA,aAKAA,uBALA,uBAKAA,uBAAuB,CAAEmB,SAAzB,EALA,KAMA,KAPF;AASD,OApBuB;AAqBxBO,MAAAA,KAAK,EAAE,MAAMnC,WArBW;AAsBxBoC,MAAAA,SAAS,EAAGrC,EAAD,IAAiB;AAC1B,YAAIA,EAAE,KAAKsC,SAAX,EAAsB;AACpB,cAAIC,OAAO,GAAGb,iBAAd;;AAEA,iBAAOa,OAAO,IAAIvC,EAAE,KAAKuC,OAAO,CAACH,KAAR,EAAzB,EAA0C;AACxCG,YAAAA,OAAO,GAAGA,OAAO,CAACF,SAAR,EAAV;AACD;;AAED,iBAAOE,OAAP;AACD;;AAED,eAAO7B,uBAAP;AACD,OAlCuB;AAmCxBP,MAAAA;AAnCwB,KAA1B;AAsCA,WAAOuB,iBAAP;AACD,GA7DM,EA6DJ,CACDzB,WADC,EAEDG,OAAO,CAACuB,IAFP,EAGDxB,QAHC,EAIDD,QAJC,EAKDI,iBALC,EAMDI,uBANC,EAODL,MAPC,CA7DI,CAAP;AAsED","sourcesContent":["import {\n CommonActions,\n NavigationAction,\n NavigationState,\n ParamListBase,\n Router,\n} from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport NavigationContext from './NavigationContext';\nimport { NavigationHelpers, PrivateValueStore } from './types';\nimport UnhandledActionContext from './UnhandledActionContext';\nimport type { NavigationEventEmitter } from './useEventEmitter';\n\n// This is to make TypeScript compiler happy\n// eslint-disable-next-line babel/no-unused-expressions\nPrivateValueStore;\n\ntype Options<State extends NavigationState, Action extends NavigationAction> = {\n id: string | undefined;\n onAction: (action: NavigationAction) => boolean;\n getState: () => State;\n emitter: NavigationEventEmitter<any>;\n router: Router<State, Action>;\n};\n\n/**\n * Navigation object with helper methods to be used by a navigator.\n * This object includes methods for common actions as well as methods the parent screen's navigation object.\n */\nexport default function useNavigationHelpers<\n State extends NavigationState,\n ActionHelpers extends Record<string, () => void>,\n Action extends NavigationAction,\n EventMap extends Record<string, any>\n>({\n id: navigatorId,\n onAction,\n getState,\n emitter,\n router,\n}: Options<State, Action>) {\n const onUnhandledAction = React.useContext(UnhandledActionContext);\n const parentNavigationHelpers = React.useContext(NavigationContext);\n\n return React.useMemo(() => {\n const dispatch = (op: Action | ((state: State) => Action)) => {\n const action = typeof op === 'function' ? op(getState()) : op;\n\n const handled = onAction(action);\n\n if (!handled) {\n onUnhandledAction?.(action);\n }\n };\n\n const actions = {\n ...router.actionCreators,\n ...CommonActions,\n };\n\n const helpers = Object.keys(actions).reduce((acc, name) => {\n // @ts-expect-error: name is a valid key, but TypeScript is dumb\n acc[name] = (...args: any) => dispatch(actions[name](...args));\n return acc;\n }, {} as ActionHelpers);\n\n const navigationHelpers = {\n ...parentNavigationHelpers,\n ...helpers,\n dispatch,\n emit: emitter.emit,\n isFocused: parentNavigationHelpers\n ? parentNavigationHelpers.isFocused\n : () => true,\n canGoBack: () => {\n const state = getState();\n\n return (\n router.getStateForAction(state, CommonActions.goBack() as Action, {\n routeNames: state.routeNames,\n routeParamList: {},\n routeGetIdList: {},\n }) !== null ||\n parentNavigationHelpers?.canGoBack() ||\n false\n );\n },\n getId: () => navigatorId,\n getParent: (id?: string) => {\n if (id !== undefined) {\n let current = navigationHelpers;\n\n while (current && id !== current.getId()) {\n current = current.getParent();\n }\n\n return current;\n }\n\n return parentNavigationHelpers;\n },\n getState,\n } as NavigationHelpers<ParamListBase, EventMap> & ActionHelpers;\n\n return navigationHelpers;\n }, [\n navigatorId,\n emitter.emit,\n getState,\n onAction,\n onUnhandledAction,\n parentNavigationHelpers,\n router,\n ]);\n}\n"]}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = usePreventRemove;
7
+
8
+ var _nonSecure = require("nanoid/non-secure");
9
+
10
+ var React = _interopRequireWildcard(require("react"));
11
+
12
+ var _useLatestCallback = _interopRequireDefault(require("use-latest-callback"));
13
+
14
+ var _useNavigation = _interopRequireDefault(require("./useNavigation"));
15
+
16
+ var _usePreventRemoveContext = _interopRequireDefault(require("./usePreventRemoveContext"));
17
+
18
+ var _useRoute = _interopRequireDefault(require("./useRoute"));
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ 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); }
23
+
24
+ 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; }
25
+
26
+ /**
27
+ * Hook to prevent screen from being removed. Can be used to prevent users from leaving the screen.
28
+ *
29
+ * @param preventRemove Boolean indicating whether to prevent screen from being removed.
30
+ * @param callback Function which is executed when screen was prevented from being removed.
31
+ */
32
+ function usePreventRemove(preventRemove, callback) {
33
+ const [id] = React.useState(() => (0, _nonSecure.nanoid)());
34
+ const navigation = (0, _useNavigation.default)();
35
+ const {
36
+ key: routeKey
37
+ } = (0, _useRoute.default)();
38
+ const {
39
+ setPreventRemove
40
+ } = (0, _usePreventRemoveContext.default)();
41
+ React.useEffect(() => {
42
+ setPreventRemove(id, routeKey, preventRemove);
43
+ return () => {
44
+ setPreventRemove(id, routeKey, false);
45
+ };
46
+ }, [setPreventRemove, id, routeKey, preventRemove]);
47
+ const beforeRemoveListener = (0, _useLatestCallback.default)(e => {
48
+ if (!preventRemove) {
49
+ return;
50
+ }
51
+
52
+ e.preventDefault();
53
+ callback({
54
+ data: e.data
55
+ });
56
+ });
57
+ React.useEffect(() => navigation === null || navigation === void 0 ? void 0 : navigation.addListener('beforeRemove', beforeRemoveListener), [navigation, beforeRemoveListener]);
58
+ }
59
+ //# sourceMappingURL=usePreventRemove.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["usePreventRemove.tsx"],"names":["usePreventRemove","preventRemove","callback","id","React","useState","navigation","key","routeKey","setPreventRemove","useEffect","beforeRemoveListener","e","preventDefault","data","addListener"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AAGA;;AACA;;AACA;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,gBAAT,CACbC,aADa,EAEbC,QAFa,EAGb;AACA,QAAM,CAACC,EAAD,IAAOC,KAAK,CAACC,QAAN,CAAe,MAAM,wBAArB,CAAb;AAEA,QAAMC,UAAU,GAAG,6BAAnB;AACA,QAAM;AAAEC,IAAAA,GAAG,EAAEC;AAAP,MAAoB,wBAA1B;AAEA,QAAM;AAAEC,IAAAA;AAAF,MAAuB,uCAA7B;AAEAL,EAAAA,KAAK,CAACM,SAAN,CAAgB,MAAM;AACpBD,IAAAA,gBAAgB,CAACN,EAAD,EAAKK,QAAL,EAAeP,aAAf,CAAhB;AACA,WAAO,MAAM;AACXQ,MAAAA,gBAAgB,CAACN,EAAD,EAAKK,QAAL,EAAe,KAAf,CAAhB;AACD,KAFD;AAGD,GALD,EAKG,CAACC,gBAAD,EAAmBN,EAAnB,EAAuBK,QAAvB,EAAiCP,aAAjC,CALH;AAOA,QAAMU,oBAAoB,GAAG,gCAE1BC,CAAD,IAAO;AACP,QAAI,CAACX,aAAL,EAAoB;AAClB;AACD;;AAEDW,IAAAA,CAAC,CAACC,cAAF;AAEAX,IAAAA,QAAQ,CAAC;AAAEY,MAAAA,IAAI,EAAEF,CAAC,CAACE;AAAV,KAAD,CAAR;AACD,GAV4B,CAA7B;AAYAV,EAAAA,KAAK,CAACM,SAAN,CACE,MAAMJ,UAAN,aAAMA,UAAN,uBAAMA,UAAU,CAAES,WAAZ,CAAwB,cAAxB,EAAwCJ,oBAAxC,CADR,EAEE,CAACL,UAAD,EAAaK,oBAAb,CAFF;AAID","sourcesContent":["import type { NavigationAction } from '@react-navigation/routers';\nimport { nanoid } from 'nanoid/non-secure';\nimport * as React from 'react';\nimport useLatestCallback from 'use-latest-callback';\n\nimport type { EventListenerCallback, EventMapCore } from './types';\nimport useNavigation from './useNavigation';\nimport usePreventRemoveContext from './usePreventRemoveContext';\nimport useRoute from './useRoute';\n\n/**\n * Hook to prevent screen from being removed. Can be used to prevent users from leaving the screen.\n *\n * @param preventRemove Boolean indicating whether to prevent screen from being removed.\n * @param callback Function which is executed when screen was prevented from being removed.\n */\nexport default function usePreventRemove(\n preventRemove: boolean,\n callback: (options: { data: { action: NavigationAction } }) => void\n) {\n const [id] = React.useState(() => nanoid());\n\n const navigation = useNavigation();\n const { key: routeKey } = useRoute();\n\n const { setPreventRemove } = usePreventRemoveContext();\n\n React.useEffect(() => {\n setPreventRemove(id, routeKey, preventRemove);\n return () => {\n setPreventRemove(id, routeKey, false);\n };\n }, [setPreventRemove, id, routeKey, preventRemove]);\n\n const beforeRemoveListener = useLatestCallback<\n EventListenerCallback<EventMapCore<any>, 'beforeRemove'>\n >((e) => {\n if (!preventRemove) {\n return;\n }\n\n e.preventDefault();\n\n callback({ data: e.data });\n });\n\n React.useEffect(\n () => navigation?.addListener('beforeRemove', beforeRemoveListener),\n [navigation, beforeRemoveListener]\n );\n}\n"]}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = usePreventRemoveContext;
7
+
8
+ var React = _interopRequireWildcard(require("react"));
9
+
10
+ var _PreventRemoveContext = _interopRequireDefault(require("./PreventRemoveContext"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ 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); }
15
+
16
+ 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; }
17
+
18
+ function usePreventRemoveContext() {
19
+ const value = React.useContext(_PreventRemoveContext.default);
20
+
21
+ if (value == null) {
22
+ throw new Error("Couldn't find the prevent remove context. Is your component inside NavigationContent?");
23
+ }
24
+
25
+ return value;
26
+ }
27
+ //# sourceMappingURL=usePreventRemoveContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["usePreventRemoveContext.tsx"],"names":["usePreventRemoveContext","value","React","useContext","PreventRemoveContext","Error"],"mappings":";;;;;;;AAAA;;AAEA;;;;;;;;AAEe,SAASA,uBAAT,GAAmC;AAChD,QAAMC,KAAK,GAAGC,KAAK,CAACC,UAAN,CAAiBC,6BAAjB,CAAd;;AAEA,MAAIH,KAAK,IAAI,IAAb,EAAmB;AACjB,UAAM,IAAII,KAAJ,CACJ,uFADI,CAAN;AAGD;;AAED,SAAOJ,KAAP;AACD","sourcesContent":["import * as React from 'react';\n\nimport PreventRemoveContext from './PreventRemoveContext';\n\nexport default function usePreventRemoveContext() {\n const value = React.useContext(PreventRemoveContext);\n\n if (value == null) {\n throw new Error(\n \"Couldn't find the prevent remove context. Is your component inside NavigationContent?\"\n );\n }\n\n return value;\n}\n"]}