react-native-screen-transitions 2.4.1 → 2.4.2-beta.0

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 (252) hide show
  1. package/lib/commonjs/__configs__/presets.js.map +1 -1
  2. package/lib/commonjs/components/root-transition-aware.js.map +1 -1
  3. package/lib/commonjs/constants.js.map +1 -1
  4. package/lib/commonjs/hooks/animation/use-screen-animation.js +9 -5
  5. package/lib/commonjs/hooks/animation/use-screen-animation.js.map +1 -1
  6. package/lib/commonjs/index.js +7 -0
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/integrations/blank-stack/components/Header.js +142 -0
  9. package/lib/commonjs/integrations/blank-stack/components/Header.js.map +1 -0
  10. package/lib/commonjs/integrations/blank-stack/components/Screens.js +64 -0
  11. package/lib/commonjs/integrations/blank-stack/components/Screens.js.map +1 -0
  12. package/lib/commonjs/integrations/blank-stack/components/StackView.js +94 -0
  13. package/lib/commonjs/integrations/blank-stack/components/StackView.js.map +1 -0
  14. package/lib/commonjs/integrations/blank-stack/navigators/createBlankStackNavigator.js +74 -0
  15. package/lib/commonjs/integrations/blank-stack/navigators/createBlankStackNavigator.js.map +1 -0
  16. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.js +66 -0
  17. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.js.map +1 -0
  18. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.js +16 -0
  19. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.js.map +1 -0
  20. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.js +208 -0
  21. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.js.map +1 -0
  22. package/lib/commonjs/{types/navigator.js → integrations/blank-stack/utils/with-stack-navigation/_types.js} +1 -1
  23. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_types.js.map +1 -0
  24. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.js +15 -0
  25. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.js.map +1 -0
  26. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.js +23 -0
  27. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.js.map +1 -0
  28. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.js +15 -0
  29. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.js.map +1 -0
  30. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.js +14 -0
  31. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.js.map +1 -0
  32. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.js +13 -0
  33. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.js.map +1 -0
  34. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/index.js +71 -0
  35. package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/index.js.map +1 -0
  36. package/lib/commonjs/integrations/native-stack/navigators/createNativeStackNavigator.js.map +1 -1
  37. package/lib/commonjs/integrations/native-stack/utils/getModalRoutesKeys.js.map +1 -1
  38. package/lib/commonjs/integrations/native-stack/utils/useInvalidPreventRemoveError.js.map +1 -1
  39. package/lib/commonjs/integrations/native-stack/views/NativeStackView.js.map +1 -1
  40. package/lib/commonjs/integrations/native-stack/views/NativeStackView.native.js.map +1 -1
  41. package/lib/commonjs/integrations/native-stack/views/useHeaderConfigProps.js.map +1 -1
  42. package/lib/commonjs/providers/keys.js.map +1 -1
  43. package/lib/commonjs/providers/screen-transition-provider.js.map +1 -1
  44. package/lib/commonjs/providers/transition-styles.js +18 -4
  45. package/lib/commonjs/providers/transition-styles.js.map +1 -1
  46. package/lib/commonjs/stores/animations.js.map +1 -1
  47. package/lib/commonjs/stores/bounds/index.js.map +1 -1
  48. package/lib/commonjs/stores/gestures.js.map +1 -1
  49. package/lib/commonjs/stores/utils/reset-stores-for-screen.js.map +1 -1
  50. package/lib/commonjs/types/blank-stack.navigator.js +6 -0
  51. package/lib/commonjs/types/{navigator.js.map → blank-stack.navigator.js.map} +1 -1
  52. package/lib/commonjs/types/native-stack.navigator.js +6 -0
  53. package/lib/commonjs/types/native-stack.navigator.js.map +1 -0
  54. package/lib/commonjs/utils/animation/derivations.js +1 -14
  55. package/lib/commonjs/utils/animation/derivations.js.map +1 -1
  56. package/lib/commonjs/utils/bounds/constants.js.map +1 -1
  57. package/lib/commonjs/utils/bounds/index.js +23 -90
  58. package/lib/commonjs/utils/bounds/index.js.map +1 -1
  59. package/lib/commonjs/utils/gesture/apply-offset-rules.js.map +1 -1
  60. package/lib/commonjs/utils/gesture/check-gesture-activation.js.map +1 -1
  61. package/lib/module/__configs__/presets.js.map +1 -1
  62. package/lib/module/components/root-transition-aware.js.map +1 -1
  63. package/lib/module/constants.js.map +1 -1
  64. package/lib/module/hooks/animation/use-screen-animation.js +9 -5
  65. package/lib/module/hooks/animation/use-screen-animation.js.map +1 -1
  66. package/lib/module/index.js +1 -0
  67. package/lib/module/index.js.map +1 -1
  68. package/lib/module/integrations/blank-stack/components/Header.js +138 -0
  69. package/lib/module/integrations/blank-stack/components/Header.js.map +1 -0
  70. package/lib/module/integrations/blank-stack/components/Screens.js +58 -0
  71. package/lib/module/integrations/blank-stack/components/Screens.js.map +1 -0
  72. package/lib/module/integrations/blank-stack/components/StackView.js +90 -0
  73. package/lib/module/integrations/blank-stack/components/StackView.js.map +1 -0
  74. package/lib/module/integrations/blank-stack/navigators/createBlankStackNavigator.js +68 -0
  75. package/lib/module/integrations/blank-stack/navigators/createBlankStackNavigator.js.map +1 -0
  76. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.js +60 -0
  77. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.js.map +1 -0
  78. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.js +11 -0
  79. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.js.map +1 -0
  80. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.js +202 -0
  81. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.js.map +1 -0
  82. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_types.js +4 -0
  83. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_types.js.map +1 -0
  84. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.js +10 -0
  85. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.js.map +1 -0
  86. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.js +19 -0
  87. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.js.map +1 -0
  88. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.js +10 -0
  89. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.js.map +1 -0
  90. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.js +9 -0
  91. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.js.map +1 -0
  92. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.js +8 -0
  93. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.js.map +1 -0
  94. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/index.js +65 -0
  95. package/lib/module/integrations/blank-stack/utils/with-stack-navigation/index.js.map +1 -0
  96. package/lib/module/integrations/native-stack/navigators/createNativeStackNavigator.js.map +1 -1
  97. package/lib/module/integrations/native-stack/utils/getModalRoutesKeys.js.map +1 -1
  98. package/lib/module/integrations/native-stack/utils/useInvalidPreventRemoveError.js.map +1 -1
  99. package/lib/module/integrations/native-stack/views/NativeStackView.js.map +1 -1
  100. package/lib/module/integrations/native-stack/views/NativeStackView.native.js.map +1 -1
  101. package/lib/module/integrations/native-stack/views/useHeaderConfigProps.js.map +1 -1
  102. package/lib/module/providers/keys.js.map +1 -1
  103. package/lib/module/providers/screen-transition-provider.js.map +1 -1
  104. package/lib/module/providers/transition-styles.js +19 -5
  105. package/lib/module/providers/transition-styles.js.map +1 -1
  106. package/lib/module/stores/animations.js.map +1 -1
  107. package/lib/module/stores/bounds/index.js.map +1 -1
  108. package/lib/module/stores/gestures.js.map +1 -1
  109. package/lib/module/stores/utils/reset-stores-for-screen.js.map +1 -1
  110. package/lib/module/types/blank-stack.navigator.js +4 -0
  111. package/lib/module/types/{navigator.js.map → blank-stack.navigator.js.map} +1 -1
  112. package/lib/module/types/native-stack.navigator.js +4 -0
  113. package/lib/module/types/native-stack.navigator.js.map +1 -0
  114. package/lib/module/utils/animation/derivations.js +1 -14
  115. package/lib/module/utils/animation/derivations.js.map +1 -1
  116. package/lib/module/utils/bounds/constants.js.map +1 -1
  117. package/lib/module/utils/bounds/index.js +24 -91
  118. package/lib/module/utils/bounds/index.js.map +1 -1
  119. package/lib/module/utils/gesture/apply-offset-rules.js.map +1 -1
  120. package/lib/module/utils/gesture/check-gesture-activation.js.map +1 -1
  121. package/lib/typescript/__configs__/index.d.ts +9 -9
  122. package/lib/typescript/__configs__/index.d.ts.map +1 -1
  123. package/lib/typescript/__configs__/presets.d.ts +1 -1
  124. package/lib/typescript/__configs__/presets.d.ts.map +1 -1
  125. package/lib/typescript/components/root-transition-aware.d.ts.map +1 -1
  126. package/lib/typescript/constants.d.ts +2 -2
  127. package/lib/typescript/constants.d.ts.map +1 -1
  128. package/lib/typescript/hooks/animation/use-screen-animation.d.ts +1 -1
  129. package/lib/typescript/hooks/animation/use-screen-animation.d.ts.map +1 -1
  130. package/lib/typescript/index.d.ts +20 -18
  131. package/lib/typescript/index.d.ts.map +1 -1
  132. package/lib/typescript/integrations/blank-stack/components/Header.d.ts +5 -0
  133. package/lib/typescript/integrations/blank-stack/components/Header.d.ts.map +1 -0
  134. package/lib/typescript/integrations/blank-stack/components/Screens.d.ts +15 -0
  135. package/lib/typescript/integrations/blank-stack/components/Screens.d.ts.map +1 -0
  136. package/lib/typescript/integrations/blank-stack/components/StackView.d.ts +2 -0
  137. package/lib/typescript/integrations/blank-stack/components/StackView.d.ts.map +1 -0
  138. package/lib/typescript/integrations/blank-stack/navigators/createBlankStackNavigator.d.ts +109 -0
  139. package/lib/typescript/integrations/blank-stack/navigators/createBlankStackNavigator.d.ts.map +1 -0
  140. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.d.ts +8 -0
  141. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.d.ts.map +1 -0
  142. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.d.ts +2 -0
  143. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.d.ts.map +1 -0
  144. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.d.ts +20 -0
  145. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.d.ts.map +1 -0
  146. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_types.d.ts +23 -0
  147. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_types.d.ts.map +1 -0
  148. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.d.ts +3 -0
  149. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.d.ts.map +1 -0
  150. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.d.ts +4 -0
  151. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.d.ts.map +1 -0
  152. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.d.ts +4 -0
  153. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.d.ts.map +1 -0
  154. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.d.ts +3 -0
  155. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.d.ts.map +1 -0
  156. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.d.ts +3 -0
  157. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.d.ts.map +1 -0
  158. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/index.d.ts +6 -0
  159. package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/index.d.ts.map +1 -0
  160. package/lib/typescript/integrations/native-stack/navigators/createNativeStackNavigator.d.ts +1 -1
  161. package/lib/typescript/integrations/native-stack/navigators/createNativeStackNavigator.d.ts.map +1 -1
  162. package/lib/typescript/integrations/native-stack/utils/getModalRoutesKeys.d.ts +1 -1
  163. package/lib/typescript/integrations/native-stack/utils/getModalRoutesKeys.d.ts.map +1 -1
  164. package/lib/typescript/integrations/native-stack/utils/useInvalidPreventRemoveError.d.ts +1 -1
  165. package/lib/typescript/integrations/native-stack/utils/useInvalidPreventRemoveError.d.ts.map +1 -1
  166. package/lib/typescript/integrations/native-stack/views/NativeStackView.d.ts +1 -1
  167. package/lib/typescript/integrations/native-stack/views/NativeStackView.d.ts.map +1 -1
  168. package/lib/typescript/integrations/native-stack/views/NativeStackView.native.d.ts +1 -1
  169. package/lib/typescript/integrations/native-stack/views/NativeStackView.native.d.ts.map +1 -1
  170. package/lib/typescript/integrations/native-stack/views/useHeaderConfigProps.d.ts +1 -1
  171. package/lib/typescript/integrations/native-stack/views/useHeaderConfigProps.d.ts.map +1 -1
  172. package/lib/typescript/providers/keys.d.ts +1 -1
  173. package/lib/typescript/providers/keys.d.ts.map +1 -1
  174. package/lib/typescript/providers/screen-transition-provider.d.ts +1 -1
  175. package/lib/typescript/providers/screen-transition-provider.d.ts.map +1 -1
  176. package/lib/typescript/providers/transition-styles.d.ts.map +1 -1
  177. package/lib/typescript/stores/animations.d.ts +1 -1
  178. package/lib/typescript/stores/animations.d.ts.map +1 -1
  179. package/lib/typescript/stores/bounds/index.d.ts +1 -1
  180. package/lib/typescript/stores/bounds/index.d.ts.map +1 -1
  181. package/lib/typescript/stores/gestures.d.ts +1 -1
  182. package/lib/typescript/stores/gestures.d.ts.map +1 -1
  183. package/lib/typescript/stores/utils/reset-stores-for-screen.d.ts +1 -1
  184. package/lib/typescript/stores/utils/reset-stores-for-screen.d.ts.map +1 -1
  185. package/lib/typescript/types/animation.d.ts +2 -4
  186. package/lib/typescript/types/animation.d.ts.map +1 -1
  187. package/lib/typescript/types/blank-stack.navigator.d.ts +219 -0
  188. package/lib/typescript/types/blank-stack.navigator.d.ts.map +1 -0
  189. package/lib/typescript/types/bounds.d.ts +0 -57
  190. package/lib/typescript/types/bounds.d.ts.map +1 -1
  191. package/lib/typescript/types/{navigator.d.ts → native-stack.navigator.d.ts} +5 -1
  192. package/lib/typescript/types/native-stack.navigator.d.ts.map +1 -0
  193. package/lib/typescript/utils/animation/derivations.d.ts +1 -4
  194. package/lib/typescript/utils/animation/derivations.d.ts.map +1 -1
  195. package/lib/typescript/utils/bounds/_types/builder.d.ts +2 -2
  196. package/lib/typescript/utils/bounds/_types/builder.d.ts.map +1 -1
  197. package/lib/typescript/utils/bounds/_utils/geometry.d.ts +2 -2
  198. package/lib/typescript/utils/bounds/_utils/geometry.d.ts.map +1 -1
  199. package/lib/typescript/utils/bounds/constants.d.ts +2 -2
  200. package/lib/typescript/utils/bounds/constants.d.ts.map +1 -1
  201. package/lib/typescript/utils/bounds/index.d.ts +4 -4
  202. package/lib/typescript/utils/bounds/index.d.ts.map +1 -1
  203. package/lib/typescript/utils/gesture/apply-offset-rules.d.ts +2 -2
  204. package/lib/typescript/utils/gesture/apply-offset-rules.d.ts.map +1 -1
  205. package/lib/typescript/utils/gesture/check-gesture-activation.d.ts +2 -2
  206. package/lib/typescript/utils/gesture/check-gesture-activation.d.ts.map +1 -1
  207. package/package.json +1 -1
  208. package/src/__configs__/presets.ts +590 -590
  209. package/src/components/root-transition-aware.tsx +27 -27
  210. package/src/constants.ts +47 -47
  211. package/src/hooks/animation/use-screen-animation.tsx +52 -47
  212. package/src/index.ts +33 -22
  213. package/src/integrations/blank-stack/components/Header.tsx +143 -0
  214. package/src/integrations/blank-stack/components/Screens.tsx +96 -0
  215. package/src/integrations/blank-stack/components/StackView.tsx +106 -0
  216. package/src/integrations/blank-stack/navigators/createBlankStackNavigator.tsx +122 -0
  217. package/src/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.tsx +62 -0
  218. package/src/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.tsx +11 -0
  219. package/src/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.tsx +280 -0
  220. package/src/integrations/blank-stack/utils/with-stack-navigation/_types.ts +36 -0
  221. package/src/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.ts +15 -0
  222. package/src/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.ts +29 -0
  223. package/src/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.ts +17 -0
  224. package/src/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.ts +12 -0
  225. package/src/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.ts +11 -0
  226. package/src/integrations/blank-stack/utils/with-stack-navigation/index.tsx +93 -0
  227. package/src/integrations/native-stack/navigators/createNativeStackNavigator.tsx +95 -95
  228. package/src/integrations/native-stack/utils/getModalRoutesKeys.ts +14 -14
  229. package/src/integrations/native-stack/utils/useInvalidPreventRemoveError.tsx +23 -23
  230. package/src/integrations/native-stack/views/NativeStackView.native.tsx +608 -608
  231. package/src/integrations/native-stack/views/NativeStackView.tsx +188 -188
  232. package/src/integrations/native-stack/views/useHeaderConfigProps.tsx +260 -260
  233. package/src/providers/keys.tsx +22 -22
  234. package/src/providers/screen-transition-provider.tsx +20 -20
  235. package/src/providers/transition-styles.tsx +24 -11
  236. package/src/stores/animations.ts +23 -23
  237. package/src/stores/bounds/index.ts +82 -82
  238. package/src/stores/gestures.ts +36 -36
  239. package/src/stores/utils/reset-stores-for-screen.ts +4 -4
  240. package/src/types/animation.ts +2 -4
  241. package/src/types/blank-stack.navigator.ts +271 -0
  242. package/src/types/bounds.ts +0 -64
  243. package/src/types/{navigator.ts → native-stack.navigator.ts} +5 -0
  244. package/src/utils/animation/derivations.ts +3 -20
  245. package/src/utils/bounds/_types/builder.ts +111 -111
  246. package/src/utils/bounds/_utils/geometry.ts +2 -2
  247. package/src/utils/bounds/constants.ts +29 -29
  248. package/src/utils/bounds/index.ts +35 -105
  249. package/src/utils/gesture/apply-offset-rules.ts +271 -271
  250. package/src/utils/gesture/check-gesture-activation.ts +260 -260
  251. package/lib/module/types/navigator.js +0 -4
  252. package/lib/typescript/types/navigator.d.ts.map +0 -1
