@react-navigation/core 7.0.0-alpha.0 → 7.0.0-alpha.10

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 (486) hide show
  1. package/lib/commonjs/BaseNavigationContainer.js +57 -63
  2. package/lib/commonjs/BaseNavigationContainer.js.map +1 -1
  3. package/lib/commonjs/CurrentRenderContext.js +4 -6
  4. package/lib/commonjs/CurrentRenderContext.js.map +1 -1
  5. package/lib/commonjs/DeprecatedNavigationInChildContext.js +4 -6
  6. package/lib/commonjs/DeprecatedNavigationInChildContext.js.map +1 -1
  7. package/lib/commonjs/EnsureSingleNavigator.js +4 -5
  8. package/lib/commonjs/EnsureSingleNavigator.js.map +1 -1
  9. package/lib/commonjs/Group.js +1 -1
  10. package/lib/commonjs/Group.js.map +1 -1
  11. package/lib/commonjs/NavigationBuilderContext.js +4 -6
  12. package/lib/commonjs/NavigationBuilderContext.js.map +1 -1
  13. package/lib/commonjs/NavigationContainerRefContext.js +4 -6
  14. package/lib/commonjs/NavigationContainerRefContext.js.map +1 -1
  15. package/lib/commonjs/NavigationContext.js +4 -6
  16. package/lib/commonjs/NavigationContext.js.map +1 -1
  17. package/lib/commonjs/NavigationHelpersContext.js +4 -6
  18. package/lib/commonjs/NavigationHelpersContext.js.map +1 -1
  19. package/lib/commonjs/NavigationIndependentTree.js +9 -10
  20. package/lib/commonjs/NavigationIndependentTree.js.map +1 -1
  21. package/lib/commonjs/NavigationIndependentTreeContext.js +4 -6
  22. package/lib/commonjs/NavigationIndependentTreeContext.js.map +1 -1
  23. package/lib/commonjs/NavigationRouteContext.js +4 -6
  24. package/lib/commonjs/NavigationRouteContext.js.map +1 -1
  25. package/lib/commonjs/NavigationStateContext.js +4 -5
  26. package/lib/commonjs/NavigationStateContext.js.map +1 -1
  27. package/lib/commonjs/PreventRemoveContext.js +9 -6
  28. package/lib/commonjs/PreventRemoveContext.js.map +1 -1
  29. package/lib/commonjs/PreventRemoveProvider.js +16 -18
  30. package/lib/commonjs/PreventRemoveProvider.js.map +1 -1
  31. package/lib/commonjs/SceneView.js +10 -11
  32. package/lib/commonjs/SceneView.js.map +1 -1
  33. package/lib/commonjs/Screen.js +1 -1
  34. package/lib/commonjs/Screen.js.map +1 -1
  35. package/lib/commonjs/StaticContainer.js +5 -7
  36. package/lib/commonjs/StaticContainer.js.map +1 -1
  37. package/lib/commonjs/StaticNavigation.js +36 -10
  38. package/lib/commonjs/StaticNavigation.js.map +1 -1
  39. package/lib/commonjs/UnhandledActionContext.js +4 -6
  40. package/lib/commonjs/UnhandledActionContext.js.map +1 -1
  41. package/lib/commonjs/checkDuplicateRouteNames.js +2 -3
  42. package/lib/commonjs/checkDuplicateRouteNames.js.map +1 -1
  43. package/lib/commonjs/checkSerializable.js +1 -1
  44. package/lib/commonjs/checkSerializable.js.map +1 -1
  45. package/lib/commonjs/createNavigationContainerRef.js +2 -3
  46. package/lib/commonjs/createNavigationContainerRef.js.map +1 -1
  47. package/lib/commonjs/createNavigatorFactory.js +7 -11
  48. package/lib/commonjs/createNavigatorFactory.js.map +1 -1
  49. package/lib/commonjs/findFocusedRoute.js +3 -5
  50. package/lib/commonjs/findFocusedRoute.js.map +1 -1
  51. package/lib/commonjs/getActionFromState.js +7 -9
  52. package/lib/commonjs/getActionFromState.js.map +1 -1
  53. package/lib/commonjs/getFocusedRouteNameFromRoute.js +2 -2
  54. package/lib/commonjs/getFocusedRouteNameFromRoute.js.map +1 -1
  55. package/lib/commonjs/getPathFromState.js +24 -25
  56. package/lib/commonjs/getPathFromState.js.map +1 -1
  57. package/lib/commonjs/getStateFromPath.js +29 -22
  58. package/lib/commonjs/getStateFromPath.js.map +1 -1
  59. package/lib/commonjs/index.js +78 -76
  60. package/lib/commonjs/index.js.map +1 -1
  61. package/lib/commonjs/isArrayEqual.js +1 -1
  62. package/lib/commonjs/isArrayEqual.js.map +1 -1
  63. package/lib/commonjs/isRecordEqual.js +1 -1
  64. package/lib/commonjs/isRecordEqual.js.map +1 -1
  65. package/lib/commonjs/theming/ThemeContext.js +12 -0
  66. package/lib/commonjs/theming/ThemeContext.js.map +1 -0
  67. package/lib/commonjs/theming/ThemeProvider.js +20 -0
  68. package/lib/commonjs/theming/ThemeProvider.js.map +1 -0
  69. package/lib/commonjs/theming/useTheme.js +18 -0
  70. package/lib/commonjs/theming/useTheme.js.map +1 -0
  71. package/lib/commonjs/types.js +1 -8
  72. package/lib/commonjs/types.js.map +1 -1
  73. package/lib/commonjs/useChildListeners.js +3 -3
  74. package/lib/commonjs/useChildListeners.js.map +1 -1
  75. package/lib/commonjs/useComponent.js +3 -3
  76. package/lib/commonjs/useComponent.js.map +1 -1
  77. package/lib/commonjs/useCurrentRender.js +5 -6
  78. package/lib/commonjs/useCurrentRender.js.map +1 -1
  79. package/lib/commonjs/useDescriptors.js +92 -41
  80. package/lib/commonjs/useDescriptors.js.map +1 -1
  81. package/lib/commonjs/useEventEmitter.js +6 -7
  82. package/lib/commonjs/useEventEmitter.js.map +1 -1
  83. package/lib/commonjs/useFocusEffect.js +7 -6
  84. package/lib/commonjs/useFocusEffect.js.map +1 -1
  85. package/lib/commonjs/useFocusEvents.js +7 -8
  86. package/lib/commonjs/useFocusEvents.js.map +1 -1
  87. package/lib/commonjs/useFocusedListenersChildrenAdapter.js +6 -7
  88. package/lib/commonjs/useFocusedListenersChildrenAdapter.js.map +1 -1
  89. package/lib/commonjs/useIsFocused.js +8 -8
  90. package/lib/commonjs/useIsFocused.js.map +1 -1
  91. package/lib/commonjs/useIsomorphicLayoutEffect.js +12 -0
  92. package/lib/commonjs/useIsomorphicLayoutEffect.js.map +1 -0
  93. package/lib/commonjs/useIsomorphicLayoutEffect.native.js +9 -0
  94. package/lib/commonjs/useIsomorphicLayoutEffect.native.js.map +1 -0
  95. package/lib/commonjs/useKeyedChildListeners.js +3 -3
  96. package/lib/commonjs/useKeyedChildListeners.js.map +1 -1
  97. package/lib/commonjs/useNavigation.js +7 -8
  98. package/lib/commonjs/useNavigation.js.map +1 -1
  99. package/lib/commonjs/useNavigationBuilder.js +115 -106
  100. package/lib/commonjs/useNavigationBuilder.js.map +1 -1
  101. package/lib/commonjs/useNavigationCache.js +60 -20
  102. package/lib/commonjs/useNavigationCache.js.map +1 -1
  103. package/lib/commonjs/useNavigationContainerRef.js +5 -6
  104. package/lib/commonjs/useNavigationContainerRef.js.map +1 -1
  105. package/lib/commonjs/useNavigationHelpers.js +9 -11
  106. package/lib/commonjs/useNavigationHelpers.js.map +1 -1
  107. package/lib/commonjs/useNavigationIndependentTree.js +5 -6
  108. package/lib/commonjs/useNavigationIndependentTree.js.map +1 -1
  109. package/lib/commonjs/useNavigationState.js +5 -6
  110. package/lib/commonjs/useNavigationState.js.map +1 -1
  111. package/lib/commonjs/useOnAction.js +13 -12
  112. package/lib/commonjs/useOnAction.js.map +1 -1
  113. package/lib/commonjs/useOnGetState.js +11 -13
  114. package/lib/commonjs/useOnGetState.js.map +1 -1
  115. package/lib/commonjs/useOnPreventRemove.js +10 -12
  116. package/lib/commonjs/useOnPreventRemove.js.map +1 -1
  117. package/lib/commonjs/useOnRouteFocus.js +5 -6
  118. package/lib/commonjs/useOnRouteFocus.js.map +1 -1
  119. package/lib/commonjs/useOptionsGetters.js +14 -16
  120. package/lib/commonjs/useOptionsGetters.js.map +1 -1
  121. package/lib/commonjs/usePreventRemove.js +10 -10
  122. package/lib/commonjs/usePreventRemove.js.map +1 -1
  123. package/lib/commonjs/usePreventRemoveContext.js +5 -6
  124. package/lib/commonjs/usePreventRemoveContext.js.map +1 -1
  125. package/lib/commonjs/useRegisterNavigator.js +3 -3
  126. package/lib/commonjs/useRegisterNavigator.js.map +1 -1
  127. package/lib/commonjs/useRoute.js +5 -6
  128. package/lib/commonjs/useRoute.js.map +1 -1
  129. package/lib/commonjs/useRouteCache.js +20 -17
  130. package/lib/commonjs/useRouteCache.js.map +1 -1
  131. package/lib/commonjs/useSyncState.js +28 -57
  132. package/lib/commonjs/useSyncState.js.map +1 -1
  133. package/lib/commonjs/validatePathConfig.js +38 -11
  134. package/lib/commonjs/validatePathConfig.js.map +1 -1
  135. package/lib/module/BaseNavigationContainer.js +39 -44
  136. package/lib/module/BaseNavigationContainer.js.map +1 -1
  137. package/lib/module/CurrentRenderContext.js +1 -2
  138. package/lib/module/CurrentRenderContext.js.map +1 -1
  139. package/lib/module/DeprecatedNavigationInChildContext.js +1 -2
  140. package/lib/module/DeprecatedNavigationInChildContext.js.map +1 -1
  141. package/lib/module/EnsureSingleNavigator.js +1 -1
  142. package/lib/module/EnsureSingleNavigator.js.map +1 -1
  143. package/lib/module/Group.js +1 -1
  144. package/lib/module/Group.js.map +1 -1
  145. package/lib/module/NavigationBuilderContext.js +1 -2
  146. package/lib/module/NavigationBuilderContext.js.map +1 -1
  147. package/lib/module/NavigationContainerRefContext.js +1 -2
  148. package/lib/module/NavigationContainerRefContext.js.map +1 -1
  149. package/lib/module/NavigationContext.js +1 -2
  150. package/lib/module/NavigationContext.js.map +1 -1
  151. package/lib/module/NavigationHelpersContext.js +1 -2
  152. package/lib/module/NavigationHelpersContext.js.map +1 -1
  153. package/lib/module/NavigationIndependentTree.js +4 -4
  154. package/lib/module/NavigationIndependentTree.js.map +1 -1
  155. package/lib/module/NavigationIndependentTreeContext.js +1 -2
  156. package/lib/module/NavigationIndependentTreeContext.js.map +1 -1
  157. package/lib/module/NavigationRouteContext.js +1 -2
  158. package/lib/module/NavigationRouteContext.js.map +1 -1
  159. package/lib/module/NavigationStateContext.js +1 -1
  160. package/lib/module/NavigationStateContext.js.map +1 -1
  161. package/lib/module/PreventRemoveContext.js +1 -2
  162. package/lib/module/PreventRemoveContext.js.map +1 -1
  163. package/lib/module/PreventRemoveProvider.js +10 -12
  164. package/lib/module/PreventRemoveProvider.js.map +1 -1
  165. package/lib/module/SceneView.js +5 -5
  166. package/lib/module/SceneView.js.map +1 -1
  167. package/lib/module/Screen.js +1 -1
  168. package/lib/module/Screen.js.map +1 -1
  169. package/lib/module/StaticContainer.js +2 -3
  170. package/lib/module/StaticContainer.js.map +1 -1
  171. package/lib/module/StaticNavigation.js +28 -6
  172. package/lib/module/StaticNavigation.js.map +1 -1
  173. package/lib/module/UnhandledActionContext.js +1 -2
  174. package/lib/module/UnhandledActionContext.js.map +1 -1
  175. package/lib/module/checkDuplicateRouteNames.js +2 -3
  176. package/lib/module/checkDuplicateRouteNames.js.map +1 -1
  177. package/lib/module/checkSerializable.js +1 -1
  178. package/lib/module/checkSerializable.js.map +1 -1
  179. package/lib/module/createNavigationContainerRef.js +1 -1
  180. package/lib/module/createNavigationContainerRef.js.map +1 -1
  181. package/lib/module/createNavigatorFactory.js +3 -6
  182. package/lib/module/createNavigatorFactory.js.map +1 -1
  183. package/lib/module/findFocusedRoute.js +3 -5
  184. package/lib/module/findFocusedRoute.js.map +1 -1
  185. package/lib/module/getActionFromState.js +7 -9
  186. package/lib/module/getActionFromState.js.map +1 -1
  187. package/lib/module/getFocusedRouteNameFromRoute.js +2 -2
  188. package/lib/module/getFocusedRouteNameFromRoute.js.map +1 -1
  189. package/lib/module/getPathFromState.js +21 -21
  190. package/lib/module/getPathFromState.js.map +1 -1
  191. package/lib/module/getStateFromPath.js +25 -18
  192. package/lib/module/getStateFromPath.js.map +1 -1
  193. package/lib/module/index.js +31 -28
  194. package/lib/module/index.js.map +1 -1
  195. package/lib/module/isArrayEqual.js +1 -1
  196. package/lib/module/isArrayEqual.js.map +1 -1
  197. package/lib/module/isRecordEqual.js +1 -1
  198. package/lib/module/isRecordEqual.js.map +1 -1
  199. package/lib/module/theming/ThemeContext.js +4 -0
  200. package/lib/module/theming/ThemeContext.js.map +1 -0
  201. package/lib/module/theming/ThemeProvider.js +12 -0
  202. package/lib/module/theming/ThemeProvider.js.map +1 -0
  203. package/lib/module/theming/useTheme.js +10 -0
  204. package/lib/module/theming/useTheme.js.map +1 -0
  205. package/lib/module/types.js +1 -8
  206. package/lib/module/types.js.map +1 -1
  207. package/lib/module/useChildListeners.js +1 -1
  208. package/lib/module/useChildListeners.js.map +1 -1
  209. package/lib/module/useComponent.js +1 -1
  210. package/lib/module/useComponent.js.map +1 -1
  211. package/lib/module/useCurrentRender.js +2 -2
  212. package/lib/module/useCurrentRender.js.map +1 -1
  213. package/lib/module/useDescriptors.js +88 -36
  214. package/lib/module/useDescriptors.js.map +1 -1
  215. package/lib/module/useEventEmitter.js +4 -5
  216. package/lib/module/useEventEmitter.js.map +1 -1
  217. package/lib/module/useFocusEffect.js +4 -2
  218. package/lib/module/useFocusEffect.js.map +1 -1
  219. package/lib/module/useFocusEvents.js +4 -4
  220. package/lib/module/useFocusEvents.js.map +1 -1
  221. package/lib/module/useFocusedListenersChildrenAdapter.js +3 -3
  222. package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
  223. package/lib/module/useIsFocused.js +2 -2
  224. package/lib/module/useIsFocused.js.map +1 -1
  225. package/lib/module/useIsomorphicLayoutEffect.js +7 -0
  226. package/lib/module/useIsomorphicLayoutEffect.js.map +1 -0
  227. package/lib/module/useIsomorphicLayoutEffect.native.js +3 -0
  228. package/lib/module/useIsomorphicLayoutEffect.native.js.map +1 -0
  229. package/lib/module/useKeyedChildListeners.js +1 -1
  230. package/lib/module/useKeyedChildListeners.js.map +1 -1
  231. package/lib/module/useNavigation.js +3 -3
  232. package/lib/module/useNavigation.js.map +1 -1
  233. package/lib/module/useNavigationBuilder.js +97 -88
  234. package/lib/module/useNavigationBuilder.js.map +1 -1
  235. package/lib/module/useNavigationCache.js +57 -16
  236. package/lib/module/useNavigationCache.js.map +1 -1
  237. package/lib/module/useNavigationContainerRef.js +2 -2
  238. package/lib/module/useNavigationContainerRef.js.map +1 -1
  239. package/lib/module/useNavigationHelpers.js +5 -6
  240. package/lib/module/useNavigationHelpers.js.map +1 -1
  241. package/lib/module/useNavigationIndependentTree.js +2 -2
  242. package/lib/module/useNavigationIndependentTree.js.map +1 -1
  243. package/lib/module/useNavigationState.js +2 -2
  244. package/lib/module/useNavigationState.js.map +1 -1
  245. package/lib/module/useOnAction.js +8 -6
  246. package/lib/module/useOnAction.js.map +1 -1
  247. package/lib/module/useOnGetState.js +6 -7
  248. package/lib/module/useOnGetState.js.map +1 -1
  249. package/lib/module/useOnPreventRemove.js +6 -7
  250. package/lib/module/useOnPreventRemove.js.map +1 -1
  251. package/lib/module/useOnRouteFocus.js +2 -2
  252. package/lib/module/useOnRouteFocus.js.map +1 -1
  253. package/lib/module/useOptionsGetters.js +10 -11
  254. package/lib/module/useOptionsGetters.js.map +1 -1
  255. package/lib/module/usePreventRemove.js +5 -5
  256. package/lib/module/usePreventRemove.js.map +1 -1
  257. package/lib/module/usePreventRemoveContext.js +2 -2
  258. package/lib/module/usePreventRemoveContext.js.map +1 -1
  259. package/lib/module/useRegisterNavigator.js +1 -1
  260. package/lib/module/useRegisterNavigator.js.map +1 -1
  261. package/lib/module/useRoute.js +2 -2
  262. package/lib/module/useRoute.js.map +1 -1
  263. package/lib/module/useRouteCache.js +17 -13
  264. package/lib/module/useRouteCache.js.map +1 -1
  265. package/lib/module/useSyncState.js +25 -54
  266. package/lib/module/useSyncState.js.map +1 -1
  267. package/lib/module/validatePathConfig.js +38 -11
  268. package/lib/module/validatePathConfig.js.map +1 -1
  269. package/lib/typescript/src/BaseNavigationContainer.d.ts +3 -3
  270. package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
  271. package/lib/typescript/src/CurrentRenderContext.d.ts +1 -2
  272. package/lib/typescript/src/CurrentRenderContext.d.ts.map +1 -1
  273. package/lib/typescript/src/DeprecatedNavigationInChildContext.d.ts +1 -2
  274. package/lib/typescript/src/DeprecatedNavigationInChildContext.d.ts.map +1 -1
  275. package/lib/typescript/src/EnsureSingleNavigator.d.ts +1 -1
  276. package/lib/typescript/src/EnsureSingleNavigator.d.ts.map +1 -1
  277. package/lib/typescript/src/Group.d.ts +1 -1
  278. package/lib/typescript/src/Group.d.ts.map +1 -1
  279. package/lib/typescript/src/NavigationBuilderContext.d.ts +1 -2
  280. package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
  281. package/lib/typescript/src/NavigationContainerRefContext.d.ts +1 -2
  282. package/lib/typescript/src/NavigationContainerRefContext.d.ts.map +1 -1
  283. package/lib/typescript/src/NavigationContext.d.ts +1 -18
  284. package/lib/typescript/src/NavigationContext.d.ts.map +1 -1
  285. package/lib/typescript/src/NavigationHelpersContext.d.ts +1 -2
  286. package/lib/typescript/src/NavigationHelpersContext.d.ts.map +1 -1
  287. package/lib/typescript/src/NavigationIndependentTree.d.ts +2 -2
  288. package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
  289. package/lib/typescript/src/NavigationIndependentTreeContext.d.ts +1 -2
  290. package/lib/typescript/src/NavigationIndependentTreeContext.d.ts.map +1 -1
  291. package/lib/typescript/src/NavigationRouteContext.d.ts +1 -2
  292. package/lib/typescript/src/NavigationRouteContext.d.ts.map +1 -1
  293. package/lib/typescript/src/NavigationStateContext.d.ts +3 -20
  294. package/lib/typescript/src/NavigationStateContext.d.ts.map +1 -1
  295. package/lib/typescript/src/PreventRemoveContext.d.ts +1 -2
  296. package/lib/typescript/src/PreventRemoveContext.d.ts.map +1 -1
  297. package/lib/typescript/src/PreventRemoveProvider.d.ts +1 -1
  298. package/lib/typescript/src/PreventRemoveProvider.d.ts.map +1 -1
  299. package/lib/typescript/src/SceneView.d.ts +2 -2
  300. package/lib/typescript/src/SceneView.d.ts.map +1 -1
  301. package/lib/typescript/src/Screen.d.ts +1 -1
  302. package/lib/typescript/src/Screen.d.ts.map +1 -1
  303. package/lib/typescript/src/StaticContainer.d.ts +1 -3
  304. package/lib/typescript/src/StaticContainer.d.ts.map +1 -1
  305. package/lib/typescript/src/StaticNavigation.d.ts +12 -5
  306. package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
  307. package/lib/typescript/src/UnhandledActionContext.d.ts +1 -2
  308. package/lib/typescript/src/UnhandledActionContext.d.ts.map +1 -1
  309. package/lib/typescript/src/checkDuplicateRouteNames.d.ts +1 -1
  310. package/lib/typescript/src/checkDuplicateRouteNames.d.ts.map +1 -1
  311. package/lib/typescript/src/checkSerializable.d.ts +1 -1
  312. package/lib/typescript/src/checkSerializable.d.ts.map +1 -1
  313. package/lib/typescript/src/createNavigationContainerRef.d.ts +1 -1
  314. package/lib/typescript/src/createNavigationContainerRef.d.ts.map +1 -1
  315. package/lib/typescript/src/createNavigatorFactory.d.ts +1 -1
  316. package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
  317. package/lib/typescript/src/findFocusedRoute.d.ts +2 -10
  318. package/lib/typescript/src/findFocusedRoute.d.ts.map +1 -1
  319. package/lib/typescript/src/getActionFromState.d.ts +1 -1
  320. package/lib/typescript/src/getActionFromState.d.ts.map +1 -1
  321. package/lib/typescript/src/getFocusedRouteNameFromRoute.d.ts +1 -1
  322. package/lib/typescript/src/getFocusedRouteNameFromRoute.d.ts.map +1 -1
  323. package/lib/typescript/src/getPathFromState.d.ts +2 -1
  324. package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
  325. package/lib/typescript/src/getStateFromPath.d.ts +2 -1
  326. package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
  327. package/lib/typescript/src/index.d.ts +31 -28
  328. package/lib/typescript/src/index.d.ts.map +1 -1
  329. package/lib/typescript/src/isArrayEqual.d.ts +1 -1
  330. package/lib/typescript/src/isArrayEqual.d.ts.map +1 -1
  331. package/lib/typescript/src/isRecordEqual.d.ts +1 -1
  332. package/lib/typescript/src/isRecordEqual.d.ts.map +1 -1
  333. package/lib/typescript/src/theming/ThemeContext.d.ts +3 -0
  334. package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -0
  335. package/lib/typescript/src/theming/ThemeProvider.d.ts +8 -0
  336. package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -0
  337. package/lib/typescript/src/theming/useTheme.d.ts +2 -0
  338. package/lib/typescript/src/theming/useTheme.d.ts.map +1 -0
  339. package/lib/typescript/src/types.d.ts +80 -1
  340. package/lib/typescript/src/types.d.ts.map +1 -1
  341. package/lib/typescript/src/useChildListeners.d.ts +1 -1
  342. package/lib/typescript/src/useChildListeners.d.ts.map +1 -1
  343. package/lib/typescript/src/useComponent.d.ts +2 -2
  344. package/lib/typescript/src/useComponent.d.ts.map +1 -1
  345. package/lib/typescript/src/useCurrentRender.d.ts +1 -1
  346. package/lib/typescript/src/useCurrentRender.d.ts.map +1 -1
  347. package/lib/typescript/src/useDescriptors.d.ts +107 -59
  348. package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
  349. package/lib/typescript/src/useEventEmitter.d.ts +1 -1
  350. package/lib/typescript/src/useEventEmitter.d.ts.map +1 -1
  351. package/lib/typescript/src/useFocusEffect.d.ts +1 -1
  352. package/lib/typescript/src/useFocusEffect.d.ts.map +1 -1
  353. package/lib/typescript/src/useFocusEvents.d.ts +1 -1
  354. package/lib/typescript/src/useFocusEvents.d.ts.map +1 -1
  355. package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +2 -2
  356. package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts.map +1 -1
  357. package/lib/typescript/src/useIsFocused.d.ts +1 -1
  358. package/lib/typescript/src/useIsFocused.d.ts.map +1 -1
  359. package/lib/typescript/src/useIsomorphicLayoutEffect.d.ts +6 -0
  360. package/lib/typescript/src/useIsomorphicLayoutEffect.d.ts.map +1 -0
  361. package/lib/typescript/src/useIsomorphicLayoutEffect.native.d.ts +3 -0
  362. package/lib/typescript/src/useIsomorphicLayoutEffect.native.d.ts.map +1 -0
  363. package/lib/typescript/src/useKeyedChildListeners.d.ts +1 -1
  364. package/lib/typescript/src/useKeyedChildListeners.d.ts.map +1 -1
  365. package/lib/typescript/src/useNavigation.d.ts +4 -1
  366. package/lib/typescript/src/useNavigation.d.ts.map +1 -1
  367. package/lib/typescript/src/useNavigationBuilder.d.ts +99 -63
  368. package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
  369. package/lib/typescript/src/useNavigationCache.d.ts +53 -3
  370. package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
  371. package/lib/typescript/src/useNavigationContainerRef.d.ts +1 -1
  372. package/lib/typescript/src/useNavigationContainerRef.d.ts.map +1 -1
  373. package/lib/typescript/src/useNavigationHelpers.d.ts +26 -40
  374. package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
  375. package/lib/typescript/src/useNavigationIndependentTree.d.ts +1 -1
  376. package/lib/typescript/src/useNavigationIndependentTree.d.ts.map +1 -1
  377. package/lib/typescript/src/useNavigationState.d.ts +1 -1
  378. package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
  379. package/lib/typescript/src/useOnAction.d.ts +2 -2
  380. package/lib/typescript/src/useOnAction.d.ts.map +1 -1
  381. package/lib/typescript/src/useOnGetState.d.ts +2 -2
  382. package/lib/typescript/src/useOnGetState.d.ts.map +1 -1
  383. package/lib/typescript/src/useOnPreventRemove.d.ts +2 -2
  384. package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
  385. package/lib/typescript/src/useOnRouteFocus.d.ts +1 -1
  386. package/lib/typescript/src/useOnRouteFocus.d.ts.map +1 -1
  387. package/lib/typescript/src/useOptionsGetters.d.ts +1 -1
  388. package/lib/typescript/src/useOptionsGetters.d.ts.map +1 -1
  389. package/lib/typescript/src/usePreventRemove.d.ts +1 -1
  390. package/lib/typescript/src/usePreventRemove.d.ts.map +1 -1
  391. package/lib/typescript/src/usePreventRemoveContext.d.ts +1 -1
  392. package/lib/typescript/src/usePreventRemoveContext.d.ts.map +1 -1
  393. package/lib/typescript/src/useRegisterNavigator.d.ts +1 -1
  394. package/lib/typescript/src/useRegisterNavigator.d.ts.map +1 -1
  395. package/lib/typescript/src/useRoute.d.ts +1 -1
  396. package/lib/typescript/src/useRoute.d.ts.map +1 -1
  397. package/lib/typescript/src/useRouteCache.d.ts +1 -1
  398. package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
  399. package/lib/typescript/src/useSyncState.d.ts +1 -4
  400. package/lib/typescript/src/useSyncState.d.ts.map +1 -1
  401. package/lib/typescript/src/validatePathConfig.d.ts +1 -1
  402. package/lib/typescript/src/validatePathConfig.d.ts.map +1 -1
  403. package/lib/typescript/utils/usePrevious.d.ts +6 -0
  404. package/lib/typescript/utils/usePrevious.d.ts.map +1 -0
  405. package/package.json +14 -14
  406. package/src/BaseNavigationContainer.tsx +52 -55
  407. package/src/CurrentRenderContext.tsx +1 -3
  408. package/src/DeprecatedNavigationInChildContext.tsx +1 -3
  409. package/src/EnsureSingleNavigator.tsx +1 -1
  410. package/src/Group.tsx +2 -2
  411. package/src/NavigationBuilderContext.tsx +1 -3
  412. package/src/NavigationContainerRefContext.tsx +1 -3
  413. package/src/NavigationContext.tsx +1 -3
  414. package/src/NavigationHelpersContext.tsx +1 -3
  415. package/src/NavigationIndependentTree.tsx +4 -4
  416. package/src/NavigationIndependentTreeContext.tsx +1 -3
  417. package/src/NavigationRouteContext.tsx +3 -5
  418. package/src/NavigationStateContext.tsx +1 -1
  419. package/src/PreventRemoveContext.tsx +1 -3
  420. package/src/PreventRemoveProvider.tsx +7 -4
  421. package/src/SceneView.tsx +6 -6
  422. package/src/Screen.tsx +2 -2
  423. package/src/StaticContainer.tsx +19 -18
  424. package/src/StaticNavigation.tsx +35 -33
  425. package/src/UnhandledActionContext.tsx +1 -3
  426. package/src/checkDuplicateRouteNames.tsx +2 -2
  427. package/src/checkSerializable.tsx +1 -1
  428. package/src/createNavigationContainerRef.tsx +2 -2
  429. package/src/createNavigatorFactory.tsx +5 -7
  430. package/src/findFocusedRoute.tsx +1 -1
  431. package/src/getActionFromState.tsx +2 -2
  432. package/src/getFocusedRouteNameFromRoute.tsx +4 -4
  433. package/src/getPathFromState.tsx +16 -13
  434. package/src/getStateFromPath.tsx +25 -6
  435. package/src/index.tsx +33 -30
  436. package/src/isArrayEqual.tsx +1 -1
  437. package/src/isRecordEqual.tsx +1 -4
  438. package/src/theming/ThemeContext.tsx +7 -0
  439. package/src/theming/ThemeProvider.tsx +14 -0
  440. package/src/theming/useTheme.tsx +15 -0
  441. package/src/types.tsx +133 -17
  442. package/src/useChildListeners.tsx +1 -1
  443. package/src/useComponent.tsx +1 -1
  444. package/src/useCurrentRender.tsx +2 -6
  445. package/src/useDescriptors.tsx +161 -66
  446. package/src/useEventEmitter.tsx +1 -1
  447. package/src/useFocusEffect.tsx +3 -2
  448. package/src/useFocusEvents.tsx +2 -2
  449. package/src/useFocusedListenersChildrenAdapter.tsx +5 -4
  450. package/src/useIsFocused.tsx +2 -2
  451. package/src/useIsomorphicLayoutEffect.native.tsx +3 -0
  452. package/src/useIsomorphicLayoutEffect.tsx +7 -0
  453. package/src/useKeyedChildListeners.tsx +1 -1
  454. package/src/useNavigation.tsx +7 -4
  455. package/src/useNavigationBuilder.tsx +141 -122
  456. package/src/useNavigationCache.tsx +93 -32
  457. package/src/useNavigationContainerRef.tsx +3 -3
  458. package/src/useNavigationHelpers.tsx +9 -10
  459. package/src/useNavigationIndependentTree.tsx +2 -2
  460. package/src/useNavigationState.tsx +2 -2
  461. package/src/useOnAction.tsx +13 -7
  462. package/src/useOnGetState.tsx +6 -8
  463. package/src/useOnPreventRemove.tsx +5 -4
  464. package/src/useOnRouteFocus.tsx +2 -2
  465. package/src/useOptionsGetters.tsx +5 -9
  466. package/src/usePreventRemove.tsx +4 -4
  467. package/src/usePreventRemoveContext.tsx +2 -2
  468. package/src/useRegisterNavigator.tsx +1 -1
  469. package/src/useRoute.tsx +2 -2
  470. package/src/useRouteCache.tsx +18 -17
  471. package/src/useSyncState.tsx +31 -59
  472. package/src/validatePathConfig.tsx +58 -14
  473. package/lib/commonjs/fromEntries.js +0 -18
  474. package/lib/commonjs/fromEntries.js.map +0 -1
  475. package/lib/commonjs/useScheduleUpdate.js +0 -37
  476. package/lib/commonjs/useScheduleUpdate.js.map +0 -1
  477. package/lib/module/fromEntries.js +0 -12
  478. package/lib/module/fromEntries.js.map +0 -1
  479. package/lib/module/useScheduleUpdate.js +0 -27
  480. package/lib/module/useScheduleUpdate.js.map +0 -1
  481. package/lib/typescript/src/fromEntries.d.ts +0 -2
  482. package/lib/typescript/src/fromEntries.d.ts.map +0 -1
  483. package/lib/typescript/src/useScheduleUpdate.d.ts +0 -14
  484. package/lib/typescript/src/useScheduleUpdate.d.ts.map +0 -1
  485. package/src/fromEntries.tsx +0 -13
  486. package/src/useScheduleUpdate.tsx +0 -32
