react-native-screen-transitions 3.0.0-rc.2 → 3.0.0-rc.4

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 (241) hide show
  1. package/README.md +421 -371
  2. package/lib/commonjs/blank-stack/components/{Overlay.js → overlay.js} +7 -5
  3. package/lib/commonjs/blank-stack/components/overlay.js.map +1 -0
  4. package/lib/commonjs/blank-stack/components/{Screens.js → screens.js} +20 -17
  5. package/lib/commonjs/blank-stack/components/screens.js.map +1 -0
  6. package/lib/commonjs/blank-stack/components/stack-view.js +101 -0
  7. package/lib/commonjs/blank-stack/components/stack-view.js.map +1 -0
  8. package/lib/commonjs/blank-stack/index.js +1 -8
  9. package/lib/commonjs/blank-stack/index.js.map +1 -1
  10. package/lib/commonjs/blank-stack/navigators/{createBlankStackNavigator.js → create-blank-stack-navigator.js} +3 -3
  11. package/lib/commonjs/blank-stack/navigators/create-blank-stack-navigator.js.map +1 -0
  12. package/lib/commonjs/blank-stack/utils/with-stack-navigation/helpers/compose-descriptors.js +1 -11
  13. package/lib/commonjs/blank-stack/utils/with-stack-navigation/helpers/compose-descriptors.js.map +1 -1
  14. package/lib/commonjs/blank-stack/utils/with-stack-navigation/hooks/use-closing-route-keys.js +1 -12
  15. package/lib/commonjs/blank-stack/utils/with-stack-navigation/hooks/use-closing-route-keys.js.map +1 -1
  16. package/lib/commonjs/blank-stack/utils/with-stack-navigation/hooks/use-stack-navigation-state.js.map +1 -1
  17. package/lib/commonjs/blank-stack/utils/with-stack-navigation/index.js +49 -55
  18. package/lib/commonjs/blank-stack/utils/with-stack-navigation/index.js.map +1 -1
  19. package/lib/commonjs/blank-stack/utils/with-stack-navigation/{_types.js → types.js} +1 -1
  20. package/lib/commonjs/blank-stack/utils/with-stack-navigation/types.js.map +1 -0
  21. package/lib/commonjs/native-stack/views/NativeStackView.native.js +110 -103
  22. package/lib/commonjs/native-stack/views/NativeStackView.native.js.map +1 -1
  23. package/lib/commonjs/shared/components/controllers/blank-stack-lifecycle.js +72 -0
  24. package/lib/commonjs/shared/components/controllers/blank-stack-lifecycle.js.map +1 -0
  25. package/lib/commonjs/shared/components/controllers/native-stack-lifecycle.js +79 -0
  26. package/lib/commonjs/shared/components/controllers/native-stack-lifecycle.js.map +1 -0
  27. package/lib/commonjs/shared/hooks/animation/use-screen-animation.js +49 -23
  28. package/lib/commonjs/shared/hooks/animation/use-screen-animation.js.map +1 -1
  29. package/lib/commonjs/shared/hooks/gestures/use-build-gestures.js +11 -6
  30. package/lib/commonjs/shared/hooks/gestures/use-build-gestures.js.map +1 -1
  31. package/lib/commonjs/shared/hooks/gestures/use-scroll-registry.js +7 -7
  32. package/lib/commonjs/shared/hooks/gestures/use-scroll-registry.js.map +1 -1
  33. package/lib/commonjs/shared/providers/flags.provider.js +25 -0
  34. package/lib/commonjs/shared/providers/flags.provider.js.map +1 -0
  35. package/lib/commonjs/shared/providers/gestures.provider.js +32 -5
  36. package/lib/commonjs/shared/providers/gestures.provider.js.map +1 -1
  37. package/lib/commonjs/shared/providers/register-bounds.provider.js +72 -45
  38. package/lib/commonjs/shared/providers/register-bounds.provider.js.map +1 -1
  39. package/lib/commonjs/shared/providers/routes.provider.js +48 -0
  40. package/lib/commonjs/shared/providers/routes.provider.js.map +1 -0
  41. package/lib/commonjs/shared/providers/screen-transition.provider.js.map +1 -1
  42. package/lib/commonjs/shared/stores/bounds.store.js +91 -47
  43. package/lib/commonjs/shared/stores/bounds.store.js.map +1 -1
  44. package/lib/commonjs/shared/types/state.types.js +9 -0
  45. package/lib/commonjs/shared/types/state.types.js.map +1 -0
  46. package/lib/commonjs/shared/utils/animation/compute-stack-progress.js +20 -0
  47. package/lib/commonjs/shared/utils/animation/compute-stack-progress.js.map +1 -0
  48. package/lib/commonjs/shared/utils/animation/derivations.js +1 -1
  49. package/lib/commonjs/shared/utils/animation/start-screen-transition.js +11 -11
  50. package/lib/commonjs/shared/utils/animation/start-screen-transition.js.map +1 -1
  51. package/lib/commonjs/shared/utils/bounds/helpers/is-bounds-equal.js +1 -1
  52. package/lib/commonjs/shared/utils/bounds/helpers/is-bounds-equal.js.map +1 -1
  53. package/lib/commonjs/shared/utils/bounds/index.js +4 -5
  54. package/lib/commonjs/shared/utils/bounds/index.js.map +1 -1
  55. package/lib/commonjs/shared/utils/create-provider.js +20 -1
  56. package/lib/commonjs/shared/utils/create-provider.js.map +1 -1
  57. package/lib/commonjs/shared/utils/reset-stores-for-screen.js +2 -0
  58. package/lib/commonjs/shared/utils/reset-stores-for-screen.js.map +1 -1
  59. package/lib/module/blank-stack/components/{Overlay.js → overlay.js} +7 -5
  60. package/lib/module/blank-stack/components/overlay.js.map +1 -0
  61. package/lib/module/blank-stack/components/screens.js +61 -0
  62. package/lib/module/blank-stack/components/screens.js.map +1 -0
  63. package/lib/module/blank-stack/components/stack-view.js +96 -0
  64. package/lib/module/blank-stack/components/stack-view.js.map +1 -0
  65. package/lib/module/blank-stack/index.js +1 -2
  66. package/lib/module/blank-stack/index.js.map +1 -1
  67. package/lib/module/blank-stack/navigators/{createBlankStackNavigator.js → create-blank-stack-navigator.js} +2 -2
  68. package/lib/module/blank-stack/navigators/create-blank-stack-navigator.js.map +1 -0
  69. package/lib/module/blank-stack/utils/with-stack-navigation/helpers/compose-descriptors.js +1 -11
  70. package/lib/module/blank-stack/utils/with-stack-navigation/helpers/compose-descriptors.js.map +1 -1
  71. package/lib/module/blank-stack/utils/with-stack-navigation/hooks/use-closing-route-keys.js +1 -12
  72. package/lib/module/blank-stack/utils/with-stack-navigation/hooks/use-closing-route-keys.js.map +1 -1
  73. package/lib/module/blank-stack/utils/with-stack-navigation/hooks/use-stack-navigation-state.js.map +1 -1
  74. package/lib/module/blank-stack/utils/with-stack-navigation/index.js +48 -54
  75. package/lib/module/blank-stack/utils/with-stack-navigation/index.js.map +1 -1
  76. package/lib/module/blank-stack/utils/with-stack-navigation/types.js +4 -0
  77. package/lib/module/blank-stack/utils/with-stack-navigation/types.js.map +1 -0
  78. package/lib/module/native-stack/views/NativeStackView.native.js +109 -102
  79. package/lib/module/native-stack/views/NativeStackView.native.js.map +1 -1
  80. package/lib/module/shared/components/controllers/blank-stack-lifecycle.js +66 -0
  81. package/lib/module/shared/components/controllers/blank-stack-lifecycle.js.map +1 -0
  82. package/lib/module/shared/components/controllers/native-stack-lifecycle.js +73 -0
  83. package/lib/module/shared/components/controllers/native-stack-lifecycle.js.map +1 -0
  84. package/lib/module/shared/hooks/animation/use-screen-animation.js +49 -23
  85. package/lib/module/shared/hooks/animation/use-screen-animation.js.map +1 -1
  86. package/lib/module/shared/hooks/gestures/use-build-gestures.js +11 -6
  87. package/lib/module/shared/hooks/gestures/use-build-gestures.js.map +1 -1
  88. package/lib/module/shared/hooks/gestures/use-scroll-registry.js +7 -7
  89. package/lib/module/shared/hooks/gestures/use-scroll-registry.js.map +1 -1
  90. package/lib/module/shared/providers/flags.provider.js +19 -0
  91. package/lib/module/shared/providers/flags.provider.js.map +1 -0
  92. package/lib/module/shared/providers/gestures.provider.js +31 -4
  93. package/lib/module/shared/providers/gestures.provider.js.map +1 -1
  94. package/lib/module/shared/providers/register-bounds.provider.js +72 -45
  95. package/lib/module/shared/providers/register-bounds.provider.js.map +1 -1
  96. package/lib/module/shared/providers/routes.provider.js +42 -0
  97. package/lib/module/shared/providers/routes.provider.js.map +1 -0
  98. package/lib/module/shared/providers/screen-transition.provider.js.map +1 -1
  99. package/lib/module/shared/stores/bounds.store.js +91 -47
  100. package/lib/module/shared/stores/bounds.store.js.map +1 -1
  101. package/lib/module/shared/types/state.types.js +5 -0
  102. package/lib/module/shared/types/state.types.js.map +1 -0
  103. package/lib/module/shared/utils/animation/compute-stack-progress.js +15 -0
  104. package/lib/module/shared/utils/animation/compute-stack-progress.js.map +1 -0
  105. package/lib/module/shared/utils/animation/derivations.js +1 -1
  106. package/lib/module/shared/utils/animation/start-screen-transition.js +11 -11
  107. package/lib/module/shared/utils/animation/start-screen-transition.js.map +1 -1
  108. package/lib/module/shared/utils/bounds/helpers/is-bounds-equal.js +1 -1
  109. package/lib/module/shared/utils/bounds/helpers/is-bounds-equal.js.map +1 -1
  110. package/lib/module/shared/utils/bounds/index.js +4 -5
  111. package/lib/module/shared/utils/bounds/index.js.map +1 -1
  112. package/lib/module/shared/utils/create-provider.js +20 -1
  113. package/lib/module/shared/utils/create-provider.js.map +1 -1
  114. package/lib/module/shared/utils/reset-stores-for-screen.js +2 -0
  115. package/lib/module/shared/utils/reset-stores-for-screen.js.map +1 -1
  116. package/lib/typescript/blank-stack/components/{Overlay.d.ts → overlay.d.ts} +1 -1
  117. package/lib/typescript/blank-stack/components/overlay.d.ts.map +1 -0
  118. package/lib/typescript/blank-stack/components/{Screens.d.ts → screens.d.ts} +1 -1
  119. package/lib/typescript/blank-stack/components/screens.d.ts.map +1 -0
  120. package/lib/typescript/blank-stack/components/stack-view.d.ts +3 -0
  121. package/lib/typescript/blank-stack/components/stack-view.d.ts.map +1 -0
  122. package/lib/typescript/blank-stack/index.d.ts +1 -2
  123. package/lib/typescript/blank-stack/index.d.ts.map +1 -1
  124. package/lib/typescript/blank-stack/navigators/{createBlankStackNavigator.d.ts → create-blank-stack-navigator.d.ts} +1 -1
  125. package/lib/typescript/blank-stack/navigators/create-blank-stack-navigator.d.ts.map +1 -0
  126. package/lib/typescript/blank-stack/types.d.ts +5 -39
  127. package/lib/typescript/blank-stack/types.d.ts.map +1 -1
  128. package/lib/typescript/blank-stack/utils/with-stack-navigation/helpers/compose-descriptors.d.ts.map +1 -1
  129. package/lib/typescript/blank-stack/utils/with-stack-navigation/hooks/use-closing-route-keys.d.ts.map +1 -1
  130. package/lib/typescript/blank-stack/utils/with-stack-navigation/hooks/use-stack-navigation-state.d.ts +1 -1
  131. package/lib/typescript/blank-stack/utils/with-stack-navigation/hooks/use-stack-navigation-state.d.ts.map +1 -1
  132. package/lib/typescript/blank-stack/utils/with-stack-navigation/index.d.ts +3 -5
  133. package/lib/typescript/blank-stack/utils/with-stack-navigation/index.d.ts.map +1 -1
  134. package/lib/typescript/blank-stack/utils/with-stack-navigation/{_types.d.ts → types.d.ts} +1 -1
  135. package/lib/typescript/blank-stack/utils/with-stack-navigation/types.d.ts.map +1 -0
  136. package/lib/typescript/native-stack/views/NativeStackView.native.d.ts.map +1 -1
  137. package/lib/typescript/shared/components/controllers/blank-stack-lifecycle.d.ts +8 -0
  138. package/lib/typescript/shared/components/controllers/blank-stack-lifecycle.d.ts.map +1 -0
  139. package/lib/typescript/shared/components/controllers/native-stack-lifecycle.d.ts +8 -0
  140. package/lib/typescript/shared/components/controllers/native-stack-lifecycle.d.ts.map +1 -0
  141. package/lib/typescript/shared/hooks/animation/use-screen-animation.d.ts.map +1 -1
  142. package/lib/typescript/shared/hooks/gestures/use-build-gestures.d.ts +2 -2
  143. package/lib/typescript/shared/hooks/gestures/use-build-gestures.d.ts.map +1 -1
  144. package/lib/typescript/shared/index.d.ts +20 -20
  145. package/lib/typescript/shared/providers/flags.provider.d.ts +10 -0
  146. package/lib/typescript/shared/providers/flags.provider.d.ts.map +1 -0
  147. package/lib/typescript/shared/providers/gestures.provider.d.ts +8 -2
  148. package/lib/typescript/shared/providers/gestures.provider.d.ts.map +1 -1
  149. package/lib/typescript/shared/providers/register-bounds.provider.d.ts.map +1 -1
  150. package/lib/typescript/shared/providers/routes.provider.d.ts +19 -0
  151. package/lib/typescript/shared/providers/routes.provider.d.ts.map +1 -0
  152. package/lib/typescript/shared/providers/screen-transition.provider.d.ts +2 -2
  153. package/lib/typescript/shared/providers/screen-transition.provider.d.ts.map +1 -1
  154. package/lib/typescript/shared/stores/bounds.store.d.ts +23 -11
  155. package/lib/typescript/shared/stores/bounds.store.d.ts.map +1 -1
  156. package/lib/typescript/shared/types/animation.types.d.ts +12 -0
  157. package/lib/typescript/shared/types/animation.types.d.ts.map +1 -1
  158. package/lib/typescript/shared/types/bounds.types.d.ts +2 -2
  159. package/lib/typescript/shared/types/bounds.types.d.ts.map +1 -1
  160. package/lib/typescript/shared/types/state.types.d.ts +3 -0
  161. package/lib/typescript/shared/types/state.types.d.ts.map +1 -0
  162. package/lib/typescript/shared/utils/animation/compute-stack-progress.d.ts +3 -0
  163. package/lib/typescript/shared/utils/animation/compute-stack-progress.d.ts.map +1 -0
  164. package/lib/typescript/shared/utils/animation/start-screen-transition.d.ts.map +1 -1
  165. package/lib/typescript/shared/utils/bounds/index.d.ts.map +1 -1
  166. package/lib/typescript/shared/utils/create-provider.d.ts +2 -2
  167. package/lib/typescript/shared/utils/create-provider.d.ts.map +1 -1
  168. package/lib/typescript/shared/utils/reset-stores-for-screen.d.ts.map +1 -1
  169. package/package.json +2 -1
  170. package/src/blank-stack/components/{Overlay.tsx → overlay.tsx} +4 -3
  171. package/src/blank-stack/components/{Screens.tsx → screens.tsx} +24 -20
  172. package/src/blank-stack/components/stack-view.tsx +115 -0
  173. package/src/blank-stack/index.ts +1 -2
  174. package/src/blank-stack/navigators/{createBlankStackNavigator.tsx → create-blank-stack-navigator.tsx} +1 -1
  175. package/src/blank-stack/types.ts +6 -31
  176. package/src/blank-stack/utils/with-stack-navigation/helpers/compose-descriptors.ts +1 -8
  177. package/src/blank-stack/utils/with-stack-navigation/hooks/use-closing-route-keys.tsx +1 -12
  178. package/src/blank-stack/utils/with-stack-navigation/hooks/use-stack-navigation-state.tsx +1 -1
  179. package/src/blank-stack/utils/with-stack-navigation/index.tsx +42 -62
  180. package/src/native-stack/views/NativeStackView.native.tsx +121 -112
  181. package/src/shared/__tests__/bounds.store.test.ts +376 -167
  182. package/src/shared/__tests__/determine-dismissal.test.ts +2 -12
  183. package/src/shared/__tests__/geometry.test.ts +1 -1
  184. package/src/shared/__tests__/gesture.velocity.test.ts +2 -10
  185. package/src/shared/components/controllers/blank-stack-lifecycle.tsx +70 -0
  186. package/src/shared/components/controllers/native-stack-lifecycle.tsx +87 -0
  187. package/src/shared/hooks/animation/use-screen-animation.tsx +61 -30
  188. package/src/shared/hooks/gestures/use-build-gestures.tsx +16 -7
  189. package/src/shared/hooks/gestures/use-scroll-registry.tsx +7 -7
  190. package/src/shared/providers/flags.provider.tsx +21 -0
  191. package/src/shared/providers/gestures.provider.tsx +34 -5
  192. package/src/shared/providers/register-bounds.provider.tsx +86 -54
  193. package/src/shared/providers/routes.provider.tsx +54 -0
  194. package/src/shared/providers/screen-transition.provider.tsx +2 -2
  195. package/src/shared/stores/bounds.store.ts +90 -54
  196. package/src/shared/types/animation.types.ts +13 -0
  197. package/src/shared/types/bounds.types.ts +2 -2
  198. package/src/shared/types/state.types.ts +2 -0
  199. package/src/shared/utils/animation/compute-stack-progress.ts +16 -0
  200. package/src/shared/utils/animation/derivations.ts +1 -1
  201. package/src/shared/utils/animation/start-screen-transition.ts +13 -10
  202. package/src/shared/utils/bounds/helpers/is-bounds-equal.ts +1 -1
  203. package/src/shared/utils/bounds/index.ts +7 -10
  204. package/src/shared/utils/create-provider.tsx +35 -1
  205. package/src/shared/utils/reset-stores-for-screen.ts +2 -0
  206. package/lib/commonjs/blank-stack/components/Overlay.js.map +0 -1
  207. package/lib/commonjs/blank-stack/components/Screens.js.map +0 -1
  208. package/lib/commonjs/blank-stack/components/StackView.js +0 -93
  209. package/lib/commonjs/blank-stack/components/StackView.js.map +0 -1
  210. package/lib/commonjs/blank-stack/navigators/createBlankStackNavigator.js.map +0 -1
  211. package/lib/commonjs/blank-stack/utils/with-stack-navigation/_types.js.map +0 -1
  212. package/lib/commonjs/shared/components/controllers/screen-lifecycle.js +0 -142
  213. package/lib/commonjs/shared/components/controllers/screen-lifecycle.js.map +0 -1
  214. package/lib/commonjs/shared/hooks/gestures/use-parent-gesture-registry.js +0 -28
  215. package/lib/commonjs/shared/hooks/gestures/use-parent-gesture-registry.js.map +0 -1
  216. package/lib/module/blank-stack/components/Overlay.js.map +0 -1
  217. package/lib/module/blank-stack/components/Screens.js +0 -58
  218. package/lib/module/blank-stack/components/Screens.js.map +0 -1
  219. package/lib/module/blank-stack/components/StackView.js +0 -88
  220. package/lib/module/blank-stack/components/StackView.js.map +0 -1
  221. package/lib/module/blank-stack/navigators/createBlankStackNavigator.js.map +0 -1
  222. package/lib/module/blank-stack/utils/with-stack-navigation/_types.js +0 -4
  223. package/lib/module/blank-stack/utils/with-stack-navigation/_types.js.map +0 -1
  224. package/lib/module/shared/components/controllers/screen-lifecycle.js +0 -136
  225. package/lib/module/shared/components/controllers/screen-lifecycle.js.map +0 -1
  226. package/lib/module/shared/hooks/gestures/use-parent-gesture-registry.js +0 -23
  227. package/lib/module/shared/hooks/gestures/use-parent-gesture-registry.js.map +0 -1
  228. package/lib/typescript/blank-stack/components/Overlay.d.ts.map +0 -1
  229. package/lib/typescript/blank-stack/components/Screens.d.ts.map +0 -1
  230. package/lib/typescript/blank-stack/components/StackView.d.ts +0 -2
  231. package/lib/typescript/blank-stack/components/StackView.d.ts.map +0 -1
  232. package/lib/typescript/blank-stack/navigators/createBlankStackNavigator.d.ts.map +0 -1
  233. package/lib/typescript/blank-stack/utils/with-stack-navigation/_types.d.ts.map +0 -1
  234. package/lib/typescript/shared/components/controllers/screen-lifecycle.d.ts +0 -12
  235. package/lib/typescript/shared/components/controllers/screen-lifecycle.d.ts.map +0 -1
  236. package/lib/typescript/shared/hooks/gestures/use-parent-gesture-registry.d.ts +0 -6
  237. package/lib/typescript/shared/hooks/gestures/use-parent-gesture-registry.d.ts.map +0 -1
  238. package/src/blank-stack/components/StackView.tsx +0 -108
  239. package/src/shared/components/controllers/screen-lifecycle.tsx +0 -154
  240. package/src/shared/hooks/gestures/use-parent-gesture-registry.tsx +0 -18
  241. /package/src/blank-stack/utils/with-stack-navigation/{_types.ts → types.ts} +0 -0