@@ -0,0 +1,11 @@
1
+ import type { Route } from "@react-navigation/native";
2
+
3
+ export const routesAreIdentical = (
4
+ a: Route<string>[],
5
+ b: Route<string>[],
6
+ ): boolean => {
7
+ if (a === b) return true;
8
+ if (a.length !== b.length) return false;
9
+
10
+ return a.every((route, index) => route === b[index]);
11
+ };
@@ -0,0 +1,93 @@
1
+ import {
2
+ type ComponentType,
3
+ createContext,
4
+ memo,
5
+ useContext,
6
+ useMemo,
7
+ } from "react";
8
+ import { Header } from "../../components/Header";
9
+ import type { BlankStackScene } from "../../../../types/blank-stack.navigator";
10
+ import { useStackNavigationState } from "./_hooks/use-stack-navigation-state";
11
+ import type {
12
+ StackNavigationContextProps,
13
+ StackNavigationContextValue,
14
+ } from "./_types";
15
+ import { calculateActiveScreensLimit } from "./_utils/calculateActiveScreensLimit";
16
+
17
+ export const StackNavigationContext =
18
+ createContext<StackNavigationContextValue | null>(null);
19
+
20
+ export function withStackNavigationProvider(
21
+ Component: ComponentType<StackNavigationContextValue>
22
+ ) {
23
+ return function StackNavigationWrapper(props: StackNavigationContextProps) {
24
+ const { state, handleCloseRoute, closingRouteKeys } =
25
+ useStackNavigationState(props);
26
+
27
+ const scenes = useMemo(() => {
28
+ return state.routes.reduce((acc, route) => {
29
+ acc.push({
30
+ route,
31
+ descriptor: state.descriptors[route.key],
32
+ });
33
+ return acc;
34
+ }, [] as BlankStackScene[]);
35
+ }, [state.routes, state.descriptors]);
36
+
37
+ const activeScreensLimit = useMemo(() => {
38
+ return calculateActiveScreensLimit(state.routes, state.descriptors);
39
+ }, [state.routes, state.descriptors]);
40
+
41
+ const FloatHeader = memo(() => {
42
+ const shouldShowFloatHeader = props.state.routes.some((route) => {
43
+ const options = props.descriptors[route.key]?.options;
44
+ return options?.headerMode === "float" && options?.headerShown;
45
+ });
46
+
47
+ if (!shouldShowFloatHeader) {
48
+ return null;
49
+ }
50
+
51
+ return <Header.Float />;
52
+ });
53
+
54
+ const contextValue = useMemo<StackNavigationContextValue>(() => {
55
+ return {
56
+ routes: state.routes,
57
+ focusedIndex: props.state.index,
58
+ descriptors: state.descriptors,
59
+ closingRouteKeysShared: closingRouteKeys.shared,
60
+ activeScreensLimit,
61
+ handleCloseRoute,
62
+ scenes,
63
+ FloatHeader,
64
+ };
65
+ }, [
66
+ state,
67
+ scenes,
68
+ activeScreensLimit,
69
+ closingRouteKeys,
70
+ handleCloseRoute,
71
+ props.state.index,
72
+ FloatHeader,
73
+ ]);
74
+
75
+ return (
76
+ <StackNavigationContext.Provider value={contextValue}>
77
+ <Component {...contextValue} />
78
+ </StackNavigationContext.Provider>
79
+ );
80
+ };
81
+ }
82
+
83
+ export const useStackNavigationContext = () => {
84
+ const context = useContext(StackNavigationContext);
85
+
86
+ if (!context) {
87
+ throw new Error(
88
+ "StackNavigationContext.Provider is missing in the component tree."
89
+ );
90
+ }
91
+
92
+ return context;
93
+ };
@@ -1,112 +1,112 @@
1
1
  import {
2
- createNavigatorFactory,
3
- type EventArg,
4
- type NavigatorTypeBagBase,
5
- type ParamListBase,
6
- type StackActionHelpers,
7
- StackActions,
8
- type StackNavigationState,
9
- StackRouter,
10
- type StackRouterOptions,
11
- type StaticConfig,
12
- type TypedNavigator,
13
- useNavigationBuilder,
2
+ createNavigatorFactory,
3
+ type EventArg,
4
+ type NavigatorTypeBagBase,
5
+ type ParamListBase,
6
+ type StackActionHelpers,
7
+ StackActions,
8
+ type StackNavigationState,
9
+ StackRouter,
10
+ type StackRouterOptions,
11
+ type StaticConfig,
12
+ type TypedNavigator,
13
+ useNavigationBuilder,
14
14
  } from "@react-navigation/native";
