@react-navigation/core 7.0.0-alpha.4 → 7.0.0-alpha.6

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 (297) hide show
  1. package/lib/commonjs/BaseNavigationContainer.js +16 -29
  2. package/lib/commonjs/BaseNavigationContainer.js.map +1 -1
  3. package/lib/commonjs/CurrentRenderContext.js +3 -4
  4. package/lib/commonjs/CurrentRenderContext.js.map +1 -1
  5. package/lib/commonjs/DeprecatedNavigationInChildContext.js +3 -4
  6. package/lib/commonjs/DeprecatedNavigationInChildContext.js.map +1 -1
  7. package/lib/commonjs/EnsureSingleNavigator.js +3 -4
  8. package/lib/commonjs/EnsureSingleNavigator.js.map +1 -1
  9. package/lib/commonjs/Group.js.map +1 -1
  10. package/lib/commonjs/NavigationBuilderContext.js +3 -4
  11. package/lib/commonjs/NavigationBuilderContext.js.map +1 -1
  12. package/lib/commonjs/NavigationContainerRefContext.js +3 -4
  13. package/lib/commonjs/NavigationContainerRefContext.js.map +1 -1
  14. package/lib/commonjs/NavigationContext.js +3 -4
  15. package/lib/commonjs/NavigationContext.js.map +1 -1
  16. package/lib/commonjs/NavigationHelpersContext.js +3 -4
  17. package/lib/commonjs/NavigationHelpersContext.js.map +1 -1
  18. package/lib/commonjs/NavigationIndependentTree.js +2 -2
  19. package/lib/commonjs/NavigationIndependentTree.js.map +1 -1
  20. package/lib/commonjs/NavigationIndependentTreeContext.js +3 -4
  21. package/lib/commonjs/NavigationIndependentTreeContext.js.map +1 -1
  22. package/lib/commonjs/NavigationRouteContext.js +3 -4
  23. package/lib/commonjs/NavigationRouteContext.js.map +1 -1
  24. package/lib/commonjs/NavigationStateContext.js +3 -4
  25. package/lib/commonjs/NavigationStateContext.js.map +1 -1
  26. package/lib/commonjs/PreventRemoveContext.js +8 -4
  27. package/lib/commonjs/PreventRemoveContext.js.map +1 -1
  28. package/lib/commonjs/PreventRemoveProvider.js +8 -10
  29. package/lib/commonjs/PreventRemoveProvider.js.map +1 -1
  30. package/lib/commonjs/SceneView.js +2 -2
  31. package/lib/commonjs/SceneView.js.map +1 -1
  32. package/lib/commonjs/Screen.js.map +1 -1
  33. package/lib/commonjs/StaticContainer.js +3 -4
  34. package/lib/commonjs/StaticContainer.js.map +1 -1
  35. package/lib/commonjs/StaticNavigation.js +27 -3
  36. package/lib/commonjs/StaticNavigation.js.map +1 -1
  37. package/lib/commonjs/UnhandledActionContext.js +3 -4
  38. package/lib/commonjs/UnhandledActionContext.js.map +1 -1
  39. package/lib/commonjs/checkDuplicateRouteNames.js +1 -2
  40. package/lib/commonjs/checkDuplicateRouteNames.js.map +1 -1
  41. package/lib/commonjs/checkSerializable.js.map +1 -1
  42. package/lib/commonjs/createNavigationContainerRef.js +1 -2
  43. package/lib/commonjs/createNavigationContainerRef.js.map +1 -1
  44. package/lib/commonjs/createNavigatorFactory.js +0 -3
  45. package/lib/commonjs/createNavigatorFactory.js.map +1 -1
  46. package/lib/commonjs/findFocusedRoute.js +2 -4
  47. package/lib/commonjs/findFocusedRoute.js.map +1 -1
  48. package/lib/commonjs/getActionFromState.js +6 -8
  49. package/lib/commonjs/getActionFromState.js.map +1 -1
  50. package/lib/commonjs/getFocusedRouteNameFromRoute.js +1 -1
  51. package/lib/commonjs/getFocusedRouteNameFromRoute.js.map +1 -1
  52. package/lib/commonjs/getPathFromState.js +15 -19
  53. package/lib/commonjs/getPathFromState.js.map +1 -1
  54. package/lib/commonjs/getStateFromPath.js +11 -19
  55. package/lib/commonjs/getStateFromPath.js.map +1 -1
  56. package/lib/commonjs/index.js.map +1 -1
  57. package/lib/commonjs/isArrayEqual.js.map +1 -1
  58. package/lib/commonjs/isRecordEqual.js.map +1 -1
  59. package/lib/commonjs/types.js.map +1 -1
  60. package/lib/commonjs/useChildListeners.js +2 -2
  61. package/lib/commonjs/useChildListeners.js.map +1 -1
  62. package/lib/commonjs/useComponent.js +2 -2
  63. package/lib/commonjs/useComponent.js.map +1 -1
  64. package/lib/commonjs/useCurrentRender.js +2 -2
  65. package/lib/commonjs/useCurrentRender.js.map +1 -1
  66. package/lib/commonjs/useDescriptors.js +2 -2
  67. package/lib/commonjs/useDescriptors.js.map +1 -1
  68. package/lib/commonjs/useEventEmitter.js +5 -6
  69. package/lib/commonjs/useEventEmitter.js.map +1 -1
  70. package/lib/commonjs/useFocusEffect.js +4 -2
  71. package/lib/commonjs/useFocusEffect.js.map +1 -1
  72. package/lib/commonjs/useFocusEvents.js +4 -4
  73. package/lib/commonjs/useFocusEvents.js.map +1 -1
  74. package/lib/commonjs/useFocusedListenersChildrenAdapter.js +3 -3
  75. package/lib/commonjs/useFocusedListenersChildrenAdapter.js.map +1 -1
  76. package/lib/commonjs/useIsFocused.js +5 -4
  77. package/lib/commonjs/useIsFocused.js.map +1 -1
  78. package/lib/commonjs/useIsomorphicLayoutEffect.js +12 -0
  79. package/lib/commonjs/useIsomorphicLayoutEffect.js.map +1 -0
  80. package/lib/commonjs/useIsomorphicLayoutEffect.native.js +9 -0
  81. package/lib/commonjs/useIsomorphicLayoutEffect.native.js.map +1 -0
  82. package/lib/commonjs/useKeyedChildListeners.js +2 -2
  83. package/lib/commonjs/useKeyedChildListeners.js.map +1 -1
  84. package/lib/commonjs/useNavigation.js +2 -2
  85. package/lib/commonjs/useNavigation.js.map +1 -1
  86. package/lib/commonjs/useNavigationBuilder.js +68 -64
  87. package/lib/commonjs/useNavigationBuilder.js.map +1 -1
  88. package/lib/commonjs/useNavigationCache.js +2 -2
  89. package/lib/commonjs/useNavigationCache.js.map +1 -1
  90. package/lib/commonjs/useNavigationContainerRef.js +2 -2
  91. package/lib/commonjs/useNavigationContainerRef.js.map +1 -1
  92. package/lib/commonjs/useNavigationHelpers.js +4 -5
  93. package/lib/commonjs/useNavigationHelpers.js.map +1 -1
  94. package/lib/commonjs/useNavigationIndependentTree.js +2 -2
  95. package/lib/commonjs/useNavigationIndependentTree.js.map +1 -1
  96. package/lib/commonjs/useNavigationState.js +2 -2
  97. package/lib/commonjs/useNavigationState.js.map +1 -1
  98. package/lib/commonjs/useOnAction.js +3 -3
  99. package/lib/commonjs/useOnAction.js.map +1 -1
  100. package/lib/commonjs/useOnGetState.js +4 -5
  101. package/lib/commonjs/useOnGetState.js.map +1 -1
  102. package/lib/commonjs/useOnPreventRemove.js +5 -6
  103. package/lib/commonjs/useOnPreventRemove.js.map +1 -1
  104. package/lib/commonjs/useOnRouteFocus.js +2 -2
  105. package/lib/commonjs/useOnRouteFocus.js.map +1 -1
  106. package/lib/commonjs/useOptionsGetters.js +9 -10
  107. package/lib/commonjs/useOptionsGetters.js.map +1 -1
  108. package/lib/commonjs/usePreventRemove.js +3 -3
  109. package/lib/commonjs/usePreventRemove.js.map +1 -1
  110. package/lib/commonjs/usePreventRemoveContext.js +2 -2
  111. package/lib/commonjs/usePreventRemoveContext.js.map +1 -1
  112. package/lib/commonjs/useRegisterNavigator.js +2 -2
  113. package/lib/commonjs/useRegisterNavigator.js.map +1 -1
  114. package/lib/commonjs/useRoute.js +2 -2
  115. package/lib/commonjs/useRoute.js.map +1 -1
  116. package/lib/commonjs/useRouteCache.js +3 -4
  117. package/lib/commonjs/useRouteCache.js.map +1 -1
  118. package/lib/commonjs/useSyncState.js +27 -56
  119. package/lib/commonjs/useSyncState.js.map +1 -1
  120. package/lib/commonjs/validatePathConfig.js.map +1 -1
  121. package/lib/module/BaseNavigationContainer.js +13 -25
  122. package/lib/module/BaseNavigationContainer.js.map +1 -1
  123. package/lib/module/CurrentRenderContext.js.map +1 -1
  124. package/lib/module/DeprecatedNavigationInChildContext.js.map +1 -1
  125. package/lib/module/EnsureSingleNavigator.js.map +1 -1
  126. package/lib/module/Group.js.map +1 -1
  127. package/lib/module/NavigationBuilderContext.js.map +1 -1
  128. package/lib/module/NavigationContainerRefContext.js.map +1 -1
  129. package/lib/module/NavigationContext.js.map +1 -1
  130. package/lib/module/NavigationHelpersContext.js.map +1 -1
  131. package/lib/module/NavigationIndependentTree.js.map +1 -1
  132. package/lib/module/NavigationIndependentTreeContext.js.map +1 -1
  133. package/lib/module/NavigationRouteContext.js.map +1 -1
  134. package/lib/module/NavigationStateContext.js.map +1 -1
  135. package/lib/module/PreventRemoveContext.js.map +1 -1
  136. package/lib/module/PreventRemoveProvider.js +6 -8
  137. package/lib/module/PreventRemoveProvider.js.map +1 -1
  138. package/lib/module/SceneView.js.map +1 -1
  139. package/lib/module/Screen.js.map +1 -1
  140. package/lib/module/StaticContainer.js.map +1 -1
  141. package/lib/module/StaticNavigation.js +20 -1
  142. package/lib/module/StaticNavigation.js.map +1 -1
  143. package/lib/module/UnhandledActionContext.js.map +1 -1
  144. package/lib/module/checkDuplicateRouteNames.js +1 -2
  145. package/lib/module/checkDuplicateRouteNames.js.map +1 -1
  146. package/lib/module/checkSerializable.js.map +1 -1
  147. package/lib/module/createNavigationContainerRef.js.map +1 -1
  148. package/lib/module/createNavigatorFactory.js +0 -3
  149. package/lib/module/createNavigatorFactory.js.map +1 -1
  150. package/lib/module/findFocusedRoute.js +2 -4
  151. package/lib/module/findFocusedRoute.js.map +1 -1
  152. package/lib/module/getActionFromState.js +6 -8
  153. package/lib/module/getActionFromState.js.map +1 -1
  154. package/lib/module/getFocusedRouteNameFromRoute.js +1 -1
  155. package/lib/module/getFocusedRouteNameFromRoute.js.map +1 -1
  156. package/lib/module/getPathFromState.js +13 -17
  157. package/lib/module/getPathFromState.js.map +1 -1
  158. package/lib/module/getStateFromPath.js +9 -17
  159. package/lib/module/getStateFromPath.js.map +1 -1
  160. package/lib/module/index.js.map +1 -1
  161. package/lib/module/isArrayEqual.js.map +1 -1
  162. package/lib/module/isRecordEqual.js.map +1 -1
  163. package/lib/module/types.js.map +1 -1
  164. package/lib/module/useChildListeners.js.map +1 -1
  165. package/lib/module/useComponent.js.map +1 -1
  166. package/lib/module/useCurrentRender.js.map +1 -1
  167. package/lib/module/useDescriptors.js.map +1 -1
  168. package/lib/module/useEventEmitter.js +3 -4
  169. package/lib/module/useEventEmitter.js.map +1 -1
  170. package/lib/module/useFocusEffect.js +2 -0
  171. package/lib/module/useFocusEffect.js.map +1 -1
  172. package/lib/module/useFocusEvents.js +2 -2
  173. package/lib/module/useFocusEvents.js.map +1 -1
  174. package/lib/module/useFocusedListenersChildrenAdapter.js +1 -1
  175. package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
  176. package/lib/module/useIsFocused.js.map +1 -1
  177. package/lib/module/useIsomorphicLayoutEffect.js +7 -0
  178. package/lib/module/useIsomorphicLayoutEffect.js.map +1 -0
  179. package/lib/module/useIsomorphicLayoutEffect.native.js +3 -0
  180. package/lib/module/useIsomorphicLayoutEffect.native.js.map +1 -0
  181. package/lib/module/useKeyedChildListeners.js.map +1 -1
  182. package/lib/module/useNavigation.js.map +1 -1
  183. package/lib/module/useNavigationBuilder.js +65 -62
  184. package/lib/module/useNavigationBuilder.js.map +1 -1
  185. package/lib/module/useNavigationCache.js.map +1 -1
  186. package/lib/module/useNavigationContainerRef.js.map +1 -1
  187. package/lib/module/useNavigationHelpers.js +2 -3
  188. package/lib/module/useNavigationHelpers.js.map +1 -1
  189. package/lib/module/useNavigationIndependentTree.js.map +1 -1
  190. package/lib/module/useNavigationState.js.map +1 -1
  191. package/lib/module/useOnAction.js +1 -1
  192. package/lib/module/useOnAction.js.map +1 -1
  193. package/lib/module/useOnGetState.js +2 -3
  194. package/lib/module/useOnGetState.js.map +1 -1
  195. package/lib/module/useOnPreventRemove.js +3 -4
  196. package/lib/module/useOnPreventRemove.js.map +1 -1
  197. package/lib/module/useOnRouteFocus.js.map +1 -1
  198. package/lib/module/useOptionsGetters.js +7 -8
  199. package/lib/module/useOptionsGetters.js.map +1 -1
  200. package/lib/module/usePreventRemove.js +1 -1
  201. package/lib/module/usePreventRemove.js.map +1 -1
  202. package/lib/module/usePreventRemoveContext.js.map +1 -1
  203. package/lib/module/useRegisterNavigator.js.map +1 -1
  204. package/lib/module/useRoute.js.map +1 -1
  205. package/lib/module/useRouteCache.js.map +1 -1
  206. package/lib/module/useSyncState.js +25 -54
  207. package/lib/module/useSyncState.js.map +1 -1
  208. package/lib/module/validatePathConfig.js.map +1 -1
  209. package/lib/typescript/src/BaseNavigationContainer.d.ts +1 -1
  210. package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
  211. package/lib/typescript/src/EnsureSingleNavigator.d.ts +1 -1
  212. package/lib/typescript/src/EnsureSingleNavigator.d.ts.map +1 -1
  213. package/lib/typescript/src/NavigationContext.d.ts +1 -17
  214. package/lib/typescript/src/NavigationContext.d.ts.map +1 -1
  215. package/lib/typescript/src/NavigationHelpersContext.d.ts +1 -1
  216. package/lib/typescript/src/NavigationHelpersContext.d.ts.map +1 -1
  217. package/lib/typescript/src/NavigationIndependentTree.d.ts +1 -1
  218. package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
  219. package/lib/typescript/src/NavigationRouteContext.d.ts +1 -1
  220. package/lib/typescript/src/NavigationRouteContext.d.ts.map +1 -1
  221. package/lib/typescript/src/PreventRemoveProvider.d.ts +1 -1
  222. package/lib/typescript/src/PreventRemoveProvider.d.ts.map +1 -1
  223. package/lib/typescript/src/SceneView.d.ts +2 -1
  224. package/lib/typescript/src/SceneView.d.ts.map +1 -1
  225. package/lib/typescript/src/StaticNavigation.d.ts +1 -1
  226. package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
  227. package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
  228. package/lib/typescript/src/index.d.ts +1 -1
  229. package/lib/typescript/src/index.d.ts.map +1 -1
  230. package/lib/typescript/src/types.d.ts +25 -0
  231. package/lib/typescript/src/types.d.ts.map +1 -1
  232. package/lib/typescript/src/useComponent.d.ts +1 -1
  233. package/lib/typescript/src/useComponent.d.ts.map +1 -1
  234. package/lib/typescript/src/useDescriptors.d.ts +3 -2
  235. package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
  236. package/lib/typescript/src/useFocusEffect.d.ts.map +1 -1
  237. package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +1 -1
  238. package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts.map +1 -1
  239. package/lib/typescript/src/useIsomorphicLayoutEffect.d.ts +6 -0
  240. package/lib/typescript/src/useIsomorphicLayoutEffect.d.ts.map +1 -0
  241. package/lib/typescript/src/useIsomorphicLayoutEffect.native.d.ts +3 -0
  242. package/lib/typescript/src/useIsomorphicLayoutEffect.native.d.ts.map +1 -0
  243. package/lib/typescript/src/useNavigationBuilder.d.ts +38 -4
  244. package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
  245. package/lib/typescript/src/useNavigationCache.d.ts +1 -1
  246. package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
  247. package/lib/typescript/src/useNavigationHelpers.d.ts +35 -18
  248. package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
  249. package/lib/typescript/src/useOnAction.d.ts +1 -1
  250. package/lib/typescript/src/useOnAction.d.ts.map +1 -1
  251. package/lib/typescript/src/useOnGetState.d.ts +1 -1
  252. package/lib/typescript/src/useOnGetState.d.ts.map +1 -1
  253. package/lib/typescript/src/useOnPreventRemove.d.ts +1 -1
  254. package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
  255. package/lib/typescript/src/useRouteCache.d.ts +1 -1
  256. package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
  257. package/lib/typescript/src/useSyncState.d.ts +1 -4
  258. package/lib/typescript/src/useSyncState.d.ts.map +1 -1
  259. package/lib/typescript/utils/usePrevious.d.ts +6 -0
  260. package/lib/typescript/utils/usePrevious.d.ts.map +1 -0
  261. package/package.json +13 -13
  262. package/src/BaseNavigationContainer.tsx +27 -36
  263. package/src/Group.tsx +1 -1
  264. package/src/PreventRemoveProvider.tsx +4 -1
  265. package/src/SceneView.tsx +1 -1
  266. package/src/Screen.tsx +1 -1
  267. package/src/StaticNavigation.tsx +7 -7
  268. package/src/checkDuplicateRouteNames.tsx +1 -1
  269. package/src/createNavigationContainerRef.tsx +1 -1
  270. package/src/createNavigatorFactory.tsx +2 -4
  271. package/src/getActionFromState.tsx +1 -1
  272. package/src/getPathFromState.tsx +6 -8
  273. package/src/getStateFromPath.tsx +6 -3
  274. package/src/index.tsx +2 -2
  275. package/src/types.tsx +59 -16
  276. package/src/useDescriptors.tsx +5 -5
  277. package/src/useFocusEffect.tsx +1 -0
  278. package/src/useFocusedListenersChildrenAdapter.tsx +2 -2
  279. package/src/useIsomorphicLayoutEffect.native.tsx +3 -0
  280. package/src/useIsomorphicLayoutEffect.tsx +7 -0
  281. package/src/useNavigation.tsx +1 -1
  282. package/src/useNavigationBuilder.tsx +99 -77
  283. package/src/useNavigationCache.tsx +7 -7
  284. package/src/useNavigationContainerRef.tsx +1 -1
  285. package/src/useNavigationHelpers.tsx +6 -7
  286. package/src/useOnAction.tsx +2 -2
  287. package/src/useOnGetState.tsx +1 -1
  288. package/src/useOnPreventRemove.tsx +1 -1
  289. package/src/useOptionsGetters.tsx +2 -2
  290. package/src/useSyncState.tsx +31 -59
  291. package/lib/commonjs/useScheduleUpdate.js +0 -37
  292. package/lib/commonjs/useScheduleUpdate.js.map +0 -1
  293. package/lib/module/useScheduleUpdate.js +0 -27
  294. package/lib/module/useScheduleUpdate.js.map +0 -1
  295. package/lib/typescript/src/useScheduleUpdate.d.ts +0 -14
  296. package/lib/typescript/src/useScheduleUpdate.d.ts.map +0 -1
  297. package/src/useScheduleUpdate.tsx +0 -32
