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
@@ -33,7 +33,8 @@ import {
33
33
  ScreenStack,
34
34
  ScreenStackItem,
35
35
  } from "react-native-screens";
36
- import { NativeStackScreenLifecycleController } from "../../shared/components/controllers/screen-lifecycle";
36
+ import { NativeStackScreenLifecycleController } from "../../shared/components/controllers/native-stack-lifecycle";
37
+ import { RoutesProvider } from "../../shared/providers/routes.provider";
37
38
  import { ScreenTransitionProvider } from "../../shared/providers/screen-transition.provider";
38
39
  import type {
39
40
  NativeStackDescriptor,
@@ -515,118 +516,126 @@ export function NativeStackView({
515
516
 
516
517
  const routes = state.routes.concat(state.preloadedRoutes);
517
518
 
519
+ // Memoize route keys array for RoutesProvider
520
+ const routeKeys = React.useMemo(
521
+ () => routes.map((route) => route.key),
522
+ [routes],
523
+ );
524
+
518
525
  return (
519
- <GestureHandlerRootView>
520
- <SafeAreaProviderCompat>
521
- <ScreenStack style={styles.container}>
522
- {routes.map((route, index) => {
523
- const descriptor =
524
- descriptors[route.key] ?? preloadedDescriptors[route.key];
525
- const isFocused = state.index === index;
526
- const isBelowFocused = state.index - 1 === index;
527
- const previousKey = state.routes[index - 1]?.key;
528
- const nextKey = state.routes[index + 1]?.key;
529
- const previousDescriptor = previousKey
530
- ? descriptors[previousKey]
531
- : undefined;
532
- const nextDescriptor = nextKey ? descriptors[nextKey] : undefined;
533
-
534
- const isModal = modalRouteKeys.includes(route.key);
535
-
536
- const isPreloaded =
537
- preloadedDescriptors[route.key] !== undefined &&
538
- descriptors[route.key] === undefined;
539
-
540
- // On Fabric, when screen is frozen, animated and reanimated values are not updated
541
- // due to component being unmounted. To avoid this, we don't freeze the previous screen there
542
- const shouldFreeze = isFabric()
543
- ? !isPreloaded && !isFocused && !isBelowFocused
544
- : !isPreloaded && !isFocused;
545
-
546
- return (
547
- <SceneView
548
- key={route.key}
549
- index={index}
550
- focused={isFocused}
551
- shouldFreeze={shouldFreeze}
552
- descriptor={descriptor}
553
- previousDescriptor={previousDescriptor}
554
- nextDescriptor={nextDescriptor}
555
- isPresentationModal={isModal}
556
- isPreloaded={isPreloaded}
557
- onWillDisappear={() => {
558
- navigation.emit({
559
- type: "transitionStart",
560
- data: { closing: true },
561
- target: route.key,
562
- });
563
- }}
564
- onWillAppear={() => {
565
- navigation.emit({
566
- type: "transitionStart",
567
- data: { closing: false },
568
- target: route.key,
569
- });
570
- }}
571
- onAppear={() => {
572
- navigation.emit({
573
- type: "transitionEnd",
574
- data: { closing: false },
575
- target: route.key,
576
- });
577
- }}
578
- onDisappear={() => {
579
- navigation.emit({
580
- type: "transitionEnd",
581
- data: { closing: true },
582
- target: route.key,
583
- });
584
- }}
585
- onDismissed={(event) => {
586
- navigation.dispatch({
587
- ...StackActions.pop(event.nativeEvent.dismissCount),
588
- source: route.key,
589
- target: state.key,
590
- });
591
-
592
- setNextDismissedKey(route.key);
593
- }}
594
- onHeaderBackButtonClicked={() => {
595
- navigation.dispatch({
596
- ...StackActions.pop(),
597
- source: route.key,
598
- target: state.key,
599
- });
600
- }}
601
- onNativeDismissCancelled={(event) => {
602
- navigation.dispatch({
603
- ...StackActions.pop(event.nativeEvent.dismissCount),
604
- source: route.key,
605
- target: state.key,
606
- });
607
- }}
608
- onGestureCancel={() => {
609
- navigation.emit({
610
- type: "gestureCancel",
611
- target: route.key,
612
- });
613
- }}
614
- onSheetDetentChanged={(event) => {
615
- navigation.emit({
616
- type: "sheetDetentChange",
617
- target: route.key,
618
- data: {
619
- index: event.nativeEvent.index,
620
- stable: event.nativeEvent.isStable,
621
- },
622
- });
623
- }}
624
- />
625
- );
626
- })}
627
- </ScreenStack>
628
- </SafeAreaProviderCompat>
629
- </GestureHandlerRootView>
526
+ <RoutesProvider routeKeys={routeKeys}>
527
+ <GestureHandlerRootView>
528
+ <SafeAreaProviderCompat>
529
+ <ScreenStack style={styles.container}>
530
+ {routes.map((route, index) => {
531
+ const descriptor =
532
+ descriptors[route.key] ?? preloadedDescriptors[route.key];
533
+ const isFocused = state.index === index;
534
+ const isBelowFocused = state.index - 1 === index;
535
+ const previousKey = state.routes[index - 1]?.key;
536
+ const nextKey = state.routes[index + 1]?.key;
537
+ const previousDescriptor = previousKey
538
+ ? descriptors[previousKey]
539
+ : undefined;
540
+ const nextDescriptor = nextKey ? descriptors[nextKey] : undefined;
541
+
542
+ const isModal = modalRouteKeys.includes(route.key);
543
+
544
+ const isPreloaded =
545
+ preloadedDescriptors[route.key] !== undefined &&
546
+ descriptors[route.key] === undefined;
547
+
548
+ // On Fabric, when screen is frozen, animated and reanimated values are not updated
549
+ // due to component being unmounted. To avoid this, we don't freeze the previous screen there
550
+ const shouldFreeze = isFabric()
551
+ ? !isPreloaded && !isFocused && !isBelowFocused
552
+ : !isPreloaded && !isFocused;
553
+
554
+ return (
555
+ <SceneView
556
+ key={route.key}
557
+ index={index}
558
+ focused={isFocused}
559
+ shouldFreeze={shouldFreeze}
560
+ descriptor={descriptor}
561
+ previousDescriptor={previousDescriptor}
562
+ nextDescriptor={nextDescriptor}
563
+ isPresentationModal={isModal}
564
+ isPreloaded={isPreloaded}
565
+ onWillDisappear={() => {
566
+ navigation.emit({
567
+ type: "transitionStart",
568
+ data: { closing: true },
569
+ target: route.key,
570
+ });
571
+ }}
572
+ onWillAppear={() => {
573
+ navigation.emit({
574
+ type: "transitionStart",
575
+ data: { closing: false },
576
+ target: route.key,
577
+ });
578
+ }}
579
+ onAppear={() => {
580
+ navigation.emit({
581
+ type: "transitionEnd",
582
+ data: { closing: false },
583
+ target: route.key,
584
+ });
585
+ }}
586
+ onDisappear={() => {
587
+ navigation.emit({
588
+ type: "transitionEnd",
589
+ data: { closing: true },
590
+ target: route.key,
591
+ });
592
+ }}
593
+ onDismissed={(event) => {
594
+ navigation.dispatch({
595
+ ...StackActions.pop(event.nativeEvent.dismissCount),
596
+ source: route.key,
597
+ target: state.key,
598
+ });
599
+
600
+ setNextDismissedKey(route.key);
601
+ }}
602
+ onHeaderBackButtonClicked={() => {
603
+ navigation.dispatch({
604
+ ...StackActions.pop(),
605
+ source: route.key,
606
+ target: state.key,
607
+ });
608
+ }}
609
+ onNativeDismissCancelled={(event) => {
610
+ navigation.dispatch({
611
+ ...StackActions.pop(event.nativeEvent.dismissCount),
612
+ source: route.key,
613
+ target: state.key,
614
+ });
615
+ }}
616
+ onGestureCancel={() => {
617
+ navigation.emit({
618
+ type: "gestureCancel",
619
+ target: route.key,
620
+ });
621
+ }}
622
+ onSheetDetentChanged={(event) => {
623
+ navigation.emit({
624
+ type: "sheetDetentChange",
625
+ target: route.key,
626
+ data: {
627
+ index: event.nativeEvent.index,
628
+ stable: event.nativeEvent.isStable,
629
+ },
630
+ });
631
+ }}
632
+ />
633
+ );
634
+ })}
635
+ </ScreenStack>
636
+ </SafeAreaProviderCompat>
637
+ </GestureHandlerRootView>
638
+ </RoutesProvider>
630
639
  );
631
640
  }
632
641