@react-navigation/core 8.0.0-alpha.34 → 8.0.0-alpha.35

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 (84) hide show
  1. package/README.md +17 -14
  2. package/lib/module/BaseNavigationContainer.js +14 -2
  3. package/lib/module/BaseNavigationContainer.js.map +1 -1
  4. package/lib/module/NavigationIndependentTree.js +9 -6
  5. package/lib/module/NavigationIndependentTree.js.map +1 -1
  6. package/lib/module/NavigationProvider.js +9 -4
  7. package/lib/module/NavigationProvider.js.map +1 -1
  8. package/lib/module/PreventRemoveProvider.js +2 -2
  9. package/lib/module/PreventRemoveProvider.js.map +1 -1
  10. package/lib/module/SceneView.js +2 -1
  11. package/lib/module/SceneView.js.map +1 -1
  12. package/lib/module/useDescriptors.js +7 -4
  13. package/lib/module/useDescriptors.js.map +1 -1
  14. package/lib/module/useFocusEffect.js +4 -2
  15. package/lib/module/useFocusEffect.js.map +1 -1
  16. package/lib/module/useFocusEvents.js +4 -2
  17. package/lib/module/useFocusEvents.js.map +1 -1
  18. package/lib/module/useIsFocused.js +1 -0
  19. package/lib/module/useIsFocused.js.map +1 -1
  20. package/lib/module/useNavigationBuilder.js +40 -37
  21. package/lib/module/useNavigationBuilder.js.map +1 -1
  22. package/lib/module/useNavigationCache.js +82 -78
  23. package/lib/module/useNavigationCache.js.map +1 -1
  24. package/lib/module/useNavigationState.js +48 -23
  25. package/lib/module/useNavigationState.js.map +1 -1
  26. package/lib/module/useOptionsGetters.js +18 -17
  27. package/lib/module/useOptionsGetters.js.map +1 -1
  28. package/lib/module/usePreventRemoveContext.js +1 -1
  29. package/lib/module/usePreventRemoveContext.js.map +1 -1
  30. package/lib/module/useRouteCache.js +43 -33
  31. package/lib/module/useRouteCache.js.map +1 -1
  32. package/lib/module/useScheduleUpdate.js +3 -1
  33. package/lib/module/useScheduleUpdate.js.map +1 -1
  34. package/lib/module/useSyncState.js +9 -10
  35. package/lib/module/useSyncState.js.map +1 -1
  36. package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
  37. package/lib/typescript/src/NavigationBuilderContext.d.ts +1 -1
  38. package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
  39. package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
  40. package/lib/typescript/src/NavigationProvider.d.ts.map +1 -1
  41. package/lib/typescript/src/PreventRemoveProvider.d.ts.map +1 -1
  42. package/lib/typescript/src/SceneView.d.ts +2 -1
  43. package/lib/typescript/src/SceneView.d.ts.map +1 -1
  44. package/lib/typescript/src/useDescriptors.d.ts +2 -2
  45. package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
  46. package/lib/typescript/src/useFocusEffect.d.ts.map +1 -1
  47. package/lib/typescript/src/useFocusEvents.d.ts.map +1 -1
  48. package/lib/typescript/src/useIsFocused.d.ts +1 -0
  49. package/lib/typescript/src/useIsFocused.d.ts.map +1 -1
  50. package/lib/typescript/src/useNavigationBuilder.d.ts +1 -3
  51. package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
  52. package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
  53. package/lib/typescript/src/useNavigationState.d.ts +1 -0
  54. package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
  55. package/lib/typescript/src/useOptionsGetters.d.ts +2 -4
  56. package/lib/typescript/src/useOptionsGetters.d.ts.map +1 -1
  57. package/lib/typescript/src/useRouteCache.d.ts +7 -12
  58. package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
  59. package/lib/typescript/src/useScheduleUpdate.d.ts.map +1 -1
  60. package/lib/typescript/src/useSyncState.d.ts.map +1 -1
  61. package/package.json +2 -2
  62. package/src/BaseNavigationContainer.tsx +19 -2
  63. package/src/NavigationBuilderContext.tsx +1 -1
  64. package/src/NavigationIndependentTree.tsx +16 -8
  65. package/src/NavigationProvider.tsx +13 -4
  66. package/src/PreventRemoveProvider.tsx +2 -8
  67. package/src/SceneView.tsx +3 -1
  68. package/src/useDescriptors.tsx +18 -5
  69. package/src/useFocusEffect.tsx +5 -2
  70. package/src/useFocusEvents.tsx +5 -2
  71. package/src/useIsFocused.tsx +4 -0
  72. package/src/useNavigationBuilder.tsx +53 -45
  73. package/src/useNavigationCache.tsx +127 -105
  74. package/src/useNavigationState.tsx +60 -29
  75. package/src/useOptionsGetters.tsx +24 -24
  76. package/src/usePreventRemoveContext.tsx +1 -1
  77. package/src/useRouteCache.tsx +49 -33
  78. package/src/useScheduleUpdate.tsx +4 -1
  79. package/src/useSyncState.tsx +9 -11
  80. package/lib/module/useComponent.js +0 -34
  81. package/lib/module/useComponent.js.map +0 -1
  82. package/lib/typescript/src/useComponent.d.ts +0 -7
  83. package/lib/typescript/src/useComponent.d.ts.map +0 -1
  84. package/src/useComponent.tsx +0 -37