@@ -1,17 +1,18 @@
1
1
  import {
2
2
  CommonActions,
3
- DefaultRouterOptions,
4
- NavigationAction,
5
- NavigationState,
6
- ParamListBase,
7
- PartialState,
8
- Route,
9
- Router,
10
- RouterConfigOptions,
11
- RouterFactory,
3
+ type DefaultRouterOptions,
4
+ type NavigationAction,
5
+ type NavigationState,
6
+ type ParamListBase,
7
+ type PartialState,
8
+ type Route,
9
+ type Router,
10
+ type RouterConfigOptions,
11
+ type RouterFactory,
12
12
  } from '@react-navigation/routers';
13
13
  import * as React from 'react';
14
14
  import { isValidElementType } from 'react-is';
15
+ import useLatestCallback from 'use-latest-callback';
15
16
 
16
17
  import { Group } from './Group';
17
18
  import { isArrayEqual } from './isArrayEqual';
@@ -22,30 +23,29 @@ import { NavigationStateContext } from './NavigationStateContext';
22
23
  import { PreventRemoveProvider } from './PreventRemoveProvider';
23
24
  import { Screen } from './Screen';
24
25
  import {
25
- DefaultNavigatorOptions,
26
- EventMapBase,
27
- EventMapCore,
28
- NavigatorScreenParams,
26
+ type DefaultNavigatorOptions,
27
+ type EventMapBase,
28
+ type EventMapCore,
29
+ type NavigatorScreenParams,
29
30
  PrivateValueStore,
30
- RouteConfig,
31
+ type RouteConfig,
31
32
  } from './types';