15
15
  import * as React from "react";
16
16
 
17
17
  import type {
18
- NativeStackNavigationEventMap,
19
- NativeStackNavigationOptions,
20
- NativeStackNavigationProp,
21
- NativeStackNavigatorProps,
22
- } from "../../../types/navigator";
18
+ NativeStackNavigationEventMap,
19
+ NativeStackNavigationOptions,
20
+ NativeStackNavigationProp,
21
+ NativeStackNavigatorProps,
22
+ } from "../../../types/native-stack.navigator";
23
23
  import { NativeStackView } from "../views/NativeStackView";
24
24
 
25
25
  function NativeStackNavigator({
26
- id,
27
- initialRouteName,
28
- children,
29
- layout,
30
- screenListeners,
31
- screenOptions,
32
- screenLayout,
33
- ...rest
26
+ id,
27
+ initialRouteName,
28
+ children,
29
+ layout,
30
+ screenListeners,
31
+ screenOptions,
32
+ screenLayout,
33
+ ...rest
34
34
  }: NativeStackNavigatorProps) {
35
- const { state, describe, descriptors, navigation, NavigationContent } =
36
- useNavigationBuilder<
37
- StackNavigationState<ParamListBase>,
38
- StackRouterOptions,
39
- StackActionHelpers<ParamListBase>,
40
- NativeStackNavigationOptions,
41
- NativeStackNavigationEventMap
42
- >(StackRouter, {
43
- id,
44
- initialRouteName,
45
- children,
46
- layout,
47
- screenListeners,
48
- screenOptions,
49
- screenLayout,
50
- });
35
+ const { state, describe, descriptors, navigation, NavigationContent } =
36
+ useNavigationBuilder<
37
+ StackNavigationState<ParamListBase>,
38
+ StackRouterOptions,
39
+ StackActionHelpers<ParamListBase>,
40
+ NativeStackNavigationOptions,
41
+ NativeStackNavigationEventMap
42
+ >(StackRouter, {
43
+ id,
44
+ initialRouteName,
45
+ children,
46
+ layout,
47
+ screenListeners,
48
+ screenOptions,
49
+ screenLayout,
50
+ });
51
51
 
52
- React.useEffect(
53
- () =>
54
- // @ts-expect-error: there may not be a tab navigator in parent
55
- navigation?.addListener?.("tabPress", (e: any) => {
56
- const isFocused = navigation.isFocused();
52
+ React.useEffect(
53
+ () =>
54
+ // @ts-expect-error: there may not be a tab navigator in parent
55
+ navigation?.addListener?.("tabPress", (e: any) => {
56
+ const isFocused = navigation.isFocused();
57
57
 
58
- // Run the operation in the next frame so we're sure all listeners have been run
59
- // This is necessary to know if preventDefault() has been called
60
- requestAnimationFrame(() => {
61
- if (
62
- state.index > 0 &&
63
- isFocused &&
64
- !(e as EventArg<"tabPress", true>).defaultPrevented
65
- ) {
66
- // When user taps on already focused tab and we're inside the tab,
67
- // reset the stack to replicate native behaviour
68
- navigation.dispatch({
69
- ...StackActions.popToTop(),
70
- target: state.key,
71
- });
72
- }
73
- });
74
- }),
75
- [navigation, state.index, state.key],
76
- );
58
+ // Run the operation in the next frame so we're sure all listeners have been run
59
+ // This is necessary to know if preventDefault() has been called
60
+ requestAnimationFrame(() => {
61
+ if (
62
+ state.index > 0 &&
63
+ isFocused &&
64
+ !(e as EventArg<"tabPress", true>).defaultPrevented
65
+ ) {
66
+ // When user taps on already focused tab and we're inside the tab,
67
+ // reset the stack to replicate native behaviour
68
+ navigation.dispatch({
69
+ ...StackActions.popToTop(),
70
+ target: state.key,
71
+ });
72
+ }
73
+ });
74
+ }),
75
+ [navigation, state.index, state.key]
76
+ );
77
77
 
78
- return (
79
- <NavigationContent>
80
- <NativeStackView
81
- {...rest}
82
- state={state}
83
- navigation={navigation}
84
- descriptors={descriptors}
85
- describe={describe}
86
- />
87
- </NavigationContent>
88
- );
78
+ return (
79
+ <NavigationContent>
80
+ <NativeStackView
81
+ {...rest}
82
+ state={state}
83
+ navigation={navigation}
84
+ descriptors={descriptors}
85
+ describe={describe}
86
+ />
87
+ </NavigationContent>
88
+ );
89
89
  }
