@react-navigation/core 8.0.0-alpha.4 → 8.0.0-alpha.41

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 (323) hide show
  1. package/README.md +17 -14
  2. package/lib/module/BaseNavigationContainer.js +173 -90
  3. package/lib/module/BaseNavigationContainer.js.map +1 -1
  4. package/lib/module/ConsumedParamsContext.js +5 -0
  5. package/lib/module/ConsumedParamsContext.js.map +1 -0
  6. package/lib/module/DataLoading.js +129 -0
  7. package/lib/module/DataLoading.js.map +1 -0
  8. package/lib/module/NavigationBuilderContext.js +7 -10
  9. package/lib/module/NavigationBuilderContext.js.map +1 -1
  10. package/lib/module/NavigationIndependentTree.js +54 -9
  11. package/lib/module/NavigationIndependentTree.js.map +1 -1
  12. package/lib/module/NavigationProvider.js +37 -12
  13. package/lib/module/NavigationProvider.js.map +1 -1
  14. package/lib/module/NavigationRootContext.js +8 -0
  15. package/lib/module/NavigationRootContext.js.map +1 -0
  16. package/lib/module/NavigationStateContext.js +3 -0
  17. package/lib/module/NavigationStateContext.js.map +1 -1
  18. package/lib/module/PreventRemoveContext.js.map +1 -1
  19. package/lib/module/PreventRemoveProvider.js +40 -31
  20. package/lib/module/PreventRemoveProvider.js.map +1 -1
  21. package/lib/module/SceneView.js +29 -57
  22. package/lib/module/SceneView.js.map +1 -1
  23. package/lib/module/StaticNavigation.js +219 -67
  24. package/lib/module/StaticNavigation.js.map +1 -1
  25. package/lib/module/StaticTreeContext.js +5 -0
  26. package/lib/module/StaticTreeContext.js.map +1 -0
  27. package/lib/module/createNavigationContainerRef.js +7 -9
  28. package/lib/module/createNavigationContainerRef.js.map +1 -1
  29. package/lib/module/createNavigatorFactory.js +27 -5
  30. package/lib/module/createNavigatorFactory.js.map +1 -1
  31. package/lib/module/findFocusedRoute.js +7 -4
  32. package/lib/module/findFocusedRoute.js.map +1 -1
  33. package/lib/module/getActionFromState.js +45 -20
  34. package/lib/module/getActionFromState.js.map +1 -1
  35. package/lib/module/getPathFromState.js +204 -94
  36. package/lib/module/getPathFromState.js.map +1 -1
  37. package/lib/module/getPatternParts.js +61 -14
  38. package/lib/module/getPatternParts.js.map +1 -1
  39. package/lib/module/getStateFromPath.js +608 -272
  40. package/lib/module/getStateFromPath.js.map +1 -1
  41. package/lib/module/getStateFromRouteParams.js +23 -0
  42. package/lib/module/getStateFromRouteParams.js.map +1 -0
  43. package/lib/module/index.js +7 -6
  44. package/lib/module/index.js.map +1 -1
  45. package/lib/module/internal.js +2 -0
  46. package/lib/module/internal.js.map +1 -0
  47. package/lib/module/isRecordEqual.js +1 -1
  48. package/lib/module/isRecordEqual.js.map +1 -1
  49. package/lib/module/queryString.js +71 -0
  50. package/lib/module/queryString.js.map +1 -0
  51. package/lib/module/theming/useTheme.js +1 -1
  52. package/lib/module/theming/useTheme.js.map +1 -1
  53. package/lib/module/types.js +35 -1
  54. package/lib/module/types.js.map +1 -1
  55. package/lib/module/useDescriptors.js +65 -25
  56. package/lib/module/useDescriptors.js.map +1 -1
  57. package/lib/module/useEventEmitter.js +48 -33
  58. package/lib/module/useEventEmitter.js.map +1 -1
  59. package/lib/module/useFocusEffect.js +4 -2
  60. package/lib/module/useFocusEffect.js.map +1 -1
  61. package/lib/module/useFocusEvents.js +15 -5
  62. package/lib/module/useFocusEvents.js.map +1 -1
  63. package/lib/module/useFocusedListenersChildrenAdapter.js +3 -3
  64. package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
  65. package/lib/module/useIsFocused.js +8 -12
  66. package/lib/module/useIsFocused.js.map +1 -1
  67. package/lib/module/useKeyedChildListeners.js +5 -2
  68. package/lib/module/useKeyedChildListeners.js.map +1 -1
  69. package/lib/module/useLazyValue.js.map +1 -1
  70. package/lib/module/useNavigation.js +4 -17
  71. package/lib/module/useNavigation.js.map +1 -1
  72. package/lib/module/useNavigationBuilder.js +244 -147
  73. package/lib/module/useNavigationBuilder.js.map +1 -1
  74. package/lib/module/useNavigationCache.js +92 -89
  75. package/lib/module/useNavigationCache.js.map +1 -1
  76. package/lib/module/useNavigationHelpers.js +22 -29
  77. package/lib/module/useNavigationHelpers.js.map +1 -1
  78. package/lib/module/useNavigationIndependentTree.js +1 -1
  79. package/lib/module/useNavigationIndependentTree.js.map +1 -1
  80. package/lib/module/useNavigationState.js +158 -46
  81. package/lib/module/useNavigationState.js.map +1 -1
  82. package/lib/module/useOnAction.js +58 -11
  83. package/lib/module/useOnAction.js.map +1 -1
  84. package/lib/module/useOnGetNavigation.js +26 -0
  85. package/lib/module/useOnGetNavigation.js.map +1 -0
  86. package/lib/module/useOnGetState.js +7 -4
  87. package/lib/module/useOnGetState.js.map +1 -1
  88. package/lib/module/useOnPreventRemove.js +40 -31
  89. package/lib/module/useOnPreventRemove.js.map +1 -1
  90. package/lib/module/useOnRouteFocus.js +2 -2
  91. package/lib/module/useOnRouteFocus.js.map +1 -1
  92. package/lib/module/useOptionsGetters.js +35 -27
  93. package/lib/module/useOptionsGetters.js.map +1 -1
  94. package/lib/module/usePreventRemove.js +11 -5
  95. package/lib/module/usePreventRemove.js.map +1 -1
  96. package/lib/module/usePreventRemoveContext.js +2 -2
  97. package/lib/module/usePreventRemoveContext.js.map +1 -1
  98. package/lib/module/useRegisterNavigator.js +3 -4
  99. package/lib/module/useRegisterNavigator.js.map +1 -1
  100. package/lib/module/useRoute.js +2 -0
  101. package/lib/module/useRoute.js.map +1 -1
  102. package/lib/module/useRouteCache.js +51 -35
  103. package/lib/module/useRouteCache.js.map +1 -1
  104. package/lib/module/useScheduleUpdate.js +12 -10
  105. package/lib/module/useScheduleUpdate.js.map +1 -1
  106. package/lib/module/useStateForPath.js +1 -1
  107. package/lib/module/useStateForPath.js.map +1 -1
  108. package/lib/module/useSyncState.js +37 -15
  109. package/lib/module/useSyncState.js.map +1 -1
  110. package/lib/module/validatePathConfig.js +50 -36
  111. package/lib/module/validatePathConfig.js.map +1 -1
  112. package/lib/typescript/src/BaseNavigationContainer.d.ts +6 -3
  113. package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
  114. package/lib/typescript/src/ConsumedParamsContext.d.ts +3 -0
  115. package/lib/typescript/src/ConsumedParamsContext.d.ts.map +1 -0
  116. package/lib/typescript/src/DataLoading.d.ts +21 -0
  117. package/lib/typescript/src/DataLoading.d.ts.map +1 -0
  118. package/lib/typescript/src/EnsureSingleNavigator.d.ts +1 -1
  119. package/lib/typescript/src/EnsureSingleNavigator.d.ts.map +1 -1
  120. package/lib/typescript/src/Group.d.ts +1 -1
  121. package/lib/typescript/src/Group.d.ts.map +1 -1
  122. package/lib/typescript/src/NavigationBuilderContext.d.ts +22 -14
  123. package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
  124. package/lib/typescript/src/NavigationContainerRefContext.d.ts +1 -1
  125. package/lib/typescript/src/NavigationContainerRefContext.d.ts.map +1 -1
  126. package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts +4 -4
  127. package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts.map +1 -1
  128. package/lib/typescript/src/NavigationHelpersContext.d.ts +1 -1
  129. package/lib/typescript/src/NavigationHelpersContext.d.ts.map +1 -1
  130. package/lib/typescript/src/NavigationIndependentTree.d.ts +1 -1
  131. package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
  132. package/lib/typescript/src/NavigationProvider.d.ts +21 -18
  133. package/lib/typescript/src/NavigationProvider.d.ts.map +1 -1
  134. package/lib/typescript/src/NavigationRootContext.d.ts +8 -0
  135. package/lib/typescript/src/NavigationRootContext.d.ts.map +1 -0
  136. package/lib/typescript/src/NavigationStateContext.d.ts +3 -3
  137. package/lib/typescript/src/NavigationStateContext.d.ts.map +1 -1
  138. package/lib/typescript/src/PreventRemoveContext.d.ts +1 -0
  139. package/lib/typescript/src/PreventRemoveContext.d.ts.map +1 -1
  140. package/lib/typescript/src/PreventRemoveProvider.d.ts +1 -1
  141. package/lib/typescript/src/PreventRemoveProvider.d.ts.map +1 -1
  142. package/lib/typescript/src/SceneView.d.ts +5 -2
  143. package/lib/typescript/src/SceneView.d.ts.map +1 -1
  144. package/lib/typescript/src/Screen.d.ts +1 -1
  145. package/lib/typescript/src/Screen.d.ts.map +1 -1
  146. package/lib/typescript/src/StaticContainer.d.ts +1 -1
  147. package/lib/typescript/src/StaticContainer.d.ts.map +1 -1
  148. package/lib/typescript/src/StaticNavigation.d.ts +189 -111
  149. package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
  150. package/lib/typescript/src/StaticTreeContext.d.ts +4 -0
  151. package/lib/typescript/src/StaticTreeContext.d.ts.map +1 -0
  152. package/lib/typescript/src/createNavigationContainerRef.d.ts +1 -1
  153. package/lib/typescript/src/createNavigationContainerRef.d.ts.map +1 -1
  154. package/lib/typescript/src/createNavigatorFactory.d.ts +23 -5
  155. package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
  156. package/lib/typescript/src/findFocusedRoute.d.ts +3 -8
  157. package/lib/typescript/src/findFocusedRoute.d.ts.map +1 -1
  158. package/lib/typescript/src/getActionFromState.d.ts +4 -4
  159. package/lib/typescript/src/getActionFromState.d.ts.map +1 -1
  160. package/lib/typescript/src/getPathFromState.d.ts +3 -3
  161. package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
  162. package/lib/typescript/src/getPatternParts.d.ts +5 -2
  163. package/lib/typescript/src/getPatternParts.d.ts.map +1 -1
  164. package/lib/typescript/src/getStateFromPath.d.ts +4 -7
  165. package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
  166. package/lib/typescript/src/getStateFromRouteParams.d.ts +3 -0
  167. package/lib/typescript/src/getStateFromRouteParams.d.ts.map +1 -0
  168. package/lib/typescript/src/index.d.ts +36 -33
  169. package/lib/typescript/src/index.d.ts.map +1 -1
  170. package/lib/typescript/src/internal.d.ts +3 -0
  171. package/lib/typescript/src/internal.d.ts.map +1 -0
  172. package/lib/typescript/src/isRecordEqual.d.ts.map +1 -1
  173. package/lib/typescript/src/queryString.d.ts +5 -0
  174. package/lib/typescript/src/queryString.d.ts.map +1 -0
  175. package/lib/typescript/src/theming/ThemeContext.d.ts +1 -1
  176. package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -1
  177. package/lib/typescript/src/theming/ThemeProvider.d.ts +2 -2
  178. package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -1
  179. package/lib/typescript/src/theming/useTheme.d.ts +1 -1
  180. package/lib/typescript/src/theming/useTheme.d.ts.map +1 -1
  181. package/lib/typescript/src/types.d.ts +265 -167
  182. package/lib/typescript/src/types.d.ts.map +1 -1
  183. package/lib/typescript/src/useChildListeners.d.ts +3 -3
  184. package/lib/typescript/src/useChildListeners.d.ts.map +1 -1
  185. package/lib/typescript/src/useDescriptors.d.ts +13 -11
  186. package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
  187. package/lib/typescript/src/useEventEmitter.d.ts +2 -2
  188. package/lib/typescript/src/useEventEmitter.d.ts.map +1 -1
  189. package/lib/typescript/src/useFocusEffect.d.ts.map +1 -1
  190. package/lib/typescript/src/useFocusEvents.d.ts +2 -2
  191. package/lib/typescript/src/useFocusEvents.d.ts.map +1 -1
  192. package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +2 -2
  193. package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts.map +1 -1
  194. package/lib/typescript/src/useIsFocused.d.ts +4 -0
  195. package/lib/typescript/src/useIsFocused.d.ts.map +1 -1
  196. package/lib/typescript/src/useKeyedChildListeners.d.ts +4 -3
  197. package/lib/typescript/src/useKeyedChildListeners.d.ts.map +1 -1
  198. package/lib/typescript/src/useLazyValue.d.ts.map +1 -1
  199. package/lib/typescript/src/useNavigation.d.ts +4 -2
  200. package/lib/typescript/src/useNavigation.d.ts.map +1 -1
  201. package/lib/typescript/src/useNavigationBuilder.d.ts +22 -63
  202. package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
  203. package/lib/typescript/src/useNavigationCache.d.ts +6 -5
  204. package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
  205. package/lib/typescript/src/useNavigationContainerRef.d.ts +1 -1
  206. package/lib/typescript/src/useNavigationContainerRef.d.ts.map +1 -1
  207. package/lib/typescript/src/useNavigationHelpers.d.ts +18 -58
  208. package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
  209. package/lib/typescript/src/useNavigationState.d.ts +19 -3
  210. package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
  211. package/lib/typescript/src/useOnAction.d.ts +9 -9
  212. package/lib/typescript/src/useOnAction.d.ts.map +1 -1
  213. package/lib/typescript/src/useOnGetNavigation.d.ts +12 -0
  214. package/lib/typescript/src/useOnGetNavigation.d.ts.map +1 -0
  215. package/lib/typescript/src/useOnGetState.d.ts +1 -1
  216. package/lib/typescript/src/useOnGetState.d.ts.map +1 -1
  217. package/lib/typescript/src/useOnPreventRemove.d.ts +5 -9
  218. package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
  219. package/lib/typescript/src/useOnRouteFocus.d.ts +6 -6
  220. package/lib/typescript/src/useOnRouteFocus.d.ts.map +1 -1
  221. package/lib/typescript/src/useOptionsGetters.d.ts +4 -4
  222. package/lib/typescript/src/useOptionsGetters.d.ts.map +1 -1
  223. package/lib/typescript/src/usePreventRemove.d.ts.map +1 -1
  224. package/lib/typescript/src/usePreventRemoveContext.d.ts +2 -1
  225. package/lib/typescript/src/usePreventRemoveContext.d.ts.map +1 -1
  226. package/lib/typescript/src/useRegisterNavigator.d.ts.map +1 -1
  227. package/lib/typescript/src/useRoute.d.ts +7 -3
  228. package/lib/typescript/src/useRoute.d.ts.map +1 -1
  229. package/lib/typescript/src/useRouteCache.d.ts +7 -12
  230. package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
  231. package/lib/typescript/src/useScheduleUpdate.d.ts +5 -4
  232. package/lib/typescript/src/useScheduleUpdate.d.ts.map +1 -1
  233. package/lib/typescript/src/useStateForPath.d.ts +1 -1
  234. package/lib/typescript/src/useStateForPath.d.ts.map +1 -1
  235. package/lib/typescript/src/useSyncState.d.ts +1 -0
  236. package/lib/typescript/src/useSyncState.d.ts.map +1 -1
  237. package/lib/typescript/src/utilities.d.ts +79 -39
  238. package/lib/typescript/src/utilities.d.ts.map +1 -1
  239. package/lib/typescript/src/validatePathConfig.d.ts.map +1 -1
  240. package/package.json +26 -22
  241. package/src/BaseNavigationContainer.tsx +459 -332
  242. package/src/ConsumedParamsContext.tsx +5 -0
  243. package/src/DataLoading.tsx +206 -0
  244. package/src/NavigationBuilderContext.tsx +44 -25
  245. package/src/NavigationFocusedRouteStateContext.tsx +4 -4
  246. package/src/NavigationIndependentTree.tsx +60 -12
  247. package/src/NavigationProvider.tsx +59 -21
  248. package/src/NavigationRootContext.tsx +11 -0
  249. package/src/NavigationStateContext.tsx +6 -6
  250. package/src/PreventRemoveContext.tsx +1 -0
  251. package/src/PreventRemoveProvider.tsx +55 -56
  252. package/src/SceneView.tsx +31 -57
  253. package/src/StaticNavigation.tsx +715 -328
  254. package/src/StaticTreeContext.tsx +7 -0
  255. package/src/createNavigationContainerRef.tsx +12 -11
  256. package/src/createNavigatorFactory.tsx +92 -8
  257. package/src/findFocusedRoute.tsx +16 -16
  258. package/src/getActionFromState.tsx +87 -51
  259. package/src/getPathFromState.tsx +310 -134
  260. package/src/getPatternParts.tsx +98 -16
  261. package/src/getStateFromPath.tsx +971 -344
  262. package/src/getStateFromRouteParams.tsx +59 -0
  263. package/src/index.tsx +57 -6
  264. package/src/internal.tsx +2 -0
  265. package/src/isRecordEqual.tsx +3 -1
  266. package/src/queryString.ts +109 -0
  267. package/src/theming/useTheme.tsx +1 -1
  268. package/src/types.tsx +799 -377
  269. package/src/useDescriptors.tsx +151 -43
  270. package/src/useEventEmitter.tsx +53 -39
  271. package/src/useFocusEffect.tsx +5 -2
  272. package/src/useFocusEvents.tsx +19 -8
  273. package/src/useFocusedListenersChildrenAdapter.tsx +3 -3
  274. package/src/useIsFocused.tsx +18 -21
  275. package/src/useKeyedChildListeners.tsx +5 -2
  276. package/src/useLazyValue.tsx +2 -2
  277. package/src/useNavigation.tsx +9 -26
  278. package/src/useNavigationBuilder.tsx +370 -201
  279. package/src/useNavigationCache.tsx +148 -123
  280. package/src/useNavigationHelpers.tsx +27 -37
  281. package/src/useNavigationIndependentTree.tsx +1 -1
  282. package/src/useNavigationState.tsx +207 -69
  283. package/src/useOnAction.tsx +92 -18
  284. package/src/useOnGetNavigation.tsx +30 -0
  285. package/src/useOnGetState.tsx +8 -4
  286. package/src/useOnPreventRemove.tsx +78 -43
  287. package/src/useOnRouteFocus.tsx +11 -15
  288. package/src/useOptionsGetters.tsx +44 -30
  289. package/src/usePreventRemove.tsx +13 -5
  290. package/src/usePreventRemoveContext.tsx +2 -2
  291. package/src/useRegisterNavigator.tsx +4 -4
  292. package/src/useRoute.tsx +20 -6
  293. package/src/useRouteCache.tsx +57 -35
  294. package/src/useScheduleUpdate.tsx +13 -11
  295. package/src/useStateForPath.tsx +1 -1
  296. package/src/useSyncState.tsx +39 -15
  297. package/src/utilities.tsx +151 -35
  298. package/src/validatePathConfig.tsx +86 -57
  299. package/lib/module/CurrentRenderContext.js +0 -10
  300. package/lib/module/CurrentRenderContext.js.map +0 -1
  301. package/lib/module/NavigationMetaContext.js +0 -15
  302. package/lib/module/NavigationMetaContext.js.map +0 -1
  303. package/lib/module/checkSerializable.js +0 -46
  304. package/lib/module/checkSerializable.js.map +0 -1
  305. package/lib/module/useComponent.js +0 -34
  306. package/lib/module/useComponent.js.map +0 -1
  307. package/lib/module/useCurrentRender.js +0 -19
  308. package/lib/module/useCurrentRender.js.map +0 -1
  309. package/lib/typescript/src/CurrentRenderContext.d.ts +0 -9
  310. package/lib/typescript/src/CurrentRenderContext.d.ts.map +0 -1
  311. package/lib/typescript/src/NavigationMetaContext.d.ts +0 -12
  312. package/lib/typescript/src/NavigationMetaContext.d.ts.map +0 -1
  313. package/lib/typescript/src/checkSerializable.d.ts +0 -10
  314. package/lib/typescript/src/checkSerializable.d.ts.map +0 -1
  315. package/lib/typescript/src/useComponent.d.ts +0 -7
  316. package/lib/typescript/src/useComponent.d.ts.map +0 -1
  317. package/lib/typescript/src/useCurrentRender.d.ts +0 -14
  318. package/lib/typescript/src/useCurrentRender.d.ts.map +0 -1
  319. package/src/CurrentRenderContext.tsx +0 -9
  320. package/src/NavigationMetaContext.tsx +0 -14
  321. package/src/checkSerializable.tsx +0 -74
  322. package/src/useComponent.tsx +0 -37
  323. package/src/useCurrentRender.tsx +0 -31