32
33
  import { useChildListeners } from './useChildListeners';
33
34
  import { useComponent } from './useComponent';
34
35
  import { useCurrentRender } from './useCurrentRender';
35
- import { ScreenConfigWithParent, useDescriptors } from './useDescriptors';
36
+ import { type ScreenConfigWithParent, useDescriptors } from './useDescriptors';
36
37
  import { useEventEmitter } from './useEventEmitter';
37
38
  import { useFocusedListenersChildrenAdapter } from './useFocusedListenersChildrenAdapter';
38
39
  import { useFocusEvents } from './useFocusEvents';
40
+ import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
39
41
  import { useKeyedChildListeners } from './useKeyedChildListeners';
40
42
  import { useNavigationHelpers } from './useNavigationHelpers';
41
43
  import { useOnAction } from './useOnAction';
42
44
  import { useOnGetState } from './useOnGetState';
43
45
  import { useOnRouteFocus } from './useOnRouteFocus';
44
46
  import { useRegisterNavigator } from './useRegisterNavigator';
45
- import { useScheduleUpdate } from './useScheduleUpdate';
46
47
 
47
48
  // This is to make TypeScript compiler happy
48
- // eslint-disable-next-line babel/no-unused-expressions
49
49
  PrivateValueStore;
50
50
 