@@ -47,7 +47,7 @@ const OverlayHost = ({ scene, isFloating }: OverlayHostProps) => {
47
47
  const OverlayComponent = scene.descriptor.options.overlay;
48
48
 
49
49
  const { overlayAnimation, optimisticActiveIndex } = useOverlayAnimation();
50
- const { scenes } = useStackNavigationContext();
50
+ const { scenes, routes } = useStackNavigationContext();
51
51
 
52
52
  const overlaySceneIndex = useMemo(() => {
53
53
  return scenes.findIndex(
@@ -76,12 +76,13 @@ const OverlayHost = ({ scene, isFloating }: OverlayHostProps) => {
76
76
  }
77
77
 
78
78
  const overlayProps: BlankStackOverlayProps = {
79
+ routes,
80
+ overlayAnimation,
81
+ screenAnimation,
79
82
  focusedRoute: focusedScene.route,
80
83
  focusedIndex: optimisticActiveIndex,
81
84
  overlayOptions: focusedScene.descriptor.options.overlayOptions,
82
85
  navigation: scene.descriptor.navigation,
83
- overlayAnimation,
84
- screenAnimation,
85
86
  };
86
87
 
87
88
  return (
@@ -1,4 +1,3 @@
1
- import type { NavigationRoute, ParamListBase } from "@react-navigation/native";
2
1
  import type * as React from "react";
3
2
  import { StyleSheet } from "react-native";
4
3
  import Animated, {
@@ -20,13 +19,14 @@ interface ScreenProps {
20
19
  shouldFreeze?: boolean;
21
20
  activeScreensLimit: number;
22
21
  }
22
+ enum ScreenActivity {
23
+ INACTIVE = 0,
24
+ TRANSITIONING_OR_BELOW_TOP = 1,
25
+ ON_TOP = 2,
26
+ }
23
27
 
24
28
  const EPSILON = 1e-5;
25
29
 
26
- const STATE_INACTIVE = 0;
27
- const STATE_TRANSITIONING_OR_BELOW_TOP = 1;
28
- const STATE_ON_TOP = 2;
29
-
30
30
  const AnimatedScreen = Animated.createAnimatedComponent(RNSScreen);
31
31
 
32
32
  export const Screen = ({
@@ -40,45 +40,50 @@ export const Screen = ({
40
40
  shouldFreeze,
41
41
  }: ScreenProps) => {
42
42
  const sceneProgress = AnimationStore.getAnimation(routeKey, "progress");
43
- const screenActivity = useSharedValue<0 | 1 | 2>(1);
43
+ const sceneClosing = AnimationStore.getAnimation(routeKey, "closing");
44
+ const screenActivity = useSharedValue<ScreenActivity>(
45
+ ScreenActivity.TRANSITIONING_OR_BELOW_TOP,
46
+ );
44
47
 
45
48
  useDerivedValue(() => {
46
49
  if (!sceneProgress) {
47
- screenActivity.value = STATE_TRANSITIONING_OR_BELOW_TOP;
50
+ screenActivity.set(ScreenActivity.TRANSITIONING_OR_BELOW_TOP);
48
51
  return;
49
52
  }
50
53
 
51
54
  if (index < routesLength - activeScreensLimit - 1 || isPreloaded) {
52
- screenActivity.value = STATE_INACTIVE;
55
+ screenActivity.set(ScreenActivity.INACTIVE);
53
56
  } else {
54
57
  const outputValue =
55
58
  index === routesLength - 1
56
- ? STATE_ON_TOP
59
+ ? ScreenActivity.ON_TOP
57
60
  : index >= routesLength - activeScreensLimit
58
- ? STATE_TRANSITIONING_OR_BELOW_TOP
59
- : STATE_INACTIVE;
61
+ ? ScreenActivity.TRANSITIONING_OR_BELOW_TOP
62
+ : ScreenActivity.INACTIVE;
60
63
 
61
64
  const v = interpolate(
62
- sceneProgress.value,
65
+ sceneProgress.get(),
63
66
  [0, 1 - EPSILON, 1],
64
67
  [1, 1, outputValue],
65
68
  "clamp",
66
69
  );
67
70
 
68
- const next =
69
- (Math.trunc(v) as 0 | 1 | 2) ?? STATE_TRANSITIONING_OR_BELOW_TOP;
71
+ const next = Math.trunc(v) ?? ScreenActivity.TRANSITIONING_OR_BELOW_TOP;
70
72
 
71
- // avoid spamming JS thread
72
- if (next !== screenActivity.value) {
73
- screenActivity.value = next;
73
+ if (next !== screenActivity.get()) {
74
+ screenActivity.set(next);
74
75
  }
75
76
  }
76
77
  });
77
78
 
78
79
  const animatedProps = useAnimatedProps(() => {
80
+ const activity = screenActivity.get();
79
81
  return {
80
- activityState: screenActivity.value,
81
- shouldFreeze: screenActivity.value === STATE_INACTIVE && shouldFreeze,
82
+ activityState: activity,
83
+ shouldFreeze: activity === ScreenActivity.INACTIVE && shouldFreeze,
84
+ pointerEvents: sceneClosing.get()
85
+ ? ("none" as const)
86
+ : ("box-none" as const),
82
87
  };
83
88
  });
84
89
 
@@ -86,7 +91,6 @@ export const Screen = ({
86
91
  <AnimatedScreen
87
92
  enabled
88
93
  style={StyleSheet.absoluteFill}
89
- pointerEvents="box-none"
90
94
  freezeOnBlur={freezeOnBlur}
91
95
  animatedProps={animatedProps}
92
96
  >
@@ -0,0 +1,115 @@
1
+ import { SafeAreaProviderCompat } from "@react-navigation/elements";
2
+ import {
3
+ NavigationContext,
4
+ NavigationRouteContext,
5
+ } from "@react-navigation/native";
6
+ import * as React from "react";
7
+ import { StyleSheet } from "react-native";
8
+ import { GestureHandlerRootView } from "react-native-gesture-handler";
9
+ import { ScreenContainer } from "react-native-screens";
10
+ import { BlankStackScreenLifecycleController } from "../../shared/components/controllers/blank-stack-lifecycle";
11
+ import { FlagsProvider } from "../../shared/providers/flags.provider";
12
+ import { RoutesProvider } from "../../shared/providers/routes.provider";
13
+ import { ScreenTransitionProvider } from "../../shared/providers/screen-transition.provider";
14
+ import type { BlankStackDescriptor } from "../types";
15
+ import { withStackNavigationProvider } from "../utils/with-stack-navigation";
16
+ import { Overlay } from "./overlay";
17
+ import { Screen } from "./screens";
18
+
19
+ function isFabric() {
20
+ return "nativeFabricUIManager" in global;
21
+ }
22
+
23
+ type SceneViewProps = {
24
+ descriptor: BlankStackDescriptor;
25
+ };
26
+
27
+ const SceneView = React.memo(({ descriptor }: SceneViewProps) => {
28
+ const { route, navigation, render } = descriptor;
29
+
30
+ return (
31
+ <NavigationContext.Provider value={navigation}>
32
+ <NavigationRouteContext.Provider value={route}>
33
+ {descriptor.options.overlayMode === "screen" && <Overlay.Screen />}
34
+ {render()}
35
+ </NavigationRouteContext.Provider>
36
+ </NavigationContext.Provider>
37
+ );
38
+ });
39
+
40
+ export const StackView = withStackNavigationProvider(
41
+ ({
42
+ activeScreensLimit,
43
+ descriptors,
44
+ focusedIndex,
45
+ routes,
46
+ scenes,
47
+ shouldShowFloatOverlay,
48
+ }) => {
49
+ // Memoize route keys array for ScenesProvider
50
+ const routeKeys = React.useMemo(
51
+ () => routes.map((route) => route.key),
52
+ [routes],
53
+ );
54
+
55
+ return (
56
+ <FlagsProvider TRANSITIONS_ALWAYS_ON>
57
+ <RoutesProvider routeKeys={routeKeys}>
58
+ <GestureHandlerRootView>
59
+ <SafeAreaProviderCompat>
60
+ {shouldShowFloatOverlay ? <Overlay.Float /> : null}
61
+ <ScreenContainer style={styles.container}>
62
+ {scenes.map((scene, sceneIndex) => {
63
+ const descriptor = scene.descriptor;
64
+ const route = scene.route;
65
+ const isFocused = focusedIndex === sceneIndex;
66
+ const isBelowFocused = focusedIndex - 1 === sceneIndex;
67
+
68
+ const previousDescriptor =
69
+ scenes[sceneIndex - 1]?.descriptor ?? undefined;
70
+ const nextDescriptor =
71
+ scenes[sceneIndex + 1]?.descriptor ?? undefined;
72
+
73
+ const isPreloaded = descriptors[route.key] === undefined;
74
+
75
+ // On Fabric, when screen is frozen, animated and reanimated values are not updated
76
+ // due to component being unmounted. To avoid this, we don't freeze the previous screen there
77
+ const shouldFreeze = isFabric()
78
+ ? !isPreloaded && !isFocused && !isBelowFocused
79
+ : !isPreloaded && !isFocused;
80
+ return (
81
+ <Screen
82
+ key={route.key}
83
+ isPreloaded={isPreloaded}
84
+ index={sceneIndex}
85
+ activeScreensLimit={activeScreensLimit}
86
+ routeKey={route.key}
87
+ routesLength={routes.length}
88
+ shouldFreeze={shouldFreeze}
89
+ freezeOnBlur={descriptor.options.freezeOnBlur}
90
+ >
91
+ <ScreenTransitionProvider
92
+ previous={previousDescriptor}
93
+ current={descriptor}
94
+ next={nextDescriptor}
95
+ LifecycleController={
96
+ BlankStackScreenLifecycleController
97
+ }
98
+ >
99
+ <SceneView key={route.key} descriptor={descriptor} />
100
+ </ScreenTransitionProvider>
101
+ </Screen>
102
+ );
103
+ })}
104
+ </ScreenContainer>
105
+ </SafeAreaProviderCompat>
106
+ </GestureHandlerRootView>
107
+ </RoutesProvider>
108
+ </FlagsProvider>
109
+ );
110
+ },
111
+ );
112
+
113
+ const styles = StyleSheet.create({
114
+ container: { flex: 1 },
115
+ });
@@ -1,5 +1,4 @@
1
- export { useOverlayAnimation } from "../blank-stack/hooks/use-overlay-animation";
2
- export { createBlankStackNavigator } from "../blank-stack/navigators/createBlankStackNavigator";
1
+ export { createBlankStackNavigator } from "../blank-stack/navigators/create-blank-stack-navigator";
3
2
  export type {
4
3
  BlankStackNavigationEventMap,
5
4
  BlankStackNavigationOptions,
@@ -13,7 +13,7 @@ import {
13
13
  useNavigationBuilder,
14
14
  } from "@react-navigation/native";
15
15
  import * as React from "react";
16
- import { StackView } from "../components/StackView";
16
+ import { StackView } from "../components/stack-view";
17
17
  import type {
18
18
  BlankStackNavigationEventMap,
19
19
  BlankStackNavigationOptions,
@@ -12,42 +12,13 @@ import type {
12
12
  Theme,
13
13
  } from "@react-navigation/native";
14
14
  import type { DerivedValue } from "react-native-reanimated";
15
- import type { ScreenProps } from "react-native-screens";
16
15
  import type { ScreenTransitionConfig } from "../shared";
17
16
  import type {
18
17
  OverlayInterpolationProps,
19
18
  ScreenInterpolationProps,
20
- ScreenStyleInterpolator,
21
- TransitionSpec,
22
19
  } from "../shared/types/animation.types";
23
- import type {
24
- GestureActivationArea,
25
- GestureDirection,
26
- } from "../shared/types/gesture.types";
27
20
 
28
- export type BlankStackNavigationEventMap = {
29
- /**
30
- * Event which fires when a transition animation starts.
31
- */
32
- transitionStart: { data: { closing: boolean } };
33
- /**
34
- * Event which fires when a transition animation ends.
35
- */
36
- transitionEnd: { data: { closing: boolean } };
37
- /**
38
- * Event which fires when a swipe back is canceled on iOS.
39
- */
40
- gestureCancel: { data: undefined };
41
- /**
42
- * Event which fires when screen is in sheet presentation & it's detent changes.
43
- *
44
- * In payload it caries two fields:
45
- *
46
- * * `index` - current detent index in the `sheetAllowedDetents` array,
47
- * * `stable` - on Android `false` value means that the user is dragging the sheet or it is settling; on iOS it is always `true`.
48
- */
49
- sheetDetentChange: { data: { index: number; stable: boolean } };
50
- };
21
+ export type BlankStackNavigationEventMap = {};
51
22
 
52
23
  export type BlankStackNavigationProp<
53
24
  ParamList extends ParamListBase,
@@ -104,6 +75,11 @@ export type BlankStackOverlayProps = {
104
75
  */
105
76
  focusedIndex: number;
106
77
 
78
+ /**
79
+ * All routes currently in the stack.
80
+ */
81
+ routes: Route<string>[];
82
+
107
83
  /**
108
84
  * Options passed to the overlay component.
109
85
  */
@@ -134,7 +110,6 @@ export type BlankStackScreenTransitionConfig = ScreenTransitionConfig & {
134
110
  * Whether to detach the previous screen from the view hierarchy to save memory.
135
111
  * Set it to `false` if you need the previous screen to be seen through the active screen.
136
112
  * Only applicable if `detachInactiveScreens` isn't set to `false`.
137
- * Defaults to `false` for the last screen for modals, otherwise `true`.
138
113
  */
139
114
  detachPreviousScreen?: boolean;
140
115
  };
@@ -9,15 +9,8 @@ export const composeDescriptors = (
9
9
  const composed: BlankStackDescriptorMap = {};
10
10
 
11
11
  for (const route of routes) {
12
- const adjusted =
12
+ composed[route.key] =
13
13
  nextDescriptors[route.key] ?? currentDescriptors[route.key];
14
-
15
- // useScreenAnimation depends on this, however with blank-stack, this should be enabled by default
16
- const withEnableTransitions = {
17
- ...adjusted,
18
- options: { ...adjusted.options, enableTransitions: true },
19
- };
20
- composed[route.key] = withEnableTransitions;
21
14
  }
22
15
 
23
16
  return composed;
@@ -4,7 +4,6 @@ import useStableCallback from "../../../../shared/hooks/use-stable-callback";
4
4
 
5
5
  export const useClosingRouteKeys = () => {
6
6
  const keysRef = useRef<Set<string>>(new Set());
7
- const finishedRef = useRef<Set<string>>(new Set());
8
7
  const shared = useSharedValue<string[]>([]);
9
8
 
10
9
  const add = useStableCallback((key: string) => {
@@ -13,7 +12,6 @@ export const useClosingRouteKeys = () => {
13
12
  return;
14
13
  }
15
14
 
16
- finishedRef.current.delete(key);
17
15
  keys.add(key);
18
16
  shared.modify((prev) => {
19
17
  "worklet";
@@ -26,12 +24,8 @@ export const useClosingRouteKeys = () => {
26
24
 
27
25
  const remove = useStableCallback((key: string) => {
28
26
  const keys = keysRef.current;
29
- if (!keys.delete(key)) {
30
- finishedRef.current.delete(key);
31
- return;
32
- }
27
+ keys.delete(key);
33
28
 
34
- finishedRef.current.delete(key);
35
29
  shared.modify((prev) => {
36
30
  "worklet";
37
31
  const index = prev.indexOf(key);
@@ -44,13 +38,8 @@ export const useClosingRouteKeys = () => {
44
38
 
45
39
  const clear = useStableCallback(() => {
46
40
  const keys = keysRef.current;
47
- if (!keys.size) {
48
- finishedRef.current.clear();
49
- return;
50
- }
51
41
 
52
42
  keys.clear();
53
- finishedRef.current.clear();
54
43
  shared.modify((prev) => {
55
44
  "worklet";
56
45
  prev.length = 0;
@@ -2,11 +2,11 @@ import { type Route, StackActions } from "@react-navigation/native";
2
2
  import { useLayoutEffect, useState } from "react";
3
3
  import useStableCallback from "../../../../shared/hooks/use-stable-callback";
4
4
  import type { BlankStackDescriptorMap } from "../../../types";
5
- import type { StackNavigationContextProps } from "../_types";
6
5
  import { areDescriptorsEqual } from "../helpers/are-descriptors-equal";
7
6
  import { composeDescriptors } from "../helpers/compose-descriptors";
8
7
  import { haveSameRouteKeys } from "../helpers/have-same-route-keys";
9
8
  import { routesAreIdentical } from "../helpers/routes-are-identical";
9
+ import type { StackNavigationContextProps } from "../types";
10
10
  import { useClosingRouteKeys } from "./use-closing-route-keys";
11
11
  import { usePrevious } from "./use-previous";
12
12
 
@@ -1,45 +1,50 @@
1
- import { type ComponentType, createContext, useContext, useMemo } from "react";
1
+ import { useMemo } from "react";
2
+ import createProvider from "../../../shared/utils/create-provider";
2
3
  import type { BlankStackScene } from "../../types";
4
+ import { calculateActiveScreensLimit } from "./helpers/calculate-active-screens-limit";
3
5
  import { useStackNavigationState } from "./hooks/use-stack-navigation-state";
4
6
  import type {
5
7
  StackNavigationContextProps,
6
8
  StackNavigationContextValue,
7
- } from "./_types";
8
- import { calculateActiveScreensLimit } from "./helpers/calculate-active-screens-limit";
9
-
10
- export const StackNavigationContext =
11
- createContext<StackNavigationContextValue | null>(null);
9
+ } from "./types";
12
10
 
13
- export function withStackNavigationProvider(
14
- Component: ComponentType<StackNavigationContextValue>,
15
- ) {
16
- return function StackNavigationWrapper(props: StackNavigationContextProps) {
11
+ const { withStackNavigationProvider, useStackNavigationContext } =
12
+ createProvider("StackNavigation")<
13
+ StackNavigationContextProps,
14
+ StackNavigationContextValue
15
+ >((props) => {
17
16
  const { state, handleCloseRoute, closingRouteKeys } =
18
17
  useStackNavigationState(props);
19
18
 
20
- const scenes = useMemo(() => {
21
- return state.routes.reduce((acc, route) => {
22
- acc.push({
23
- route,
24
- descriptor: state.descriptors[route.key],
25
- });
26
- return acc;
27
- }, [] as BlankStackScene[]);
28
- }, [state.routes, state.descriptors]);
29
-
30
- const activeScreensLimit = useMemo(() => {
31
- return calculateActiveScreensLimit(state.routes, state.descriptors);
32
- }, [state.routes, state.descriptors]);
33
-
34
- const shouldShowFloatOverlay = useMemo(() => {
35
- return state.routes.some((route) => {
36
- const options = state.descriptors[route.key]?.options;
37
- return options?.overlayMode === "float" && options?.overlayShown;
38
- });
39
- }, [state.routes, state.descriptors]);
40
-
41
- const contextValue = useMemo<StackNavigationContextValue>(() => {
42
- return {
19
+ const { scenes, activeScreensLimit, shouldShowFloatOverlay } =
20
+ useMemo(() => {
21
+ const scenes: BlankStackScene[] = [];
22
+ let shouldShowFloatOverlay = false;
23
+
24
+ for (const route of state.routes) {
25
+ const descriptor = state.descriptors[route.key];
26
+ scenes.push({ route, descriptor });
27
+
28
+ if (!shouldShowFloatOverlay) {
29
+ const options = descriptor?.options;
30
+ shouldShowFloatOverlay =
31
+ options?.overlayMode === "float" &&
32
+ options?.overlayShown === true;
33
+ }
34
+ }
35
+
36
+ return {
37
+ scenes,
38
+ activeScreensLimit: calculateActiveScreensLimit(
39
+ state.routes,
40
+ state.descriptors,
41
+ ),
42
+ shouldShowFloatOverlay,
43
+ };
44
+ }, [state.routes, state.descriptors]);
45
+
46
+ return {
47
+ value: {
43
48
  routes: state.routes,
44
49
  focusedIndex: props.state.index,
45
50
  descriptors: state.descriptors,
@@ -48,33 +53,8 @@ export function withStackNavigationProvider(
48
53
  handleCloseRoute,
49
54
  scenes,
50
55
  shouldShowFloatOverlay,
51
- };
52
- }, [
53
- state,
54
- scenes,
55
- activeScreensLimit,
56
- closingRouteKeys,
57
- handleCloseRoute,
58
- props.state.index,
59
- shouldShowFloatOverlay,
60
- ]);
61
-
62
- return (
63
- <StackNavigationContext.Provider value={contextValue}>
64
- <Component {...contextValue} />
65
- </StackNavigationContext.Provider>
66
- );
67
- };
68
- }
69
-
70
- export const useStackNavigationContext = () => {
71
- const context = useContext(StackNavigationContext);
72
-
73
- if (!context) {
74
- throw new Error(
75
- "StackNavigationContext.Provider is missing in the component tree.",
76
- );
77
- }
56
+ },
57
+ };
58
+ });
78
59
 
79
- return context;
80
- };
60
+ export { useStackNavigationContext, withStackNavigationProvider };