90
90
 
91
91
  export function createNativeStackNavigator<
92
- const ParamList extends ParamListBase,
93
- const NavigatorID extends string | undefined = undefined,
94
- const TypeBag extends NavigatorTypeBagBase = {
95
- ParamList: ParamList;
96
- NavigatorID: NavigatorID;
97
- State: StackNavigationState<ParamList>;
98
- ScreenOptions: NativeStackNavigationOptions;
99
- EventMap: NativeStackNavigationEventMap;
100
- NavigationList: {
101
- [RouteName in keyof ParamList]: NativeStackNavigationProp<
102
- ParamList,
103
- RouteName,
104
- NavigatorID
105
- >;
106
- };
107
- Navigator: typeof NativeStackNavigator;
108
- },
109
- const Config extends StaticConfig<TypeBag> = StaticConfig<TypeBag>,
92
+ const ParamList extends ParamListBase,
93
+ const NavigatorID extends string | undefined = undefined,
94
+ const TypeBag extends NavigatorTypeBagBase = {
95
+ ParamList: ParamList;
96
+ NavigatorID: NavigatorID;
97
+ State: StackNavigationState<ParamList>;
98
+ ScreenOptions: NativeStackNavigationOptions;
99
+ EventMap: NativeStackNavigationEventMap;
100
+ NavigationList: {
101
+ [RouteName in keyof ParamList]: NativeStackNavigationProp<
102
+ ParamList,
103
+ RouteName,
104
+ NavigatorID
105
+ >;
106
+ };
107
+ Navigator: typeof NativeStackNavigator;
108
+ },
109
+ const Config extends StaticConfig<TypeBag> = StaticConfig<TypeBag>
110
110
  >(config?: Config): TypedNavigator<TypeBag, Config> {
111
- return createNavigatorFactory(NativeStackNavigator)(config);
111
+ return createNavigatorFactory(NativeStackNavigator)(config);
112
112
  }