@@ -108,25 +108,23 @@ export function useSyncState<T>(getInitialState: () => T) {
108
108
  return unsubscribe;
109
109
  }, [store]);
110
110
 
111
- const pendingUpdatesRef = React.useRef<(() => void)[]>([]);
111
+ const pendingUpdates = useLazyValue(() => new Set<() => void>());
112
112
 
113
113
  const scheduleUpdate = useLatestCallback((callback: () => void) => {
114
- pendingUpdatesRef.current.push(callback);
114
+ pendingUpdates.add(callback);
115
115
  });
116
116
 
117
117
  const flushUpdates = useLatestCallback(() => {
118
- 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();
119
123
 
120
- pendingUpdatesRef.current = [];
124
+ pendingUpdates.clear();
121
125
 
122
- if (pendingUpdates.length !== 0) {
123
126
  store.batchUpdates(() => {
124
- // Updates are queued child-first as insertion effects run bottom-up.
125
- // The root navigator replaces the whole state while nested navigators merge into it.
126
- // So we apply them root-first to avoid the root clobbering nested updates.
127
- pendingUpdates.reverse();
128
-
129
- for (const update of pendingUpdates) {
127
+ for (const update of callbacks) {
130
128
  update();
131
129
  }
132
130
  });
@@ -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,7 +0,0 @@
1
- import * as React from 'react';
2
- type Render = (children: React.ReactNode) => React.JSX.Element;
3
- export declare function useComponent(render: Render): ({ children }: {
4
- children: React.ReactNode;
5
- }) => React.JSX.Element;
6
- export {};
7
- //# sourceMappingURL=useComponent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useComponent.d.ts","sourceRoot":"","sources":["../../../src/useComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,KAAK,MAAM,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;AAW/D,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,kBAYN;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,uBAWjE"}
@@ -1,37 +0,0 @@
1
- import * as React from 'react';
2
-
3
- type Render = (children: React.ReactNode) => React.JSX.Element;
4
-
5
- type Props = {
6
- render: Render;
7
- children: React.ReactNode;
8
- };
9
-
10
- const NavigationContent = ({ render, children }: Props) => {
11
- return render(children);
12
- };
13
-
14
- export function useComponent(render: Render) {
15
- const renderRef = React.useRef<Render | null>(render);
16
-
17
- // Normally refs shouldn't be mutated in render
18
- // But we return a component which will be rendered
19
- // So it's just for immediate consumption
20
- renderRef.current = render;
21
-
22
- React.useEffect(() => {
23
- renderRef.current = null;
24
- });
25
-
26
- return React.useRef(({ children }: { children: React.ReactNode }) => {
27
- const render = renderRef.current;
28
-
29
- if (render === null) {
30
- throw new Error(
31
- 'The returned component must be rendered in the same render phase as the hook.'
32
- );
33
- }
34
-
35
- return <NavigationContent render={render}>{children}</NavigationContent>;
36
- }).current;
37
- }