@react-navigation/core 6.0.2

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 (327) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -0
  3. package/lib/commonjs/BaseNavigationContainer.js +393 -0
  4. package/lib/commonjs/BaseNavigationContainer.js.map +1 -0
  5. package/lib/commonjs/CurrentRenderContext.js +21 -0
  6. package/lib/commonjs/CurrentRenderContext.js.map +1 -0
  7. package/lib/commonjs/EnsureSingleNavigator.js +53 -0
  8. package/lib/commonjs/EnsureSingleNavigator.js.map +1 -0
  9. package/lib/commonjs/Group.js +15 -0
  10. package/lib/commonjs/Group.js.map +1 -0
  11. package/lib/commonjs/NavigationBuilderContext.js +23 -0
  12. package/lib/commonjs/NavigationBuilderContext.js.map +1 -0
  13. package/lib/commonjs/NavigationContainerRefContext.js +20 -0
  14. package/lib/commonjs/NavigationContainerRefContext.js.map +1 -0
  15. package/lib/commonjs/NavigationContext.js +20 -0
  16. package/lib/commonjs/NavigationContext.js.map +1 -0
  17. package/lib/commonjs/NavigationHelpersContext.js +21 -0
  18. package/lib/commonjs/NavigationHelpersContext.js.map +1 -0
  19. package/lib/commonjs/NavigationRouteContext.js +20 -0
  20. package/lib/commonjs/NavigationRouteContext.js.map +1 -0
  21. package/lib/commonjs/NavigationStateContext.js +42 -0
  22. package/lib/commonjs/NavigationStateContext.js.map +1 -0
  23. package/lib/commonjs/SceneView.js +97 -0
  24. package/lib/commonjs/SceneView.js.map +1 -0
  25. package/lib/commonjs/Screen.js +15 -0
  26. package/lib/commonjs/Screen.js.map +1 -0
  27. package/lib/commonjs/StaticContainer.js +43 -0
  28. package/lib/commonjs/StaticContainer.js.map +1 -0
  29. package/lib/commonjs/UnhandledActionContext.js +17 -0
  30. package/lib/commonjs/UnhandledActionContext.js.map +1 -0
  31. package/lib/commonjs/checkDuplicateRouteNames.js +31 -0
  32. package/lib/commonjs/checkDuplicateRouteNames.js.map +1 -0
  33. package/lib/commonjs/checkSerializable.js +59 -0
  34. package/lib/commonjs/checkSerializable.js.map +1 -0
  35. package/lib/commonjs/createNavigationContainerRef.js +82 -0
  36. package/lib/commonjs/createNavigationContainerRef.js.map +1 -0
  37. package/lib/commonjs/createNavigatorFactory.js +34 -0
  38. package/lib/commonjs/createNavigatorFactory.js.map +1 -0
  39. package/lib/commonjs/findFocusedRoute.js +22 -0
  40. package/lib/commonjs/findFocusedRoute.js.map +1 -0
  41. package/lib/commonjs/fromEntries.js +19 -0
  42. package/lib/commonjs/fromEntries.js.map +1 -0
  43. package/lib/commonjs/getActionFromState.js +99 -0
  44. package/lib/commonjs/getActionFromState.js.map +1 -0
  45. package/lib/commonjs/getFocusedRouteNameFromRoute.js +23 -0
  46. package/lib/commonjs/getFocusedRouteNameFromRoute.js.map +1 -0
  47. package/lib/commonjs/getPathFromState.js +238 -0
  48. package/lib/commonjs/getPathFromState.js.map +1 -0
  49. package/lib/commonjs/getStateFromPath.js +450 -0
  50. package/lib/commonjs/getStateFromPath.js.map +1 -0
  51. package/lib/commonjs/index.js +227 -0
  52. package/lib/commonjs/index.js.map +1 -0
  53. package/lib/commonjs/isArrayEqual.js +15 -0
  54. package/lib/commonjs/isArrayEqual.js.map +1 -0
  55. package/lib/commonjs/types.js +18 -0
  56. package/lib/commonjs/types.js.map +1 -0
  57. package/lib/commonjs/useChildListeners.js +38 -0
  58. package/lib/commonjs/useChildListeners.js.map +1 -0
  59. package/lib/commonjs/useComponent.js +36 -0
  60. package/lib/commonjs/useComponent.js.map +1 -0
  61. package/lib/commonjs/useCurrentRender.js +33 -0
  62. package/lib/commonjs/useCurrentRender.js.map +1 -0
  63. package/lib/commonjs/useDescriptors.js +141 -0
  64. package/lib/commonjs/useDescriptors.js.map +1 -0
  65. package/lib/commonjs/useEventEmitter.js +118 -0
  66. package/lib/commonjs/useEventEmitter.js.map +1 -0
  67. package/lib/commonjs/useFocusEffect.js +97 -0
  68. package/lib/commonjs/useFocusEffect.js.map +1 -0
  69. package/lib/commonjs/useFocusEvents.js +77 -0
  70. package/lib/commonjs/useFocusEvents.js.map +1 -0
  71. package/lib/commonjs/useFocusedListenersChildrenAdapter.js +57 -0
  72. package/lib/commonjs/useFocusedListenersChildrenAdapter.js.map +1 -0
  73. package/lib/commonjs/useIsFocused.js +47 -0
  74. package/lib/commonjs/useIsFocused.js.map +1 -0
  75. package/lib/commonjs/useKeyedChildListeners.js +35 -0
  76. package/lib/commonjs/useKeyedChildListeners.js.map +1 -0
  77. package/lib/commonjs/useNavigation.js +36 -0
  78. package/lib/commonjs/useNavigation.js.map +1 -0
  79. package/lib/commonjs/useNavigationBuilder.js +480 -0
  80. package/lib/commonjs/useNavigationBuilder.js.map +1 -0
  81. package/lib/commonjs/useNavigationCache.js +122 -0
  82. package/lib/commonjs/useNavigationCache.js.map +1 -0
  83. package/lib/commonjs/useNavigationContainerRef.js +27 -0
  84. package/lib/commonjs/useNavigationContainerRef.js.map +1 -0
  85. package/lib/commonjs/useNavigationHelpers.js +77 -0
  86. package/lib/commonjs/useNavigationHelpers.js.map +1 -0
  87. package/lib/commonjs/useNavigationState.js +41 -0
  88. package/lib/commonjs/useNavigationState.js.map +1 -0
  89. package/lib/commonjs/useOnAction.js +118 -0
  90. package/lib/commonjs/useOnAction.js.map +1 -0
  91. package/lib/commonjs/useOnGetState.js +60 -0
  92. package/lib/commonjs/useOnGetState.js.map +1 -0
  93. package/lib/commonjs/useOnPreventRemove.js +89 -0
  94. package/lib/commonjs/useOnPreventRemove.js.map +1 -0
  95. package/lib/commonjs/useOnRouteFocus.js +45 -0
  96. package/lib/commonjs/useOnRouteFocus.js.map +1 -0
  97. package/lib/commonjs/useOptionsGetters.js +99 -0
  98. package/lib/commonjs/useOptionsGetters.js.map +1 -0
  99. package/lib/commonjs/useRegisterNavigator.js +40 -0
  100. package/lib/commonjs/useRegisterNavigator.js.map +1 -0
  101. package/lib/commonjs/useRoute.js +32 -0
  102. package/lib/commonjs/useRoute.js.map +1 -0
  103. package/lib/commonjs/useRouteCache.js +61 -0
  104. package/lib/commonjs/useRouteCache.js.map +1 -0
  105. package/lib/commonjs/useScheduleUpdate.js +44 -0
  106. package/lib/commonjs/useScheduleUpdate.js.map +1 -0
  107. package/lib/commonjs/useSyncState.js +76 -0
  108. package/lib/commonjs/useSyncState.js.map +1 -0
  109. package/lib/commonjs/validatePathConfig.js +31 -0
  110. package/lib/commonjs/validatePathConfig.js.map +1 -0
  111. package/lib/module/BaseNavigationContainer.js +360 -0
  112. package/lib/module/BaseNavigationContainer.js.map +1 -0
  113. package/lib/module/CurrentRenderContext.js +9 -0
  114. package/lib/module/CurrentRenderContext.js.map +1 -0
  115. package/lib/module/EnsureSingleNavigator.js +38 -0
  116. package/lib/module/EnsureSingleNavigator.js.map +1 -0
  117. package/lib/module/Group.js +8 -0
  118. package/lib/module/Group.js.map +1 -0
  119. package/lib/module/NavigationBuilderContext.js +11 -0
  120. package/lib/module/NavigationBuilderContext.js.map +1 -0
  121. package/lib/module/NavigationContainerRefContext.js +8 -0
  122. package/lib/module/NavigationContainerRefContext.js.map +1 -0
  123. package/lib/module/NavigationContext.js +8 -0
  124. package/lib/module/NavigationContext.js.map +1 -0
  125. package/lib/module/NavigationHelpersContext.js +9 -0
  126. package/lib/module/NavigationHelpersContext.js.map +1 -0
  127. package/lib/module/NavigationRouteContext.js +8 -0
  128. package/lib/module/NavigationRouteContext.js.map +1 -0
  129. package/lib/module/NavigationStateContext.js +27 -0
  130. package/lib/module/NavigationStateContext.js.map +1 -0
  131. package/lib/module/SceneView.js +80 -0
  132. package/lib/module/SceneView.js.map +1 -0
  133. package/lib/module/Screen.js +8 -0
  134. package/lib/module/Screen.js.map +1 -0
  135. package/lib/module/StaticContainer.js +30 -0
  136. package/lib/module/StaticContainer.js.map +1 -0
  137. package/lib/module/UnhandledActionContext.js +4 -0
  138. package/lib/module/UnhandledActionContext.js.map +1 -0
  139. package/lib/module/checkDuplicateRouteNames.js +24 -0
  140. package/lib/module/checkDuplicateRouteNames.js.map +1 -0
  141. package/lib/module/checkSerializable.js +52 -0
  142. package/lib/module/checkSerializable.js.map +1 -0
  143. package/lib/module/createNavigationContainerRef.js +71 -0
  144. package/lib/module/createNavigationContainerRef.js.map +1 -0
  145. package/lib/module/createNavigatorFactory.js +24 -0
  146. package/lib/module/createNavigatorFactory.js.map +1 -0
  147. package/lib/module/findFocusedRoute.js +15 -0
  148. package/lib/module/findFocusedRoute.js.map +1 -0
  149. package/lib/module/fromEntries.js +12 -0
  150. package/lib/module/fromEntries.js.map +1 -0
  151. package/lib/module/getActionFromState.js +92 -0
  152. package/lib/module/getActionFromState.js.map +1 -0
  153. package/lib/module/getFocusedRouteNameFromRoute.js +15 -0
  154. package/lib/module/getFocusedRouteNameFromRoute.js.map +1 -0
  155. package/lib/module/getPathFromState.js +223 -0
  156. package/lib/module/getPathFromState.js.map +1 -0
  157. package/lib/module/getStateFromPath.js +434 -0
  158. package/lib/module/getStateFromPath.js.map +1 -0
  159. package/lib/module/index.js +24 -0
  160. package/lib/module/index.js.map +1 -0
  161. package/lib/module/isArrayEqual.js +8 -0
  162. package/lib/module/isArrayEqual.js.map +1 -0
  163. package/lib/module/types.js +9 -0
  164. package/lib/module/types.js.map +1 -0
  165. package/lib/module/useChildListeners.js +27 -0
  166. package/lib/module/useChildListeners.js.map +1 -0
  167. package/lib/module/useComponent.js +24 -0
  168. package/lib/module/useComponent.js.map +1 -0
  169. package/lib/module/useCurrentRender.js +19 -0
  170. package/lib/module/useCurrentRender.js.map +1 -0
  171. package/lib/module/useDescriptors.js +122 -0
  172. package/lib/module/useDescriptors.js.map +1 -0
  173. package/lib/module/useEventEmitter.js +107 -0
  174. package/lib/module/useEventEmitter.js.map +1 -0
  175. package/lib/module/useFocusEffect.js +83 -0
  176. package/lib/module/useFocusEffect.js.map +1 -0
  177. package/lib/module/useFocusEvents.js +63 -0
  178. package/lib/module/useFocusEvents.js.map +1 -0
  179. package/lib/module/useFocusedListenersChildrenAdapter.js +43 -0
  180. package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -0
  181. package/lib/module/useIsFocused.js +34 -0
  182. package/lib/module/useIsFocused.js.map +1 -0
  183. package/lib/module/useKeyedChildListeners.js +24 -0
  184. package/lib/module/useKeyedChildListeners.js.map +1 -0
  185. package/lib/module/useNavigation.js +21 -0
  186. package/lib/module/useNavigation.js.map +1 -0
  187. package/lib/module/useNavigationBuilder.js +443 -0
  188. package/lib/module/useNavigationBuilder.js.map +1 -0
  189. package/lib/module/useNavigationCache.js +107 -0
  190. package/lib/module/useNavigationCache.js.map +1 -0
  191. package/lib/module/useNavigationContainerRef.js +12 -0
  192. package/lib/module/useNavigationContainerRef.js.map +1 -0
  193. package/lib/module/useNavigationHelpers.js +59 -0
  194. package/lib/module/useNavigationHelpers.js.map +1 -0
  195. package/lib/module/useNavigationState.js +27 -0
  196. package/lib/module/useNavigationState.js.map +1 -0
  197. package/lib/module/useOnAction.js +103 -0
  198. package/lib/module/useOnAction.js.map +1 -0
  199. package/lib/module/useOnGetState.js +43 -0
  200. package/lib/module/useOnGetState.js.map +1 -0
  201. package/lib/module/useOnPreventRemove.js +68 -0
  202. package/lib/module/useOnPreventRemove.js.map +1 -0
  203. package/lib/module/useOnRouteFocus.js +31 -0
  204. package/lib/module/useOnRouteFocus.js.map +1 -0
  205. package/lib/module/useOptionsGetters.js +83 -0
  206. package/lib/module/useOptionsGetters.js.map +1 -0
  207. package/lib/module/useRegisterNavigator.js +27 -0
  208. package/lib/module/useRegisterNavigator.js.map +1 -0
  209. package/lib/module/useRoute.js +18 -0
  210. package/lib/module/useRoute.js.map +1 -0
  211. package/lib/module/useRouteCache.js +47 -0
  212. package/lib/module/useRouteCache.js.map +1 -0
  213. package/lib/module/useScheduleUpdate.js +29 -0
  214. package/lib/module/useScheduleUpdate.js.map +1 -0
  215. package/lib/module/useSyncState.js +64 -0
  216. package/lib/module/useSyncState.js.map +1 -0
  217. package/lib/module/validatePathConfig.js +24 -0
  218. package/lib/module/validatePathConfig.js.map +1 -0
  219. package/lib/typescript/src/BaseNavigationContainer.d.ts +14 -0
  220. package/lib/typescript/src/CurrentRenderContext.d.ts +9 -0
  221. package/lib/typescript/src/EnsureSingleNavigator.d.ts +13 -0
  222. package/lib/typescript/src/Group.d.ts +6 -0
  223. package/lib/typescript/src/NavigationBuilderContext.d.ts +34 -0
  224. package/lib/typescript/src/NavigationContainerRefContext.d.ts +8 -0
  225. package/lib/typescript/src/NavigationContext.d.ts +24 -0
  226. package/lib/typescript/src/NavigationHelpersContext.d.ts +9 -0
  227. package/lib/typescript/src/NavigationRouteContext.d.ts +7 -0
  228. package/lib/typescript/src/NavigationStateContext.d.ts +45 -0
  229. package/lib/typescript/src/SceneView.d.ts +21 -0
  230. package/lib/typescript/src/Screen.d.ts +6 -0
  231. package/lib/typescript/src/StaticContainer.d.ts +7 -0
  232. package/lib/typescript/src/UnhandledActionContext.d.ts +4 -0
  233. package/lib/typescript/src/checkDuplicateRouteNames.d.ts +2 -0
  234. package/lib/typescript/src/checkSerializable.d.ts +9 -0
  235. package/lib/typescript/src/createNavigationContainerRef.d.ts +3 -0
  236. package/lib/typescript/src/createNavigatorFactory.d.ts +11 -0
  237. package/lib/typescript/src/findFocusedRoute.d.ts +22 -0
  238. package/lib/typescript/src/fromEntries.d.ts +1 -0
  239. package/lib/typescript/src/getActionFromState.d.ts +16 -0
  240. package/lib/typescript/src/getFocusedRouteNameFromRoute.d.ts +2 -0
  241. package/lib/typescript/src/getPathFromState.d.ts +38 -0
  242. package/lib/typescript/src/getStateFromPath.d.ts +32 -0
  243. package/lib/typescript/src/index.d.ts +23 -0
  244. package/lib/typescript/src/isArrayEqual.d.ts +5 -0
  245. package/lib/typescript/src/types.d.ts +485 -0
  246. package/lib/typescript/src/useChildListeners.d.ts +11 -0
  247. package/lib/typescript/src/useComponent.d.ts +2 -0
  248. package/lib/typescript/src/useCurrentRender.d.ts +13 -0
  249. package/lib/typescript/src/useDescriptors.d.ts +89 -0
  250. package/lib/typescript/src/useEventEmitter.d.ts +8 -0
  251. package/lib/typescript/src/useFocusEffect.d.ts +10 -0
  252. package/lib/typescript/src/useFocusEvents.d.ts +12 -0
  253. package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +12 -0
  254. package/lib/typescript/src/useIsFocused.d.ts +5 -0
  255. package/lib/typescript/src/useKeyedChildListeners.d.ts +11 -0
  256. package/lib/typescript/src/useNavigation.d.ts +7 -0
  257. package/lib/typescript/src/useNavigationBuilder.d.ts +223 -0
  258. package/lib/typescript/src/useNavigationCache.d.ts +19 -0
  259. package/lib/typescript/src/useNavigationContainerRef.d.ts +2 -0
  260. package/lib/typescript/src/useNavigationHelpers.d.ts +174 -0
  261. package/lib/typescript/src/useNavigationState.d.ts +9 -0
  262. package/lib/typescript/src/useOnAction.d.ts +25 -0
  263. package/lib/typescript/src/useOnGetState.d.ts +8 -0
  264. package/lib/typescript/src/useOnPreventRemove.d.ts +16 -0
  265. package/lib/typescript/src/useOnRouteFocus.d.ts +14 -0
  266. package/lib/typescript/src/useOptionsGetters.d.ts +12 -0
  267. package/lib/typescript/src/useRegisterNavigator.d.ts +5 -0
  268. package/lib/typescript/src/useRoute.d.ts +8 -0
  269. package/lib/typescript/src/useRouteCache.d.ts +13 -0
  270. package/lib/typescript/src/useScheduleUpdate.d.ts +13 -0
  271. package/lib/typescript/src/useSyncState.d.ts +4 -0
  272. package/lib/typescript/src/validatePathConfig.d.ts +1 -0
  273. package/package.json +73 -0
  274. package/src/BaseNavigationContainer.tsx +453 -0
  275. package/src/CurrentRenderContext.tsx +10 -0
  276. package/src/EnsureSingleNavigator.tsx +53 -0
  277. package/src/Group.tsx +14 -0
  278. package/src/NavigationBuilderContext.tsx +70 -0
  279. package/src/NavigationContainerRefContext.tsx +14 -0
  280. package/src/NavigationContext.tsx +12 -0
  281. package/src/NavigationHelpersContext.tsx +13 -0
  282. package/src/NavigationRouteContext.tsx +10 -0
  283. package/src/NavigationStateContext.tsx +39 -0
  284. package/src/SceneView.tsx +134 -0
  285. package/src/Screen.tsx +17 -0
  286. package/src/StaticContainer.tsx +29 -0
  287. package/src/UnhandledActionContext.tsx +9 -0
  288. package/src/checkDuplicateRouteNames.tsx +33 -0
  289. package/src/checkSerializable.tsx +74 -0
  290. package/src/createNavigationContainerRef.tsx +97 -0
  291. package/src/createNavigatorFactory.tsx +40 -0
  292. package/src/findFocusedRoute.tsx +13 -0
  293. package/src/fromEntries.tsx +13 -0
  294. package/src/getActionFromState.tsx +154 -0
  295. package/src/getFocusedRouteNameFromRoute.tsx +28 -0
  296. package/src/getPathFromState.tsx +297 -0
  297. package/src/getStateFromPath.tsx +575 -0
  298. package/src/index.tsx +23 -0
  299. package/src/isArrayEqual.tsx +7 -0
  300. package/src/types.tsx +645 -0
  301. package/src/useChildListeners.tsx +37 -0
  302. package/src/useComponent.tsx +30 -0
  303. package/src/useCurrentRender.tsx +35 -0
  304. package/src/useDescriptors.tsx +229 -0
  305. package/src/useEventEmitter.tsx +130 -0
  306. package/src/useFocusEffect.tsx +112 -0
  307. package/src/useFocusEvents.tsx +73 -0
  308. package/src/useFocusedListenersChildrenAdapter.tsx +47 -0
  309. package/src/useIsFocused.tsx +43 -0
  310. package/src/useKeyedChildListeners.tsx +40 -0
  311. package/src/useNavigation.tsx +26 -0
  312. package/src/useNavigationBuilder.tsx +640 -0
  313. package/src/useNavigationCache.tsx +159 -0
  314. package/src/useNavigationContainerRef.tsx +17 -0
  315. package/src/useNavigationHelpers.tsx +98 -0
  316. package/src/useNavigationState.tsx +41 -0
  317. package/src/useOnAction.tsx +166 -0
  318. package/src/useOnGetState.tsx +47 -0
  319. package/src/useOnPreventRemove.tsx +99 -0
  320. package/src/useOnRouteFocus.tsx +47 -0
  321. package/src/useOptionsGetters.tsx +98 -0
  322. package/src/useRegisterNavigator.tsx +29 -0
  323. package/src/useRoute.tsx +22 -0
  324. package/src/useRouteCache.tsx +55 -0
  325. package/src/useScheduleUpdate.tsx +32 -0
  326. package/src/useSyncState.tsx +74 -0
  327. package/src/validatePathConfig.tsx +32 -0
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useEventEmitter;
7
+
8
+ var React = _interopRequireWildcard(require("react"));
9
+
10
+ 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); }
11
+
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
+
14
+ /**
15
+ * Hook to manage the event system used by the navigator to notify screens of various events.
16
+ */
17
+ function useEventEmitter(listen) {
18
+ const listenRef = React.useRef(listen);
19
+ React.useEffect(() => {
20
+ listenRef.current = listen;
21
+ });
22
+ const listeners = React.useRef({});
23
+ const create = React.useCallback(target => {
24
+ const removeListener = (type, callback) => {
25
+ const callbacks = listeners.current[type] ? listeners.current[type][target] : undefined;
26
+
27
+ if (!callbacks) {
28
+ return;
29
+ }
30
+
31
+ const index = callbacks.indexOf(callback);
32
+ callbacks.splice(index, 1);
33
+ };
34
+
35
+ const addListener = (type, callback) => {
36
+ listeners.current[type] = listeners.current[type] || {};
37
+ listeners.current[type][target] = listeners.current[type][target] || [];
38
+ listeners.current[type][target].push(callback);
39
+ return () => removeListener(type, callback);
40
+ };
41
+
42
+ return {
43
+ addListener,
44
+ removeListener
45
+ };
46
+ }, []);
47
+ const emit = React.useCallback(({
48
+ type,
49
+ data,
50
+ target,
51
+ canPreventDefault
52
+ }) => {
53
+ var _items$target, _listenRef$current;
54
+
55
+ const items = listeners.current[type] || {}; // Copy the current list of callbacks in case they are mutated during execution
56
+
57
+ const callbacks = target !== undefined ? (_items$target = items[target]) === null || _items$target === void 0 ? void 0 : _items$target.slice() : [].concat(...Object.keys(items).map(t => items[t])).filter((cb, i, self) => self.lastIndexOf(cb) === i);
58
+ const event = {
59
+ get type() {
60
+ return type;
61
+ }
62
+
63
+ };
64
+
65
+ if (target !== undefined) {
66
+ Object.defineProperty(event, 'target', {
67
+ enumerable: true,
68
+
69
+ get() {
70
+ return target;
71
+ }
72
+
73
+ });
74
+ }
75
+
76
+ if (data !== undefined) {
77
+ Object.defineProperty(event, 'data', {
78
+ enumerable: true,
79
+
80
+ get() {
81
+ return data;
82
+ }
83
+
84
+ });
85
+ }
86
+
87
+ if (canPreventDefault) {
88
+ let defaultPrevented = false;
89
+ Object.defineProperties(event, {
90
+ defaultPrevented: {
91
+ enumerable: true,
92
+
93
+ get() {
94
+ return defaultPrevented;
95
+ }
96
+
97
+ },
98
+ preventDefault: {
99
+ enumerable: true,
100
+
101
+ value() {
102
+ defaultPrevented = true;
103
+ }
104
+
105
+ }
106
+ });
107
+ }
108
+
109
+ (_listenRef$current = listenRef.current) === null || _listenRef$current === void 0 ? void 0 : _listenRef$current.call(listenRef, event);
110
+ callbacks === null || callbacks === void 0 ? void 0 : callbacks.forEach(cb => cb(event));
111
+ return event;
112
+ }, []);
113
+ return React.useMemo(() => ({
114
+ create,
115
+ emit
116
+ }), [create, emit]);
117
+ }
118
+ //# sourceMappingURL=useEventEmitter.js.map
@@ -0,0 +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":"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","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"]}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useFocusEffect;
7
+
8
+ var React = _interopRequireWildcard(require("react"));
9
+
10
+ var _useNavigation = _interopRequireDefault(require("./useNavigation"));
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
+ /**
19
+ * Hook to run an effect in a focused screen, similar to `React.useEffect`.
20
+ * This can be used to perform side-effects such as fetching data or subscribing to events.
21
+ * The passed callback should be wrapped in `React.useCallback` to avoid running the effect too often.
22
+ *
23
+ * @param callback Memoized callback containing the effect, should optionally return a cleanup function.
24
+ */
25
+ function useFocusEffect(effect) {
26
+ const navigation = (0, _useNavigation.default)();
27
+
28
+ if (arguments[1] !== undefined) {
29
+ const message = "You passed a second argument to 'useFocusEffect', but it only accepts one argument. " + "If you want to pass a dependency array, you can use 'React.useCallback':\n\n" + 'useFocusEffect(\n' + ' React.useCallback(() => {\n' + ' // Your code here\n' + ' }, [depA, depB])\n' + ');\n\n' + 'See usage guide: https://reactnavigation.org/docs/use-focus-effect';
30
+ console.error(message);
31
+ }
32
+
33
+ React.useEffect(() => {
34
+ let isFocused = false;
35
+ let cleanup;
36
+
37
+ const callback = () => {
38
+ const destroy = effect();
39
+
40
+ if (destroy === undefined || typeof destroy === 'function') {
41
+ return destroy;
42
+ }
43
+
44
+ if (process.env.NODE_ENV !== 'production') {
45
+ let message = 'An effect function must not return anything besides a function, which is used for clean-up.';
46
+
47
+ if (destroy === null) {
48
+ message += " You returned 'null'. If your effect does not require clean-up, return 'undefined' (or nothing).";
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';
51
+ } else {
52
+ message += ` You returned '${JSON.stringify(destroy)}'.`;
53
+ }
54
+
55
+ console.error(message);
56
+ }
57
+ }; // We need to run the effect on intial render/dep changes if the screen is focused
58
+
59
+
60
+ if (navigation.isFocused()) {
61
+ cleanup = callback();
62
+ isFocused = true;
63
+ }
64
+
65
+ const unsubscribeFocus = navigation.addListener('focus', () => {
66
+ // If callback was already called for focus, avoid calling it again
67
+ // The focus event may also fire on intial render, so we guard against runing the effect twice
68
+ if (isFocused) {
69
+ return;
70
+ }
71
+
72
+ if (cleanup !== undefined) {
73
+ cleanup();
74
+ }
75
+
76
+ cleanup = callback();
77
+ isFocused = true;
78
+ });
79
+ const unsubscribeBlur = navigation.addListener('blur', () => {
80
+ if (cleanup !== undefined) {
81
+ cleanup();
82
+ }
83
+
84
+ cleanup = undefined;
85
+ isFocused = false;
86
+ });
87
+ return () => {
88
+ if (cleanup !== undefined) {
89
+ cleanup();
90
+ }
91
+
92
+ unsubscribeFocus();
93
+ unsubscribeBlur();
94
+ };
95
+ }, [effect, navigation]);
96
+ }
97
+ //# sourceMappingURL=useFocusEffect.js.map
@@ -0,0 +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,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,8BAJA,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"]}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useFocusEvents;
7
+
8
+ var React = _interopRequireWildcard(require("react"));
9
+
10
+ var _NavigationContext = _interopRequireDefault(require("./NavigationContext"));
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
+ /**
19
+ * Hook to take care of emitting `focus` and `blur` events.
20
+ */
21
+ function useFocusEvents({
22
+ state,
23
+ emitter
24
+ }) {
25
+ const navigation = React.useContext(_NavigationContext.default);
26
+ const lastFocusedKeyRef = React.useRef();
27
+ const currentFocusedKey = state.routes[state.index].key; // When the parent screen changes its focus state, we also need to change child's focus
28
+ // Coz the child screen can't be focused if the parent screen is out of focus
29
+
30
+ React.useEffect(() => navigation === null || navigation === void 0 ? void 0 : navigation.addListener('focus', () => {
31
+ lastFocusedKeyRef.current = currentFocusedKey;
32
+ emitter.emit({
33
+ type: 'focus',
34
+ target: currentFocusedKey
35
+ });
36
+ }), [currentFocusedKey, emitter, navigation]);
37
+ React.useEffect(() => navigation === null || navigation === void 0 ? void 0 : navigation.addListener('blur', () => {
38
+ lastFocusedKeyRef.current = undefined;
39
+ emitter.emit({
40
+ type: 'blur',
41
+ target: currentFocusedKey
42
+ });
43
+ }), [currentFocusedKey, emitter, navigation]);
44
+ React.useEffect(() => {
45
+ const lastFocusedKey = lastFocusedKeyRef.current;
46
+ lastFocusedKeyRef.current = currentFocusedKey; // We wouldn't have `lastFocusedKey` on initial mount
47
+ // Fire focus event for the current route on mount if there's no parent navigator
48
+
49
+ if (lastFocusedKey === undefined && !navigation) {
50
+ emitter.emit({
51
+ type: 'focus',
52
+ target: currentFocusedKey
53
+ });
54
+ } // We should only emit events when the focused key changed and navigator is focused
55
+ // When navigator is not focused, screens inside shouldn't receive focused status either
56
+
57
+
58
+ if (lastFocusedKey === currentFocusedKey || !(navigation ? navigation.isFocused() : true)) {
59
+ return;
60
+ }
61
+
62
+ if (lastFocusedKey === undefined) {
63
+ // Only fire events after initial mount
64
+ return;
65
+ }
66
+
67
+ emitter.emit({
68
+ type: 'blur',
69
+ target: lastFocusedKey
70
+ });
71
+ emitter.emit({
72
+ type: 'focus',
73
+ target: currentFocusedKey
74
+ });
75
+ }, [currentFocusedKey, emitter, navigation]);
76
+ }
77
+ //# sourceMappingURL=useFocusEvents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useFocusEvents.tsx"],"names":["useFocusEvents","state","emitter","navigation","React","useContext","NavigationContext","lastFocusedKeyRef","useRef","currentFocusedKey","routes","index","key","useEffect","addListener","current","emit","type","target","undefined","lastFocusedKey","isFocused"],"mappings":";;;;;;;AACA;;AAEA;;;;;;;;AASA;AACA;AACA;AACe,SAASA,cAAT,CAAuD;AACpEC,EAAAA,KADoE;AAEpEC,EAAAA;AAFoE,CAAvD,EAGI;AACjB,QAAMC,UAAU,GAAGC,KAAK,CAACC,UAAN,CAAiBC,0BAAjB,CAAnB;AACA,QAAMC,iBAAiB,GAAGH,KAAK,CAACI,MAAN,EAA1B;AAEA,QAAMC,iBAAiB,GAAGR,KAAK,CAACS,MAAN,CAAaT,KAAK,CAACU,KAAnB,EAA0BC,GAApD,CAJiB,CAMjB;AACA;;AACAR,EAAAA,KAAK,CAACS,SAAN,CACE,MACEV,UADF,aACEA,UADF,uBACEA,UAAU,CAAEW,WAAZ,CAAwB,OAAxB,EAAiC,MAAM;AACrCP,IAAAA,iBAAiB,CAACQ,OAAlB,GAA4BN,iBAA5B;AACAP,IAAAA,OAAO,CAACc,IAAR,CAAa;AAAEC,MAAAA,IAAI,EAAE,OAAR;AAAiBC,MAAAA,MAAM,EAAET;AAAzB,KAAb;AACD,GAHD,CAFJ,EAME,CAACA,iBAAD,EAAoBP,OAApB,EAA6BC,UAA7B,CANF;AASAC,EAAAA,KAAK,CAACS,SAAN,CACE,MACEV,UADF,aACEA,UADF,uBACEA,UAAU,CAAEW,WAAZ,CAAwB,MAAxB,EAAgC,MAAM;AACpCP,IAAAA,iBAAiB,CAACQ,OAAlB,GAA4BI,SAA5B;AACAjB,IAAAA,OAAO,CAACc,IAAR,CAAa;AAAEC,MAAAA,IAAI,EAAE,MAAR;AAAgBC,MAAAA,MAAM,EAAET;AAAxB,KAAb;AACD,GAHD,CAFJ,EAME,CAACA,iBAAD,EAAoBP,OAApB,EAA6BC,UAA7B,CANF;AASAC,EAAAA,KAAK,CAACS,SAAN,CAAgB,MAAM;AACpB,UAAMO,cAAc,GAAGb,iBAAiB,CAACQ,OAAzC;AAEAR,IAAAA,iBAAiB,CAACQ,OAAlB,GAA4BN,iBAA5B,CAHoB,CAKpB;AACA;;AACA,QAAIW,cAAc,KAAKD,SAAnB,IAAgC,CAAChB,UAArC,EAAiD;AAC/CD,MAAAA,OAAO,CAACc,IAAR,CAAa;AAAEC,QAAAA,IAAI,EAAE,OAAR;AAAiBC,QAAAA,MAAM,EAAET;AAAzB,OAAb;AACD,KATmB,CAWpB;AACA;;;AACA,QACEW,cAAc,KAAKX,iBAAnB,IACA,EAAEN,UAAU,GAAGA,UAAU,CAACkB,SAAX,EAAH,GAA4B,IAAxC,CAFF,EAGE;AACA;AACD;;AAED,QAAID,cAAc,KAAKD,SAAvB,EAAkC;AAChC;AACA;AACD;;AAEDjB,IAAAA,OAAO,CAACc,IAAR,CAAa;AAAEC,MAAAA,IAAI,EAAE,MAAR;AAAgBC,MAAAA,MAAM,EAAEE;AAAxB,KAAb;AACAlB,IAAAA,OAAO,CAACc,IAAR,CAAa;AAAEC,MAAAA,IAAI,EAAE,OAAR;AAAiBC,MAAAA,MAAM,EAAET;AAAzB,KAAb;AACD,GA3BD,EA2BG,CAACA,iBAAD,EAAoBP,OAApB,EAA6BC,UAA7B,CA3BH;AA4BD","sourcesContent":["import type { NavigationState } from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport NavigationContext from './NavigationContext';\nimport type { EventMapCore } from './types';\nimport type { NavigationEventEmitter } from './useEventEmitter';\n\ntype Options<State extends NavigationState> = {\n state: State;\n emitter: NavigationEventEmitter<EventMapCore<State>>;\n};\n\n/**\n * Hook to take care of emitting `focus` and `blur` events.\n */\nexport default function useFocusEvents<State extends NavigationState>({\n state,\n emitter,\n}: Options<State>) {\n const navigation = React.useContext(NavigationContext);\n const lastFocusedKeyRef = React.useRef<string | undefined>();\n\n const currentFocusedKey = state.routes[state.index].key;\n\n // When the parent screen changes its focus state, we also need to change child's focus\n // Coz the child screen can't be focused if the parent screen is out of focus\n React.useEffect(\n () =>\n navigation?.addListener('focus', () => {\n lastFocusedKeyRef.current = currentFocusedKey;\n emitter.emit({ type: 'focus', target: currentFocusedKey });\n }),\n [currentFocusedKey, emitter, navigation]\n );\n\n React.useEffect(\n () =>\n navigation?.addListener('blur', () => {\n lastFocusedKeyRef.current = undefined;\n emitter.emit({ type: 'blur', target: currentFocusedKey });\n }),\n [currentFocusedKey, emitter, navigation]\n );\n\n React.useEffect(() => {\n const lastFocusedKey = lastFocusedKeyRef.current;\n\n lastFocusedKeyRef.current = currentFocusedKey;\n\n // We wouldn't have `lastFocusedKey` on initial mount\n // Fire focus event for the current route on mount if there's no parent navigator\n if (lastFocusedKey === undefined && !navigation) {\n emitter.emit({ type: 'focus', target: currentFocusedKey });\n }\n\n // We should only emit events when the focused key changed and navigator is focused\n // When navigator is not focused, screens inside shouldn't receive focused status either\n if (\n lastFocusedKey === currentFocusedKey ||\n !(navigation ? navigation.isFocused() : true)\n ) {\n return;\n }\n\n if (lastFocusedKey === undefined) {\n // Only fire events after initial mount\n return;\n }\n\n emitter.emit({ type: 'blur', target: lastFocusedKey });\n emitter.emit({ type: 'focus', target: currentFocusedKey });\n }, [currentFocusedKey, emitter, navigation]);\n}\n"]}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useFocusedListenersChildrenAdapter;
7
+
8
+ var React = _interopRequireWildcard(require("react"));
9
+
10
+ var _NavigationBuilderContext = _interopRequireDefault(require("./NavigationBuilderContext"));
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
+ /**
19
+ * Hook for passing focus callback to children
20
+ */
21
+ function useFocusedListenersChildrenAdapter({
22
+ navigation,
23
+ focusedListeners
24
+ }) {
25
+ const {
26
+ addListener
27
+ } = React.useContext(_NavigationBuilderContext.default);
28
+ const listener = React.useCallback(callback => {
29
+ if (navigation.isFocused()) {
30
+ for (const listener of focusedListeners) {
31
+ const {
32
+ handled,
33
+ result
34
+ } = listener(callback);
35
+
36
+ if (handled) {
37
+ return {
38
+ handled,
39
+ result
40
+ };
41
+ }
42
+ }
43
+
44
+ return {
45
+ handled: true,
46
+ result: callback(navigation)
47
+ };
48
+ } else {
49
+ return {
50
+ handled: false,
51
+ result: null
52
+ };
53
+ }
54
+ }, [focusedListeners, navigation]);
55
+ React.useEffect(() => addListener === null || addListener === void 0 ? void 0 : addListener('focus', listener), [addListener, listener]);
56
+ }
57
+ //# sourceMappingURL=useFocusedListenersChildrenAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useFocusedListenersChildrenAdapter.tsx"],"names":["useFocusedListenersChildrenAdapter","navigation","focusedListeners","addListener","React","useContext","NavigationBuilderContext","listener","useCallback","callback","isFocused","handled","result","useEffect"],"mappings":";;;;;;;AACA;;AAEA;;;;;;;;AAWA;AACA;AACA;AACe,SAASA,kCAAT,CAA4C;AACzDC,EAAAA,UADyD;AAEzDC,EAAAA;AAFyD,CAA5C,EAGH;AACV,QAAM;AAAEC,IAAAA;AAAF,MAAkBC,KAAK,CAACC,UAAN,CAAiBC,iCAAjB,CAAxB;AAEA,QAAMC,QAAQ,GAAGH,KAAK,CAACI,WAAN,CACdC,QAAD,IAA8C;AAC5C,QAAIR,UAAU,CAACS,SAAX,EAAJ,EAA4B;AAC1B,WAAK,MAAMH,QAAX,IAAuBL,gBAAvB,EAAyC;AACvC,cAAM;AAAES,UAAAA,OAAF;AAAWC,UAAAA;AAAX,YAAsBL,QAAQ,CAACE,QAAD,CAApC;;AAEA,YAAIE,OAAJ,EAAa;AACX,iBAAO;AAAEA,YAAAA,OAAF;AAAWC,YAAAA;AAAX,WAAP;AACD;AACF;;AAED,aAAO;AAAED,QAAAA,OAAO,EAAE,IAAX;AAAiBC,QAAAA,MAAM,EAAEH,QAAQ,CAACR,UAAD;AAAjC,OAAP;AACD,KAVD,MAUO;AACL,aAAO;AAAEU,QAAAA,OAAO,EAAE,KAAX;AAAkBC,QAAAA,MAAM,EAAE;AAA1B,OAAP;AACD;AACF,GAfc,EAgBf,CAACV,gBAAD,EAAmBD,UAAnB,CAhBe,CAAjB;AAmBAG,EAAAA,KAAK,CAACS,SAAN,CACE,MAAMV,WAAN,aAAMA,WAAN,uBAAMA,WAAW,CAAG,OAAH,EAAYI,QAAZ,CADnB,EAEE,CAACJ,WAAD,EAAcI,QAAd,CAFF;AAID","sourcesContent":["import type { ParamListBase } from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport NavigationBuilderContext, {\n FocusedNavigationCallback,\n FocusedNavigationListener,\n} from './NavigationBuilderContext';\nimport type { NavigationHelpers } from './types';\n\ntype Options = {\n navigation: NavigationHelpers<ParamListBase>;\n focusedListeners: FocusedNavigationListener[];\n};\n\n/**\n * Hook for passing focus callback to children\n */\nexport default function useFocusedListenersChildrenAdapter({\n navigation,\n focusedListeners,\n}: Options) {\n const { addListener } = React.useContext(NavigationBuilderContext);\n\n const listener = React.useCallback(\n (callback: FocusedNavigationCallback<any>) => {\n if (navigation.isFocused()) {\n for (const listener of focusedListeners) {\n const { handled, result } = listener(callback);\n\n if (handled) {\n return { handled, result };\n }\n }\n\n return { handled: true, result: callback(navigation) };\n } else {\n return { handled: false, result: null };\n }\n },\n [focusedListeners, navigation]\n );\n\n React.useEffect(\n () => addListener?.('focus', listener),\n [addListener, listener]\n );\n}\n"]}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useIsFocused;
7
+
8
+ var React = _interopRequireWildcard(require("react"));
9
+
10
+ var _useNavigation = _interopRequireDefault(require("./useNavigation"));
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
+ /**
19
+ * Hook to get the current focus state of the screen. Returns a `true` if screen is focused, otherwise `false`.
20
+ * This can be used if a component needs to render something based on the focus state.
21
+ */
22
+ function useIsFocused() {
23
+ const navigation = (0, _useNavigation.default)();
24
+ const [isFocused, setIsFocused] = (0, React.useState)(navigation.isFocused);
25
+ const valueToReturn = navigation.isFocused();
26
+
27
+ if (isFocused !== valueToReturn) {
28
+ // If the value has changed since the last render, we need to update it.
29
+ // This could happen if we missed an update from the event listeners during re-render.
30
+ // React will process this update immediately, so the old subscription value won't be committed.
31
+ // It is still nice to avoid returning a mismatched value though, so let's override the return value.
32
+ // This is the same logic as in https://github.com/facebook/react/tree/master/packages/use-subscription
33
+ setIsFocused(valueToReturn);
34
+ }
35
+
36
+ React.useEffect(() => {
37
+ const unsubscribeFocus = navigation.addListener('focus', () => setIsFocused(true));
38
+ const unsubscribeBlur = navigation.addListener('blur', () => setIsFocused(false));
39
+ return () => {
40
+ unsubscribeFocus();
41
+ unsubscribeBlur();
42
+ };
43
+ }, [navigation]);
44
+ React.useDebugValue(valueToReturn);
45
+ return valueToReturn;
46
+ }
47
+ //# sourceMappingURL=useIsFocused.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useIsFocused.tsx"],"names":["useIsFocused","navigation","isFocused","setIsFocused","valueToReturn","React","useEffect","unsubscribeFocus","addListener","unsubscribeBlur","useDebugValue"],"mappings":";;;;;;;AAAA;;AAGA;;;;;;;;AAEA;AACA;AACA;AACA;AACe,SAASA,YAAT,GAAiC;AAC9C,QAAMC,UAAU,GAAG,6BAAnB;AACA,QAAM,CAACC,SAAD,EAAYC,YAAZ,IAA4B,oBAASF,UAAU,CAACC,SAApB,CAAlC;AAEA,QAAME,aAAa,GAAGH,UAAU,CAACC,SAAX,EAAtB;;AAEA,MAAIA,SAAS,KAAKE,aAAlB,EAAiC;AAC/B;AACA;AACA;AACA;AACA;AACAD,IAAAA,YAAY,CAACC,aAAD,CAAZ;AACD;;AAEDC,EAAAA,KAAK,CAACC,SAAN,CAAgB,MAAM;AACpB,UAAMC,gBAAgB,GAAGN,UAAU,CAACO,WAAX,CAAuB,OAAvB,EAAgC,MACvDL,YAAY,CAAC,IAAD,CADW,CAAzB;AAIA,UAAMM,eAAe,GAAGR,UAAU,CAACO,WAAX,CAAuB,MAAvB,EAA+B,MACrDL,YAAY,CAAC,KAAD,CADU,CAAxB;AAIA,WAAO,MAAM;AACXI,MAAAA,gBAAgB;AAChBE,MAAAA,eAAe;AAChB,KAHD;AAID,GAbD,EAaG,CAACR,UAAD,CAbH;AAeAI,EAAAA,KAAK,CAACK,aAAN,CAAoBN,aAApB;AAEA,SAAOA,aAAP;AACD","sourcesContent":["import * as React from 'react';\nimport { useState } from 'react';\n\nimport useNavigation from './useNavigation';\n\n/**\n * Hook to get the current focus state of the screen. Returns a `true` if screen is focused, otherwise `false`.\n * This can be used if a component needs to render something based on the focus state.\n */\nexport default function useIsFocused(): boolean {\n const navigation = useNavigation();\n const [isFocused, setIsFocused] = useState(navigation.isFocused);\n\n const valueToReturn = navigation.isFocused();\n\n if (isFocused !== valueToReturn) {\n // If the value has changed since the last render, we need to update it.\n // This could happen if we missed an update from the event listeners during re-render.\n // React will process this update immediately, so the old subscription value won't be committed.\n // It is still nice to avoid returning a mismatched value though, so let's override the return value.\n // This is the same logic as in https://github.com/facebook/react/tree/master/packages/use-subscription\n setIsFocused(valueToReturn);\n }\n\n React.useEffect(() => {\n const unsubscribeFocus = navigation.addListener('focus', () =>\n setIsFocused(true)\n );\n\n const unsubscribeBlur = navigation.addListener('blur', () =>\n setIsFocused(false)\n );\n\n return () => {\n unsubscribeFocus();\n unsubscribeBlur();\n };\n }, [navigation]);\n\n React.useDebugValue(valueToReturn);\n\n return valueToReturn;\n}\n"]}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useKeyedChildListeners;
7
+
8
+ var React = _interopRequireWildcard(require("react"));
9
+
10
+ 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); }
11
+
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
+
14
+ /**
15
+ * Hook which lets child navigators add getters to be called for obtaining rehydrated state.
16
+ */
17
+ function useKeyedChildListeners() {
18
+ const {
19
+ current: keyedListeners
20
+ } = React.useRef({
21
+ getState: {},
22
+ beforeRemove: {}
23
+ });
24
+ const addKeyedListener = React.useCallback((type, key, listener) => {
25
+ keyedListeners[type][key] = listener;
26
+ return () => {
27
+ keyedListeners[type][key] = undefined;
28
+ };
29
+ }, [keyedListeners]);
30
+ return {
31
+ keyedListeners,
32
+ addKeyedListener
33
+ };
34
+ }
35
+ //# sourceMappingURL=useKeyedChildListeners.js.map
@@ -0,0 +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,CAOlC;AACAC,IAAAA,QAAQ,EAAE,EADV;AAEAC,IAAAA,YAAY,EAAE;AAFd,GAPkC,CAApC;AAYA,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 {\n [K in keyof KeyedListenerMap]: Record<\n string,\n KeyedListenerMap[K] | undefined\n >;\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"]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useNavigation;
7
+
8
+ var React = _interopRequireWildcard(require("react"));
9
+
10
+ var _NavigationContainerRefContext = _interopRequireDefault(require("./NavigationContainerRefContext"));
11
+
12
+ var _NavigationContext = _interopRequireDefault(require("./NavigationContext"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ 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); }
17
+
18
+ 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; }
19
+
20
+ /**
21
+ * Hook to access the navigation prop of the parent screen anywhere.
22
+ *
23
+ * @returns Navigation prop of the parent screen.
24
+ */
25
+ function useNavigation() {
26
+ const root = React.useContext(_NavigationContainerRefContext.default);
27
+ const navigation = React.useContext(_NavigationContext.default);
28
+
29
+ if (navigation === undefined && root === undefined) {
30
+ throw new Error("Couldn't find a navigation object. Is your component inside NavigationContainer?");
31
+ } // FIXME: Figure out a better way to do this
32
+
33
+
34
+ return navigation !== null && navigation !== void 0 ? navigation : root;
35
+ }
36
+ //# sourceMappingURL=useNavigation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useNavigation.tsx"],"names":["useNavigation","root","React","useContext","NavigationContainerRefContext","navigation","NavigationContext","undefined","Error"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;;;;;;;AAGA;AACA;AACA;AACA;AACA;AACe,SAASA,aAAT,GAER;AACL,QAAMC,IAAI,GAAGC,KAAK,CAACC,UAAN,CAAiBC,sCAAjB,CAAb;AACA,QAAMC,UAAU,GAAGH,KAAK,CAACC,UAAN,CAAiBG,0BAAjB,CAAnB;;AAEA,MAAID,UAAU,KAAKE,SAAf,IAA4BN,IAAI,KAAKM,SAAzC,EAAoD;AAClD,UAAM,IAAIC,KAAJ,CACJ,kFADI,CAAN;AAGD,GARI,CAUL;;;AACA,SAAQH,UAAR,aAAQA,UAAR,cAAQA,UAAR,GAAsBJ,IAAtB;AACD","sourcesContent":["import * as React from 'react';\n\nimport NavigationContainerRefContext from './NavigationContainerRefContext';\nimport NavigationContext from './NavigationContext';\nimport type { NavigationProp } from './types';\n\n/**\n * Hook to access the navigation prop of the parent screen anywhere.\n *\n * @returns Navigation prop of the parent screen.\n */\nexport default function useNavigation<\n T = NavigationProp<ReactNavigation.RootParamList>\n>(): T {\n const root = React.useContext(NavigationContainerRefContext);\n const navigation = React.useContext(NavigationContext);\n\n if (navigation === undefined && root === undefined) {\n throw new Error(\n \"Couldn't find a navigation object. Is your component inside NavigationContainer?\"\n );\n }\n\n // FIXME: Figure out a better way to do this\n return (navigation ?? root) as unknown as T;\n}\n"]}