@@ -1,21 +1,21 @@
1
1
  import type { Route } from "@react-navigation/native";
2
2
 
3
- import type { NativeStackDescriptorMap } from "../../../types/navigator";
3
+ import type { NativeStackDescriptorMap } from "../../../types/native-stack.navigator";
4
4
 
5
5
  export const getModalRouteKeys = (
6
- routes: Route<string>[],
7
- descriptors: NativeStackDescriptorMap,
6
+ routes: Route<string>[],
7
+ descriptors: NativeStackDescriptorMap
8
8
  ) =>
9
- routes.reduce<string[]>((acc, route) => {
10
- const { presentation } = descriptors[route.key]?.options ?? {};
9
+ routes.reduce<string[]>((acc, route) => {
10
+ const { presentation } = descriptors[route.key]?.options ?? {};
11
11
 
12
- if (
13
- (acc.length && !presentation) ||
14
- presentation === "modal" ||
15
- presentation === "transparentModal"
16
- ) {
17
- acc.push(route.key);
18
- }
12
+ if (
13
+ (acc.length && !presentation) ||
14
+ presentation === "modal" ||
15
+ presentation === "transparentModal"
16
+ ) {
17
+ acc.push(route.key);
18
+ }
19
19
 
20
- return acc;
21
- }, []);
20
+ return acc;
21
+ }, []);
@@ -1,31 +1,31 @@
1
1
  import { usePreventRemoveContext } from "@react-navigation/native";
