@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,480 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useNavigationBuilder;
7
+
8
+ var _routers = require("@react-navigation/routers");
9
+
10
+ var React = _interopRequireWildcard(require("react"));
11
+
12
+ var _reactIs = require("react-is");
13
+
14
+ var _Group = _interopRequireDefault(require("./Group"));
15
+
16
+ var _isArrayEqual = _interopRequireDefault(require("./isArrayEqual"));
17
+
18
+ var _NavigationHelpersContext = _interopRequireDefault(require("./NavigationHelpersContext"));
19
+
20
+ var _NavigationRouteContext = _interopRequireDefault(require("./NavigationRouteContext"));
21
+
22
+ var _NavigationStateContext = _interopRequireDefault(require("./NavigationStateContext"));
23
+
24
+ var _Screen = _interopRequireDefault(require("./Screen"));
25
+
26
+ var _types = require("./types");
27
+
28
+ var _useChildListeners = _interopRequireDefault(require("./useChildListeners"));
29
+
30
+ var _useComponent = _interopRequireDefault(require("./useComponent"));
31
+
32
+ var _useCurrentRender = _interopRequireDefault(require("./useCurrentRender"));
33
+
34
+ var _useDescriptors = _interopRequireDefault(require("./useDescriptors"));
35
+
36
+ var _useEventEmitter = _interopRequireDefault(require("./useEventEmitter"));
37
+
38
+ var _useFocusedListenersChildrenAdapter = _interopRequireDefault(require("./useFocusedListenersChildrenAdapter"));
39
+
40
+ var _useFocusEvents = _interopRequireDefault(require("./useFocusEvents"));
41
+
42
+ var _useKeyedChildListeners = _interopRequireDefault(require("./useKeyedChildListeners"));
43
+
44
+ var _useNavigationHelpers = _interopRequireDefault(require("./useNavigationHelpers"));
45
+
46
+ var _useOnAction = _interopRequireDefault(require("./useOnAction"));
47
+
48
+ var _useOnGetState = _interopRequireDefault(require("./useOnGetState"));
49
+
50
+ var _useOnRouteFocus = _interopRequireDefault(require("./useOnRouteFocus"));
51
+
52
+ var _useRegisterNavigator = _interopRequireDefault(require("./useRegisterNavigator"));
53
+
54
+ var _useScheduleUpdate = _interopRequireDefault(require("./useScheduleUpdate"));
55
+
56
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
57
+
58
+ 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); }
59
+
60
+ 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; }
61
+
62
+ // This is to make TypeScript compiler happy
63
+ // eslint-disable-next-line babel/no-unused-expressions
64
+ _types.PrivateValueStore;
65
+
66
+ /**
67
+ * Extract route config object from React children elements.
68
+ *
69
+ * @param children React Elements to extract the config from.
70
+ */
71
+ const getRouteConfigsFromChildren = (children, options) => {
72
+ const configs = React.Children.toArray(children).reduce((acc, child) => {
73
+ var _child$type, _child$props;
74
+
75
+ if ( /*#__PURE__*/React.isValidElement(child)) {
76
+ if (child.type === _Screen.default) {
77
+ // We can only extract the config from `Screen` elements
78
+ // If something else was rendered, it's probably a bug
79
+ acc.push([options, child.props]);
80
+ return acc;
81
+ }
82
+
83
+ if (child.type === React.Fragment || child.type === _Group.default) {
84
+ // When we encounter a fragment or group, we need to dive into its children to extract the configs
85
+ // This is handy to conditionally define a group of screens
86
+ acc.push(...getRouteConfigsFromChildren(child.props.children, child.type !== _Group.default ? options : options != null ? [...options, child.props.screenOptions] : [child.props.screenOptions]));
87
+ return acc;
88
+ }
89
+ }
90
+
91
+ 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'.`);
92
+ }, []);
93
+
94
+ if (process.env.NODE_ENV !== 'production') {
95
+ configs.forEach(config => {
96
+ const {
97
+ name,
98
+ children,
99
+ component,
100
+ getComponent
101
+ } = config[1];
102
+
103
+ if (typeof name !== 'string' || !name) {
104
+ throw new Error(`Got an invalid name (${JSON.stringify(name)}) for the screen. It must be a non-empty string.`);
105
+ }
106
+
107
+ if (children != null || component !== undefined || getComponent !== undefined) {
108
+ if (children != null && component !== undefined) {
109
+ throw new Error(`Got both 'component' and 'children' props for the screen '${name}'. You must pass only one of them.`);
110
+ }
111
+
112
+ if (children != null && getComponent !== undefined) {
113
+ throw new Error(`Got both 'getComponent' and 'children' props for the screen '${name}'. You must pass only one of them.`);
114
+ }
115
+
116
+ if (component !== undefined && getComponent !== undefined) {
117
+ throw new Error(`Got both 'component' and 'getComponent' props for the screen '${name}'. You must pass only one of them.`);
118
+ }
119
+
120
+ if (children != null && typeof children !== 'function') {
121
+ throw new Error(`Got an invalid value for 'children' prop for the screen '${name}'. It must be a function returning a React Element.`);
122
+ }
123
+
124
+ if (component !== undefined && !(0, _reactIs.isValidElementType)(component)) {
125
+ throw new Error(`Got an invalid value for 'component' prop for the screen '${name}'. It must be a valid React Component.`);
126
+ }
127
+
128
+ if (getComponent !== undefined && typeof getComponent !== 'function') {
129
+ throw new Error(`Got an invalid value for 'getComponent' prop for the screen '${name}'. It must be a function returning a React Component.`);
130
+ }
131
+
132
+ if (typeof component === 'function' && component.name === 'component') {
133
+ // Inline anonymous functions passed in the `component` prop will have the name of the prop
134
+ // It's relatively safe to assume that it's not a component since it should also have PascalCase name
135
+ // We won't catch all scenarios here, but this should catch a good chunk of incorrect use.
136
+ 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.`);
137
+ }
138
+ } else {
139
+ 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.`);
140
+ }
141
+ });
142
+ }
143
+
144
+ return configs;
145
+ };
146
+ /**
147
+ * Hook for building navigators.
148
+ *
149
+ * @param createRouter Factory method which returns router object.
150
+ * @param options Options object containing `children` and additional options for the router.
151
+ * @returns An object containing `state`, `navigation`, `descriptors` objects.
152
+ */
153
+
154
+
155
+ function useNavigationBuilder(createRouter, options) {
156
+ const navigatorKey = (0, _useRegisterNavigator.default)();
157
+ const route = React.useContext(_NavigationRouteContext.default);
158
+ const {
159
+ children,
160
+ screenListeners,
161
+ ...rest
162
+ } = options;
163
+ const {
164
+ current: router
165
+ } = React.useRef(createRouter({ ...rest,
166
+ ...(route !== null && route !== void 0 && route.params && route.params.state == null && route.params.initial !== false && typeof route.params.screen === 'string' ? {
167
+ initialRouteName: route.params.screen
168
+ } : null)
169
+ }));
170
+ const routeConfigs = getRouteConfigsFromChildren(children);
171
+ const screens = routeConfigs.reduce((acc, config) => {
172
+ if (config[1].name in acc) {
173
+ throw new Error(`A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named '${config[1].name}')`);
174
+ }
175
+
176
+ acc[config[1].name] = config;
177
+ return acc;
178
+ }, {});
179
+ const routeNames = routeConfigs.map(config => config[1].name);
180
+ const routeParamList = routeNames.reduce((acc, curr) => {
181
+ const {
182
+ initialParams
183
+ } = screens[curr][1];
184
+ acc[curr] = initialParams;
185
+ return acc;
186
+ }, {});
187
+ const routeGetIdList = routeNames.reduce((acc, curr) => Object.assign(acc, {
188
+ [curr]: screens[curr][1].getId
189
+ }), {});
190
+
191
+ if (!routeNames.length) {
192
+ throw new Error("Couldn't find any screens for the navigator. Have you defined any screens as its children?");
193
+ }
194
+
195
+ const isStateValid = React.useCallback(state => state.type === undefined || state.type === router.type, [router.type]);
196
+ const isStateInitialized = React.useCallback(state => state !== undefined && state.stale === false && isStateValid(state), [isStateValid]);
197
+ const {
198
+ state: currentState,
199
+ getState: getCurrentState,
200
+ setState: setCurrentState,
201
+ setKey,
202
+ getKey,
203
+ getIsInitial
204
+ } = React.useContext(_NavigationStateContext.default);
205
+ const stateCleanedUp = React.useRef(false);
206
+ const cleanUpState = React.useCallback(() => {
207
+ setCurrentState(undefined);
208
+ stateCleanedUp.current = true;
209
+ }, [setCurrentState]);
210
+ const setState = React.useCallback(state => {
211
+ if (stateCleanedUp.current) {
212
+ // State might have been already cleaned up due to unmount
213
+ // We do not want to expose API allowing to override this
214
+ // This would lead to old data preservation on main navigator unmount
215
+ return;
216
+ }
217
+
218
+ setCurrentState(state);
219
+ }, [setCurrentState]);
220
+ const [initializedState, isFirstStateInitialization] = React.useMemo(() => {
221
+ var _route$params4;
222
+
223
+ const initialRouteParamList = routeNames.reduce((acc, curr) => {
224
+ var _route$params, _route$params2, _route$params3;
225
+
226
+ const {
227
+ initialParams
228
+ } = screens[curr][1];
229
+ 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;
230
+ acc[curr] = initialParams !== undefined || initialParamsFromParams !== undefined ? { ...initialParams,
231
+ ...initialParamsFromParams
232
+ } : undefined;
233
+ return acc;
234
+ }, {}); // If the current state isn't initialized on first render, we initialize it
235
+ // We also need to re-initialize it if the state passed from parent was changed (maybe due to reset)
236
+ // Otherwise assume that the state was provided as initial state
237
+ // So we need to rehydrate it to make it usable
238
+
239
+ 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) {
240
+ return [router.getInitialState({
241
+ routeNames,
242
+ routeParamList: initialRouteParamList,
243
+ routeGetIdList
244
+ }), true];
245
+ } else {
246
+ var _route$params$state, _route$params5;
247
+
248
+ 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, {
249
+ routeNames,
250
+ routeParamList: initialRouteParamList,
251
+ routeGetIdList
252
+ }), false];
253
+ } // We explicitly don't include routeNames, route.params etc. in the dep list
254
+ // below. We want to avoid forcing a new state to be calculated in those cases
255
+ // Instead, we handle changes to these in the nextState code below. Note
256
+ // that some changes to routeConfigs are explicitly ignored, such as changes
257
+ // to initialParams
258
+ // eslint-disable-next-line react-hooks/exhaustive-deps
259
+
260
+ }, [currentState, router, isStateValid]);
261
+ let state = // If the state isn't initialized, or stale, use the state we initialized instead
262
+ // The state won't update until there's a change needed in the state we have initalized locally
263
+ // So it'll be `undefined` or stale until the first navigation event happens
264
+ isStateInitialized(currentState) ? currentState : initializedState;
265
+ let nextState = state;
266
+
267
+ if (!(0, _isArrayEqual.default)(state.routeNames, routeNames)) {
268
+ // When the list of route names change, the router should handle it to remove invalid routes
269
+ nextState = router.getStateForRouteNamesChange(state, {
270
+ routeNames,
271
+ routeParamList,
272
+ routeGetIdList
273
+ });
274
+ }
275
+
276
+ const previousNestedParamsRef = React.useRef(route === null || route === void 0 ? void 0 : route.params);
277
+ React.useEffect(() => {
278
+ previousNestedParamsRef.current = route === null || route === void 0 ? void 0 : route.params;
279
+ }, [route === null || route === void 0 ? void 0 : route.params]);
280
+
281
+ if (route !== null && route !== void 0 && route.params) {
282
+ const previousParams = previousNestedParamsRef.current;
283
+ let action;
284
+
285
+ if (typeof route.params.state === 'object' && route.params.state != null && route.params !== previousParams) {
286
+ // If the route was updated with new state, we should reset to it
287
+ action = _routers.CommonActions.reset(route.params.state);
288
+ } else if (typeof route.params.screen === 'string' && (route.params.initial === false && isFirstStateInitialization || route.params !== previousParams)) {
289
+ // If the route was updated with new screen name and/or params, we should navigate there
290
+ action = _routers.CommonActions.navigate({
291
+ name: route.params.screen,
292
+ params: route.params.params,
293
+ path: route.params.path
294
+ });
295
+ } // The update should be limited to current navigator only, so we call the router manually
296
+
297
+
298
+ const updatedState = action ? router.getStateForAction(nextState, action, {
299
+ routeNames,
300
+ routeParamList,
301
+ routeGetIdList
302
+ }) : null;
303
+ nextState = updatedState !== null ? router.getRehydratedState(updatedState, {
304
+ routeNames,
305
+ routeParamList,
306
+ routeGetIdList
307
+ }) : nextState;
308
+ }
309
+
310
+ const shouldUpdate = state !== nextState;
311
+ (0, _useScheduleUpdate.default)(() => {
312
+ if (shouldUpdate) {
313
+ // If the state needs to be updated, we'll schedule an update
314
+ setState(nextState);
315
+ }
316
+ }); // The up-to-date state will come in next render, but we don't need to wait for it
317
+ // We can't use the outdated state since the screens have changed, which will cause error due to mismatched config
318
+ // So we override the state object we return to use the latest state as soon as possible
319
+
320
+ state = nextState;
321
+ React.useEffect(() => {
322
+ setKey(navigatorKey);
323
+
324
+ if (!getIsInitial()) {
325
+ // If it's not initial render, we need to update the state
326
+ // This will make sure that our container gets notifier of state changes due to new mounts
327
+ // This is necessary for proper screen tracking, URL updates etc.
328
+ setState(nextState);
329
+ }
330
+
331
+ return () => {
332
+ // We need to clean up state for this navigator on unmount
333
+ // We do it in a timeout because we need to detect if another navigator mounted in the meantime
334
+ // For example, if another navigator has started rendering, we should skip cleanup
335
+ // Otherwise, our cleanup step will cleanup state for the other navigator and re-initialize it
336
+ setTimeout(() => {
337
+ if (getCurrentState() !== undefined && getKey() === navigatorKey) {
338
+ cleanUpState();
339
+ }
340
+ }, 0);
341
+ }; // eslint-disable-next-line react-hooks/exhaustive-deps
342
+ }, []); // We initialize this ref here to avoid a new getState getting initialized
343
+ // whenever initializedState changes. We want getState to have access to the
344
+ // latest initializedState, but don't need it to change when that happens
345
+
346
+ const initializedStateRef = React.useRef();
347
+ initializedStateRef.current = initializedState;
348
+ const getState = React.useCallback(() => {
349
+ const currentState = getCurrentState();
350
+ return isStateInitialized(currentState) ? currentState : initializedStateRef.current;
351
+ }, [getCurrentState, isStateInitialized]);
352
+ const emitter = (0, _useEventEmitter.default)(e => {
353
+ let routeNames = [];
354
+ let route;
355
+
356
+ if (e.target) {
357
+ var _route;
358
+
359
+ route = state.routes.find(route => route.key === e.target);
360
+
361
+ if ((_route = route) !== null && _route !== void 0 && _route.name) {
362
+ routeNames.push(route.name);
363
+ }
364
+ } else {
365
+ route = state.routes[state.index];
366
+ routeNames.push(...Object.keys(screens).filter(name => {
367
+ var _route2;
368
+
369
+ return ((_route2 = route) === null || _route2 === void 0 ? void 0 : _route2.name) === name;
370
+ }));
371
+ }
372
+
373
+ if (route == null) {
374
+ return;
375
+ }
376
+
377
+ const navigation = descriptors[route.key].navigation;
378
+ const listeners = [].concat( // Get an array of listeners for all screens + common listeners on navigator
379
+ ...[screenListeners, ...routeNames.map(name => {
380
+ const {
381
+ listeners
382
+ } = screens[name][1];
383
+ return listeners;
384
+ })].map(listeners => {
385
+ const map = typeof listeners === 'function' ? listeners({
386
+ route: route,
387
+ navigation
388
+ }) : listeners;
389
+ return map ? Object.keys(map).filter(type => type === e.type).map(type => map === null || map === void 0 ? void 0 : map[type]) : undefined;
390
+ })) // We don't want same listener to be called multiple times for same event
391
+ // So we remove any duplicate functions from the array
392
+ .filter((cb, i, self) => cb && self.lastIndexOf(cb) === i);
393
+ listeners.forEach(listener => listener === null || listener === void 0 ? void 0 : listener(e));
394
+ });
395
+ (0, _useFocusEvents.default)({
396
+ state,
397
+ emitter
398
+ });
399
+ React.useEffect(() => {
400
+ emitter.emit({
401
+ type: 'state',
402
+ data: {
403
+ state
404
+ }
405
+ });
406
+ }, [emitter, state]);
407
+ const {
408
+ listeners: childListeners,
409
+ addListener
410
+ } = (0, _useChildListeners.default)();
411
+ const {
412
+ keyedListeners,
413
+ addKeyedListener
414
+ } = (0, _useKeyedChildListeners.default)();
415
+ const onAction = (0, _useOnAction.default)({
416
+ router,
417
+ getState,
418
+ setState,
419
+ key: route === null || route === void 0 ? void 0 : route.key,
420
+ actionListeners: childListeners.action,
421
+ beforeRemoveListeners: keyedListeners.beforeRemove,
422
+ routerConfigOptions: {
423
+ routeNames,
424
+ routeParamList,
425
+ routeGetIdList
426
+ },
427
+ emitter
428
+ });
429
+ const onRouteFocus = (0, _useOnRouteFocus.default)({
430
+ router,
431
+ key: route === null || route === void 0 ? void 0 : route.key,
432
+ getState,
433
+ setState
434
+ });
435
+ const navigation = (0, _useNavigationHelpers.default)({
436
+ onAction,
437
+ getState,
438
+ emitter,
439
+ router
440
+ });
441
+ (0, _useFocusedListenersChildrenAdapter.default)({
442
+ navigation,
443
+ focusedListeners: childListeners.focus
444
+ });
445
+ (0, _useOnGetState.default)({
446
+ getState,
447
+ getStateListeners: keyedListeners.getState
448
+ });
449
+ const descriptors = (0, _useDescriptors.default)({
450
+ state,
451
+ screens,
452
+ navigation,
453
+ screenOptions: options.screenOptions,
454
+ defaultScreenOptions: options.defaultScreenOptions,
455
+ onAction,
456
+ getState,
457
+ setState,
458
+ onRouteFocus,
459
+ addListener,
460
+ addKeyedListener,
461
+ router,
462
+ // @ts-expect-error: this should have both core and custom events, but too much work right now
463
+ emitter
464
+ });
465
+ (0, _useCurrentRender.default)({
466
+ state,
467
+ navigation,
468
+ descriptors
469
+ });
470
+ const NavigationContent = (0, _useComponent.default)(_NavigationHelpersContext.default.Provider, {
471
+ value: navigation
472
+ });
473
+ return {
474
+ state,
475
+ navigation,
476
+ descriptors,
477
+ NavigationContent
478
+ };
479
+ }
480
+ //# sourceMappingURL=useNavigationBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useNavigationBuilder.tsx"],"names":["PrivateValueStore","getRouteConfigsFromChildren","children","options","configs","React","Children","toArray","reduce","acc","child","isValidElement","type","Screen","push","props","Fragment","Group","screenOptions","Error","name","JSON","stringify","String","process","env","NODE_ENV","forEach","config","component","getComponent","undefined","console","warn","useNavigationBuilder","createRouter","navigatorKey","route","useContext","NavigationRouteContext","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","NavigationStateContext","stateCleanedUp","cleanUpState","initializedState","isFirstStateInitialization","useMemo","initialRouteParamList","initialParamsFromParams","getInitialState","getRehydratedState","nextState","getStateForRouteNamesChange","previousNestedParamsRef","useEffect","previousParams","action","CommonActions","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","NavigationHelpersContext","Provider","value"],"mappings":";;;;;;;AAAA;;AAYA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA;AACA;AACAA;;AAOA;AACA;AACA;AACA;AACA;AACA,MAAMC,2BAA2B,GA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,aAAEA,KAAF,uBAAEA,KAAK,CAAEmE,GAFuB;AAGnCrC,IAAAA,QAHmC;AAInCE,IAAAA;AAJmC,GAAhB,CAArB;AAOA,QAAMuC,UAAU,GAAG,mCAKjB;AACAe,IAAAA,QADA;AAEAxD,IAAAA,QAFA;AAGAgC,IAAAA,OAHA;AAIAxD,IAAAA;AAJA,GALiB,CAAnB;AAYA,mDAAmC;AACjCiE,IAAAA,UADiC;AAEjCqB,IAAAA,gBAAgB,EAAEV,cAAc,CAACW;AAFA,GAAnC;AAKA,8BAAc;AACZ/D,IAAAA,QADY;AAEZgE,IAAAA,iBAAiB,EAAEV,cAAc,CAACtD;AAFtB,GAAd;AAKA,QAAM0C,WAAW,GAAG,6BAKlB;AACA/D,IAAAA,KADA;AAEAK,IAAAA,OAFA;AAGAyD,IAAAA,UAHA;AAIA1F,IAAAA,aAAa,EAAEf,OAAO,CAACe,aAJvB;AAKAkH,IAAAA,oBAAoB,EAAEjI,OAAO,CAACiI,oBAL9B;AAMAT,IAAAA,QANA;AAOAxD,IAAAA,QAPA;AAQAE,IAAAA,QARA;AASA2D,IAAAA,YATA;AAUAR,IAAAA,WAVA;AAWAE,IAAAA,gBAXA;AAYA/E,IAAAA,MAZA;AAaA;AACAwD,IAAAA;AAdA,GALkB,CAApB;AAsBA,iCAAiB;AACfrD,IAAAA,KADe;AAEf8D,IAAAA,UAFe;AAGfC,IAAAA;AAHe,GAAjB;AAMA,QAAMwB,iBAAiB,GAAG,2BAAaC,kCAAyBC,QAAtC,EAAgD;AACxEC,IAAAA,KAAK,EAAE5B;AADiE,GAAhD,CAA1B;AAIA,SAAO;AACL9D,IAAAA,KADK;AAEL8D,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"]}