@@ -1,38 +1,38 @@
1
1
  import {
2
2
  CommonActions,
3
- InitialState,
4
- NavigationAction,
5
- NavigationState,
6
- ParamListBase,
7
- PartialState,
8
- Route,
3
+ type InitialState,
4
+ type NavigationAction,
5
+ type NavigationState,
6
+ type ParamListBase,
7
+ type PartialState,
8
+ type Route,
9
9
  } from '@react-navigation/routers';
10
10
  import * as React from 'react';
11
11
  import useLatestCallback from 'use-latest-callback';
12
12
 
13
- import checkDuplicateRouteNames from './checkDuplicateRouteNames';
14
- import checkSerializable from './checkSerializable';
13
+ import { checkDuplicateRouteNames } from './checkDuplicateRouteNames';
14
+ import { checkSerializable } from './checkSerializable';
15
15
  import { NOT_INITIALIZED_ERROR } from './createNavigationContainerRef';
16
- import DeprecatedNavigationInChildContext from './DeprecatedNavigationInChildContext';
17
- import EnsureSingleNavigator from './EnsureSingleNavigator';
18
- import findFocusedRoute from './findFocusedRoute';
19
- import NavigationBuilderContext from './NavigationBuilderContext';
20
- import NavigationContainerRefContext from './NavigationContainerRefContext';
21
- import NavigationIndependentTreeContext from './NavigationIndependentTreeContext';
22
- import NavigationStateContext from './NavigationStateContext';
16
+ import { DeprecatedNavigationInChildContext } from './DeprecatedNavigationInChildContext';
17
+ import { EnsureSingleNavigator } from './EnsureSingleNavigator';
18
+ import { findFocusedRoute } from './findFocusedRoute';
19
+ import { NavigationBuilderContext } from './NavigationBuilderContext';
20
+ import { NavigationContainerRefContext } from './NavigationContainerRefContext';
21
+ import { NavigationIndependentTreeContext } from './NavigationIndependentTreeContext';
22
+ import { NavigationStateContext } from './NavigationStateContext';
23
+ import { ThemeProvider } from './theming/ThemeProvider';
23
24
  import type {
24
25
  NavigationContainerEventMap,
25
26
  NavigationContainerProps,
26
27
  NavigationContainerRef,
27
28
  } from './types';