2
2
  import * as React from "react";
3
3
 
4
- import type { NativeStackDescriptorMap } from "../../../types/navigator";
4
+ import type { NativeStackDescriptorMap } from "../../../types/native-stack.navigator";
5
5
 
6
6
  export function useInvalidPreventRemoveError(
7
- descriptors: NativeStackDescriptorMap,
7
+ descriptors: NativeStackDescriptorMap
8
8
  ) {
9
- const { preventedRoutes } = usePreventRemoveContext();
10
- const preventedRouteKey = Object.keys(preventedRoutes)[0];
11
- const preventedDescriptor = descriptors[preventedRouteKey];
12
- const isHeaderBackButtonMenuEnabledOnPreventedScreen =
13
- preventedDescriptor?.options?.headerBackButtonMenuEnabled;
14
- const preventedRouteName = preventedDescriptor?.route?.name;
9
+ const { preventedRoutes } = usePreventRemoveContext();
10
+ const preventedRouteKey = Object.keys(preventedRoutes)[0];
11
+ const preventedDescriptor = descriptors[preventedRouteKey];
12
+ const isHeaderBackButtonMenuEnabledOnPreventedScreen =
13
+ preventedDescriptor?.options?.headerBackButtonMenuEnabled;
14
+ const preventedRouteName = preventedDescriptor?.route?.name;
15
15
 
16
- React.useEffect(() => {
17
- if (
18
- preventedRouteKey != null &&
19
- isHeaderBackButtonMenuEnabledOnPreventedScreen
20
- ) {
21
- const message =
22
- `The screen ${preventedRouteName} uses 'usePreventRemove' hook alongside 'headerBackButtonMenuEnabled: true', which is not supported. \n\n` +
23
- `Consider removing 'headerBackButtonMenuEnabled: true' from ${preventedRouteName} screen to get rid of this error.`;
24
- console.error(message);
25
- }
26
- }, [
27
- preventedRouteKey,
28
- isHeaderBackButtonMenuEnabledOnPreventedScreen,
29
- preventedRouteName,
30
- ]);
16
+ React.useEffect(() => {
17
+ if (
18
+ preventedRouteKey != null &&
19
+ isHeaderBackButtonMenuEnabledOnPreventedScreen
20
+ ) {
21
+ const message =
22
+ `The screen ${preventedRouteName} uses 'usePreventRemove' hook alongside 'headerBackButtonMenuEnabled: true', which is not supported. \n\n` +
23
+ `Consider removing 'headerBackButtonMenuEnabled: true' from ${preventedRouteName} screen to get rid of this error.`;
24
+ console.error(message);
25
+ }
26
+ }, [
27
+ preventedRouteKey,
28
+ isHeaderBackButtonMenuEnabledOnPreventedScreen,
29
+ preventedRouteName,
30
+ ]);
31
31
  }