react-native-screen-transitions 2.0.6 → 2.1.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 (297) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +100 -77
  3. package/lib/commonjs/components/{bounds-activator.js → bound-capture.js} +4 -4
  4. package/lib/commonjs/components/bound-capture.js.map +1 -0
  5. package/lib/commonjs/components/controllers/screen-lifecycle.js +18 -4
  6. package/lib/commonjs/components/controllers/screen-lifecycle.js.map +1 -1
  7. package/lib/commonjs/components/create-transition-aware-component.js +14 -12
  8. package/lib/commonjs/components/create-transition-aware-component.js.map +1 -1
  9. package/lib/commonjs/components/integrations/masked-view.js +52 -0
  10. package/lib/commonjs/components/integrations/masked-view.js.map +1 -0
  11. package/lib/commonjs/components/root-transition-aware.js +6 -15
  12. package/lib/commonjs/components/root-transition-aware.js.map +1 -1
  13. package/lib/commonjs/configs/index.js +4 -1
  14. package/lib/commonjs/configs/index.js.map +1 -1
  15. package/lib/commonjs/configs/presets.js +378 -7
  16. package/lib/commonjs/configs/presets.js.map +1 -1
  17. package/lib/commonjs/configs/specs.js +2 -1
  18. package/lib/commonjs/configs/specs.js.map +1 -1
  19. package/lib/commonjs/hooks/animation/use-associated-style.js +7 -10
  20. package/lib/commonjs/hooks/animation/use-associated-style.js.map +1 -1
  21. package/lib/commonjs/hooks/animation/use-screen-animation.js +37 -37
  22. package/lib/commonjs/hooks/animation/use-screen-animation.js.map +1 -1
  23. package/lib/commonjs/hooks/bounds/use-bound-registry.js +73 -0
  24. package/lib/commonjs/hooks/bounds/use-bound-registry.js.map +1 -0
  25. package/lib/commonjs/hooks/gestures/use-build-gestures.js +156 -152
  26. package/lib/commonjs/hooks/gestures/use-build-gestures.js.map +1 -1
  27. package/lib/commonjs/hooks/gestures/use-parent-gesture-registry.js +28 -0
  28. package/lib/commonjs/hooks/gestures/use-parent-gesture-registry.js.map +1 -0
  29. package/lib/commonjs/hooks/gestures/use-scroll-registry.js +146 -0
  30. package/lib/commonjs/hooks/gestures/use-scroll-registry.js.map +1 -0
  31. package/lib/commonjs/index.js +3 -0
  32. package/lib/commonjs/index.js.map +1 -1
  33. package/lib/commonjs/integrations/native-stack/views/NativeStackView.native.js +7 -4
  34. package/lib/commonjs/integrations/native-stack/views/NativeStackView.native.js.map +1 -1
  35. package/lib/commonjs/providers/gestures.js +16 -16
  36. package/lib/commonjs/providers/gestures.js.map +1 -1
  37. package/lib/commonjs/providers/transition-styles.js +44 -0
  38. package/lib/commonjs/providers/transition-styles.js.map +1 -0
  39. package/lib/commonjs/stores/bounds.js +142 -1
  40. package/lib/commonjs/stores/bounds.js.map +1 -1
  41. package/lib/commonjs/stores/utils/reset-stores-for-screen.js +4 -2
  42. package/lib/commonjs/stores/utils/reset-stores-for-screen.js.map +1 -1
  43. package/lib/commonjs/types/gesture.js +11 -0
  44. package/lib/commonjs/types/gesture.js.map +1 -1
  45. package/lib/commonjs/utils/animation/derivations.js +39 -0
  46. package/lib/commonjs/utils/animation/derivations.js.map +1 -0
  47. package/lib/commonjs/utils/animation/run-transition.js +6 -2
  48. package/lib/commonjs/utils/animation/run-transition.js.map +1 -1
  49. package/lib/commonjs/utils/bounds/_utils/flatten-styles.js.map +1 -0
  50. package/lib/commonjs/utils/bounds/_utils/geometry.js +179 -0
  51. package/lib/commonjs/utils/bounds/_utils/geometry.js.map +1 -0
  52. package/lib/commonjs/utils/bounds/{get-bounds.js → _utils/get-bounds.js} +7 -9
  53. package/lib/commonjs/utils/bounds/_utils/get-bounds.js.map +1 -0
  54. package/lib/commonjs/utils/bounds/_utils/is-bounds-equal.js +19 -0
  55. package/lib/commonjs/utils/bounds/_utils/is-bounds-equal.js.map +1 -0
  56. package/lib/commonjs/utils/bounds/_utils/style-composers.js +201 -0
  57. package/lib/commonjs/utils/bounds/_utils/style-composers.js.map +1 -0
  58. package/lib/commonjs/utils/bounds/constants.js +14 -3
  59. package/lib/commonjs/utils/bounds/constants.js.map +1 -1
  60. package/lib/commonjs/utils/bounds/index.js +210 -17
  61. package/lib/commonjs/utils/bounds/index.js.map +1 -1
  62. package/lib/commonjs/utils/gesture/apply-offset-rules.js +233 -0
  63. package/lib/commonjs/utils/gesture/apply-offset-rules.js.map +1 -0
  64. package/lib/commonjs/utils/gesture/check-gesture-activation.js +231 -0
  65. package/lib/commonjs/utils/gesture/check-gesture-activation.js.map +1 -0
  66. package/lib/commonjs/utils/gesture/determine-dismissal.js +98 -0
  67. package/lib/commonjs/utils/gesture/determine-dismissal.js.map +1 -0
  68. package/lib/module/components/{bounds-activator.js → bound-capture.js} +2 -2
  69. package/lib/module/components/bound-capture.js.map +1 -0
  70. package/lib/module/components/controllers/screen-lifecycle.js +18 -4
  71. package/lib/module/components/controllers/screen-lifecycle.js.map +1 -1
  72. package/lib/module/components/create-transition-aware-component.js +14 -12
  73. package/lib/module/components/create-transition-aware-component.js.map +1 -1
  74. package/lib/module/components/integrations/masked-view.js +48 -0
  75. package/lib/module/components/integrations/masked-view.js.map +1 -0
  76. package/lib/module/components/root-transition-aware.js +7 -16
  77. package/lib/module/components/root-transition-aware.js.map +1 -1
  78. package/lib/module/configs/index.js +6 -3
  79. package/lib/module/configs/index.js.map +1 -1
  80. package/lib/module/configs/presets.js +374 -6
  81. package/lib/module/configs/presets.js.map +1 -1
  82. package/lib/module/configs/specs.js +2 -1
  83. package/lib/module/configs/specs.js.map +1 -1
  84. package/lib/module/hooks/animation/use-associated-style.js +6 -10
  85. package/lib/module/hooks/animation/use-associated-style.js.map +1 -1
  86. package/lib/module/hooks/animation/use-screen-animation.js +37 -37
  87. package/lib/module/hooks/animation/use-screen-animation.js.map +1 -1
  88. package/lib/module/hooks/bounds/use-bound-registry.js +68 -0
  89. package/lib/module/hooks/bounds/use-bound-registry.js.map +1 -0
  90. package/lib/module/hooks/gestures/use-build-gestures.js +156 -153
  91. package/lib/module/hooks/gestures/use-build-gestures.js.map +1 -1
  92. package/lib/module/hooks/gestures/use-parent-gesture-registry.js +23 -0
  93. package/lib/module/hooks/gestures/use-parent-gesture-registry.js.map +1 -0
  94. package/lib/module/hooks/gestures/use-scroll-registry.js +140 -0
  95. package/lib/module/hooks/gestures/use-scroll-registry.js.map +1 -0
  96. package/lib/module/index.js +2 -0
  97. package/lib/module/index.js.map +1 -1
  98. package/lib/module/integrations/native-stack/views/NativeStackView.native.js +7 -4
  99. package/lib/module/integrations/native-stack/views/NativeStackView.native.js.map +1 -1
  100. package/lib/module/providers/gestures.js +16 -16
  101. package/lib/module/providers/gestures.js.map +1 -1
  102. package/lib/module/providers/transition-styles.js +39 -0
  103. package/lib/module/providers/transition-styles.js.map +1 -0
  104. package/lib/module/stores/bounds.js +142 -1
  105. package/lib/module/stores/bounds.js.map +1 -1
  106. package/lib/module/stores/utils/reset-stores-for-screen.js +4 -2
  107. package/lib/module/stores/utils/reset-stores-for-screen.js.map +1 -1
  108. package/lib/module/types/gesture.js +7 -0
  109. package/lib/module/types/gesture.js.map +1 -1
  110. package/lib/module/utils/animation/derivations.js +34 -0
  111. package/lib/module/utils/animation/derivations.js.map +1 -0
  112. package/lib/module/utils/animation/run-transition.js +6 -2
  113. package/lib/module/utils/animation/run-transition.js.map +1 -1
  114. package/lib/module/utils/bounds/_utils/flatten-styles.js.map +1 -0
  115. package/lib/module/utils/bounds/_utils/geometry.js +174 -0
  116. package/lib/module/utils/bounds/_utils/geometry.js.map +1 -0
  117. package/lib/module/utils/bounds/{get-bounds.js → _utils/get-bounds.js} +7 -9
  118. package/lib/module/utils/bounds/_utils/get-bounds.js.map +1 -0
  119. package/lib/module/utils/bounds/_utils/is-bounds-equal.js +14 -0
  120. package/lib/module/utils/bounds/_utils/is-bounds-equal.js.map +1 -0
  121. package/lib/module/utils/bounds/_utils/style-composers.js +194 -0
  122. package/lib/module/utils/bounds/_utils/style-composers.js.map +1 -0
  123. package/lib/module/utils/bounds/constants.js +14 -3
  124. package/lib/module/utils/bounds/constants.js.map +1 -1
  125. package/lib/module/utils/bounds/index.js +208 -15
  126. package/lib/module/utils/bounds/index.js.map +1 -1
  127. package/lib/module/utils/gesture/apply-offset-rules.js +228 -0
  128. package/lib/module/utils/gesture/apply-offset-rules.js.map +1 -0
  129. package/lib/module/utils/gesture/check-gesture-activation.js +226 -0
  130. package/lib/module/utils/gesture/check-gesture-activation.js.map +1 -0
  131. package/lib/module/utils/gesture/determine-dismissal.js +93 -0
  132. package/lib/module/utils/gesture/determine-dismissal.js.map +1 -0
  133. package/lib/typescript/components/bound-capture.d.ts +8 -0
  134. package/lib/typescript/components/bound-capture.d.ts.map +1 -0
  135. package/lib/typescript/components/controllers/screen-lifecycle.d.ts.map +1 -1
  136. package/lib/typescript/components/create-transition-aware-component.d.ts.map +1 -1
  137. package/lib/typescript/components/integrations/masked-view.d.ts +6 -0
  138. package/lib/typescript/components/integrations/masked-view.d.ts.map +1 -0
  139. package/lib/typescript/components/root-transition-aware.d.ts +3 -3
  140. package/lib/typescript/components/root-transition-aware.d.ts.map +1 -1
  141. package/lib/typescript/configs/index.d.ts +3 -0
  142. package/lib/typescript/configs/index.d.ts.map +1 -1
  143. package/lib/typescript/configs/presets.d.ts +3 -0
  144. package/lib/typescript/configs/presets.d.ts.map +1 -1
  145. package/lib/typescript/configs/specs.d.ts.map +1 -1
  146. package/lib/typescript/hooks/animation/use-associated-style.d.ts +6 -4
  147. package/lib/typescript/hooks/animation/use-associated-style.d.ts.map +1 -1
  148. package/lib/typescript/hooks/animation/use-screen-animation.d.ts.map +1 -1
  149. package/lib/typescript/hooks/bounds/{use-bound-measurer.d.ts → use-bound-registry.d.ts} +5 -4
  150. package/lib/typescript/hooks/bounds/{use-bound-measurer.d.ts.map → use-bound-registry.d.ts.map} +1 -1
  151. package/lib/typescript/hooks/gestures/use-build-gestures.d.ts +6 -5
  152. package/lib/typescript/hooks/gestures/use-build-gestures.d.ts.map +1 -1
  153. package/lib/typescript/hooks/gestures/use-parent-gesture-registry.d.ts +6 -0
  154. package/lib/typescript/hooks/gestures/use-parent-gesture-registry.d.ts.map +1 -0
  155. package/lib/typescript/hooks/gestures/{use-scroll-progress.d.ts → use-scroll-registry.d.ts} +2 -2
  156. package/lib/typescript/hooks/gestures/use-scroll-registry.d.ts.map +1 -0
  157. package/lib/typescript/index.d.ts +13 -8
  158. package/lib/typescript/index.d.ts.map +1 -1
  159. package/lib/typescript/integrations/native-stack/views/NativeStackView.native.d.ts.map +1 -1
  160. package/lib/typescript/providers/gestures.d.ts +4 -2
  161. package/lib/typescript/providers/gestures.d.ts.map +1 -1
  162. package/lib/typescript/providers/transition-styles.d.ts +8 -0
  163. package/lib/typescript/providers/transition-styles.d.ts.map +1 -0
  164. package/lib/typescript/stores/bounds.d.ts +11 -0
  165. package/lib/typescript/stores/bounds.d.ts.map +1 -1
  166. package/lib/typescript/stores/utils/reset-stores-for-screen.d.ts +3 -1
  167. package/lib/typescript/stores/utils/reset-stores-for-screen.d.ts.map +1 -1
  168. package/lib/typescript/types/bounds.d.ts +5 -1
  169. package/lib/typescript/types/bounds.d.ts.map +1 -1
  170. package/lib/typescript/types/gesture.d.ts +14 -0
  171. package/lib/typescript/types/gesture.d.ts.map +1 -1
  172. package/lib/typescript/types/navigator.d.ts +5 -1
  173. package/lib/typescript/types/navigator.d.ts.map +1 -1
  174. package/lib/typescript/utils/animation/derivations.d.ts +19 -0
  175. package/lib/typescript/utils/animation/derivations.d.ts.map +1 -0
  176. package/lib/typescript/utils/animation/run-transition.d.ts +2 -1
  177. package/lib/typescript/utils/animation/run-transition.d.ts.map +1 -1
  178. package/lib/typescript/utils/bounds/_types/builder.d.ts +96 -14
  179. package/lib/typescript/utils/bounds/_types/builder.d.ts.map +1 -1
  180. package/lib/typescript/utils/bounds/_types/geometry.d.ts +0 -1
  181. package/lib/typescript/utils/bounds/_types/geometry.d.ts.map +1 -1
  182. package/lib/typescript/utils/bounds/_utils/flatten-styles.d.ts.map +1 -0
  183. package/lib/typescript/utils/bounds/{geometry.d.ts → _utils/geometry.d.ts} +8 -5
  184. package/lib/typescript/utils/bounds/_utils/geometry.d.ts.map +1 -0
  185. package/lib/typescript/utils/bounds/_utils/get-bounds.d.ts +4 -0
  186. package/lib/typescript/utils/bounds/_utils/get-bounds.d.ts.map +1 -0
  187. package/lib/typescript/utils/bounds/_utils/is-bounds-equal.d.ts +7 -0
  188. package/lib/typescript/utils/bounds/_utils/is-bounds-equal.d.ts.map +1 -0
  189. package/lib/typescript/utils/bounds/{style-composers.d.ts → _utils/style-composers.d.ts} +7 -10
  190. package/lib/typescript/utils/bounds/_utils/style-composers.d.ts.map +1 -0
  191. package/lib/typescript/utils/bounds/constants.d.ts +5 -5
  192. package/lib/typescript/utils/bounds/constants.d.ts.map +1 -1
  193. package/lib/typescript/utils/bounds/index.d.ts +2 -4
  194. package/lib/typescript/utils/bounds/index.d.ts.map +1 -1
  195. package/lib/typescript/utils/gesture/apply-offset-rules.d.ts +38 -0
  196. package/lib/typescript/utils/gesture/apply-offset-rules.d.ts.map +1 -0
  197. package/lib/typescript/utils/gesture/check-gesture-activation.d.ts +38 -0
  198. package/lib/typescript/utils/gesture/check-gesture-activation.d.ts.map +1 -0
  199. package/lib/typescript/utils/gesture/determine-dismissal.d.ts +25 -0
  200. package/lib/typescript/utils/gesture/determine-dismissal.d.ts.map +1 -0
  201. package/package.json +2 -2
  202. package/src/__tests__/geometry.test.ts +15 -12
  203. package/src/components/{bounds-activator.tsx → bound-capture.tsx} +1 -1
  204. package/src/components/controllers/screen-lifecycle.tsx +13 -5
  205. package/src/components/create-transition-aware-component.tsx +17 -11
  206. package/src/components/integrations/masked-view.tsx +56 -0
  207. package/src/components/root-transition-aware.tsx +31 -39
  208. package/src/configs/index.ts +20 -8
  209. package/src/configs/presets.ts +401 -6
  210. package/src/configs/specs.ts +1 -0
  211. package/src/hooks/animation/use-associated-style.tsx +12 -11
  212. package/src/hooks/animation/use-screen-animation.tsx +48 -49
  213. package/src/hooks/bounds/{use-bound-measurer.tsx → use-bound-registry.tsx} +32 -20
  214. package/src/hooks/gestures/use-build-gestures.tsx +193 -228
  215. package/src/hooks/gestures/use-parent-gesture-registry.tsx +18 -0
  216. package/src/hooks/gestures/use-scroll-registry.tsx +145 -0
  217. package/src/index.ts +2 -0
  218. package/src/integrations/native-stack/views/NativeStackView.native.tsx +8 -5
  219. package/src/providers/gestures.tsx +19 -22
  220. package/src/providers/transition-styles.tsx +52 -0
  221. package/src/stores/bounds.ts +156 -0
  222. package/src/stores/utils/reset-stores-for-screen.ts +7 -2
  223. package/src/types/bounds.ts +8 -1
  224. package/src/types/gesture.ts +19 -0
  225. package/src/types/navigator.ts +5 -1
  226. package/src/utils/animation/derivations.ts +38 -0
  227. package/src/utils/animation/run-transition.ts +4 -1
  228. package/src/utils/bounds/_types/builder.ts +127 -11
  229. package/src/utils/bounds/_types/geometry.ts +0 -1
  230. package/src/utils/bounds/_utils/geometry.ts +166 -0
  231. package/src/utils/bounds/_utils/get-bounds.ts +54 -0
  232. package/src/utils/bounds/_utils/is-bounds-equal.ts +24 -0
  233. package/src/utils/bounds/_utils/style-composers.ts +216 -0
  234. package/src/utils/bounds/constants.ts +37 -22
  235. package/src/utils/bounds/index.ts +269 -19
  236. package/src/utils/gesture/apply-offset-rules.ts +314 -0
  237. package/src/utils/gesture/check-gesture-activation.ts +310 -0
  238. package/src/utils/gesture/determine-dismissal.ts +131 -0
  239. package/lib/commonjs/components/bounds-activator.js.map +0 -1
  240. package/lib/commonjs/hooks/bounds/use-bound-measurer.js +0 -52
  241. package/lib/commonjs/hooks/bounds/use-bound-measurer.js.map +0 -1
  242. package/lib/commonjs/hooks/gestures/use-scroll-progress.js +0 -57
  243. package/lib/commonjs/hooks/gestures/use-scroll-progress.js.map +0 -1
  244. package/lib/commonjs/utils/bounds/build-bound-styles.js +0 -145
  245. package/lib/commonjs/utils/bounds/build-bound-styles.js.map +0 -1
  246. package/lib/commonjs/utils/bounds/flatten-styles.js.map +0 -1
  247. package/lib/commonjs/utils/bounds/geometry.js +0 -94
  248. package/lib/commonjs/utils/bounds/geometry.js.map +0 -1
  249. package/lib/commonjs/utils/bounds/get-bounds.js.map +0 -1
  250. package/lib/commonjs/utils/bounds/style-composers.js +0 -199
  251. package/lib/commonjs/utils/bounds/style-composers.js.map +0 -1
  252. package/lib/commonjs/utils/gesture/apply-gesture-activation-criteria.js +0 -81
  253. package/lib/commonjs/utils/gesture/apply-gesture-activation-criteria.js.map +0 -1
  254. package/lib/commonjs/utils/gesture/normalize-gesture-translation.js +0 -21
  255. package/lib/commonjs/utils/gesture/normalize-gesture-translation.js.map +0 -1
  256. package/lib/module/components/bounds-activator.js.map +0 -1
  257. package/lib/module/hooks/bounds/use-bound-measurer.js +0 -47
  258. package/lib/module/hooks/bounds/use-bound-measurer.js.map +0 -1
  259. package/lib/module/hooks/gestures/use-scroll-progress.js +0 -52
  260. package/lib/module/hooks/gestures/use-scroll-progress.js.map +0 -1
  261. package/lib/module/utils/bounds/build-bound-styles.js +0 -141
  262. package/lib/module/utils/bounds/build-bound-styles.js.map +0 -1
  263. package/lib/module/utils/bounds/flatten-styles.js.map +0 -1
  264. package/lib/module/utils/bounds/geometry.js +0 -89
  265. package/lib/module/utils/bounds/geometry.js.map +0 -1
  266. package/lib/module/utils/bounds/get-bounds.js.map +0 -1
  267. package/lib/module/utils/bounds/style-composers.js +0 -191
  268. package/lib/module/utils/bounds/style-composers.js.map +0 -1
  269. package/lib/module/utils/gesture/apply-gesture-activation-criteria.js +0 -76
  270. package/lib/module/utils/gesture/apply-gesture-activation-criteria.js.map +0 -1
  271. package/lib/module/utils/gesture/normalize-gesture-translation.js +0 -16
  272. package/lib/module/utils/gesture/normalize-gesture-translation.js.map +0 -1
  273. package/lib/typescript/components/bounds-activator.d.ts +0 -8
  274. package/lib/typescript/components/bounds-activator.d.ts.map +0 -1
  275. package/lib/typescript/hooks/gestures/use-scroll-progress.d.ts.map +0 -1
  276. package/lib/typescript/utils/bounds/build-bound-styles.d.ts +0 -4
  277. package/lib/typescript/utils/bounds/build-bound-styles.d.ts.map +0 -1
  278. package/lib/typescript/utils/bounds/flatten-styles.d.ts.map +0 -1
  279. package/lib/typescript/utils/bounds/geometry.d.ts.map +0 -1
  280. package/lib/typescript/utils/bounds/get-bounds.d.ts +0 -4
  281. package/lib/typescript/utils/bounds/get-bounds.d.ts.map +0 -1
  282. package/lib/typescript/utils/bounds/style-composers.d.ts.map +0 -1
  283. package/lib/typescript/utils/gesture/apply-gesture-activation-criteria.d.ts +0 -17
  284. package/lib/typescript/utils/gesture/apply-gesture-activation-criteria.d.ts.map +0 -1
  285. package/lib/typescript/utils/gesture/normalize-gesture-translation.d.ts +0 -6
  286. package/lib/typescript/utils/gesture/normalize-gesture-translation.d.ts.map +0 -1
  287. package/src/hooks/gestures/use-scroll-progress.tsx +0 -60
  288. package/src/utils/bounds/build-bound-styles.ts +0 -184
  289. package/src/utils/bounds/geometry.ts +0 -113
  290. package/src/utils/bounds/get-bounds.ts +0 -56
  291. package/src/utils/bounds/style-composers.ts +0 -172
  292. package/src/utils/gesture/apply-gesture-activation-criteria.ts +0 -109
  293. package/src/utils/gesture/normalize-gesture-translation.ts +0 -20
  294. /package/lib/commonjs/utils/bounds/{flatten-styles.js → _utils/flatten-styles.js} +0 -0
  295. /package/lib/module/utils/bounds/{flatten-styles.js → _utils/flatten-styles.js} +0 -0
  296. /package/lib/typescript/utils/bounds/{flatten-styles.d.ts → _utils/flatten-styles.d.ts} +0 -0
  297. /package/src/utils/bounds/{flatten-styles.ts → _utils/flatten-styles.ts} +0 -0