51
51
  type NavigatorRoute = {
@@ -64,7 +64,7 @@ const isValidKey = (key: unknown) =>
64
64
  const getRouteConfigsFromChildren = <
65
65
  State extends NavigationState,
66
66
  ScreenOptions extends {},
67
- EventMap extends EventMapBase
67
+ EventMap extends EventMapBase,
68
68
  >(
69
69
  children: React.ReactNode,
70
70
  groupKey?: string,
@@ -242,7 +242,7 @@ export function useNavigationBuilder<
242
242
  RouterOptions extends DefaultRouterOptions,
243
243
  ActionHelpers extends Record<string, () => void>,
244
244
  ScreenOptions extends {},
245
- EventMap extends Record<string, any>
245
+ EventMap extends Record<string, any>,
246
246
  >(
247
247
  createRouter: RouterFactory<State, any, RouterOptions>,
248
248
  options: DefaultNavigatorOptions<
@@ -259,17 +259,9 @@ export function useNavigationBuilder<
259
259
  | NavigatorRoute
260
260
  | undefined;
261
261
 
262
- const { children, screenListeners, ...rest } = options;
262
+ const { children, layout, screenOptions, screenListeners, ...rest } = options;
263
263
  const { current: router } = React.useRef<Router<State, any>>(
264
- createRouter({
265
- ...(rest as unknown as RouterOptions),
266
- ...(route?.params &&
267
- route.params.state == null &&
268
- route.params.initial !== false &&
269
- typeof route.params.screen === 'string'
270
- ? { initialRouteName: route.params.screen }
271
- : null),
272
- })
264
+ createRouter(rest as unknown as RouterOptions)
273
265
  );
274
266
 
275
267
  const routeConfigs = getRouteConfigsFromChildren<
@@ -346,12 +338,7 @@ export function useNavigationBuilder<
346
338
 
347
339
  const stateCleanedUp = React.useRef(false);
348
340
 
349
- const cleanUpState = React.useCallback(() => {
350
- setCurrentState(undefined);
351
- stateCleanedUp.current = true;
352
- }, [setCurrentState]);
353
-
354
- const setState = React.useCallback(
341
+ const setState = useLatestCallback(
355
342
  (state: NavigationState | PartialState<NavigationState> | undefined) => {
356
343
  if (stateCleanedUp.current) {
357
344
  // State might have been already cleaned up due to unmount
@@ -359,9 +346,9 @@ export function useNavigationBuilder<
359
346
  // This would lead to old data preservation on main navigator unmount
360
347
  return;
361
348
  }
349
+
362
350
  setCurrentState(state);
363
- },
364
- [setCurrentState]
351
+ }
365
352
  );
366
353
 
367
354
  const [initializedState, isFirstStateInitialization] = React.useMemo(() => {
@@ -393,7 +380,11 @@ export function useNavigationBuilder<
393
380
  // So we need to rehydrate it to make it usable
394
381
  if (
395
382
  (currentState === undefined || !isStateValid(currentState)) &&
396
- route?.params?.state == null
383
+ route?.params?.state == null &&
384
+ !(
385
+ typeof route?.params?.screen === 'string' &&
386
+ route?.params?.initial !== false
387
+ )
397
388
  ) {
398
389
  return [
399
390
  router.getInitialState({
@@ -404,9 +395,29 @@ export function useNavigationBuilder<
404
395
  true,
405
396
  ];
406
397
  } else {
398
+ let stateFromParams;
399
+
400
+ if (route?.params?.state != null) {
401
+ stateFromParams = route.params.state;
402
+ } else if (
403
+ typeof route?.params?.screen === 'string' &&
404
+ route?.params?.initial !== false
405
+ ) {
406
+ stateFromParams = {
407
+ index: 0,
408
+ routes: [
409
+ {
410
+ name: route.params.screen,
411
+ params: route.params.params,
412
+ path: route.params.path,
413
+ },
414
+ ],
415
+ };
416
+ }
417
+
407
418
  return [
408
419
  router.getRehydratedState(
409
- (route?.params?.state ?? currentState) as PartialState<State>,
420
+ (stateFromParams ?? currentState) as PartialState<State>,
410
421
  {
411
422
  routeNames,
412
423
  routeParamList: initialRouteParamList,
@@ -446,17 +457,26 @@ export function useNavigationBuilder<
446
457
  !isArrayEqual(state.routeNames, routeNames) ||
447
458
  !isRecordEqual(routeKeyList, previousRouteKeyList)
448
459
  ) {
460
+ const navigatorStateForNextRouteNamesChange =
461
+ options.getStateForRouteNamesChange?.(state);
449
462
  // When the list of route names change, the router should handle it to remove invalid routes
450
- nextState = router.getStateForRouteNamesChange(state, {
451
- routeNames,
452
- routeParamList,
453
- routeGetIdList,
454
- routeKeyChanges: Object.keys(routeKeyList).filter(
455
- (name) =>
456
- previousRouteKeyList.hasOwnProperty(name) &&
457
- routeKeyList[name] !== previousRouteKeyList[name]
458
- ),
459
- });
463
+ nextState = navigatorStateForNextRouteNamesChange
464
+ ? // @ts-expect-error this is ok
465
+ router.getRehydratedState(navigatorStateForNextRouteNamesChange, {
466
+ routeNames,
467
+ routeParamList,
468
+ routeGetIdList,
469
+ })
470
+ : router.getStateForRouteNamesChange(state, {
471
+ routeNames,
472
+ routeParamList,
473
+ routeGetIdList,
474
+ routeKeyChanges: Object.keys(routeKeyList).filter(
475
+ (name) =>
476
+ name in previousRouteKeyList &&
477
+ routeKeyList[name] !== previousRouteKeyList[name]
478
+ ),
479
+ });
460
480
  }
461
481
 
462
482
  const previousNestedParamsRef = React.useRef(route?.params);
@@ -511,7 +531,7 @@ export function useNavigationBuilder<
511
531
 
512
532
  const shouldUpdate = state !== nextState;
513
533
 
514
- useScheduleUpdate(() => {
534
+ useIsomorphicLayoutEffect(() => {
515
535
  if (shouldUpdate) {
516
536
  // If the state needs to be updated, we'll schedule an update
517
537
  setState(nextState);
@@ -535,34 +555,24 @@ export function useNavigationBuilder<
535
555
 
536
556
  return () => {
537
557
  // We need to clean up state for this navigator on unmount
538
- // We do it in a timeout because we need to detect if another navigator mounted in the meantime
539
- // For example, if another navigator has started rendering, we should skip cleanup
540
- // Otherwise, our cleanup step will cleanup state for the other navigator and re-initialize it
541
- setTimeout(() => {
542
- if (getCurrentState() !== undefined && getKey() === navigatorKey) {
543
- cleanUpState();
544
- }
545
- }, 0);
558
+ if (getCurrentState() !== undefined && getKey() === navigatorKey) {
559
+ setCurrentState(undefined);
560
+ stateCleanedUp.current = true;
561
+ }
546
562
  };
547
563
  // eslint-disable-next-line react-hooks/exhaustive-deps
548
564
  }, []);
549
565
 
550
- // We initialize this ref here to avoid a new getState getting initialized
551
- // whenever initializedState changes. We want getState to have access to the
552
- // latest initializedState, but don't need it to change when that happens
553
- const initializedStateRef = React.useRef<State>();
554
- initializedStateRef.current = initializedState;
566
+ const getState = useLatestCallback((): State => {
567
+ const currentState = shouldUpdate ? nextState : getCurrentState();
555
568
 
556
- const getState = React.useCallback((): State => {
557
- const currentState = getCurrentState();
558
-
559
- return isStateInitialized(currentState)
560
- ? (currentState as State)
561
- : (initializedStateRef.current as State);
562
- }, [getCurrentState, isStateInitialized]);
569
+ return (
570
+ isStateInitialized(currentState) ? currentState : initializedState
571
+ ) as State;
572
+ });
563
573
 
564
574
  const emitter = useEventEmitter<EventMapCore<State>>((e) => {
565
- let routeNames = [];
575
+ const routeNames = [];
566
576
 
567
577
  let route: Route<string> | undefined;
568
578
 
@@ -678,7 +688,7 @@ export function useNavigationBuilder<
678
688
  state,
679
689
  screens,
680
690
  navigation,
681
- screenOptions: options.screenOptions,
691
+ screenOptions,
682
692
  onAction,
683
693
  getState,
684
694
  setState,
@@ -696,11 +706,23 @@ export function useNavigationBuilder<
696
706
  descriptors,
697
707
  });
698
708
 
699
- const NavigationContent = useComponent((children: React.ReactNode) => (
700
- <NavigationHelpersContext.Provider value={navigation}>
701
- <PreventRemoveProvider>{children}</PreventRemoveProvider>
702
- </NavigationHelpersContext.Provider>
703
- ));
709
+ const NavigationContent = useComponent((children: React.ReactNode) => {
710
+ const element =
711
+ layout != null
712
+ ? layout({
713
+ state,
714
+ descriptors,
715
+ navigation,
716
+ children,
717
+ })
718
+ : children;
719
+
720
+ return (
721
+ <NavigationHelpersContext.Provider value={navigation}>
722
+ <PreventRemoveProvider>{element}</PreventRemoveProvider>
723
+ </NavigationHelpersContext.Provider>
724
+ );
725
+ });
704
726
 
705
727
  return {
706
728
  state,
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  CommonActions,
3
- NavigationAction,
4
- NavigationState,
5
- ParamListBase,
6
- Router,
3
+ type NavigationAction,
4
+ type NavigationState,
5
+ type ParamListBase,
6
+ type Router,
7
7
  } from '@react-navigation/routers';
8
8
  import * as React from 'react';
9
9
 
@@ -14,7 +14,7 @@ import type { NavigationEventEmitter } from './useEventEmitter';
14
14
  type Options<
15
15
  State extends NavigationState,
16
16
  ScreenOptions extends {},
17
- EventMap extends Record<string, any>
17
+ EventMap extends Record<string, any>,
18
18
  > = {
19
19
  state: State;
20
20
  getState: () => State;
@@ -32,7 +32,7 @@ type Options<
32
32
  type NavigationCache<
33
33
  State extends NavigationState,
34
34
  ScreenOptions extends {},
35
- EventMap extends Record<string, any>
35
+ EventMap extends Record<string, any>,
36
36
  > = Record<
37
37
  string,
38
38
  NavigationProp<
@@ -53,7 +53,7 @@ type NavigationCache<
53
53
  export function useNavigationCache<
54
54
  State extends NavigationState,
55
55
  ScreenOptions extends {},
56
- EventMap extends Record<string, any>
56
+ EventMap extends Record<string, any>,
57
57
  >({
58
58
  state,
59
59
  getState,
@@ -4,7 +4,7 @@ import { createNavigationContainerRef } from './createNavigationContainerRef';
4
4
  import type { NavigationContainerRefWithCurrent } from './types';
5
5
 
6
6
  export function useNavigationContainerRef<
7
- ParamList extends {} = ReactNavigation.RootParamList
7
+ ParamList extends {} = ReactNavigation.RootParamList,
8
8
  >(): NavigationContainerRefWithCurrent<ParamList> {
9
9
  const navigation =
10
10
  React.useRef<NavigationContainerRefWithCurrent<ParamList> | null>(null);
@@ -1,19 +1,18 @@
1
1
  import {
2
2
  CommonActions,
3
- NavigationAction,
4
- NavigationState,
5
- ParamListBase,
6
- Router,
3
+ type NavigationAction,
4
+ type NavigationState,
5
+ type ParamListBase,
6
+ type Router,
7
7
  } from '@react-navigation/routers';
8
8
  import * as React from 'react';
9
9
 
10
10
  import { NavigationContext } from './NavigationContext';
11
- import { NavigationHelpers, PrivateValueStore } from './types';
11
+ import { type NavigationHelpers, PrivateValueStore } from './types';
12
12
  import { UnhandledActionContext } from './UnhandledActionContext';
13
13
  import type { NavigationEventEmitter } from './useEventEmitter';
14
14
 
15
15
  // This is to make TypeScript compiler happy
16
- // eslint-disable-next-line babel/no-unused-expressions
17
16
  PrivateValueStore;
18
17
 
19
18
  type Options<State extends NavigationState, Action extends NavigationAction> = {
@@ -32,7 +31,7 @@ export function useNavigationHelpers<
32
31
  State extends NavigationState,
33
32
  ActionHelpers extends Record<string, () => void>,
34
33
  Action extends NavigationAction,
35
- EventMap extends Record<string, any>
34
+ EventMap extends Record<string, any>,
36
35
  >({
37
36
  id: navigatorId,
38
37
  onAction,
@@ -9,8 +9,8 @@ import * as React from 'react';
9
9
 
10
10
  import { DeprecatedNavigationInChildContext } from './DeprecatedNavigationInChildContext';
11
11
  import {
12
- ChildActionListener,
13
- ChildBeforeRemoveListener,
12
+ type ChildActionListener,
13
+ type ChildBeforeRemoveListener,
14
14
  NavigationBuilderContext,
15
15
  } from './NavigationBuilderContext';
16
16
  import type { EventMapCore } from './types';
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
 
4
4
  import { isArrayEqual } from './isArrayEqual';
5
5
  import {
6
- GetStateListener,
6
+ type GetStateListener,
7
7
  NavigationBuilderContext,
8
8
  } from './NavigationBuilderContext';
9
9
  import { NavigationRouteContext } from './NavigationRouteContext';
@@ -5,7 +5,7 @@ import type {
5
5
  import * as React from 'react';
6
6
 
7
7
  import {
8
- ChildBeforeRemoveListener,
8
+ type ChildBeforeRemoveListener,
9
9
  NavigationBuilderContext,
10
10
  } from './NavigationBuilderContext';
11
11
  import { NavigationRouteContext } from './NavigationRouteContext';
@@ -39,8 +39,8 @@ export function useOptionsGetters({ key, options, navigation }: Options) {
39
39
  }, [navigation, options, optionsChangeListener]);
40
40
 
41
41
  const getOptionsFromListener = React.useCallback(() => {
42
- for (let key in optionsGettersFromChildRef.current) {
43
- if (optionsGettersFromChildRef.current.hasOwnProperty(key)) {
42
+ for (const key in optionsGettersFromChildRef.current) {
43
+ if (key in optionsGettersFromChildRef.current) {
44
44
  const result = optionsGettersFromChildRef.current[key]?.();
45
45
 
46
46
  // null means unfocused route
@@ -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 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,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ScheduleUpdateContext = void 0;
7
- exports.useScheduleUpdate = 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;AAOO,SAASO,iBAAiB,CAACC,QAAoB,EAAE;EACtD,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,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 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,OAAO,SAASM,iBAAiB,CAACC,QAAoB,EAAE;EACtD,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,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 declare 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,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,IAAI,QAQrD"}
@@ -1,32 +0,0 @@
1
- import * as React from 'react';
2
-
3
- const MISSING_CONTEXT_ERROR = "Couldn't find a schedule context.";
4
-
5
- export const ScheduleUpdateContext = React.createContext<{
6
- scheduleUpdate: (callback: () => void) => void;
7
- flushUpdates: () => void;
8
- }>({
9
- scheduleUpdate() {
10
- throw new Error(MISSING_CONTEXT_ERROR);
11
- },
12
- flushUpdates() {
13
- throw new Error(MISSING_CONTEXT_ERROR);
14
- },
15
- });
16
-
17
- /**
18
- * When screen config changes, we want to update the navigator in the same update phase.
19
- * However, navigation state is in the root component and React won't let us update it from a child.
20
- * This is a workaround for that, the scheduled update is stored in the ref without actually calling setState.
21
- * It lets all subsequent updates access the latest state so it stays correct.
22
- * Then we call setState during after the component updates.
23
- */
24
- export function useScheduleUpdate(callback: () => void) {
25
- const { scheduleUpdate, flushUpdates } = React.useContext(
26
- ScheduleUpdateContext
27
- );
28
-
29
- scheduleUpdate(callback);
30
-
31
- React.useEffect(flushUpdates);
32
- }