28
- import UnhandledActionContext from './UnhandledActionContext';
29
- import useChildListeners from './useChildListeners';
30
- import useEventEmitter from './useEventEmitter';
31
- import useKeyedChildListeners from './useKeyedChildListeners';
32
- import useNavigationIndependentTree from './useNavigationIndependentTree';
33
- import useOptionsGetters from './useOptionsGetters';
34
- import { ScheduleUpdateContext } from './useScheduleUpdate';
35
- import useSyncState from './useSyncState';
29
+ import { UnhandledActionContext } from './UnhandledActionContext';
30
+ import { useChildListeners } from './useChildListeners';
31
+ import { useEventEmitter } from './useEventEmitter';
32
+ import { useKeyedChildListeners } from './useKeyedChildListeners';
33
+ import { useNavigationIndependentTree } from './useNavigationIndependentTree';
34
+ import { useOptionsGetters } from './useOptionsGetters';
35
+ import { useSyncState } from './useSyncState';
36
36
 
37
37
  type State = NavigationState | PartialState<NavigationState> | undefined;
38
38
 
@@ -77,10 +77,11 @@ const getPartialState = (
77
77
  * @param props.onReady Callback which is called after the navigation tree mounts.
78
78
  * @param props.onStateChange Callback which is called with the latest navigation state when it changes.
79
79
  * @param props.onUnhandledAction Callback which is called when an action is not handled.
80
+ * @param props.theme Theme object for the UI elements.
80
81
  * @param props.children Child elements to render the content.
81
82
  * @param props.ref Ref object which refers to the navigation object containing helper methods.
82
83
  */
83
- const BaseNavigationContainer = React.forwardRef(
84
+ export const BaseNavigationContainer = React.forwardRef(
84
85
  function BaseNavigationContainer(
85
86
  {
86
87
  initialState,
@@ -88,6 +89,7 @@ const BaseNavigationContainer = React.forwardRef(
88
89
  onReady,
89
90
  onUnhandledAction,
90
91
  navigationInChildEnabled = false,
92
+ theme,
91
93
  children,
92
94
  }: NavigationContainerProps,
93
95
  ref?: React.Ref<NavigationContainerRef<ParamListBase>>
@@ -101,10 +103,9 @@ const BaseNavigationContainer = React.forwardRef(
101
103
  );
102
104
  }
103
105
 
104
- const [state, getState, setState, scheduleUpdate, flushUpdates] =
105
- useSyncState<State>(() =>
106
- getPartialState(initialState == null ? undefined : initialState)
107
- );
106
+ const [state, getState, setState] = useSyncState<State>(() =>
107
+ getPartialState(initialState == null ? undefined : initialState)
108
+ );
108
109
 
109
110
  const isFirstMountRef = React.useRef<boolean>(true);
110
111
 
@@ -203,11 +204,14 @@ const BaseNavigationContainer = React.forwardRef(
203
204
  isFocused: () => true,
204
205
  canGoBack,
205
206
  getParent: () => undefined,
206
- getState: () => stateRef.current,
207
+ getState,
207
208
  getRootState,
208
209
  getCurrentRoute,
209
210
  getCurrentOptions,
210
211
  isReady,
212
+ setOptions: () => {
213
+ throw new Error('Cannot call setOptions outside a screen');
214
+ },
211
215
  }),
212
216
  [
213
217
  canGoBack,
@@ -216,6 +220,7 @@ const BaseNavigationContainer = React.forwardRef(
216
220
  getCurrentOptions,
217
221
  getCurrentRoute,
218
222
  getRootState,
223
+ getState,
219
224
  isReady,
220
225
  resetRoot,
221
226
  ]
@@ -260,11 +265,6 @@ const BaseNavigationContainer = React.forwardRef(
260
265
  [addListener, addKeyedListener, onDispatchAction, onOptionsChange]
261
266
  );
262
267
 
263
- const scheduleContext = React.useMemo(
264
- () => ({ scheduleUpdate, flushUpdates }),
265
- [scheduleUpdate, flushUpdates]
266
- );
267
-
268
268
  const isInitialRef = React.useRef(true);
269
269
 
270
270
  const getIsInitial = React.useCallback(() => isInitialRef.current, []);
@@ -292,22 +292,21 @@ const BaseNavigationContainer = React.forwardRef(
292
292
 
293
293
  const onReadyRef = React.useRef(onReady);
294
294
  const onStateChangeRef = React.useRef(onStateChange);
295
- const stateRef = React.useRef(state);
296
295
 
297
296
  React.useEffect(() => {
298
297
  isInitialRef.current = false;
299
298
  onStateChangeRef.current = onStateChange;
300
299
  onReadyRef.current = onReady;
301
- stateRef.current = state;
302
300
  });
303
301
 
304
- const isNavigationReady = isReady();
302
+ const onReadyCalledRef = React.useRef(false);
305
303
 
306
304
  React.useEffect(() => {
307
- if (isNavigationReady) {
305
+ if (!onReadyCalledRef.current && isReady()) {
306
+ onReadyCalledRef.current = true;
308
307
  onReadyRef.current?.();
309
308
  }
310
- }, [isNavigationReady]);
309
+ }, [state, isReady]);
311
310
 
312
311
  React.useEffect(() => {
313
312
  const hydratedState = getRootState();
@@ -433,25 +432,23 @@ const BaseNavigationContainer = React.forwardRef(
433
432
  return (
434
433
  <NavigationIndependentTreeContext.Provider value={false}>
435
434
  <NavigationContainerRefContext.Provider value={navigation}>
436
- <ScheduleUpdateContext.Provider value={scheduleContext}>
437
- <NavigationBuilderContext.Provider value={builderContext}>
438
- <NavigationStateContext.Provider value={context}>
439
- <UnhandledActionContext.Provider
440
- value={onUnhandledAction ?? defaultOnUnhandledAction}
435
+ <NavigationBuilderContext.Provider value={builderContext}>
436
+ <NavigationStateContext.Provider value={context}>
437
+ <UnhandledActionContext.Provider
438
+ value={onUnhandledAction ?? defaultOnUnhandledAction}
439
+ >
440
+ <DeprecatedNavigationInChildContext.Provider
441
+ value={navigationInChildEnabled}
441
442
  >
442
- <DeprecatedNavigationInChildContext.Provider
443
- value={navigationInChildEnabled}
444
- >
445
- <EnsureSingleNavigator>{children}</EnsureSingleNavigator>
446
- </DeprecatedNavigationInChildContext.Provider>
447
- </UnhandledActionContext.Provider>
448
- </NavigationStateContext.Provider>
449
- </NavigationBuilderContext.Provider>
450
- </ScheduleUpdateContext.Provider>
443
+ <EnsureSingleNavigator>
444
+ <ThemeProvider value={theme}>{children}</ThemeProvider>
445
+ </EnsureSingleNavigator>
446
+ </DeprecatedNavigationInChildContext.Provider>
447
+ </UnhandledActionContext.Provider>
448
+ </NavigationStateContext.Provider>
449
+ </NavigationBuilderContext.Provider>
451
450
  </NavigationContainerRefContext.Provider>
452
451
  </NavigationIndependentTreeContext.Provider>
453
452
  );
454
453
  }
455
454
  );
456
-
457
- export default BaseNavigationContainer;
@@ -4,8 +4,6 @@ import * as React from 'react';
4
4
  * Context which holds the values for the current navigation tree.
5
5
  * Intended for use in SSR. This is not safe to use on the client.
6
6
  */
7
- const CurrentRenderContext = React.createContext<
7
+ export const CurrentRenderContext = React.createContext<
8
8
  { options?: object } | undefined
9
9
  >(undefined);
10
-
11
- export default CurrentRenderContext;
@@ -3,6 +3,4 @@ import * as React from 'react';
3
3
  /**
4
4
  * Context which enables deprecated bubbling to child navigators.
5
5
  */
6
- const DeprecatedNavigationInChildContext = React.createContext(false);
7
-
8
- export default DeprecatedNavigationInChildContext;
6
+ export const DeprecatedNavigationInChildContext = React.createContext(false);
@@ -17,7 +17,7 @@ export const SingleNavigatorContext = React.createContext<
17
17
  /**
18
18
  * Component which ensures that there's only one navigator nested under it.
19
19
  */
20
- export default function EnsureSingleNavigator({ children }: Props) {
20
+ export function EnsureSingleNavigator({ children }: Props) {
21
21
  const navigatorKeyRef = React.useRef<string | undefined>();
22
22
 
23
23
  const value = React.useMemo(
package/src/Group.tsx CHANGED
@@ -5,9 +5,9 @@ import type { RouteGroupConfig } from './types';
5
5
  /**
6
6
  * Empty component used for grouping screen configs.
7
7
  */
8
- export default function Group<
8
+ export function Group<
9
9
  ParamList extends ParamListBase,
10
- ScreenOptions extends {}
10
+ ScreenOptions extends {},
11
11
  >(_: RouteGroupConfig<ParamList, ScreenOptions>) {
12
12
  /* istanbul ignore next */
13
13
  return null;
@@ -51,7 +51,7 @@ export type ChildBeforeRemoveListener = (action: NavigationAction) => boolean;
51
51
  /**
52
52
  * Context which holds the required helpers needed to build nested navigators.
53
53
  */
54
- const NavigationBuilderContext = React.createContext<{
54
+ export const NavigationBuilderContext = React.createContext<{
55
55
  onAction?: (
56
56
  action: NavigationAction,
57
57
  visitedNavigators?: Set<string>
@@ -66,5 +66,3 @@ const NavigationBuilderContext = React.createContext<{
66
66
  onDispatchAction: () => undefined,
67
67
  onOptionsChange: () => undefined,
68
68
  });
69
-
70
- export default NavigationBuilderContext;
@@ -6,8 +6,6 @@ import type { NavigationContainerRef } from './types';
6
6
  /**
7
7
  * Context which holds the route prop for a screen.
8
8
  */
9
- const NavigationContainerRefContext = React.createContext<
9
+ export const NavigationContainerRefContext = React.createContext<
10
10
  NavigationContainerRef<ParamListBase> | undefined
11
11
  >(undefined);
12
-
13
- export default NavigationContainerRefContext;
@@ -6,8 +6,6 @@ import type { NavigationProp } from './types';
6
6
  /**
7
7
  * Context which holds the navigation prop for a screen.
8
8
  */
9
- const NavigationContext = React.createContext<
9
+ export const NavigationContext = React.createContext<
10
10
  NavigationProp<ParamListBase> | undefined
11
11
  >(undefined);
12
-
13
- export default NavigationContext;
@@ -7,8 +7,6 @@ import type { NavigationHelpers } from './types';
7
7
  * Context which holds the navigation helpers of the parent navigator.
8
8
  * Navigators should use this context in their view component.
9
9
  */
10
- const NavigationHelpersContext = React.createContext<
10
+ export const NavigationHelpersContext = React.createContext<
11
11
  NavigationHelpers<ParamListBase> | undefined
12
12
  >(undefined);
13
-
14
- export default NavigationHelpersContext;
@@ -1,13 +1,13 @@
1
1
  import * as React from 'react';
2
2
 
3
- import NavigationContext from './NavigationContext';
4
- import NavigationIndependentTreeContext from './NavigationIndependentTreeContext';
5
- import NavigationRouteContext from './NavigationRouteContext';
3
+ import { NavigationContext } from './NavigationContext';
4
+ import { NavigationIndependentTreeContext } from './NavigationIndependentTreeContext';
5
+ import { NavigationRouteContext } from './NavigationRouteContext';
6
6
 
7
7
  /**
8
8
  * Component to make the child navigation container independent of parent containers.
9
9
  */
10
- export default function NavigationIndependentTree({
10
+ export function NavigationIndependentTree({
11
11
  children,
12
12
  }: {
13
13
  children: React.ReactNode;
@@ -3,6 +3,4 @@ import * as React from 'react';
3
3
  /**
4
4
  * Context which marks the navigation tree as independent.
5
5
  */
6
- const NavigationIndependentTreeContext = React.createContext(false);
7
-
8
- export default NavigationIndependentTreeContext;
6
+ export const NavigationIndependentTreeContext = React.createContext(false);
@@ -4,8 +4,6 @@ import * as React from 'react';
4
4
  /**
5
5
  * Context which holds the route prop for a screen.
6
6
  */
7
- const NavigationRouteContext = React.createContext<Route<string> | undefined>(
8
- undefined
9
- );
10
-
11
- export default NavigationRouteContext;
7
+ export const NavigationRouteContext = React.createContext<
8
+ Route<string> | undefined
9
+ >(undefined);
@@ -4,7 +4,7 @@ import * as React from 'react';
4
4
  const MISSING_CONTEXT_ERROR =
5
5
  "Couldn't find a navigation context. Have you wrapped your app with 'NavigationContainer'? See https://reactnavigation.org/docs/getting-started for setup instructions.";
6
6
 
7
- export default React.createContext<{
7
+ export const NavigationStateContext = React.createContext<{
8
8
  isDefault?: true;
9
9
  state?: NavigationState | PartialState<NavigationState>;
10
10
  getKey: () => string | undefined;
@@ -6,7 +6,7 @@ import * as React from 'react';
6
6
  */
7
7
  export type PreventedRoutes = Record<string, { preventRemove: boolean }>;
8
8
 
9
- const PreventRemoveContext = React.createContext<
9
+ export const PreventRemoveContext = React.createContext<
10
10
  | {
11
11
  preventedRoutes: PreventedRoutes;
12
12
  setPreventRemove: (
@@ -17,5 +17,3 @@ const PreventRemoveContext = React.createContext<
17
17
  }
18
18
  | undefined
19
19
  >(undefined);
20
-
21
- export default PreventRemoveContext;
@@ -2,9 +2,12 @@ import { nanoid } from 'nanoid/non-secure';
2
2
  import * as React from 'react';
3
3
  import useLatestCallback from 'use-latest-callback';
4
4
 
5
- import NavigationHelpersContext from './NavigationHelpersContext';
6
- import NavigationRouteContext from './NavigationRouteContext';
7
- import PreventRemoveContext, { PreventedRoutes } from './PreventRemoveContext';
5
+ import { NavigationHelpersContext } from './NavigationHelpersContext';
6
+ import { NavigationRouteContext } from './NavigationRouteContext';
7
+ import {
8
+ type PreventedRoutes,
9
+ PreventRemoveContext,
10
+ } from './PreventRemoveContext';
8
11
 
9
12
  type Props = {
10
13
  children: React.ReactNode;
@@ -42,7 +45,7 @@ const transformPreventedRoutes = (
42
45
  /**
43
46
  * Component used for managing which routes have to be prevented from removal in native-stack.
44
47
  */
45
- export default function PreventRemoveProvider({ children }: Props) {
48
+ export function PreventRemoveProvider({ children }: Props) {
46
49
  const [parentId] = React.useState(() => nanoid());
47
50
  const [preventedRoutesMap, setPreventedRoutesMap] =
48
51
  React.useState<PreventedRoutesMap>(new Map());
package/src/SceneView.tsx CHANGED
@@ -6,11 +6,11 @@ import type {
6
6
  } from '@react-navigation/routers';
7
7
  import * as React from 'react';
8
8
 
9
- import EnsureSingleNavigator from './EnsureSingleNavigator';
10
- import NavigationStateContext from './NavigationStateContext';
11
- import StaticContainer from './StaticContainer';
9
+ import { EnsureSingleNavigator } from './EnsureSingleNavigator';
10
+ import { NavigationStateContext } from './NavigationStateContext';
11
+ import { StaticContainer } from './StaticContainer';
12
12
  import type { NavigationProp, RouteConfigComponent } from './types';
13
- import useOptionsGetters from './useOptionsGetters';
13
+ import { useOptionsGetters } from './useOptionsGetters';
14
14
 
15
15
  type Props<State extends NavigationState, ScreenOptions extends {}> = {
16
16
  screen: RouteConfigComponent<ParamListBase, string> & { name: string };
@@ -33,9 +33,9 @@ type Props<State extends NavigationState, ScreenOptions extends {}> = {
33
33
  * Component which takes care of rendering the screen for a route.
34
34
  * It provides all required contexts and applies optimizations when applicable.
35
35
  */
36
- export default function SceneView<
36
+ export function SceneView<
37
37
  State extends NavigationState,
38
- ScreenOptions extends {}
38
+ ScreenOptions extends {},
39
39
  >({
40
40
  screen,
41
41
  route,
package/src/Screen.tsx CHANGED
@@ -5,12 +5,12 @@ import type { EventMapBase, RouteConfig } from './types';
5
5
  /**
6
6
  * Empty component used for specifying route configuration.
7
7
  */
8
- export default function Screen<
8
+ export function Screen<
9
9
  ParamList extends ParamListBase,
10
10
  RouteName extends keyof ParamList,
11
11
  State extends NavigationState,
12
12
  ScreenOptions extends {},
13
- EventMap extends EventMapBase
13
+ EventMap extends EventMapBase,
14
14
  >(_: RouteConfig<ParamList, RouteName, State, ScreenOptions, EventMap>) {
15
15
  /* istanbul ignore next */
16
16
  return null;
@@ -3,27 +3,28 @@ import * as React from 'react';
3
3
  /**
4
4
  * Component which prevents updates for children if no props changed
5
5
  */
6
- function StaticContainer(props: any) {
7
- return props.children;
8
- }
6
+ export const StaticContainer = React.memo(
7
+ function StaticContainer(props: any) {
8
+ return props.children;
9
+ },
10
+ (prevProps: any, nextProps: any) => {
11
+ const prevPropKeys = Object.keys(prevProps);
12
+ const nextPropKeys = Object.keys(nextProps);
9
13
 
10
- export default React.memo(StaticContainer, (prevProps: any, nextProps: any) => {
11
- const prevPropKeys = Object.keys(prevProps);
12
- const nextPropKeys = Object.keys(nextProps);
14
+ if (prevPropKeys.length !== nextPropKeys.length) {
15
+ return false;
16
+ }
13
17
 
14
- if (prevPropKeys.length !== nextPropKeys.length) {
15
- return false;
16
- }
18
+ for (const key of prevPropKeys) {
19
+ if (key === 'children') {
20
+ continue;
21
+ }
17
22
 
18
- for (const key of prevPropKeys) {
19
- if (key === 'children') {
20
- continue;
23
+ if (prevProps[key] !== nextProps[key]) {
24
+ return false;
25
+ }
21
26
  }
22
27
 
23
- if (prevProps[key] !== nextProps[key]) {
24
- return false;
25
- }
28
+ return true;
26
29
  }
27
-
28
- return true;
29
- });
30
+ );
@@ -1,7 +1,7 @@
1
1
  import type { NavigationState, ParamListBase } from '@react-navigation/routers';
2
2
  import * as React from 'react';
3
+ import { isValidElementType } from 'react-is';
3
4
 
4
- import fromEntries from './fromEntries';
5
5
  import type {
6
6
  DefaultNavigatorOptions,
7
7
  EventMapBase,
@@ -10,7 +10,7 @@ import type {
10
10
  RouteConfig,
11
11
  RouteGroupConfig,
12
12
  } from './types';
13
- import useRoute from './useRoute';
13
+ import { useRoute } from './useRoute';
14
14
 
15
15
  /**
16
16
  * Flatten a type to remove all type alias names, unions etc.
@@ -22,7 +22,17 @@ type FlatType<T> = { [K in keyof T]: T[K] } & {};
22
22
  * keyof T doesn't work for union types. We can use distributive conditional types instead.
23
23
  * https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
24
24
  */
25
- type KeysOf<T> = T extends any ? keyof T : never;
25
+ type KeysOf<T> = T extends {} ? keyof T : never;
26
+
27
+ /**
28
+ * We get a union type when using keyof, but we want an intersection instead.
29
+ * https://stackoverflow.com/a/50375286/1665026
30
+ */
31
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
32
+ k: infer I
33
+ ) => void
34
+ ? I
35
+ : never;
26
36
 
27
37
  type UnknownToUndefined<T> = unknown extends T ? undefined : T;
28
38
 
@@ -31,23 +41,16 @@ type ParamsForScreenComponent<T> = T extends {
31
41
  }
32
42
  ? P
33
43
  : T extends React.ComponentType<{ route: { params: infer P } }>
34
- ? P
35
- : undefined;
44
+ ? P
45
+ : undefined;
36
46
 
37
47
  type ParamsForScreen<T> = T extends { screen: StaticNavigation<any, any, any> }
38
48
  ? NavigatorScreenParams<StaticParamList<T['screen']>> | undefined
39
49
  : T extends StaticNavigation<any, any, any>
40
- ? NavigatorScreenParams<StaticParamList<T>> | undefined
41
- : UnknownToUndefined<ParamsForScreenComponent<T>>;
50
+ ? NavigatorScreenParams<StaticParamList<T>> | undefined
51
+ : UnknownToUndefined<ParamsForScreenComponent<T>>;
42
52
 
43
- type ParamListForScreens<
44
- Screens extends StaticConfigScreens<
45
- ParamListBase,
46
- NavigationState,
47
- {},
48
- EventMapBase
49
- >
50
- > = {
53
+ type ParamListForScreens<Screens> = {
51
54
  [Key in KeysOf<Screens>]: ParamsForScreen<Screens[Key]>;
52
55
  };
53
56
 
@@ -63,7 +66,7 @@ type ParamListForGroups<
63
66
  >;
64
67
  };
65
68
  }>
66
- | undefined
69
+ | undefined,
67
70
  > = Groups extends {
68
71
  [key: string]: {
69
72
  screens: StaticConfigScreens<
@@ -74,14 +77,14 @@ type ParamListForGroups<
74
77
  >;
75
78
  };
76
79
  }
77
- ? ParamListForScreens<Groups[keyof Groups]['screens']>
80
+ ? ParamListForScreens<UnionToIntersection<Groups[keyof Groups]['screens']>>
78
81
  : {};
79
82
 
80
83
  type StaticConfigScreens<
81
84
  ParamList extends ParamListBase,
82
85
  State extends NavigationState,
83
86
  ScreenOptions extends {},
84
- EventMap extends EventMapBase
87
+ EventMap extends EventMapBase,
85
88
  > = {
86
89
  [key in keyof ParamList]:
87
90
  | React.ComponentType<any>
@@ -115,14 +118,7 @@ type StaticConfigScreens<
115
118
  * },
116
119
  * ```
117
120
  */
118
- linking?:
119
- | FlatType<
120
- Pick<
121
- PathConfig<ParamList>,
122
- 'path' | 'exact' | 'parse' | 'stringify'
123
- >
124
- >
125
- | string;
121
+ linking?: PathConfig<ParamList> | string;
126
122
  /**
127
123
  * Static navigation config or Component to render for the screen.
128
124
  */
@@ -134,7 +130,7 @@ type GroupConfig<
134
130
  ParamList extends ParamListBase,
135
131
  State extends NavigationState,
136
132
  ScreenOptions extends {},
137
- EventMap extends EventMapBase
133
+ EventMap extends EventMapBase,
138
134
  > = Omit<RouteGroupConfig<ParamList, ScreenOptions>, 'screens' | 'children'> & {
139
135
  /**
140
136
  * Callback to determine whether the screens in the group should be rendered or not.
@@ -152,7 +148,7 @@ export type StaticConfig<
152
148
  State extends NavigationState,
153
149
  ScreenOptions extends {},
154
150
  EventMap extends EventMapBase,
155
- Navigator extends React.ComponentType<{}>
151
+ Navigator extends React.ComponentType<{}>,
156
152
  > = Omit<
157
153
  Omit<
158
154
  React.ComponentProps<Navigator>,
@@ -201,7 +197,7 @@ export type StaticParamList<
201
197
  };
202
198
  };
203
199
  };
204
- }
200
+ },
205
201
  > = FlatType<
206
202
  ParamListForScreens<T['config']['screens']> &
207
203
  ParamListForGroups<T['config']['groups']>
@@ -246,7 +242,7 @@ const getItemsFromScreens = (
246
242
  useIf = _if;
247
243
  props = rest;
248
244
 
249
- if (typeof screen === 'function') {
245
+ if (isValidElementType(screen)) {
250
246
  component = screen;
251
247
  } else if ('config' in screen) {
252
248
  isNavigator = true;
@@ -255,7 +251,7 @@ const getItemsFromScreens = (
255
251
  `${name}Navigator`
256
252
  );
257
253
  }
258
- } else if (typeof item === 'function') {
254
+ } else if (isValidElementType(item)) {
259
255
  component = item;
260
256
  } else if ('config' in item) {
261
257
  isNavigator = true;
@@ -268,7 +264,7 @@ const getItemsFromScreens = (
268
264
  );
269
265
  }
270
266
 
271
- let element = isNavigator ? (
267
+ const element = isNavigator ? (
272
268
  React.createElement(component, {})
273
269
  ) : (
274
270
  <MemoizedScreen component={component} />
@@ -304,6 +300,12 @@ export function createComponentForStaticNavigation(
304
300
  const { Navigator, Group, Screen, config } = tree;
305
301
  const { screens, groups, ...rest } = config;
306
302
 
303
+ if (screens == null) {
304
+ throw new Error(
305
+ "Couldn't find a 'screens' property. Make sure to define your screens under a 'screens' property in the configuration."
306
+ );
307
+ }
308
+
307
309
  const items = getItemsFromScreens(Screen, screens);
308
310
 
309
311
  if (groups) {
@@ -369,7 +371,7 @@ export function createPathConfigForStaticNavigation(tree: {
369
371
  >;
370
372
  };
371
373
  }) {
372
- return fromEntries(
374
+ return Object.fromEntries(
373
375
  Object.entries(tree.config.screens)
374
376
  .map(([key, item]) => {
375
377
  const screenConfig: PathConfig<ParamListBase> = {};
@@ -1,8 +1,6 @@
1
1
  import type { NavigationAction } from '@react-navigation/routers';
2
2
  import * as React from 'react';
3
3
 
4
- const UnhandledActionContext = React.createContext<
4
+ export const UnhandledActionContext = React.createContext<
5
5
  ((action: NavigationAction) => void) | undefined
6
6
  >(undefined);
7
-
8
- export default UnhandledActionContext;