@@ -1,3 +1,4 @@
1
+ import { Platform } from "react-native";
1
2
  import {
2
3
  Extrapolation,
3
4
  interpolate,
@@ -6,6 +7,8 @@ import {
6
7
  import type { ScreenTransitionConfig } from "../types/navigator";
7
8
  import { DefaultSpec } from "./specs";
8
9
 
10
+ const platform = Platform.OS;
11
+
9
12
  export const SlideFromTop = (
10
13
  config: Partial<ScreenTransitionConfig> = {},
11
14
  ): ScreenTransitionConfig => {
@@ -181,9 +184,7 @@ export const ElasticCard = (
181
184
 
182
185
  const scale = interpolate(progress, [0, 1, 2], [0, 1, 0.8]);
183
186
 
184
- /**
185
- * Applies to current screen
186
- */
187
+ // applies to current screen
187
188
  const maxElasticityX = screen.width * (config.elasticFactor ?? 0.5);
188
189
  const maxElasticityY = screen.height * (config.elasticFactor ?? 0.5);
189
190
  const translateX = interpolate(
@@ -200,9 +201,7 @@ export const ElasticCard = (
200
201
  "clamp",
201
202
  );
202
203
 
203
- /**
204
- * Applies to unfocused screen ( previous screen )
205
- */
204
+ // applies to unfocused screen ( previous screen )
206
205
  const overlayColor = interpolateColor(
207
206
  progress,
208
207
  [0, 1],
@@ -225,3 +224,399 @@ export const ElasticCard = (
225
224
  ...config,
226
225
  };
227
226
  };
227
+
228
+ export const SharedIGImage = (
229
+ config: Partial<ScreenTransitionConfig> = {},
230
+ ): ScreenTransitionConfig => {
231
+ return {
232
+ gestureEnabled: true,
233
+ gestureDirection: ["vertical", "horizontal"],
234
+ enableTransitions: true,
235
+ gestureDrivesProgress: false,
236
+ screenStyleInterpolator: ({
237
+ current,
238
+ layouts: {
239
+ screen: { height, width },
240
+ },
241
+ bounds,
242
+ progress,
243
+ focused,
244
+ activeBoundId,
245
+ next,
246
+ }) => {
247
+ "worklet";
248
+
249
+ const normX = focused
250
+ ? current.gesture.normalizedX
251
+ : (next?.gesture.normalizedX ?? 0);
252
+ const normY = focused
253
+ ? current.gesture.normalizedY
254
+ : (next?.gesture.normalizedY ?? 0);
255
+
256
+ // animations for both bounds
257
+ const dragX = interpolate(
258
+ normX,
259
+ [-1, 0, 1],
260
+ [-width * 0.7, 0, width * 0.7],
261
+ );
262
+ const dragY = interpolate(
263
+ normY,
264
+ [-1, 0, 1],
265
+ [-height * 0.4, 0, height * 0.4],
266
+ );
267
+ const dragXScale = interpolate(normX, [0, 1], [1, 0.8]);
268
+ const dragYScale = interpolate(normY, [0, 1], [1, 0.8]);
269
+
270
+ const boundValues = bounds({
271
+ method: focused ? "content" : "transform",
272
+ scaleMode: "uniform",
273
+ raw: true,
274
+ });
275
+
276
+ // focused specific animations
277
+ if (focused) {
278
+ const maskedValues = bounds({
279
+ space: "absolute",
280
+ target: "fullscreen",
281
+ method: "size",
282
+ raw: true,
283
+ });
284
+
285
+ return {
286
+ overlayStyle: {
287
+ backgroundColor: "black",
288
+ opacity: interpolate(progress, [0, 1], [0, 0.5]),
289
+ },
290
+ contentStyle: {
291
+ transform: [
292
+ { translateX: dragX },
293
+ { translateY: dragY },
294
+ { scale: dragXScale },
295
+ { scale: dragYScale },
296
+ ],
297
+ },
298
+
299
+ _ROOT_CONTAINER: {
300
+ transform: [
301
+ { translateX: boundValues.translateX || 0 },
302
+ { translateY: boundValues.translateY || 0 },
303
+ //@ts-expect-error
304
+ { scale: boundValues.scale || 1 },
305
+ ],
306
+ },
307
+ _ROOT_MASKED: {
308
+ width: maskedValues.width,
309
+ height: maskedValues.height,
310
+ transform: [
311
+ { translateX: maskedValues.translateX || 0 },
312
+ { translateY: maskedValues.translateY || 0 },
313
+ ],
314
+ borderRadius: interpolate(progress, [0, 1], [0, 24]),
315
+ },
316
+ };
317
+ }
318
+
319
+ return {
320
+ contentStyle: {
321
+ pointerEvents: current.gesture.isDismissing ? "none" : "auto",
322
+ },
323
+ [activeBoundId]: {
324
+ transform: [
325
+ { translateX: dragX || 0 },
326
+ { translateY: dragY || 0 },
327
+ { translateX: boundValues.translateX || 0 },
328
+ { translateY: boundValues.translateY || 0 },
329
+ { scaleX: boundValues.scaleX || 1 },
330
+ { scaleY: boundValues.scaleY || 1 },
331
+ { scale: dragXScale },
332
+ { scale: dragYScale },
333
+ ],
334
+ },
335
+ };
336
+ },
337
+ transitionSpec: {
338
+ open: {
339
+ stiffness: 1500,
340
+ damping: 1000,
341
+ mass: 3,
342
+ overshootClamping: true,
343
+ restSpeedThreshold: 0.02,
344
+ },
345
+ close: {
346
+ stiffness: 1500,
347
+ damping: 1000,
348
+ mass: 3,
349
+ overshootClamping: true,
350
+ restSpeedThreshold: 0.02,
351
+ },
352
+ },
353
+ ...config,
354
+ };
355
+ };
356
+
357
+ export const SharedAppleMusic = (
358
+ config: Partial<ScreenTransitionConfig> = {},
359
+ ): ScreenTransitionConfig => {
360
+ return {
361
+ enableTransitions: true,
362
+ gestureEnabled: true,
363
+ gestureDirection: ["vertical", "horizontal"],
364
+ gestureDrivesProgress: false,
365
+ screenStyleInterpolator: ({
366
+ bounds,
367
+ activeBoundId,
368
+ focused,
369
+ progress,
370
+ layouts: { screen },
371
+ current,
372
+ next,
373
+ }) => {
374
+ "worklet";
375
+
376
+ const normX = focused
377
+ ? current.gesture.normalizedX
378
+ : (next?.gesture.normalizedX ?? 0);
379
+ const normY = focused
380
+ ? current.gesture.normalizedY
381
+ : (next?.gesture.normalizedY ?? 0);
382
+
383
+ /**
384
+ * ===============================
385
+ * Animations for both bounds
386
+ * ===============================
387
+ */
388
+ const dragX = interpolate(normX, [0, 1], [0, screen.width * 0.8]);
389
+ const dragY = interpolate(normY, [0, 1], [0, screen.height * 0.8]);
390
+ const dragXScale = interpolate(normX, [0, 1], [1, 0.75]);
391
+ const dragYScale = interpolate(normY, [0, 1], [1, 0.75]);
392
+
393
+ const boundValues = bounds({
394
+ method: focused ? "content" : "transform",
395
+ anchor: "top",
396
+ scaleMode: "uniform",
397
+ raw: true,
398
+ });
399
+
400
+ const opacity = interpolate(
401
+ progress,
402
+ [0, 0.35, 1, 1.25, 2],
403
+ [0, 1, 1, 1, 0],
404
+ "clamp",
405
+ );
406
+
407
+ /**
408
+ * ===============================
409
+ * Focused specific animations
410
+ * ===============================
411
+ */
412
+ if (focused) {
413
+ const maskedValues = bounds({
414
+ space: "absolute",
415
+ method: "size",
416
+ target: "fullscreen",
417
+ raw: true,
418
+ });
419
+
420
+ // Apple Music style drop shadow that increases with drag magnitude
421
+ const dragMagnitude = Math.max(Math.abs(normX), Math.abs(normY));
422
+ const shadowOpacity = interpolate(
423
+ dragMagnitude,
424
+ [0, 1],
425
+ [0, 0.25],
426
+ "clamp",
427
+ );
428
+ const shadowRadius = interpolate(
429
+ dragMagnitude,
430
+ [0, 1],
431
+ [0, 24],
432
+ "clamp",
433
+ );
434
+ const shadowOffsetY = interpolate(
435
+ dragMagnitude,
436
+ [0, 1],
437
+ [0, 20],
438
+ "clamp",
439
+ );
440
+ const elevation = interpolate(dragMagnitude, [0, 1], [0, 24], "clamp");
441
+
442
+ const IOSShadowStyle = {
443
+ shadowColor: "#000",
444
+ shadowOpacity,
445
+ shadowRadius,
446
+ shadowOffset: { width: 0, height: shadowOffsetY },
447
+ };
448
+
449
+ const AndroidShadowStyle = {
450
+ elevation,
451
+ shadowColor: "#000",
452
+ };
453
+
454
+ return {
455
+ contentStyle: {
456
+ pointerEvents: current.animating ? "none" : "auto",
457
+ transform: [
458
+ { translateX: dragX || 0 },
459
+ { translateY: dragY || 0 },
460
+ { scale: dragXScale },
461
+ { scale: dragYScale },
462
+ ],
463
+ opacity,
464
+ ...(platform === "ios" ? IOSShadowStyle : AndroidShadowStyle),
465
+ },
466
+ _ROOT_CONTAINER: {
467
+ transform: [
468
+ { translateX: boundValues.translateX || 0 },
469
+ { translateY: boundValues.translateY || 0 },
470
+ //@ts-expect-error
471
+ { scale: boundValues.scale || 1 },
472
+ ],
473
+ },
474
+ _ROOT_MASKED: {
475
+ width: maskedValues.width,
476
+ height: maskedValues.height,
477
+ transform: [
478
+ { translateX: maskedValues.translateX || 0 },
479
+ { translateY: maskedValues.translateY || 0 },
480
+ ],
481
+ borderRadius: interpolate(progress, [0, 1], [0, 24]),
482
+ },
483
+ };
484
+ }
485
+
486
+ /**
487
+ * ===============================
488
+ * Unfocused specific animations
489
+ * ===============================
490
+ */
491
+
492
+ const scaledBoundTranslateX = (boundValues.translateX || 0) * dragXScale;
493
+ const scaledBoundTranslateY = (boundValues.translateY || 0) * dragYScale;
494
+ const scaledBoundScaleX = (boundValues.scaleX || 1) * dragXScale;
495
+ const scaledBoundScaleY = (boundValues.scaleY || 1) * dragYScale;
496
+
497
+ const contentScale = interpolate(progress, [1, 2], [1, 0.9], "clamp");
498
+
499
+ return {
500
+ [activeBoundId]: {
501
+ transform: [
502
+ { translateX: dragX || 0 },
503
+ { translateY: dragY || 0 },
504
+ { translateX: scaledBoundTranslateX },
505
+ { translateY: scaledBoundTranslateY },
506
+ { scale: dragXScale },
507
+ { scale: dragYScale },
508
+ { scaleX: scaledBoundScaleX },
509
+ { scaleY: scaledBoundScaleY },
510
+ ],
511
+ opacity,
512
+ zIndex: current.animating ? 999 : -1,
513
+ position: "relative",
514
+ },
515
+ contentStyle: {
516
+ transform: [{ scale: contentScale }],
517
+ },
518
+ };
519
+ },
520
+ transitionSpec: {
521
+ open: {
522
+ stiffness: 1000,
523
+ damping: 500,
524
+ mass: 3,
525
+ overshootClamping: true,
526
+ restSpeedThreshold: 0.02,
527
+ },
528
+ close: {
529
+ stiffness: 600,
530
+ damping: 60,
531
+ mass: 3,
532
+ overshootClamping: false,
533
+ restSpeedThreshold: 0.02,
534
+ restDisplacementThreshold: 0.002,
535
+ },
536
+ },
537
+ ...config,
538
+ };
539
+ };
540
+
541
+ export const SharedXImage = (
542
+ config: Partial<ScreenTransitionConfig> = {},
543
+ ): ScreenTransitionConfig => {
544
+ return {
545
+ enableTransitions: true,
546
+ gestureEnabled: true,
547
+ gestureDirection: ["vertical", "vertical-inverted"],
548
+ gestureDrivesProgress: false,
549
+ screenStyleInterpolator: ({
550
+ focused,
551
+ activeBoundId,
552
+ bounds,
553
+ current,
554
+ layouts: { screen },
555
+ progress,
556
+ }) => {
557
+ "worklet";
558
+
559
+ // twitter doesn't animate the unfocused screen
560
+ if (!focused) return {};
561
+
562
+ const boundValues = bounds({ method: "transform", raw: true });
563
+
564
+ // content styles
565
+ const dragY = interpolate(
566
+ current.gesture.normalizedY,
567
+ [-1, 0, 1],
568
+ [-screen.height, 0, screen.height],
569
+ );
570
+
571
+ // dynamically changes direction based on the drag direction
572
+ const contentY = interpolate(
573
+ progress,
574
+ [0, 1],
575
+ [dragY >= 0 ? screen.height : -screen.height, 0],
576
+ );
577
+
578
+ const overlayClr = interpolateColor(
579
+ current.progress - Math.abs(current.gesture.normalizedY),
580
+ [0, 1],
581
+ ["rgba(0,0,0,0)", "rgba(0,0,0,1)"],
582
+ );
583
+
584
+ const borderRadius = interpolate(current.progress, [0, 1], [12, 0]);
585
+
586
+ // bound styles - only enter animation
587
+ const x = !current.closing ? boundValues.translateX : 0;
588
+ const y = !current.closing ? boundValues.translateY : 0;
589
+ const scaleX = !current.closing ? boundValues.scaleX : 1;
590
+ const scaleY = !current.closing ? boundValues.scaleY : 1;
591
+
592
+ return {
593
+ [activeBoundId]: {
594
+ transform: [
595
+ {
596
+ translateX: x,
597
+ },
598
+ {
599
+ translateY: y,
600
+ },
601
+ { scaleX: scaleX },
602
+ { scaleY: scaleY },
603
+ ],
604
+ borderRadius,
605
+ overflow: "hidden",
606
+ },
607
+ contentStyle: {
608
+ transform: [{ translateY: contentY }, { translateY: dragY }],
609
+ pointerEvents: current.animating ? "none" : "auto",
610
+ },
611
+ overlayStyle: {
612
+ backgroundColor: overlayClr,
613
+ },
614
+ };
615
+ },
616
+ transitionSpec: {
617
+ open: DefaultSpec,
618
+ close: DefaultSpec,
619
+ },
620
+ ...config,
621
+ };
622
+ };
@@ -5,4 +5,5 @@ export const DefaultSpec: WithSpringConfig = {
5
5
  damping: 500,
6
6
  mass: 3,
7
7
  overshootClamping: true,
8
+ restSpeedThreshold: 0.02,
8
9
  };
@@ -1,27 +1,28 @@
1
1
  import { useAnimatedStyle } from "react-native-reanimated";
2
- import { _useScreenAnimation } from "./use-screen-animation";
2
+ import { useTransitionStyles } from "../../providers/transition-styles";
3
+
4
+ type Props = {
5
+ id?: string;
6
+ };
7
+
8
+ const EMPTY_STYLE = Object.freeze({});
3
9
 
4
10
  /**
5
11
  * This hook is used to get the associated styles for a given styleId.
6
12
  * It is used to get the associated styles for a given styleId.
7
13
  * It is used to get the associated styles for a given styleId.
8
14
  */
9
- export const useAssociatedStyles = ({ id }: { id?: string } = {}) => {
10
- const { screenStyleInterpolator, screenInterpolatorProps } =
11
- _useScreenAnimation();
15
+ export const useAssociatedStyles = ({ id }: Props = {}) => {
16
+ const stylesMap = useTransitionStyles();
12
17
 
13
18
  const associatedStyles = useAnimatedStyle(() => {
14
19
  "worklet";
15
20
 
16
- if (!id || !screenStyleInterpolator) {
17
- return {};
21
+ if (!id || !stylesMap) {
22
+ return EMPTY_STYLE;
18
23
  }
19
24
 
20
- return (
21
- screenStyleInterpolator(screenInterpolatorProps.value)[id] || {
22
- opacity: 1, // <-- This fixes flickering?? We'll have to deep dive this?? wtf
23
- }
24
- );
25
+ return stylesMap.value[id] || EMPTY_STYLE;
25
26
  });
26
27
 
27
28
  return { associatedStyles };
@@ -1,4 +1,5 @@
1
1
  import type { ParamListBase, RouteProp } from "@react-navigation/native";
2
+ import { useMemo } from "react";
2
3
  import { useWindowDimensions } from "react-native";
3
4
  import { type SharedValue, useDerivedValue } from "react-native-reanimated";
4
5
  import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -12,7 +13,7 @@ import type {
12
13
  } from "../../types/animation";
13
14
  import type { BoundEntry } from "../../types/bounds";
14
15
  import type { NativeStackDescriptor } from "../../types/navigator";
15
- import { buildBoundsAccessor } from "../../utils/bounds";
16
+ import { derivations } from "../../utils/animation/derivations";
16
17
 
17
18
  type BuiltState = {
18
19
  progress: SharedValue<number>;
@@ -22,7 +23,9 @@ type BuiltState = {
22
23
  route: RouteProp<ParamListBase>;
23
24
  };
24
25
 
25
- const FALLBACK = Object.freeze({
26
+ const EMPTY_BOUNDS = Object.freeze({}) as Record<string, BoundEntry>;
27
+
28
+ const FALLBACK: ScreenTransitionState = Object.freeze({
26
29
  progress: 0,
27
30
  closing: 0,
28
31
  animating: 0,
@@ -38,62 +41,64 @@ const FALLBACK = Object.freeze({
38
41
  route: {} as RouteProp<ParamListBase>,
39
42
  });
40
43
 
41
- const useBuildScreenTransitionState = (
42
- descriptor: NativeStackDescriptor | undefined,
43
- ): BuiltState | undefined => {
44
- const key = descriptor?.route.key;
45
- if (!key) return undefined;
46
- const progress = Animations.getAnimation(key, "progress");
47
- const closing = Animations.getAnimation(key, "closing");
48
- const animating = Animations.getAnimation(key, "animating");
49
- const gesture = Gestures.getRouteGestures(key);
50
- const route = descriptor?.route;
51
-
52
- return { progress, closing, animating, gesture, route };
53
- };
54
-
55
44
  const unwrap = (
56
45
  s: BuiltState | undefined,
57
46
  key: string | undefined,
58
47
  ): ScreenTransitionState | undefined => {
59
48
  "worklet";
60
- return s && key
61
- ? {
62
- progress: s.progress.value ?? 0,
63
- closing: s.closing.value ?? 0,
64
- animating: s.animating.value ?? 0,
65
- gesture: {
66
- x: s.gesture.x.value ?? 0,
67
- y: s.gesture.y.value ?? 0,
68
- normalizedX: s.gesture.normalizedX.value ?? 0,
69
- normalizedY: s.gesture.normalizedY.value ?? 0,
70
- isDismissing: s.gesture.isDismissing.value ?? 0,
71
- isDragging: s.gesture.isDragging.value ?? 0,
72
- },
73
- bounds: Bounds.getBounds(key) ?? {},
74
- route: s.route,
75
- }
76
- : undefined;
49
+ if (!s || !key) return undefined;
50
+
51
+ return {
52
+ progress: s.progress.value,
53
+ closing: s.closing.value,
54
+ animating: s.animating.value,
55
+ gesture: {
56
+ x: s.gesture.x.value,
57
+ y: s.gesture.y.value,
58
+ normalizedX: s.gesture.normalizedX.value,
59
+ normalizedY: s.gesture.normalizedY.value,
60
+ isDismissing: s.gesture.isDismissing.value,
61
+ isDragging: s.gesture.isDragging.value,
62
+ },
63
+ bounds: Bounds.getBounds(key) || EMPTY_BOUNDS,
64
+ route: s.route,
65
+ };
66
+ };
67
+
68
+ const useBuildScreenTransitionState = (
69
+ descriptor: NativeStackDescriptor | undefined,
70
+ ): BuiltState | undefined => {
71
+ const key = descriptor?.route.key;
72
+
73
+ return useMemo(() => {
74
+ if (!key) return undefined;
75
+
76
+ return {
77
+ progress: Animations.getAnimation(key, "progress"),
78
+ closing: Animations.getAnimation(key, "closing"),
79
+ animating: Animations.getAnimation(key, "animating"),
80
+ gesture: Gestures.getRouteGestures(key),
81
+ route: descriptor.route,
82
+ };
83
+ }, [key, descriptor?.route]);
77
84
  };
78
85
 
79
86
  export function _useScreenAnimation() {
87
+ const dimensions = useWindowDimensions();
88
+ const insets = useSafeAreaInsets();
89
+
80
90
  const {
81
91
  current: currentDescriptor,
82
92
  next: nextDescriptor,
83
93
  previous: previousDescriptor,
84
94
  } = useKeys();
85
95
 
86
- const dimensions = useWindowDimensions();
87
-
88
96
  const currentAnimation = useBuildScreenTransitionState(currentDescriptor);
89
-
90
97
  const nextAnimation = useBuildScreenTransitionState(nextDescriptor);
91
98
  const prevAnimation = useBuildScreenTransitionState(previousDescriptor);
92
99
 
93
- const insets = useSafeAreaInsets();
94
-
95
100
  const screenInterpolatorProps = useDerivedValue<ScreenInterpolationProps>(
96
- () => {
101
+ (): ScreenInterpolationProps => {
97
102
  "worklet";
98
103
 
99
104
  const previous = unwrap(prevAnimation, previousDescriptor?.route.key);
@@ -101,17 +106,10 @@ export function _useScreenAnimation() {
101
106
  const current =
102
107
  unwrap(currentAnimation, currentDescriptor?.route.key) ?? FALLBACK;
103
108
 
104
- const progress = current.progress + (next?.progress ?? 0);
105
-
106
- const focused = !next;
107
- const activeBoundId = Bounds.getActiveBoundId() || "";
108
-
109
- const bounds = buildBoundsAccessor({
110
- activeBoundId,
109
+ const { progress, focused, activeBoundId, bounds } = derivations({
111
110
  current,
112
- previous,
113
111
  next,
114
- progress,
112
+ previous,
115
113
  dimensions,
116
114
  });
117
115
 
@@ -125,7 +123,7 @@ export function _useScreenAnimation() {
125
123
  activeBoundId,
126
124
  progress,
127
125
  bounds,
128
- } satisfies ScreenInterpolationProps;
126
+ };
129
127
  },
130
128
  );
131
129
 
@@ -135,6 +133,7 @@ export function _useScreenAnimation() {
135
133
 
136
134
  return { screenInterpolatorProps, screenStyleInterpolator };
137
135
  }
136
+
138
137
  export function useScreenAnimation() {
139
138
  const { screenInterpolatorProps } = _useScreenAnimation();
140
139