@@ -24,12 +24,29 @@ const createStore = <T,>(getInitialState: () => T) => {
24
24
  let isBatching = false;
25
25
  let didUpdate = false;
26
26
 
27
+ const notify = () => {
28
+ let error: { value: unknown } | undefined;
29
+
30
+ listeners.forEach((listener) => {
31
+ try {
32
+ listener();
33
+ } catch (e) {
34
+ error = error ?? { value: e };
35
+ }
36
+ });
37
+
38
+ if (error) {
39
+ throw error.value;
40
+ }
41
+ };
42
+
27
43
  const setState = (newState: T) => {
28
44
  state = deepFreeze(newState);
29
- didUpdate = true;
30
45
 
31
- if (!isBatching) {
32
- listeners.forEach((listener) => listener());
46
+ if (isBatching) {
47
+ didUpdate = true;
48
+ } else {
49
+ notify();
33
50
  }
34
51
  };
35
52
 
@@ -43,12 +60,16 @@ const createStore = <T,>(getInitialState: () => T) => {
43
60
 
44
61
  const batchUpdates = (callback: () => void) => {
45
62
  isBatching = true;
46
- callback();
47
- isBatching = false;
48
63
 
49
- if (didUpdate) {
50
- didUpdate = false;
51
- listeners.forEach((listener) => listener());
64
+ try {
65
+ callback();
66
+ } finally {
67
+ isBatching = false;
68
+
69
+ if (didUpdate) {
70
+ didUpdate = false;
71
+ notify();
72
+ }
52
73
  }
53
74
  };
54
75
 
@@ -87,21 +108,23 @@ export function useSyncState<T>(getInitialState: () => T) {
87
108
  return unsubscribe;
88
109
  }, [store]);
89
110
 
90
- const pendingUpdatesRef = React.useRef<(() => void)[]>([]);
111
+ const pendingUpdates = useLazyValue(() => new Set<() => void>());
91
112
 
92
113
  const scheduleUpdate = useLatestCallback((callback: () => void) => {
93
- pendingUpdatesRef.current.push(callback);
114
+ pendingUpdates.add(callback);
94
115
  });
95
116
 
96
117
  const flushUpdates = useLatestCallback(() => {
97
- const pendingUpdates = pendingUpdatesRef.current;
118
+ if (pendingUpdates.size !== 0) {
119
+ // Updates are queued child-first as insertion effects run bottom-up.
120
+ // The root navigator replaces the whole state while nested navigators merge into it.
121
+ // So we apply them root-first to avoid the root clobbering nested updates.
122
+ const callbacks = Array.from(pendingUpdates).reverse();
98
123
 
99
- pendingUpdatesRef.current = [];
124
+ pendingUpdates.clear();
100
125
 
101
- if (pendingUpdates.length !== 0) {
102
126
  store.batchUpdates(() => {
103
- // Flush all the pending updates
104
- for (const update of pendingUpdates) {
127
+ for (const update of callbacks) {
105
128
  update();
106
129
  }
107
130
  });
@@ -114,6 +137,7 @@ export function useSyncState<T>(getInitialState: () => T) {
114
137
  state,
115
138
  getState: store.getState,
116
139
  setState: store.setState,
140
+ subscribe: store.subscribe,
117
141
  scheduleUpdate,
118
142
  flushUpdates,
119
143
  } as const;
package/src/utilities.tsx CHANGED
@@ -15,6 +15,39 @@ export type KeysOf<T> = T extends {} ? keyof T : never;
15
15
  */
16
16
  export type KeyOf<T extends {}> = Extract<keyof T, string>;
17
17
 
18
+ /**
19
+ * TS only checks object literals for excess properties when they are not generic.
20
+ * When an object is captured as a generic type, unknown keys are not caught.
21
+ * This builds a type from the provided object where any key not in the allowed type has the type `never`.
22
+ * Checking the provided object against this type then produces an error for each unknown key.
23
+ *
24
+ * When `Provided` has a string index signature (e.g. a type built from `any`,
25
+ * whose `keyof` includes `string`), there are no specific excess keys to flag,
26
+ * so this resolves to an empty type to avoid marking every key as `never`.
27
+ */
28
+ export type NoExcessObject<Provided, Allowed> = string extends keyof Provided
29
+ ? {}
30
+ : Record<Exclude<keyof Provided, keyof Allowed>, never>;
31
+
32
+ /**
33
+ * Check an object captured as a generic type against an allowed type,
34
+ * e.g. an object returned from a callback isn't checked for excess properties.
35
+ */
36
+ export type NoExcessCallbackReturn<
37
+ Provided extends {},
38
+ Allowed extends {},
39
+ > = Allowed & Provided & NoExcessObject<Provided, Allowed>;
40
+
41
+ /**
42
+ * Apply excess property checking to a value,
43
+ * or to the return value if the value is a function.
44
+ */
45
+ export type NoExcessValue<Provided, Allowed extends {}> = Provided extends (
46
+ ...args: never[]
47
+ ) => infer Return
48
+ ? (...args: never[]) => Allowed & NoExcessObject<Return, Allowed>
49
+ : NoExcessObject<Provided, Allowed>;
50
+
18
51
  /**
19
52
  * We get a union type when using keyof, but we want an intersection instead.
20
53
  * https://stackoverflow.com/a/50375286/1665026
@@ -25,8 +58,6 @@ export type UnionToIntersection<U> = (
25
58
  ? I
26
59
  : never;
27
60
 
28
- export type UnknownToUndefined<T> = unknown extends T ? undefined : T;
29
-
30
61
  /**
31
62
  * Exclude undefined from a type.
32
63
  * Similar to NonNullable but only excludes undefined, not null.
@@ -35,6 +66,33 @@ export type NotUndefined<T> = T extends undefined ? never : T;
35
66
 
36
67
  export type AnyToUnknown<T> = 0 extends 1 & T ? unknown : T;
37
68
 
69
+ export type RequiredKeys<T extends object> = {
70
+ [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
71
+ }[keyof T];
72
+
73
+ type OptionalKeys<T extends object> = Exclude<keyof T, RequiredKeys<T>>;
74
+
75
+ /**
76
+ * Remove `| undefined` from the object type,
77
+ * and adjust the optionality of the keys based on the original type.
78
+ */
79
+ export type NotUndefinedObject<
80
+ T extends object | undefined,
81
+ O extends object = NotUndefined<T>,
82
+ > = undefined extends T
83
+ ? {
84
+ [K in RequiredKeys<O>]: O[K];
85
+ } & {
86
+ [K in OptionalKeys<O>]?: O[K] | undefined;
87
+ }
88
+ : T;
89
+
90
+ export type UndefinedIfAllOptional<T> = T extends object
91
+ ? RequiredKeys<T> extends never
92
+ ? T | undefined
93
+ : T
94
+ : T;
95
+
38
96
  /**
39
97
  * Check if a function type has arguments.
40
98
  */
@@ -62,61 +120,119 @@ type StripRegex<Param extends string> = Param extends `${infer Name}(${string})`
62
120
  type ExtractSegmentParam<Segment extends string> =
63
121
  Segment extends `:${infer Param}?`
64
122
  ? { [K in StripRegex<Param>]?: string }
65
- : Segment extends `:${infer Param}`
123
+ : Segment extends `:${infer Param}${'+' | '*'}`
66
124
  ? { [K in StripRegex<Param>]: string }
67
- : {};
125
+ : Segment extends `:${infer Param}`
126
+ ? { [K in StripRegex<Param>]: string }
127
+ : {};
128
+
129
+ export type StandardSchemaValidationResult<Output> =
130
+ | { value: Output; issues?: undefined }
131
+ | { value?: undefined; issues: readonly unknown[] };
132
+
133
+ export type StandardSchemaV1<Input = unknown, Output = Input> = {
134
+ readonly '~standard': {
135
+ readonly version: 1;
136
+ readonly vendor: string;
137
+ readonly validate: (
138
+ value: Input
139
+ ) =>
140
+ | StandardSchemaValidationResult<Output>
141
+ | Promise<StandardSchemaValidationResult<Output>>;
142
+ };
143
+ };
144
+
145
+ export type QueryParamInput = string | string[] | null | undefined;
68
146
 
69
147
  /**
70
148
  * Extract path params from a path string.
71
149
  * e.g. `/foo/:userId/:postId` -> `{ userId: string; postId: string }`
72
150
  * Supports optional params with `?` suffix.
151
+ * Supports repeated params with `+` and `*` suffixes as strings.
73
152
  * Params must start with `:` at the beginning of a segment (after `/`).
74
153
  */
75
- export type ExtractParamStrings<Path extends string> =
154
+ type ExtractParamStrings<Path extends string> =
76
155
  Path extends `${infer Segment}/${infer Rest}`
77
156
  ? ExtractSegmentParam<Segment> & ExtractParamStrings<Rest>
78
157
  : ExtractSegmentParam<Path>;
79
158
 
80
159
  /**
81
- * Extract the parsed params type from base params and parse functions.
82
- * Applies the return type of parse functions to the corresponding params.
160
+ * Get the type of params based on the `parse` config and the path pattern.
83
161
  */
84
- export type ExtractParamsType<Params, Parse> = {
162
+ type ExtractParamsType<Params, Parse> = {
163
+ /**
164
+ * Base param types from path pattern
165
+ * Refine the type based on standard schema, then parse function
166
+ * Otherwise, use the type from path pattern
167
+ */
85
168
  [K in keyof Params]: K extends keyof Parse
86
- ? Parse[K] extends (value: string) => infer R
169
+ ? Parse[K] extends StandardSchemaV1<unknown, infer R>
87
170
  ? R
88
- : Params[K]
171
+ : Parse[K] extends (value: string) => infer R
172
+ ? R
173
+ : Params[K]
89
174
  : Params[K];
90
- };
175
+ } & // Query params are the parse keys not present in the path pattern. When there
176
+ // are none (the common case), skip building the query param mapped types.
177
+ ([Exclude<keyof Parse, keyof Params>] extends [never]
178
+ ? {}
179
+ : {
180
+ /**
181
+ * Optional param types not in path pattern (for query params)
182
+ */
183
+ [K in QueryParamOptionalKeys<Params, Parse>]?: QueryParamValue<
184
+ Parse[K]
185
+ >;
186
+ } & {
187
+ /**
188
+ * Required param types not in path pattern (for query params)
189
+ */
190
+ [K in QueryParamRequiredKeys<Params, Parse>]: QueryParamValue<Parse[K]>;
191
+ });
91
192
 
92
- /**
93
- * Infer the path string from a linking config.
94
- */
95
- export type InferPath<T> = T extends { path: infer P extends string }
96
- ? P
97
- : never;
193
+ type QueryParamValue<ParseValue> =
194
+ ParseValue extends StandardSchemaV1<unknown, infer R>
195
+ ? R
196
+ : ParseValue extends (value: string) => infer R
197
+ ? R
198
+ : never;
98
199
 
99
200
  /**
100
- * Infer the parse functions from a linking config.
201
+ * For schema, it's optional if the output has `undefined`, otherwise required
202
+ * For parse function, it's always optional as it can't say if it's required or not
101
203
  */
102
- export type InferParse<T> = T extends { parse: infer P } ? P : {};
204
+ type QueryParamOptionalKeys<Params, Parse> = {
205
+ [K in Exclude<keyof Parse, keyof Params>]: Parse[K] extends StandardSchemaV1<
206
+ unknown,
207
+ infer R
208
+ >
209
+ ? undefined extends R
210
+ ? K
211
+ : never
212
+ : Parse[K] extends (value: string) => unknown
213
+ ? K
214
+ : never;
215
+ }[Exclude<keyof Parse, keyof Params>];
103
216
 
104
217
  /**
105
- * Infer the params type from a screen component or nested navigator.
218
+ * Exclude optional keys to get required keys
219
+ * For schema, it's required if the output doesn't have `undefined`, otherwise optional
220
+ * It doesn't include parse functions (as they are always optional)
106
221
  */
107
- export type InferScreenParams<T> =
108
- T extends React.ComponentType<{ route: { params: infer P } }>
109
- ? P
110
- : T extends { config: { screens: infer Screens } }
111
- ? import('./types').NavigatorScreenParams<{
112
- [K in keyof Screens]: Screens[K] extends React.ComponentType<{
113
- route: { params: infer P };
114
- }>
115
- ? P
116
- : Screens[K] extends { screen: infer S }
117
- ? S extends React.ComponentType<{ route: { params: infer P } }>
118
- ? P
119
- : undefined
120
- : undefined;
121
- }>
222
+ type QueryParamRequiredKeys<Params, Parse> = Exclude<
223
+ Exclude<keyof Parse, keyof Params>,
224
+ QueryParamOptionalKeys<Params, Parse>
225
+ >;
226
+
227
+ export type InferParamsFromLinking<T> = T extends {
228
+ path: infer P extends string;
229
+ parse: infer Parse;
230
+ }
231
+ ? UndefinedIfAllOptional<ExtractParamsType<ExtractParamStrings<P>, Parse>>
232
+ : T extends {
233
+ path: infer P extends string;
234
+ }
235
+ ? UndefinedIfAllOptional<ExtractParamStrings<P>>
236
+ : T extends string
237
+ ? UndefinedIfAllOptional<ExtractParamStrings<T>>
122
238
  : undefined;
@@ -1,23 +1,39 @@
1
- const formatToList = (items: Record<string, string>) =>
2
- Object.entries(items)
3
- .map(([key, value]) => `- ${key} (${value})`)
4
- .join('\n');
1
+ const ROOT_VALIDATION_LIST = [
2
+ '- path (string)',
3
+ '- initialRouteName (string)',
4
+ '- screens (object)',
5
+ ].join('\n');
5
6
 
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
- alias: 'array',
15
- exact: 'boolean',
16
- stringify: 'object',
17
- parse: 'object',
18
- }),
19
- };
7
+ const NESTED_VALIDATION_LIST = [
8
+ ROOT_VALIDATION_LIST,
9
+ '- alias (array)',
10
+ '- exact (boolean)',
11
+ '- stringify (object)',
12
+ '- parse (object)',
13
+ '- shared (boolean)',
14
+ ].join('\n');
15
+
16
+ const getValidationType = (key: string, root: boolean) => {
17
+ switch (key) {
18
+ case 'path':
19
+ case 'initialRouteName':
20
+ return 'string';
21
+ case 'screens':
22
+ return 'object';
23
+ case 'alias':
24
+ return root ? undefined : 'array';
25
+ case 'exact':
26
+ case 'shared':
27
+ return root ? undefined : 'boolean';
28
+ case 'stringify':
29
+ case 'parse':
30
+ return root ? undefined : 'object';
31
+ default:
32
+ return undefined;
33
+ }
34
+ };
20
35
 
36
+ export function validatePathConfig(config: unknown, root = true) {
21
37
  if (typeof config !== 'object' || config === null) {
22
38
  throw new Error(
23
39
  `Expected the configuration to be an object, but got ${JSON.stringify(
@@ -26,58 +42,71 @@ export function validatePathConfig(config: unknown, root = true) {
26
42
  );
27
43
  }
28
44
 
29
- const validationErrors = Object.fromEntries(
30
- Object.keys(config)
31
- .map((key) => {
32
- if (key in validation) {
33
- const type = validation[key as keyof typeof validation];
34
- // @ts-expect-error: we know the key exists
35
- const value = config[key];
36
-
37
- if (value !== undefined) {
38
- if (type === 'array') {
39
- if (!Array.isArray(value)) {
40
- return [key, `expected 'Array', got '${typeof value}'`];
41
- }
42
- } else if (typeof value !== type) {
43
- return [key, `expected '${type}', got '${typeof value}'`];
44
- }
45
- }
46
- } else {
47
- return [key, 'extraneous'];
48
- }
49
-
50
- return null;
51
- })
52
- .filter(Boolean) as [string, string][]
53
- );
54
-
55
- if (Object.keys(validationErrors).length) {
45
+ const pathConfig = config as Record<string, unknown>;
46
+
47
+ let validationErrors: string[] | undefined;
48
+
49
+ for (const key in pathConfig) {
50
+ const type = getValidationType(key, root);
51
+
52
+ if (type === undefined) {
53
+ (validationErrors ??= []).push(`- ${key} (extraneous)`);
54
+ continue;
55
+ }
56
+
57
+ const value = pathConfig[key];
58
+
59
+ if (value === undefined) {
60
+ continue;
61
+ }
62
+
63
+ if (type === 'array') {
64
+ if (!Array.isArray(value)) {
65
+ (validationErrors ??= []).push(
66
+ `- ${key} (expected 'Array', got '${typeof value}')`
67
+ );
68
+ }
69
+ } else if (typeof value !== type) {
70
+ (validationErrors ??= []).push(
71
+ `- ${key} (expected '${type}', got '${typeof value}')`
72
+ );
73
+ }
74
+ }
75
+
76
+ if (validationErrors) {
56
77
  throw new Error(
57
- `Found invalid properties in the configuration:\n${formatToList(
58
- validationErrors
59
- )}\n\nYou can only specify the following properties:\n${formatToList(
60
- validation
61
- )}\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.`
78
+ `Found invalid properties in the configuration:\n${validationErrors.join(
79
+ '\n'
80
+ )}\n\nYou can only specify the following properties:\n${
81
+ root ? ROOT_VALIDATION_LIST : NESTED_VALIDATION_LIST
82
+ }\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.`
62
83
  );
63
84
  }
64
85
 
86
+ const path = pathConfig.path;
87
+
65
88
  if (
66
89
  root &&
67
- 'path' in config &&
68
- typeof config.path === 'string' &&
69
- config.path.includes(':')
90
+ 'path' in pathConfig &&
91
+ typeof path === 'string' &&
92
+ path.includes(':')
70
93
  ) {
71
94
  throw new Error(
72
- `Found invalid path '${config.path}'. The 'path' in the top-level configuration cannot contain patterns for params.`
95
+ `Found invalid path '${path}'. The 'path' in the top-level configuration cannot contain patterns for params.`
73
96
  );
74
97
  }
75
98
 
76
- if ('screens' in config && config.screens) {
77
- Object.entries(config.screens).forEach(([_, value]) => {
99
+ const screens = pathConfig.screens;
100
+
101
+ if (screens && typeof screens === 'object') {
102
+ const screenConfig = screens as Record<string, unknown>;
103
+
104
+ for (const name in screenConfig) {
105
+ const value = screenConfig[name];
106
+
78
107
  if (typeof value !== 'string') {
79
108
  validatePathConfig(value, false);
80
109
  }
81
- });
110
+ }
82
111
  }
83
112
  }
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- import * as React from 'react';
4
-
5
- /**
6
- * Context which holds the values for the current navigation tree.
7
- * Intended for use in SSR. This is not safe to use on the client.
8
- */
9
- export const CurrentRenderContext = /*#__PURE__*/React.createContext(undefined);
10
- //# sourceMappingURL=CurrentRenderContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","CurrentRenderContext","createContext","undefined"],"sourceRoot":"../../src","sources":["CurrentRenderContext.tsx"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;;AAE9B;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,gBAAGD,KAAK,CAACE,aAAa,CAErDC,SAAS,CAAC","ignoreList":[]}
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- import * as React from 'react';
4
-
5
- /**
6
- * Context with additional metadata to pass to child navigator in a screen.
7
- * For example, child native stack to know it's inside native tabs.
8
- * So it doesn't implement features such as `popToTop` that are handled by native tabs.
9
- *
10
- * Consumers should not make any assumptions about the shape of the object.
11
- * It can be different depending on the navigator and may change without notice.
12
- * This is not intended to be used by application code.
13
- */
14
- export const NavigationMetaContext = /*#__PURE__*/React.createContext(undefined);
15
- //# sourceMappingURL=NavigationMetaContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","NavigationMetaContext","createContext","undefined"],"sourceRoot":"../../src","sources":["NavigationMetaContext.tsx"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;;AAE9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,qBAAqB,gBAAGD,KAAK,CAACE,aAAa,CACtDC,SACF,CAAC","ignoreList":[]}
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- const checkSerializableWithoutCircularReference = (o, seen, location) => {
4
- if (o === undefined || o === null || typeof o === 'boolean' || typeof o === 'number' || typeof o === 'string') {
5
- return {
6
- serializable: true
7
- };
8
- }
9
- if (Object.prototype.toString.call(o) !== '[object Object]' && !Array.isArray(o)) {
10
- return {
11
- serializable: false,
12
- location,
13
- reason: typeof o === 'function' ? 'Function' : String(o)
14
- };
15
- }
16
- if (seen.has(o)) {
17
- return {
18
- serializable: false,
19
- reason: 'Circular reference',
20
- location
21
- };
22
- }
23
- seen.add(o);
24
- if (Array.isArray(o)) {
25
- for (let i = 0; i < o.length; i++) {
26
- const childResult = checkSerializableWithoutCircularReference(o[i], new Set(seen), [...location, i]);
27
- if (!childResult.serializable) {
28
- return childResult;
29
- }
30
- }
31
- } else {
32
- for (const key in o) {
33
- const childResult = checkSerializableWithoutCircularReference(o[key], new Set(seen), [...location, key]);
34
- if (!childResult.serializable) {
35
- return childResult;
36
- }
37
- }
38
- }
39
- return {
40
- serializable: true
41
- };
42
- };
43
- export function checkSerializable(o) {
44
- return checkSerializableWithoutCircularReference(o, new Set(), []);
45
- }
46
- //# sourceMappingURL=checkSerializable.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["checkSerializableWithoutCircularReference","o","seen","location","undefined","serializable","Object","prototype","toString","call","Array","isArray","reason","String","has","add","i","length","childResult","Set","key","checkSerializable"],"sourceRoot":"../../src","sources":["checkSerializable.tsx"],"mappings":";;AAAA,MAAMA,yCAAyC,GAAGA,CAChDC,CAAyB,EACzBC,IAAc,EACdC,QAA6B,KAOtB;EACP,IACEF,CAAC,KAAKG,SAAS,IACfH,CAAC,KAAK,IAAI,IACV,OAAOA,CAAC,KAAK,SAAS,IACtB,OAAOA,CAAC,KAAK,QAAQ,IACrB,OAAOA,CAAC,KAAK,QAAQ,EACrB;IACA,OAAO;MAAEI,YAAY,EAAE;IAAK,CAAC;EAC/B;EAEA,IACEC,MAAM,CAACC,SAAS,CAACC,QAAQ,CAACC,IAAI,CAACR,CAAC,CAAC,KAAK,iBAAiB,IACvD,CAACS,KAAK,CAACC,OAAO,CAACV,CAAC,CAAC,EACjB;IACA,OAAO;MACLI,YAAY,EAAE,KAAK;MACnBF,QAAQ;MACRS,MAAM,EAAE,OAAOX,CAAC,KAAK,UAAU,GAAG,UAAU,GAAGY,MAAM,CAACZ,CAAC;IACzD,CAAC;EACH;EAEA,IAAIC,IAAI,CAACY,GAAG,CAACb,CAAC,CAAC,EAAE;IACf,OAAO;MACLI,YAAY,EAAE,KAAK;MACnBO,MAAM,EAAE,oBAAoB;MAC5BT;IACF,CAAC;EACH;EAEAD,IAAI,CAACa,GAAG,CAACd,CAAC,CAAC;EAEX,IAAIS,KAAK,CAACC,OAAO,CAACV,CAAC,CAAC,EAAE;IACpB,KAAK,IAAIe,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGf,CAAC,CAACgB,MAAM,EAAED,CAAC,EAAE,EAAE;MACjC,MAAME,WAAW,GAAGlB,yCAAyC,CAC3DC,CAAC,CAACe,CAAC,CAAC,EACJ,IAAIG,GAAG,CAAMjB,IAAI,CAAC,EAClB,CAAC,GAAGC,QAAQ,EAAEa,CAAC,CACjB,CAAC;MAED,IAAI,CAACE,WAAW,CAACb,YAAY,EAAE;QAC7B,OAAOa,WAAW;MACpB;IACF;EACF,CAAC,MAAM;IACL,KAAK,MAAME,GAAG,IAAInB,CAAC,EAAE;MACnB,MAAMiB,WAAW,GAAGlB,yCAAyC,CAC3DC,CAAC,CAACmB,GAAG,CAAC,EACN,IAAID,GAAG,CAAMjB,IAAI,CAAC,EAClB,CAAC,GAAGC,QAAQ,EAAEiB,GAAG,CACnB,CAAC;MAED,IAAI,CAACF,WAAW,CAACb,YAAY,EAAE;QAC7B,OAAOa,WAAW;MACpB;IACF;EACF;EAEA,OAAO;IAAEb,YAAY,EAAE;EAAK,CAAC;AAC/B,CAAC;AAED,OAAO,SAASgB,iBAAiBA,CAACpB,CAAyB,EAAE;EAC3D,OAAOD,yCAAyC,CAACC,CAAC,EAAE,IAAIkB,GAAG,CAAM,CAAC,EAAE,EAAE,CAAC;AACzE","ignoreList":[]}
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- import * as React from 'react';
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- const NavigationContent = ({
6
- render,
7
- children
8
- }) => {
9
- return render(children);
10
- };
11
- export function useComponent(render) {
12
- const renderRef = React.useRef(render);
13
-
14
- // Normally refs shouldn't be mutated in render
15
- // But we return a component which will be rendered
16
- // So it's just for immediate consumption
17
- renderRef.current = render;
18
- React.useEffect(() => {
19
- renderRef.current = null;
20
- });
21
- return React.useRef(({
22
- children
23
- }) => {
24
- const render = renderRef.current;
25
- if (render === null) {
26
- throw new Error('The returned component must be rendered in the same render phase as the hook.');
27
- }
28
- return /*#__PURE__*/_jsx(NavigationContent, {
29
- render: render,
30
- children: children
31
- });
32
- }).current;
33
- }
34
- //# sourceMappingURL=useComponent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","jsx","_jsx","NavigationContent","render","children","useComponent","renderRef","useRef","current","useEffect","Error"],"sourceRoot":"../../src","sources":["useComponent.tsx"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAS/B,MAAMC,iBAAiB,GAAGA,CAAC;EAAEC,MAAM;EAAEC;AAAgB,CAAC,KAAK;EACzD,OAAOD,MAAM,CAACC,QAAQ,CAAC;AACzB,CAAC;AAED,OAAO,SAASC,YAAYA,CAACF,MAAc,EAAE;EAC3C,MAAMG,SAAS,GAAGP,KAAK,CAACQ,MAAM,CAAgBJ,MAAM,CAAC;;EAErD;EACA;EACA;EACAG,SAAS,CAACE,OAAO,GAAGL,MAAM;EAE1BJ,KAAK,CAACU,SAAS,CAAC,MAAM;IACpBH,SAAS,CAACE,OAAO,GAAG,IAAI;EAC1B,CAAC,CAAC;EAEF,OAAOT,KAAK,CAACQ,MAAM,CAAC,CAAC;IAAEH;EAAwC,CAAC,KAAK;IACnE,MAAMD,MAAM,GAAGG,SAAS,CAACE,OAAO;IAEhC,IAAIL,MAAM,KAAK,IAAI,EAAE;MACnB,MAAM,IAAIO,KAAK,CACb,+EACF,CAAC;IACH;IAEA,oBAAOT,IAAA,CAACC,iBAAiB;MAACC,MAAM,EAAEA,MAAO;MAAAC,QAAA,EAAEA;IAAQ,CAAoB,CAAC;EAC1E,CAAC,CAAC,CAACI,OAAO;AACZ","ignoreList":[]}
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- import * as React from 'react';
4
- import { CurrentRenderContext } from "./CurrentRenderContext.js";
5
- /**
6
- * Write the current options, so that server renderer can get current values
7
- * Mutating values like this is not safe in async mode, but it doesn't apply to SSR
8
- */
9
- export function useCurrentRender({
10
- state,
11
- navigation,
12
- descriptors
13
- }) {
14
- const current = React.useContext(CurrentRenderContext);
15
- if (current && navigation.isFocused()) {
16
- current.options = descriptors[state.routes[state.index].key].options;
17
- }
18
- }
19
- //# sourceMappingURL=useCurrentRender.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","CurrentRenderContext","useCurrentRender","state","navigation","descriptors","current","useContext","isFocused","options","routes","index","key"],"sourceRoot":"../../src","sources":["useCurrentRender.tsx"],"mappings":";;AACA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,SAASC,oBAAoB,QAAQ,2BAAwB;AAiB7D;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAAC;EAAEC,KAAK;EAAEC,UAAU;EAAEC;AAAqB,CAAC,EAAE;EAC5E,MAAMC,OAAO,GAAGN,KAAK,CAACO,UAAU,CAACN,oBAAoB,CAAC;EAEtD,IAAIK,OAAO,IAAIF,UAAU,CAACI,SAAS,CAAC,CAAC,EAAE;IACrCF,OAAO,CAACG,OAAO,GAAGJ,WAAW,CAACF,KAAK,CAACO,MAAM,CAACP,KAAK,CAACQ,KAAK,CAAC,CAACC,GAAG,CAAC,CAACH,OAAO;EACtE;AACF","ignoreList":[]}
@@ -1,9 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * Context which holds the values for the current navigation tree.
4
- * Intended for use in SSR. This is not safe to use on the client.
5
- */
6
- export declare const CurrentRenderContext: React.Context<{
7
- options?: object;
8
- } | undefined>;
9
- //# sourceMappingURL=CurrentRenderContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CurrentRenderContext.d.ts","sourceRoot":"","sources":["../../../src/CurrentRenderContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;GAGG;AACH,eAAO,MAAM,oBAAoB;cACnB,MAAM;cACR,CAAC"}