@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,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
 
3
- import NavigationIndependentTreeContext from './NavigationIndependentTreeContext';
3
+ import { NavigationIndependentTreeContext } from './NavigationIndependentTreeContext';
4
4
 
5
- export default function useNavigationIndependentTree() {
5
+ export function useNavigationIndependentTree() {
6
6
  return React.useContext(NavigationIndependentTreeContext);
7
7
  }
@@ -2,7 +2,7 @@ import type { NavigationState, ParamListBase } from '@react-navigation/routers';
2
2
  import * as React from 'react';
3
3
 
4
4
  import type { NavigationProp } from './types';
5
- import useNavigation from './useNavigation';
5
+ import { useNavigation } from './useNavigation';
6
6
 
7
7
  type Selector<ParamList extends ParamListBase, T> = (
8
8
  state: NavigationState<ParamList>
@@ -13,7 +13,7 @@ type Selector<ParamList extends ParamListBase, T> = (
13
13
  *
14
14
  * @param selector Selector function to get a value from the state.
15
15
  */
16
- export default function useNavigationState<ParamList extends ParamListBase, T>(
16
+ export function useNavigationState<ParamList extends ParamListBase, T>(
17
17
  selector: Selector<ParamList, T>
18
18
  ): T {
19
19
  const navigation = useNavigation<NavigationProp<ParamList>>();
@@ -7,14 +7,15 @@ import type {
7
7
  } from '@react-navigation/routers';
8
8
  import * as React from 'react';
9
9
 
10
- import DeprecatedNavigationInChildContext from './DeprecatedNavigationInChildContext';
11
- import NavigationBuilderContext, {
12
- ChildActionListener,
13
- ChildBeforeRemoveListener,
10
+ import { DeprecatedNavigationInChildContext } from './DeprecatedNavigationInChildContext';
11
+ import {
12
+ type ChildActionListener,
13
+ type ChildBeforeRemoveListener,
14
+ NavigationBuilderContext,
14
15
  } from './NavigationBuilderContext';
15
16
  import type { EventMapCore } from './types';
16
17
  import type { NavigationEventEmitter } from './useEventEmitter';
17
- import useOnPreventRemove, { shouldPreventRemove } from './useOnPreventRemove';
18
+ import { shouldPreventRemove, useOnPreventRemove } from './useOnPreventRemove';
18
19
 
19
20
  type Options = {
20
21
  router: Router<NavigationState, NavigationAction>;
@@ -36,7 +37,7 @@ type Options = {
36
37
  *
37
38
  * When the action handler handles as action, it returns `true`, otherwise `false`.
38
39
  */
39
- export default function useOnAction({
40
+ export function useOnAction({
40
41
  router,
41
42
  getState,
42
43
  setState,
@@ -130,7 +131,12 @@ export default function useOnAction({
130
131
  }
131
132
  }
132
133
 
133
- if (typeof action.target === 'string' || navigationInChildEnabled) {
134
+ if (
135
+ typeof action.target === 'string' ||
136
+ // For backward compatibility
137
+ action.type === 'NAVIGATE_DEPRECATED' ||
138
+ navigationInChildEnabled
139
+ ) {
134
140
  // If the action wasn't handled by current navigator or a parent navigator, let children handle it
135
141
  // Handling this when target isn't specified is deprecated and will be removed in the future
136
142
  for (let i = actionListeners.length - 1; i >= 0; i--) {
@@ -1,21 +1,19 @@
1
1
  import type { NavigationState } from '@react-navigation/routers';
2
2
  import * as React from 'react';
3
3
 
4
- import isArrayEqual from './isArrayEqual';
5
- import NavigationBuilderContext, {
6
- GetStateListener,
4
+ import { isArrayEqual } from './isArrayEqual';
5
+ import {
6
+ type GetStateListener,
7
+ NavigationBuilderContext,
7
8
  } from './NavigationBuilderContext';
8
- import NavigationRouteContext from './NavigationRouteContext';
9
+ import { NavigationRouteContext } from './NavigationRouteContext';
9
10
 
10
11
  type Options = {
11
12
  getState: () => NavigationState;
12
13
  getStateListeners: Record<string, GetStateListener | undefined>;
13
14
  };
14
15
 
15
- export default function useOnGetState({
16
- getState,
17
- getStateListeners,
18
- }: Options) {
16
+ export function useOnGetState({ getState, getStateListeners }: Options) {
19
17
  const { addKeyedListener } = React.useContext(NavigationBuilderContext);
20
18
  const route = React.useContext(NavigationRouteContext);
21
19
  const key = route ? route.key : 'root';
@@ -4,10 +4,11 @@ import type {
4
4
  } from '@react-navigation/routers';
5
5
  import * as React from 'react';
6
6
 
7
- import NavigationBuilderContext, {
8
- ChildBeforeRemoveListener,
7
+ import {
8
+ type ChildBeforeRemoveListener,
9
+ NavigationBuilderContext,
9
10
  } from './NavigationBuilderContext';
10
- import NavigationRouteContext from './NavigationRouteContext';
11
+ import { NavigationRouteContext } from './NavigationRouteContext';
11
12
  import type { EventMapCore } from './types';
12
13
  import type { NavigationEventEmitter } from './useEventEmitter';
13
14
 
@@ -72,7 +73,7 @@ export const shouldPreventRemove = (
72
73
  return false;
73
74
  };
74
75
 
75
- export default function useOnPreventRemove({
76
+ export function useOnPreventRemove({
76
77
  getState,
77
78
  emitter,
78
79
  beforeRemoveListeners,
@@ -5,7 +5,7 @@ import type {
5
5
  } from '@react-navigation/routers';
6
6
  import * as React from 'react';
7
7
 
8
- import NavigationBuilderContext from './NavigationBuilderContext';
8
+ import { NavigationBuilderContext } from './NavigationBuilderContext';
9
9
 
10
10
  type Options<Action extends NavigationAction> = {
11
11
  router: Router<NavigationState, Action>;
@@ -19,7 +19,7 @@ type Options<Action extends NavigationAction> = {
19
19
  * Focus action needs to be treated specially, coz when a nested route is focused,
20
20
  * the parent navigators also needs to be focused.
21
21
  */
22
- export default function useOnRouteFocus<Action extends NavigationAction>({
22
+ export function useOnRouteFocus<Action extends NavigationAction>({
23
23
  router,
24
24
  getState,
25
25
  key: sourceRouteKey,
@@ -1,8 +1,8 @@
1
1
  import type { ParamListBase } from '@react-navigation/routers';
2
2
  import * as React from 'react';
3
3
 
4
- import NavigationBuilderContext from './NavigationBuilderContext';
5
- import NavigationStateContext from './NavigationStateContext';
4
+ import { NavigationBuilderContext } from './NavigationBuilderContext';
5
+ import { NavigationStateContext } from './NavigationStateContext';
6
6
  import type { NavigationProp } from './types';
7
7
 
8
8
  type Options = {
@@ -11,11 +11,7 @@ type Options = {
11
11
  options?: object | undefined;
12
12
  };
13
13
 
14
- export default function useOptionsGetters({
15
- key,
16
- options,
17
- navigation,
18
- }: Options) {
14
+ export function useOptionsGetters({ key, options, navigation }: Options) {
19
15
  const optionsRef = React.useRef<object | undefined>(options);
20
16
  const optionsGettersFromChildRef = React.useRef<
21
17
  Record<string, () => object | undefined | null>
@@ -43,8 +39,8 @@ export default function useOptionsGetters({
43
39
  }, [navigation, options, optionsChangeListener]);
44
40
 
45
41
  const getOptionsFromListener = React.useCallback(() => {
46
- for (let key in optionsGettersFromChildRef.current) {
47
- if (optionsGettersFromChildRef.current.hasOwnProperty(key)) {
42
+ for (const key in optionsGettersFromChildRef.current) {
43
+ if (key in optionsGettersFromChildRef.current) {
48
44
  const result = optionsGettersFromChildRef.current[key]?.();
49
45
 
50
46
  // null means unfocused route
@@ -4,9 +4,9 @@ import * as React from 'react';
4
4
  import useLatestCallback from 'use-latest-callback';
5
5
 
6
6
  import type { EventListenerCallback, EventMapCore } from './types';
7
- import useNavigation from './useNavigation';
8
- import usePreventRemoveContext from './usePreventRemoveContext';
9
- import useRoute from './useRoute';
7
+ import { useNavigation } from './useNavigation';
8
+ import { usePreventRemoveContext } from './usePreventRemoveContext';
9
+ import { useRoute } from './useRoute';
10
10
 
11
11
  /**
12
12
  * Hook to prevent screen from being removed. Can be used to prevent users from leaving the screen.
@@ -14,7 +14,7 @@ import useRoute from './useRoute';
14
14
  * @param preventRemove Boolean indicating whether to prevent screen from being removed.
15
15
  * @param callback Function which is executed when screen was prevented from being removed.
16
16
  */
17
- export default function usePreventRemove(
17
+ export function usePreventRemove(
18
18
  preventRemove: boolean,
19
19
  callback: (options: { data: { action: NavigationAction } }) => void
20
20
  ) {
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
2
 
3
- import PreventRemoveContext from './PreventRemoveContext';
3
+ import { PreventRemoveContext } from './PreventRemoveContext';
4
4
 
5
- export default function usePreventRemoveContext() {
5
+ export function usePreventRemoveContext() {
6
6
  const value = React.useContext(PreventRemoveContext);
7
7
 
8
8
  if (value == null) {
@@ -7,7 +7,7 @@ import { SingleNavigatorContext } from './EnsureSingleNavigator';
7
7
  * Register a navigator in the parent context (either a navigation container or a screen).
8
8
  * This is used to prevent multiple navigators under a single container or screen.
9
9
  */
10
- export default function useRegisterNavigator() {
10
+ export function useRegisterNavigator() {
11
11
  const [key] = React.useState(() => nanoid());
12
12
  const container = React.useContext(SingleNavigatorContext);
13
13
 
package/src/useRoute.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { ParamListBase } from '@react-navigation/routers';
2
2
  import * as React from 'react';
3
3
 
4
- import NavigationRouteContext from './NavigationRouteContext';
4
+ import { NavigationRouteContext } from './NavigationRouteContext';
5
5
  import type { RouteProp } from './types';
6
6
 
7
7
  /**
@@ -9,7 +9,7 @@ import type { RouteProp } from './types';
9
9
  *
10
10
  * @returns Route prop of the parent screen.
11
11
  */
12
- export default function useRoute<T extends RouteProp<ParamListBase>>(): T {
12
+ export function useRoute<T extends RouteProp<ParamListBase>>(): T {
13
13
  const route = React.useContext(NavigationRouteContext);
14
14
 
15
15
  if (route === undefined) {
@@ -1,13 +1,10 @@
1
- import type {
2
- NavigationState,
3
- ParamListBase,
4
- Route,
5
- } from '@react-navigation/routers';
1
+ import type { NavigationState, ParamListBase } from '@react-navigation/routers';
6
2
  import * as React from 'react';
7
3
 
4
+ import { isRecordEqual } from './isRecordEqual';
8
5
  import type { RouteProp } from './types';
9
6
 
10
- type RouteCache = Map<Route<string>, RouteProp<ParamListBase>>;
7
+ type RouteCache = Map<string, RouteProp<ParamListBase>>;
11
8
 
12
9
  /**
13
10
  * Utilites such as `getFocusedRouteNameFromRoute` need to access state.
@@ -20,7 +17,7 @@ export const CHILD_STATE = Symbol('CHILD_STATE');
20
17
  * Hook to cache route props for each screen in the navigator.
21
18
  * This lets add warnings and modifications to the route object but keep references between renders.
22
19
  */
23
- export default function useRouteCache<State extends NavigationState>(
20
+ export function useRouteCache<State extends NavigationState>(
24
21
  routes: State['routes']
25
22
  ) {
26
23
  // Cache object which holds route objects for each screen
@@ -32,21 +29,25 @@ export default function useRouteCache<State extends NavigationState>(
32
29
  }
33
30
 
34
31
  cache.current = routes.reduce((acc, route) => {
35
- const previous = cache.current.get(route);
32
+ const previous = cache.current.get(route.key);
33
+ const { state, ...routeWithoutState } = route;
36
34
 
37
- if (previous) {
35
+ let proxy;
36
+
37
+ if (previous && isRecordEqual(previous, routeWithoutState)) {
38
38
  // If a cached route object already exists, reuse it
39
- acc.set(route, previous);
39
+ proxy = previous;
40
40
  } else {
41
- const { state, ...proxy } = route;
41
+ proxy = routeWithoutState;
42
+ }
42
43
 
43
- Object.defineProperty(proxy, CHILD_STATE, {
44
- enumerable: false,
45
- value: state,
46
- });
44
+ Object.defineProperty(proxy, CHILD_STATE, {
45
+ enumerable: false,
46
+ configurable: true,
47
+ value: state,
48
+ });
47
49
 
48
- acc.set(route, proxy);
49
- }
50
+ acc.set(route.key, proxy);
50
51
 
51
52
  return acc;
52
53
  }, new Map() as RouteCache);
@@ -1,74 +1,46 @@
1
1
  import * as React from 'react';
2
2
 
3
- const UNINTIALIZED_STATE = {};
3
+ const createStore = <T,>(getInitialState: () => T) => {
4
+ const listeners: (() => void)[] = [];
4
5
 
5
- /**
6
- * This is definitely not compatible with concurrent mode, but we don't have a solution for sync state yet.
7
- */
8
- export default function useSyncState<T>(initialState?: (() => T) | T) {
9
- const stateRef = React.useRef<T>(UNINTIALIZED_STATE as any);
10
- const isSchedulingRef = React.useRef(false);
11
- const isMountedRef = React.useRef(true);
6
+ let state: T = getInitialState();
12
7
 
13
- React.useEffect(() => {
14
- isMountedRef.current = true;
8
+ const getState = () => state;
15
9
 
16
- return () => {
17
- isMountedRef.current = false;
18
- };
19
- }, []);
20
-
21
- if (stateRef.current === UNINTIALIZED_STATE) {
22
- stateRef.current =
23
- // @ts-expect-error: initialState is a function, but TypeScript doesn't think so
24
- typeof initialState === 'function' ? initialState() : initialState;
25
- }
26
-
27
- const [trackingState, setTrackingState] = React.useState(stateRef.current);
28
-
29
- const getState = React.useCallback(() => stateRef.current, []);
10
+ const setState = (newState: T) => {
11
+ state = newState;
12
+ listeners.forEach((listener) => listener());
13
+ };
30
14
 
31
- const setState = React.useCallback((state: T) => {
32
- if (state === stateRef.current || !isMountedRef.current) {
33
- return;
34
- }
15
+ const subscribe = (callback: () => void) => {
16
+ listeners.push(callback);
35
17
 
36
- stateRef.current = state;
37
-
38
- if (!isSchedulingRef.current) {
39
- setTrackingState(state);
40
- }
41
- }, []);
42
-
43
- const scheduleUpdate = React.useCallback((callback: () => void) => {
44
- isSchedulingRef.current = true;
45
-
46
- try {
47
- callback();
48
- } finally {
49
- isSchedulingRef.current = false;
50
- }
51
- }, []);
18
+ return () => {
19
+ const index = listeners.indexOf(callback);
52
20
 
53
- const flushUpdates = React.useCallback(() => {
54
- if (!isMountedRef.current) {
55
- return;
56
- }
21
+ if (index > -1) {
22
+ listeners.splice(index, 1);
23
+ }
24
+ };
25
+ };
57
26
 
58
- // Make sure that the tracking state is up-to-date.
59
- // We call it unconditionally, but React should skip the update if state is unchanged.
60
- setTrackingState(stateRef.current);
61
- }, []);
27
+ return {
28
+ getState,
29
+ setState,
30
+ subscribe,
31
+ };
32
+ };
62
33
 
63
- // If we're rendering and the tracking state is out of date, update it immediately
64
- // This will make sure that our updates are applied as early as possible.
65
- if (trackingState !== stateRef.current) {
66
- setTrackingState(stateRef.current);
67
- }
34
+ export function useSyncState<T>(getInitialState: () => T) {
35
+ const store = React.useRef(createStore(getInitialState)).current;
68
36
 
69
- const state = stateRef.current;
37
+ const state = React.useSyncExternalStore(
38
+ store.subscribe,
39
+ store.getState,
40
+ store.getState
41
+ );
70
42
 
71
43
  React.useDebugValue(state);
72
44
 
73
- return [state, getState, setState, scheduleUpdate, flushUpdates] as const;
45
+ return [state, store.getState, store.setState] as const;
74
46
  }
@@ -1,28 +1,72 @@
1
- const formatToList = (items: string[]) =>
2
- items.map((key) => `- ${key}`).join('\n');
1
+ const formatToList = (items: Record<string, string>) =>
2
+ Object.entries(items)
3
+ .map(([key, value]) => `- ${key} (${value})`)
4
+ .join('\n');
3
5
 
4
- export default function validatePathConfig(config: any, root = true) {
5
- const validKeys = ['initialRouteName', 'screens'];
6
+ export function validatePathConfig(config: unknown, root = true) {
7
+ const validation = {
8
+ path: 'string',
9
+ initialRouteName: 'string',
10
+ screens: 'object',
11
+ ...(root
12
+ ? null
13
+ : {
14
+ exact: 'boolean',
15
+ stringify: 'object',
16
+ parse: 'object',
17
+ }),
18
+ };
6
19
 
7
- if (!root) {
8
- validKeys.push('path', 'exact', 'stringify', 'parse');
20
+ if (typeof config !== 'object' || config === null) {
21
+ throw new Error(
22
+ `Expected the configuration to be an object, but got ${JSON.stringify(
23
+ config
24
+ )}.`
25
+ );
9
26
  }
10
27
 
11
- const invalidKeys = Object.keys(config).filter(
12
- (key) => !validKeys.includes(key)
28
+ const validationErrors = Object.fromEntries(
29
+ Object.keys(config)
30
+ .map((key) => {
31
+ if (key in validation) {
32
+ const type = validation[key as keyof typeof validation];
33
+ // @ts-expect-error: we know the key exists
34
+ const value = config[key];
35
+
36
+ if (typeof value !== type) {
37
+ return [key, `expected '${type}', got '${typeof value}'`];
38
+ }
39
+ } else {
40
+ return [key, 'extraneous'];
41
+ }
42
+
43
+ return null;
44
+ })
45
+ .filter(Boolean) as [string, string][]
13
46
  );
14
47
 
15
- if (invalidKeys.length) {
48
+ if (Object.keys(validationErrors).length) {
16
49
  throw new Error(
17
50
  `Found invalid properties in the configuration:\n${formatToList(
18
- invalidKeys
19
- )}\n\nDid you forget to specify them under a 'screens' property?\n\nYou can only specify the following properties:\n${formatToList(
20
- validKeys
21
- )}\n\nSee https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.`
51
+ validationErrors
52
+ )}\n\nYou can only specify the following properties:\n${formatToList(
53
+ validation
54
+ )}\n\nIf you want to specify configuration for screens, you need to specify them under a 'screens' property.\n\nSee https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.`
55
+ );
56
+ }
57
+
58
+ if (
59
+ root &&
60
+ 'path' in config &&
61
+ typeof config.path === 'string' &&
62
+ config.path.includes(':')
63
+ ) {
64
+ throw new Error(
65
+ `Found invalid path '${config.path}'. The 'path' in the top-level configuration cannot contain patterns for params.`
22
66
  );
23
67
  }
24
68
 
25
- if (config.screens) {
69
+ if ('screens' in config && config.screens) {
26
70
  Object.entries(config.screens).forEach(([_, value]) => {
27
71
  if (typeof value !== 'string') {
28
72
  validatePathConfig(value, false);
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = fromEntries;
7
- // Object.fromEntries is not available in older iOS versions
8
- function fromEntries(entries) {
9
- return entries.reduce((acc, _ref) => {
10
- let [k, v] = _ref;
11
- if (acc.hasOwnProperty(k)) {
12
- throw new Error(`A value for key '${k}' already exists in the object.`);
13
- }
14
- acc[k] = v;
15
- return acc;
16
- }, {});
17
- }
18
- //# sourceMappingURL=fromEntries.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["fromEntries","entries","reduce","acc","k","v","hasOwnProperty","Error"],"sourceRoot":"../../src","sources":["fromEntries.tsx"],"mappings":";;;;;;AAAA;AACe,SAASA,WAAW,CACjCC,OAA4B,EAC5B;EACA,OAAOA,OAAO,CAACC,MAAM,CAAC,CAACC,GAAG,WAAa;IAAA,IAAX,CAACC,CAAC,EAAEC,CAAC,CAAC;IAChC,IAAIF,GAAG,CAACG,cAAc,CAACF,CAAC,CAAC,EAAE;MACzB,MAAM,IAAIG,KAAK,CAAE,oBAAmBH,CAAE,iCAAgC,CAAC;IACzE;IAEAD,GAAG,CAACC,CAAC,CAAC,GAAGC,CAAC;IACV,OAAOF,GAAG;EACZ,CAAC,EAAE,CAAC,CAAC,CAAiB;AACxB"}
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ScheduleUpdateContext = void 0;
7
- exports.default = useScheduleUpdate;
8
- var React = _interopRequireWildcard(require("react"));
9
- 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); }
10
- 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; }
11
- const MISSING_CONTEXT_ERROR = "Couldn't find a schedule context.";
12
- const ScheduleUpdateContext = /*#__PURE__*/React.createContext({
13
- scheduleUpdate() {
14
- throw new Error(MISSING_CONTEXT_ERROR);
15
- },
16
- flushUpdates() {
17
- throw new Error(MISSING_CONTEXT_ERROR);
18
- }
19
- });
20
-
21
- /**
22
- * When screen config changes, we want to update the navigator in the same update phase.
23
- * However, navigation state is in the root component and React won't let us update it from a child.
24
- * This is a workaround for that, the scheduled update is stored in the ref without actually calling setState.
25
- * It lets all subsequent updates access the latest state so it stays correct.
26
- * Then we call setState during after the component updates.
27
- */
28
- exports.ScheduleUpdateContext = ScheduleUpdateContext;
29
- function useScheduleUpdate(callback) {
30
- const {
31
- scheduleUpdate,
32
- flushUpdates
33
- } = React.useContext(ScheduleUpdateContext);
34
- scheduleUpdate(callback);
35
- React.useEffect(flushUpdates);
36
- }
37
- //# sourceMappingURL=useScheduleUpdate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["MISSING_CONTEXT_ERROR","ScheduleUpdateContext","React","createContext","scheduleUpdate","Error","flushUpdates","useScheduleUpdate","callback","useContext","useEffect"],"sourceRoot":"../../src","sources":["useScheduleUpdate.tsx"],"mappings":";;;;;;;AAAA;AAA+B;AAAA;AAE/B,MAAMA,qBAAqB,GAAG,mCAAmC;AAE1D,MAAMC,qBAAqB,gBAAGC,KAAK,CAACC,aAAa,CAGrD;EACDC,cAAc,GAAG;IACf,MAAM,IAAIC,KAAK,CAACL,qBAAqB,CAAC;EACxC,CAAC;EACDM,YAAY,GAAG;IACb,MAAM,IAAID,KAAK,CAACL,qBAAqB,CAAC;EACxC;AACF,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AANA;AAOe,SAASO,iBAAiB,CAACC,QAAoB,EAAE;EAC9D,MAAM;IAAEJ,cAAc;IAAEE;EAAa,CAAC,GAAGJ,KAAK,CAACO,UAAU,CACvDR,qBAAqB,CACtB;EAEDG,cAAc,CAACI,QAAQ,CAAC;EAExBN,KAAK,CAACQ,SAAS,CAACJ,YAAY,CAAC;AAC/B"}
@@ -1,12 +0,0 @@
1
- // Object.fromEntries is not available in older iOS versions
2
- export default function fromEntries(entries) {
3
- return entries.reduce((acc, _ref) => {
4
- let [k, v] = _ref;
5
- if (acc.hasOwnProperty(k)) {
6
- throw new Error(`A value for key '${k}' already exists in the object.`);
7
- }
8
- acc[k] = v;
9
- return acc;
10
- }, {});
11
- }
12
- //# sourceMappingURL=fromEntries.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["fromEntries","entries","reduce","acc","k","v","hasOwnProperty","Error"],"sourceRoot":"../../src","sources":["fromEntries.tsx"],"mappings":"AAAA;AACA,eAAe,SAASA,WAAW,CACjCC,OAA4B,EAC5B;EACA,OAAOA,OAAO,CAACC,MAAM,CAAC,CAACC,GAAG,WAAa;IAAA,IAAX,CAACC,CAAC,EAAEC,CAAC,CAAC;IAChC,IAAIF,GAAG,CAACG,cAAc,CAACF,CAAC,CAAC,EAAE;MACzB,MAAM,IAAIG,KAAK,CAAE,oBAAmBH,CAAE,iCAAgC,CAAC;IACzE;IAEAD,GAAG,CAACC,CAAC,CAAC,GAAGC,CAAC;IACV,OAAOF,GAAG;EACZ,CAAC,EAAE,CAAC,CAAC,CAAiB;AACxB"}
@@ -1,27 +0,0 @@
1
- import * as React from 'react';
2
- const MISSING_CONTEXT_ERROR = "Couldn't find a schedule context.";
3
- export const ScheduleUpdateContext = /*#__PURE__*/React.createContext({
4
- scheduleUpdate() {
5
- throw new Error(MISSING_CONTEXT_ERROR);
6
- },
7
- flushUpdates() {
8
- throw new Error(MISSING_CONTEXT_ERROR);
9
- }
10
- });
11
-
12
- /**
13
- * When screen config changes, we want to update the navigator in the same update phase.
14
- * However, navigation state is in the root component and React won't let us update it from a child.
15
- * This is a workaround for that, the scheduled update is stored in the ref without actually calling setState.
16
- * It lets all subsequent updates access the latest state so it stays correct.
17
- * Then we call setState during after the component updates.
18
- */
19
- export default function useScheduleUpdate(callback) {
20
- const {
21
- scheduleUpdate,
22
- flushUpdates
23
- } = React.useContext(ScheduleUpdateContext);
24
- scheduleUpdate(callback);
25
- React.useEffect(flushUpdates);
26
- }
27
- //# sourceMappingURL=useScheduleUpdate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","MISSING_CONTEXT_ERROR","ScheduleUpdateContext","createContext","scheduleUpdate","Error","flushUpdates","useScheduleUpdate","callback","useContext","useEffect"],"sourceRoot":"../../src","sources":["useScheduleUpdate.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,MAAMC,qBAAqB,GAAG,mCAAmC;AAEjE,OAAO,MAAMC,qBAAqB,gBAAGF,KAAK,CAACG,aAAa,CAGrD;EACDC,cAAc,GAAG;IACf,MAAM,IAAIC,KAAK,CAACJ,qBAAqB,CAAC;EACxC,CAAC;EACDK,YAAY,GAAG;IACb,MAAM,IAAID,KAAK,CAACJ,qBAAqB,CAAC;EACxC;AACF,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASM,iBAAiB,CAACC,QAAoB,EAAE;EAC9D,MAAM;IAAEJ,cAAc;IAAEE;EAAa,CAAC,GAAGN,KAAK,CAACS,UAAU,CACvDP,qBAAqB,CACtB;EAEDE,cAAc,CAACI,QAAQ,CAAC;EAExBR,KAAK,CAACU,SAAS,CAACJ,YAAY,CAAC;AAC/B"}
@@ -1,2 +0,0 @@
1
- export default function fromEntries<K extends string, V>(entries: (readonly [K, V])[]): Record<K, V>;
2
- //# sourceMappingURL=fromEntries.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fromEntries.d.ts","sourceRoot":"","sources":["../../../src/fromEntries.tsx"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EACrD,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,gBAU7B"}
@@ -1,14 +0,0 @@
1
- import * as React from 'react';
2
- export declare const ScheduleUpdateContext: React.Context<{
3
- scheduleUpdate: (callback: () => void) => void;
4
- flushUpdates: () => void;
5
- }>;
6
- /**
7
- * When screen config changes, we want to update the navigator in the same update phase.
8
- * However, navigation state is in the root component and React won't let us update it from a child.
9
- * This is a workaround for that, the scheduled update is stored in the ref without actually calling setState.
10
- * It lets all subsequent updates access the latest state so it stays correct.
11
- * Then we call setState during after the component updates.
12
- */
13
- export default function useScheduleUpdate(callback: () => void): void;
14
- //# sourceMappingURL=useScheduleUpdate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useScheduleUpdate.d.ts","sourceRoot":"","sources":["../../../src/useScheduleUpdate.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,eAAO,MAAM,qBAAqB;+BACL,MAAM,IAAI,KAAK,IAAI;kBAChC,MAAM,IAAI;EAQxB,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,QAAQ,EAAE,MAAM,IAAI,QAQ7D"}