@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,443 @@
1
+ import { CommonActions } from '@react-navigation/routers';
2
+ import * as React from 'react';
3
+ import { isValidElementType } from 'react-is';
4
+ import Group from './Group';
5
+ import isArrayEqual from './isArrayEqual';
6
+ import NavigationHelpersContext from './NavigationHelpersContext';
7
+ import NavigationRouteContext from './NavigationRouteContext';
8
+ import NavigationStateContext from './NavigationStateContext';
9
+ import Screen from './Screen';
10
+ import { PrivateValueStore } from './types';
11
+ import useChildListeners from './useChildListeners';
12
+ import useComponent from './useComponent';
13
+ import useCurrentRender from './useCurrentRender';
14
+ import useDescriptors from './useDescriptors';
15
+ import useEventEmitter from './useEventEmitter';
16
+ import useFocusedListenersChildrenAdapter from './useFocusedListenersChildrenAdapter';
17
+ import useFocusEvents from './useFocusEvents';
18
+ import useKeyedChildListeners from './useKeyedChildListeners';
19
+ import useNavigationHelpers from './useNavigationHelpers';
20
+ import useOnAction from './useOnAction';
21
+ import useOnGetState from './useOnGetState';
22
+ import useOnRouteFocus from './useOnRouteFocus';
23
+ import useRegisterNavigator from './useRegisterNavigator';
24
+ import useScheduleUpdate from './useScheduleUpdate'; // This is to make TypeScript compiler happy
25
+ // eslint-disable-next-line babel/no-unused-expressions
26
+
27
+ PrivateValueStore;
28
+
29
+ /**
30
+ * Extract route config object from React children elements.
31
+ *
32
+ * @param children React Elements to extract the config from.
33
+ */
34
+ const getRouteConfigsFromChildren = (children, options) => {
35
+ const configs = React.Children.toArray(children).reduce((acc, child) => {
36
+ var _child$type, _child$props;
37
+
38
+ if ( /*#__PURE__*/React.isValidElement(child)) {
39
+ if (child.type === Screen) {
40
+ // We can only extract the config from `Screen` elements
41
+ // If something else was rendered, it's probably a bug
42
+ acc.push([options, child.props]);
43
+ return acc;
44
+ }
45
+
46
+ if (child.type === React.Fragment || child.type === Group) {
47
+ // When we encounter a fragment or group, we need to dive into its children to extract the configs
48
+ // This is handy to conditionally define a group of screens
49
+ acc.push(...getRouteConfigsFromChildren(child.props.children, child.type !== Group ? options : options != null ? [...options, child.props.screenOptions] : [child.props.screenOptions]));
50
+ return acc;
51
+ }
52
+ }
53
+
54
+ throw new Error(`A navigator can only contain 'Screen', 'Group' or 'React.Fragment' as its direct children (found ${/*#__PURE__*/React.isValidElement(child) ? `'${typeof child.type === 'string' ? child.type : (_child$type = child.type) === null || _child$type === void 0 ? void 0 : _child$type.name}'${(_child$props = child.props) !== null && _child$props !== void 0 && _child$props.name ? ` for the screen '${child.props.name}'` : ''}` : typeof child === 'object' ? JSON.stringify(child) : `'${String(child)}'`}). To render this component in the navigator, pass it in the 'component' prop to 'Screen'.`);
55
+ }, []);
56
+
57
+ if (process.env.NODE_ENV !== 'production') {
58
+ configs.forEach(config => {
59
+ const {
60
+ name,
61
+ children,
62
+ component,
63
+ getComponent
64
+ } = config[1];
65
+
66
+ if (typeof name !== 'string' || !name) {
67
+ throw new Error(`Got an invalid name (${JSON.stringify(name)}) for the screen. It must be a non-empty string.`);
68
+ }
69
+
70
+ if (children != null || component !== undefined || getComponent !== undefined) {
71
+ if (children != null && component !== undefined) {
72
+ throw new Error(`Got both 'component' and 'children' props for the screen '${name}'. You must pass only one of them.`);
73
+ }
74
+
75
+ if (children != null && getComponent !== undefined) {
76
+ throw new Error(`Got both 'getComponent' and 'children' props for the screen '${name}'. You must pass only one of them.`);
77
+ }
78
+
79
+ if (component !== undefined && getComponent !== undefined) {
80
+ throw new Error(`Got both 'component' and 'getComponent' props for the screen '${name}'. You must pass only one of them.`);
81
+ }
82
+
83
+ if (children != null && typeof children !== 'function') {
84
+ throw new Error(`Got an invalid value for 'children' prop for the screen '${name}'. It must be a function returning a React Element.`);
85
+ }
86
+
87
+ if (component !== undefined && !isValidElementType(component)) {
88
+ throw new Error(`Got an invalid value for 'component' prop for the screen '${name}'. It must be a valid React Component.`);
89
+ }
90
+
91
+ if (getComponent !== undefined && typeof getComponent !== 'function') {
92
+ throw new Error(`Got an invalid value for 'getComponent' prop for the screen '${name}'. It must be a function returning a React Component.`);
93
+ }
94
+
95
+ if (typeof component === 'function' && component.name === 'component') {
96
+ // Inline anonymous functions passed in the `component` prop will have the name of the prop
97
+ // It's relatively safe to assume that it's not a component since it should also have PascalCase name
98
+ // We won't catch all scenarios here, but this should catch a good chunk of incorrect use.
99
+ console.warn(`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.`);
100
+ }
101
+ } else {
102
+ throw new Error(`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.`);
103
+ }
104
+ });
105
+ }
106
+
107
+ return configs;
108
+ };
109
+ /**
110
+ * Hook for building navigators.
111
+ *
112
+ * @param createRouter Factory method which returns router object.
113
+ * @param options Options object containing `children` and additional options for the router.
114
+ * @returns An object containing `state`, `navigation`, `descriptors` objects.
115
+ */
116
+
117
+
118
+ export default function useNavigationBuilder(createRouter, options) {
119
+ const navigatorKey = useRegisterNavigator();
120
+ const route = React.useContext(NavigationRouteContext);
121
+ const {
122
+ children,
123
+ screenListeners,
124
+ ...rest
125
+ } = options;
126
+ const {
127
+ current: router
128
+ } = React.useRef(createRouter({ ...rest,
129
+ ...(route !== null && route !== void 0 && route.params && route.params.state == null && route.params.initial !== false && typeof route.params.screen === 'string' ? {
130
+ initialRouteName: route.params.screen
131
+ } : null)
132
+ }));
133
+ const routeConfigs = getRouteConfigsFromChildren(children);
134
+ const screens = routeConfigs.reduce((acc, config) => {
135
+ if (config[1].name in acc) {
136
+ throw new Error(`A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named '${config[1].name}')`);
137
+ }
138
+
139
+ acc[config[1].name] = config;
140
+ return acc;
141
+ }, {});
142
+ const routeNames = routeConfigs.map(config => config[1].name);
143
+ const routeParamList = routeNames.reduce((acc, curr) => {
144
+ const {
145
+ initialParams
146
+ } = screens[curr][1];
147
+ acc[curr] = initialParams;
148
+ return acc;
149
+ }, {});
150
+ const routeGetIdList = routeNames.reduce((acc, curr) => Object.assign(acc, {
151
+ [curr]: screens[curr][1].getId
152
+ }), {});
153
+
154
+ if (!routeNames.length) {
155
+ throw new Error("Couldn't find any screens for the navigator. Have you defined any screens as its children?");
156
+ }
157
+
158
+ const isStateValid = React.useCallback(state => state.type === undefined || state.type === router.type, [router.type]);
159
+ const isStateInitialized = React.useCallback(state => state !== undefined && state.stale === false && isStateValid(state), [isStateValid]);
160
+ const {
161
+ state: currentState,
162
+ getState: getCurrentState,
163
+ setState: setCurrentState,
164
+ setKey,
165
+ getKey,
166
+ getIsInitial
167
+ } = React.useContext(NavigationStateContext);
168
+ const stateCleanedUp = React.useRef(false);
169
+ const cleanUpState = React.useCallback(() => {
170
+ setCurrentState(undefined);
171
+ stateCleanedUp.current = true;
172
+ }, [setCurrentState]);
173
+ const setState = React.useCallback(state => {
174
+ if (stateCleanedUp.current) {
175
+ // State might have been already cleaned up due to unmount
176
+ // We do not want to expose API allowing to override this
177
+ // This would lead to old data preservation on main navigator unmount
178
+ return;
179
+ }
180
+
181
+ setCurrentState(state);
182
+ }, [setCurrentState]);
183
+ const [initializedState, isFirstStateInitialization] = React.useMemo(() => {
184
+ var _route$params4;
185
+
186
+ const initialRouteParamList = routeNames.reduce((acc, curr) => {
187
+ var _route$params, _route$params2, _route$params3;
188
+
189
+ const {
190
+ initialParams
191
+ } = screens[curr][1];
192
+ const initialParamsFromParams = (route === null || route === void 0 ? void 0 : (_route$params = route.params) === null || _route$params === void 0 ? void 0 : _route$params.state) == null && (route === null || route === void 0 ? void 0 : (_route$params2 = route.params) === null || _route$params2 === void 0 ? void 0 : _route$params2.initial) !== false && (route === null || route === void 0 ? void 0 : (_route$params3 = route.params) === null || _route$params3 === void 0 ? void 0 : _route$params3.screen) === curr ? route.params.params : undefined;
193
+ acc[curr] = initialParams !== undefined || initialParamsFromParams !== undefined ? { ...initialParams,
194
+ ...initialParamsFromParams
195
+ } : undefined;
196
+ return acc;
197
+ }, {}); // If the current state isn't initialized on first render, we initialize it
198
+ // We also need to re-initialize it if the state passed from parent was changed (maybe due to reset)
199
+ // Otherwise assume that the state was provided as initial state
200
+ // So we need to rehydrate it to make it usable
201
+
202
+ if ((currentState === undefined || !isStateValid(currentState)) && (route === null || route === void 0 ? void 0 : (_route$params4 = route.params) === null || _route$params4 === void 0 ? void 0 : _route$params4.state) == null) {
203
+ return [router.getInitialState({
204
+ routeNames,
205
+ routeParamList: initialRouteParamList,
206
+ routeGetIdList
207
+ }), true];
208
+ } else {
209
+ var _route$params$state, _route$params5;
210
+
211
+ return [router.getRehydratedState((_route$params$state = route === null || route === void 0 ? void 0 : (_route$params5 = route.params) === null || _route$params5 === void 0 ? void 0 : _route$params5.state) !== null && _route$params$state !== void 0 ? _route$params$state : currentState, {
212
+ routeNames,
213
+ routeParamList: initialRouteParamList,
214
+ routeGetIdList
215
+ }), false];
216
+ } // We explicitly don't include routeNames, route.params etc. in the dep list
217
+ // below. We want to avoid forcing a new state to be calculated in those cases
218
+ // Instead, we handle changes to these in the nextState code below. Note
219
+ // that some changes to routeConfigs are explicitly ignored, such as changes
220
+ // to initialParams
221
+ // eslint-disable-next-line react-hooks/exhaustive-deps
222
+
223
+ }, [currentState, router, isStateValid]);
224
+ let state = // If the state isn't initialized, or stale, use the state we initialized instead
225
+ // The state won't update until there's a change needed in the state we have initalized locally
226
+ // So it'll be `undefined` or stale until the first navigation event happens
227
+ isStateInitialized(currentState) ? currentState : initializedState;
228
+ let nextState = state;
229
+
230
+ if (!isArrayEqual(state.routeNames, routeNames)) {
231
+ // When the list of route names change, the router should handle it to remove invalid routes
232
+ nextState = router.getStateForRouteNamesChange(state, {
233
+ routeNames,
234
+ routeParamList,
235
+ routeGetIdList
236
+ });
237
+ }
238
+
239
+ const previousNestedParamsRef = React.useRef(route === null || route === void 0 ? void 0 : route.params);
240
+ React.useEffect(() => {
241
+ previousNestedParamsRef.current = route === null || route === void 0 ? void 0 : route.params;
242
+ }, [route === null || route === void 0 ? void 0 : route.params]);
243
+
244
+ if (route !== null && route !== void 0 && route.params) {
245
+ const previousParams = previousNestedParamsRef.current;
246
+ let action;
247
+
248
+ if (typeof route.params.state === 'object' && route.params.state != null && route.params !== previousParams) {
249
+ // If the route was updated with new state, we should reset to it
250
+ action = CommonActions.reset(route.params.state);
251
+ } else if (typeof route.params.screen === 'string' && (route.params.initial === false && isFirstStateInitialization || route.params !== previousParams)) {
252
+ // If the route was updated with new screen name and/or params, we should navigate there
253
+ action = CommonActions.navigate({
254
+ name: route.params.screen,
255
+ params: route.params.params,
256
+ path: route.params.path
257
+ });
258
+ } // The update should be limited to current navigator only, so we call the router manually
259
+
260
+
261
+ const updatedState = action ? router.getStateForAction(nextState, action, {
262
+ routeNames,
263
+ routeParamList,
264
+ routeGetIdList
265
+ }) : null;
266
+ nextState = updatedState !== null ? router.getRehydratedState(updatedState, {
267
+ routeNames,
268
+ routeParamList,
269
+ routeGetIdList
270
+ }) : nextState;
271
+ }
272
+
273
+ const shouldUpdate = state !== nextState;
274
+ useScheduleUpdate(() => {
275
+ if (shouldUpdate) {
276
+ // If the state needs to be updated, we'll schedule an update
277
+ setState(nextState);
278
+ }
279
+ }); // The up-to-date state will come in next render, but we don't need to wait for it
280
+ // We can't use the outdated state since the screens have changed, which will cause error due to mismatched config
281
+ // So we override the state object we return to use the latest state as soon as possible
282
+
283
+ state = nextState;
284
+ React.useEffect(() => {
285
+ setKey(navigatorKey);
286
+
287
+ if (!getIsInitial()) {
288
+ // If it's not initial render, we need to update the state
289
+ // This will make sure that our container gets notifier of state changes due to new mounts
290
+ // This is necessary for proper screen tracking, URL updates etc.
291
+ setState(nextState);
292
+ }
293
+
294
+ return () => {
295
+ // We need to clean up state for this navigator on unmount
296
+ // We do it in a timeout because we need to detect if another navigator mounted in the meantime
297
+ // For example, if another navigator has started rendering, we should skip cleanup
298
+ // Otherwise, our cleanup step will cleanup state for the other navigator and re-initialize it
299
+ setTimeout(() => {
300
+ if (getCurrentState() !== undefined && getKey() === navigatorKey) {
301
+ cleanUpState();
302
+ }
303
+ }, 0);
304
+ }; // eslint-disable-next-line react-hooks/exhaustive-deps
305
+ }, []); // We initialize this ref here to avoid a new getState getting initialized
306
+ // whenever initializedState changes. We want getState to have access to the
307
+ // latest initializedState, but don't need it to change when that happens
308
+
309
+ const initializedStateRef = React.useRef();
310
+ initializedStateRef.current = initializedState;
311
+ const getState = React.useCallback(() => {
312
+ const currentState = getCurrentState();
313
+ return isStateInitialized(currentState) ? currentState : initializedStateRef.current;
314
+ }, [getCurrentState, isStateInitialized]);
315
+ const emitter = useEventEmitter(e => {
316
+ let routeNames = [];
317
+ let route;
318
+
319
+ if (e.target) {
320
+ var _route;
321
+
322
+ route = state.routes.find(route => route.key === e.target);
323
+
324
+ if ((_route = route) !== null && _route !== void 0 && _route.name) {
325
+ routeNames.push(route.name);
326
+ }
327
+ } else {
328
+ route = state.routes[state.index];
329
+ routeNames.push(...Object.keys(screens).filter(name => {
330
+ var _route2;
331
+
332
+ return ((_route2 = route) === null || _route2 === void 0 ? void 0 : _route2.name) === name;
333
+ }));
334
+ }
335
+
336
+ if (route == null) {
337
+ return;
338
+ }
339
+
340
+ const navigation = descriptors[route.key].navigation;
341
+ const listeners = [].concat( // Get an array of listeners for all screens + common listeners on navigator
342
+ ...[screenListeners, ...routeNames.map(name => {
343
+ const {
344
+ listeners
345
+ } = screens[name][1];
346
+ return listeners;
347
+ })].map(listeners => {
348
+ const map = typeof listeners === 'function' ? listeners({
349
+ route: route,
350
+ navigation
351
+ }) : listeners;
352
+ return map ? Object.keys(map).filter(type => type === e.type).map(type => map === null || map === void 0 ? void 0 : map[type]) : undefined;
353
+ })) // We don't want same listener to be called multiple times for same event
354
+ // So we remove any duplicate functions from the array
355
+ .filter((cb, i, self) => cb && self.lastIndexOf(cb) === i);
356
+ listeners.forEach(listener => listener === null || listener === void 0 ? void 0 : listener(e));
357
+ });
358
+ useFocusEvents({
359
+ state,
360
+ emitter
361
+ });
362
+ React.useEffect(() => {
363
+ emitter.emit({
364
+ type: 'state',
365
+ data: {
366
+ state
367
+ }
368
+ });
369
+ }, [emitter, state]);
370
+ const {
371
+ listeners: childListeners,
372
+ addListener
373
+ } = useChildListeners();
374
+ const {
375
+ keyedListeners,
376
+ addKeyedListener
377
+ } = useKeyedChildListeners();
378
+ const onAction = useOnAction({
379
+ router,
380
+ getState,
381
+ setState,
382
+ key: route === null || route === void 0 ? void 0 : route.key,
383
+ actionListeners: childListeners.action,
384
+ beforeRemoveListeners: keyedListeners.beforeRemove,
385
+ routerConfigOptions: {
386
+ routeNames,
387
+ routeParamList,
388
+ routeGetIdList
389
+ },
390
+ emitter
391
+ });
392
+ const onRouteFocus = useOnRouteFocus({
393
+ router,
394
+ key: route === null || route === void 0 ? void 0 : route.key,
395
+ getState,
396
+ setState
397
+ });
398
+ const navigation = useNavigationHelpers({
399
+ onAction,
400
+ getState,
401
+ emitter,
402
+ router
403
+ });
404
+ useFocusedListenersChildrenAdapter({
405
+ navigation,
406
+ focusedListeners: childListeners.focus
407
+ });
408
+ useOnGetState({
409
+ getState,
410
+ getStateListeners: keyedListeners.getState
411
+ });
412
+ const descriptors = useDescriptors({
413
+ state,
414
+ screens,
415
+ navigation,
416
+ screenOptions: options.screenOptions,
417
+ defaultScreenOptions: options.defaultScreenOptions,
418
+ onAction,
419
+ getState,
420
+ setState,
421
+ onRouteFocus,
422
+ addListener,
423
+ addKeyedListener,
424
+ router,
425
+ // @ts-expect-error: this should have both core and custom events, but too much work right now
426
+ emitter
427
+ });
428
+ useCurrentRender({
429
+ state,
430
+ navigation,
431
+ descriptors
432
+ });
433
+ const NavigationContent = useComponent(NavigationHelpersContext.Provider, {
434
+ value: navigation
435
+ });
436
+ return {
437
+ state,
438
+ navigation,
439
+ descriptors,
440
+ NavigationContent
441
+ };
442
+ }
443
+ //# sourceMappingURL=useNavigationBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useNavigationBuilder.tsx"],"names":["CommonActions","React","isValidElementType","Group","isArrayEqual","NavigationHelpersContext","NavigationRouteContext","NavigationStateContext","Screen","PrivateValueStore","useChildListeners","useComponent","useCurrentRender","useDescriptors","useEventEmitter","useFocusedListenersChildrenAdapter","useFocusEvents","useKeyedChildListeners","useNavigationHelpers","useOnAction","useOnGetState","useOnRouteFocus","useRegisterNavigator","useScheduleUpdate","getRouteConfigsFromChildren","children","options","configs","Children","toArray","reduce","acc","child","isValidElement","type","push","props","Fragment","screenOptions","Error","name","JSON","stringify","String","process","env","NODE_ENV","forEach","config","component","getComponent","undefined","console","warn","useNavigationBuilder","createRouter","navigatorKey","route","useContext","screenListeners","rest","current","router","useRef","params","state","initial","screen","initialRouteName","routeConfigs","screens","routeNames","map","routeParamList","curr","initialParams","routeGetIdList","Object","assign","getId","length","isStateValid","useCallback","isStateInitialized","stale","currentState","getState","getCurrentState","setState","setCurrentState","setKey","getKey","getIsInitial","stateCleanedUp","cleanUpState","initializedState","isFirstStateInitialization","useMemo","initialRouteParamList","initialParamsFromParams","getInitialState","getRehydratedState","nextState","getStateForRouteNamesChange","previousNestedParamsRef","useEffect","previousParams","action","reset","navigate","path","updatedState","getStateForAction","shouldUpdate","setTimeout","initializedStateRef","emitter","e","target","routes","find","key","index","keys","filter","navigation","descriptors","listeners","concat","cb","i","self","lastIndexOf","listener","emit","data","childListeners","addListener","keyedListeners","addKeyedListener","onAction","actionListeners","beforeRemoveListeners","beforeRemove","routerConfigOptions","onRouteFocus","focusedListeners","focus","getStateListeners","defaultScreenOptions","NavigationContent","Provider","value"],"mappings":"AAAA,SACEA,aADF,QAWO,2BAXP;AAYA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SAASC,kBAAT,QAAmC,UAAnC;AAEA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,OAAOC,wBAAP,MAAqC,4BAArC;AACA,OAAOC,sBA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AAEV,cAAc,CAACpD;AAFtB,GAAD,CAAb;AAKA,QAAMwC,WAAW,GAAGjH,cAAc,CAKhC;AACAoD,IAAAA,KADA;AAEAK,IAAAA,OAFA;AAGAuD,IAAAA,UAHA;AAIAvF,IAAAA,aAAa,EAAEZ,OAAO,CAACY,aAJvB;AAKA+G,IAAAA,oBAAoB,EAAE3H,OAAO,CAAC2H,oBAL9B;AAMAT,IAAAA,QANA;AAOAtD,IAAAA,QAPA;AAQAE,IAAAA,QARA;AASAyD,IAAAA,YATA;AAUAR,IAAAA,WAVA;AAWAE,IAAAA,gBAXA;AAYA7E,IAAAA,MAZA;AAaA;AACAsD,IAAAA;AAdA,GALgC,CAAlC;AAsBAxG,EAAAA,gBAAgB,CAAC;AACfqD,IAAAA,KADe;AAEf4D,IAAAA,UAFe;AAGfC,IAAAA;AAHe,GAAD,CAAhB;AAMA,QAAMwB,iBAAiB,GAAG3I,YAAY,CAACN,wBAAwB,CAACkJ,QAA1B,EAAoC;AACxEC,IAAAA,KAAK,EAAE3B;AADiE,GAApC,CAAtC;AAIA,SAAO;AACL5D,IAAAA,KADK;AAEL4D,IAAAA,UAFK;AAGLC,IAAAA,WAHK;AAILwB,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 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\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 options?: ScreenConfigWithParent<State, ScreenOptions, EventMap>[0]\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 acc.push([\n options,\n 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 // 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.type !== Group\n ? options\n : options != null\n ? [...options, 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[1];\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' && 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 }\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 =\n getRouteConfigsFromChildren<State, ScreenOptions, EventMap>(children);\n\n const screens = routeConfigs.reduce<\n Record<string, ScreenConfigWithParent<State, ScreenOptions, EventMap>>\n >((acc, config) => {\n if (config[1].name in acc) {\n throw new Error(\n `A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named '${config[1].name}')`\n );\n }\n\n acc[config[1].name] = config;\n return acc;\n }, {});\n\n const routeNames = routeConfigs.map((config) => config[1].name);\n const routeParamList = routeNames.reduce<Record<string, object | undefined>>(\n (acc, curr) => {\n const { initialParams } = screens[curr][1];\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][1].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][1];\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 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 (!isArrayEqual(state.routeNames, routeNames)) {\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 });\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][1];\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 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"]}
@@ -0,0 +1,107 @@
1
+ import { CommonActions } from '@react-navigation/routers';
2
+ import * as React from 'react';
3
+ import NavigationBuilderContext from './NavigationBuilderContext';
4
+
5
+ /**
6
+ * Hook to cache navigation objects for each screen in the navigator.
7
+ * It's important to cache them to make sure navigation objects don't change between renders.
8
+ * This lets us apply optimizations like `React.memo` to minimize re-rendering screens.
9
+ */
10
+ export default function useNavigationCache({
11
+ state,
12
+ getState,
13
+ navigation,
14
+ setOptions,
15
+ router,
16
+ emitter
17
+ }) {
18
+ const {
19
+ stackRef
20
+ } = React.useContext(NavigationBuilderContext); // Cache object which holds navigation objects for each screen
21
+ // We use `React.useMemo` instead of `React.useRef` coz we want to invalidate it when deps change
22
+ // In reality, these deps will rarely change, if ever
23
+
24
+ const cache = React.useMemo(() => ({
25
+ current: {}
26
+ }), // eslint-disable-next-line react-hooks/exhaustive-deps
27
+ [getState, navigation, setOptions, router, emitter]);
28
+ const actions = { ...router.actionCreators,
29
+ ...CommonActions
30
+ };
31
+ cache.current = state.routes.reduce((acc, route) => {
32
+ const previous = cache.current[route.key];
33
+
34
+ if (previous) {
35
+ // If a cached navigation object already exists, reuse it
36
+ acc[route.key] = previous;
37
+ } else {
38
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
39
+ const {
40
+ emit,
41
+ ...rest
42
+ } = navigation;
43
+
44
+ const dispatch = thunk => {
45
+ const action = typeof thunk === 'function' ? thunk(getState()) : thunk;
46
+
47
+ if (action != null) {
48
+ navigation.dispatch({
49
+ source: route.key,
50
+ ...action
51
+ });
52
+ }
53
+ };
54
+
55
+ const withStack = callback => {
56
+ let isStackSet = false;
57
+
58
+ try {
59
+ if (process.env.NODE_ENV !== 'production' && stackRef && !stackRef.current) {
60
+ // Capture the stack trace for devtools
61
+ stackRef.current = new Error().stack;
62
+ isStackSet = true;
63
+ }
64
+
65
+ callback();
66
+ } finally {
67
+ if (isStackSet && stackRef) {
68
+ stackRef.current = undefined;
69
+ }
70
+ }
71
+ };
72
+
73
+ const helpers = Object.keys(actions).reduce((acc, name) => {
74
+ acc[name] = (...args) => withStack(() => // @ts-expect-error: name is a valid key, but TypeScript is dumb
75
+ dispatch(actions[name](...args)));
76
+
77
+ return acc;
78
+ }, {});
79
+ acc[route.key] = { ...rest,
80
+ ...helpers,
81
+ // FIXME: too much work to fix the types for now
82
+ ...emitter.create(route.key),
83
+ dispatch: thunk => withStack(() => dispatch(thunk)),
84
+ setOptions: options => setOptions(o => ({ ...o,
85
+ [route.key]: { ...o[route.key],
86
+ ...options
87
+ }
88
+ })),
89
+ isFocused: () => {
90
+ const state = getState();
91
+
92
+ if (state.routes[state.index].key !== route.key) {
93
+ return false;
94
+ } // If the current screen is focused, we also need to check if parent navigator is focused
95
+ // This makes sure that we return the focus state in the whole tree, not just this navigator
96
+
97
+
98
+ return navigation ? navigation.isFocused() : true;
99
+ }
100
+ };
101
+ }
102
+
103
+ return acc;
104
+ }, {});
105
+ return cache.current;
106
+ }
107
+ //# sourceMappingURL=useNavigationCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useNavigationCache.tsx"],"names":["CommonActions","React","NavigationBuilderContext","useNavigationCache","state","getState","navigation","setOptions","router","emitter","stackRef","useContext","cache","useMemo","current","actions","actionCreators","routes","reduce","acc","route","previous","key","emit","rest","dispatch","thunk","action","source","withStack","callback","isStackSet","process","env","NODE_ENV","Error","stack","undefined","helpers","Object","keys","name","args","create","options","o","isFocused","index"],"mappings":"AAAA,SACEA,aADF,QAMO,2BANP;AAOA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,wBAAP,MAAqC,4BAArC;;AA4BA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,kBAAT,CAIb;AACAC,EAAAA,KADA;AAEAC,EAAAA,QAFA;AAGAC,EAAAA,UAHA;AAIAC,EAAAA,UAJA;AAKAC,EAAAA,MALA;AAMAC,EAAAA;AANA,CAJa,EAWc;AAC3B,QAAM;AAAEC,IAAAA;AAAF,MAAeT,KAAK,CAACU,UAAN,CAAiBT,wBAAjB,CAArB,CAD2B,CAG3B;AACA;AACA;;AACA,QAAMU,KAAK,GAAGX,KAAK,CA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AACA,iBAAOhB,UAAU,GAAGA,UAAU,CAACwC,SAAX,EAAH,GAA4B,IAA7C;AACD;AArBc,OAAjB;AAuBD;;AAED,WAAO3B,GAAP;AACD,GArFe,EAqFb,EArFa,CAAhB;AAuFA,SAAOP,KAAK,CAACE,OAAb;AACD","sourcesContent":["import {\n CommonActions,\n NavigationAction,\n NavigationState,\n ParamListBase,\n Router,\n} from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport NavigationBuilderContext from './NavigationBuilderContext';\nimport type { NavigationHelpers, NavigationProp } from './types';\nimport type { NavigationEventEmitter } from './useEventEmitter';\n\ntype Options<\n State extends NavigationState,\n EventMap extends Record<string, any>\n> = {\n state: State;\n getState: () => State;\n navigation: NavigationHelpers<ParamListBase> &\n Partial<NavigationProp<ParamListBase, string, any, any, any>>;\n setOptions: (\n cb: (options: Record<string, object>) => Record<string, object>\n ) => void;\n router: Router<State, NavigationAction>;\n emitter: NavigationEventEmitter<EventMap>;\n};\n\ntype NavigationCache<\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends Record<string, any>\n> = Record<\n string,\n NavigationProp<ParamListBase, string, State, ScreenOptions, EventMap>\n>;\n\n/**\n * Hook to cache navigation objects for each screen in the navigator.\n * It's important to cache them to make sure navigation objects don't change between renders.\n * This lets us apply optimizations like `React.memo` to minimize re-rendering screens.\n */\nexport default function useNavigationCache<\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends Record<string, any>\n>({\n state,\n getState,\n navigation,\n setOptions,\n router,\n emitter,\n}: Options<State, EventMap>) {\n const { stackRef } = React.useContext(NavigationBuilderContext);\n\n // Cache object which holds navigation objects for each screen\n // We use `React.useMemo` instead of `React.useRef` coz we want to invalidate it when deps change\n // In reality, these deps will rarely change, if ever\n const cache = React.useMemo(\n () => ({ current: {} as NavigationCache<State, ScreenOptions, EventMap> }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [getState, navigation, setOptions, router, emitter]\n );\n\n const actions = {\n ...router.actionCreators,\n ...CommonActions,\n };\n\n cache.current = state.routes.reduce<\n NavigationCache<State, ScreenOptions, EventMap>\n >((acc, route) => {\n const previous = cache.current[route.key];\n\n type Thunk =\n | NavigationAction\n | ((state: State) => NavigationAction | null | undefined);\n\n if (previous) {\n // If a cached navigation object already exists, reuse it\n acc[route.key] = previous;\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { emit, ...rest } = navigation;\n\n const dispatch = (thunk: Thunk) => {\n const action = typeof thunk === 'function' ? thunk(getState()) : thunk;\n\n if (action != null) {\n navigation.dispatch({ source: route.key, ...action });\n }\n };\n\n const withStack = (callback: () => void) => {\n let isStackSet = false;\n\n try {\n if (\n process.env.NODE_ENV !== 'production' &&\n stackRef &&\n !stackRef.current\n ) {\n // Capture the stack trace for devtools\n stackRef.current = new Error().stack;\n isStackSet = true;\n }\n\n callback();\n } finally {\n if (isStackSet && stackRef) {\n stackRef.current = undefined;\n }\n }\n };\n\n const helpers = Object.keys(actions).reduce<Record<string, () => void>>(\n (acc, name) => {\n acc[name] = (...args: any) =>\n withStack(() =>\n // @ts-expect-error: name is a valid key, but TypeScript is dumb\n dispatch(actions[name](...args))\n );\n\n return acc;\n },\n {}\n );\n\n acc[route.key] = {\n ...rest,\n ...helpers,\n // FIXME: too much work to fix the types for now\n ...(emitter.create(route.key) as any),\n dispatch: (thunk: Thunk) => withStack(() => dispatch(thunk)),\n setOptions: (options: object) =>\n setOptions((o) => ({\n ...o,\n [route.key]: { ...o[route.key], ...options },\n })),\n isFocused: () => {\n const state = getState();\n\n if (state.routes[state.index].key !== route.key) {\n return false;\n }\n\n // If the current screen is focused, we also need to check if parent navigator is focused\n // This makes sure that we return the focus state in the whole tree, not just this navigator\n return navigation ? navigation.isFocused() : true;\n },\n };\n }\n\n return acc;\n }, {});\n\n return cache.current;\n}\n"]}