react-native-screen-transitions 2.0.6 → 2.2.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 (300) 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 +23 -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 +64 -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 +23 -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 +59 -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} +4 -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 +17 -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/core.d.ts +8 -0
  171. package/lib/typescript/types/core.d.ts.map +1 -1
  172. package/lib/typescript/types/gesture.d.ts +14 -0
  173. package/lib/typescript/types/gesture.d.ts.map +1 -1
  174. package/lib/typescript/types/navigator.d.ts +5 -1
  175. package/lib/typescript/types/navigator.d.ts.map +1 -1
  176. package/lib/typescript/utils/animation/derivations.d.ts +19 -0
  177. package/lib/typescript/utils/animation/derivations.d.ts.map +1 -0
  178. package/lib/typescript/utils/animation/run-transition.d.ts +2 -1
  179. package/lib/typescript/utils/animation/run-transition.d.ts.map +1 -1
  180. package/lib/typescript/utils/bounds/_types/builder.d.ts +96 -14
  181. package/lib/typescript/utils/bounds/_types/builder.d.ts.map +1 -1
  182. package/lib/typescript/utils/bounds/_types/geometry.d.ts +0 -1
  183. package/lib/typescript/utils/bounds/_types/geometry.d.ts.map +1 -1
  184. package/lib/typescript/utils/bounds/_utils/flatten-styles.d.ts.map +1 -0
  185. package/lib/typescript/utils/bounds/{geometry.d.ts → _utils/geometry.d.ts} +8 -5
  186. package/lib/typescript/utils/bounds/_utils/geometry.d.ts.map +1 -0
  187. package/lib/typescript/utils/bounds/_utils/get-bounds.d.ts +4 -0
  188. package/lib/typescript/utils/bounds/_utils/get-bounds.d.ts.map +1 -0
  189. package/lib/typescript/utils/bounds/_utils/is-bounds-equal.d.ts +7 -0
  190. package/lib/typescript/utils/bounds/_utils/is-bounds-equal.d.ts.map +1 -0
  191. package/lib/typescript/utils/bounds/{style-composers.d.ts → _utils/style-composers.d.ts} +7 -10
  192. package/lib/typescript/utils/bounds/_utils/style-composers.d.ts.map +1 -0
  193. package/lib/typescript/utils/bounds/constants.d.ts +5 -5
  194. package/lib/typescript/utils/bounds/constants.d.ts.map +1 -1
  195. package/lib/typescript/utils/bounds/index.d.ts +2 -4
  196. package/lib/typescript/utils/bounds/index.d.ts.map +1 -1
  197. package/lib/typescript/utils/gesture/apply-offset-rules.d.ts +38 -0
  198. package/lib/typescript/utils/gesture/apply-offset-rules.d.ts.map +1 -0
  199. package/lib/typescript/utils/gesture/check-gesture-activation.d.ts +38 -0
  200. package/lib/typescript/utils/gesture/check-gesture-activation.d.ts.map +1 -0
  201. package/lib/typescript/utils/gesture/determine-dismissal.d.ts +25 -0
  202. package/lib/typescript/utils/gesture/determine-dismissal.d.ts.map +1 -0
  203. package/package.json +2 -2
  204. package/src/__tests__/geometry.test.ts +15 -12
  205. package/src/components/{bounds-activator.tsx → bound-capture.tsx} +1 -1
  206. package/src/components/controllers/screen-lifecycle.tsx +13 -5
  207. package/src/components/create-transition-aware-component.tsx +34 -13
  208. package/src/components/integrations/masked-view.tsx +56 -0
  209. package/src/components/root-transition-aware.tsx +31 -39
  210. package/src/configs/index.ts +20 -8
  211. package/src/configs/presets.ts +401 -6
  212. package/src/configs/specs.ts +1 -0
  213. package/src/hooks/animation/use-associated-style.tsx +12 -11
  214. package/src/hooks/animation/use-screen-animation.tsx +48 -49
  215. package/src/hooks/bounds/{use-bound-measurer.tsx → use-bound-registry.tsx} +24 -20
  216. package/src/hooks/gestures/use-build-gestures.tsx +193 -228
  217. package/src/hooks/gestures/use-parent-gesture-registry.tsx +18 -0
  218. package/src/hooks/gestures/use-scroll-registry.tsx +145 -0
  219. package/src/index.ts +2 -0
  220. package/src/integrations/native-stack/views/NativeStackView.native.tsx +8 -5
  221. package/src/providers/gestures.tsx +19 -22
  222. package/src/providers/transition-styles.tsx +52 -0
  223. package/src/stores/bounds.ts +156 -0
  224. package/src/stores/utils/reset-stores-for-screen.ts +7 -2
  225. package/src/types/bounds.ts +8 -1
  226. package/src/types/core.ts +9 -0
  227. package/src/types/gesture.ts +19 -0
  228. package/src/types/navigator.ts +5 -1
  229. package/src/utils/animation/derivations.ts +38 -0
  230. package/src/utils/animation/run-transition.ts +4 -1
  231. package/src/utils/bounds/_types/builder.ts +127 -11
  232. package/src/utils/bounds/_types/geometry.ts +0 -1
  233. package/src/utils/bounds/_utils/geometry.ts +166 -0
  234. package/src/utils/bounds/_utils/get-bounds.ts +54 -0
  235. package/src/utils/bounds/_utils/is-bounds-equal.ts +24 -0
  236. package/src/utils/bounds/_utils/style-composers.ts +216 -0
  237. package/src/utils/bounds/constants.ts +37 -22
  238. package/src/utils/bounds/index.ts +269 -19
  239. package/src/utils/gesture/apply-offset-rules.ts +314 -0
  240. package/src/utils/gesture/check-gesture-activation.ts +310 -0
  241. package/src/utils/gesture/determine-dismissal.ts +131 -0
  242. package/lib/commonjs/components/bounds-activator.js.map +0 -1
  243. package/lib/commonjs/hooks/bounds/use-bound-measurer.js +0 -52
  244. package/lib/commonjs/hooks/bounds/use-bound-measurer.js.map +0 -1
  245. package/lib/commonjs/hooks/gestures/use-scroll-progress.js +0 -57
  246. package/lib/commonjs/hooks/gestures/use-scroll-progress.js.map +0 -1
  247. package/lib/commonjs/utils/bounds/build-bound-styles.js +0 -145
  248. package/lib/commonjs/utils/bounds/build-bound-styles.js.map +0 -1
  249. package/lib/commonjs/utils/bounds/flatten-styles.js.map +0 -1
  250. package/lib/commonjs/utils/bounds/geometry.js +0 -94
  251. package/lib/commonjs/utils/bounds/geometry.js.map +0 -1
  252. package/lib/commonjs/utils/bounds/get-bounds.js.map +0 -1
  253. package/lib/commonjs/utils/bounds/style-composers.js +0 -199
  254. package/lib/commonjs/utils/bounds/style-composers.js.map +0 -1
  255. package/lib/commonjs/utils/gesture/apply-gesture-activation-criteria.js +0 -81
  256. package/lib/commonjs/utils/gesture/apply-gesture-activation-criteria.js.map +0 -1
  257. package/lib/commonjs/utils/gesture/normalize-gesture-translation.js +0 -21
  258. package/lib/commonjs/utils/gesture/normalize-gesture-translation.js.map +0 -1
  259. package/lib/module/components/bounds-activator.js.map +0 -1
  260. package/lib/module/hooks/bounds/use-bound-measurer.js +0 -47
  261. package/lib/module/hooks/bounds/use-bound-measurer.js.map +0 -1
  262. package/lib/module/hooks/gestures/use-scroll-progress.js +0 -52
  263. package/lib/module/hooks/gestures/use-scroll-progress.js.map +0 -1
  264. package/lib/module/utils/bounds/build-bound-styles.js +0 -141
  265. package/lib/module/utils/bounds/build-bound-styles.js.map +0 -1
  266. package/lib/module/utils/bounds/flatten-styles.js.map +0 -1
  267. package/lib/module/utils/bounds/geometry.js +0 -89
  268. package/lib/module/utils/bounds/geometry.js.map +0 -1
  269. package/lib/module/utils/bounds/get-bounds.js.map +0 -1
  270. package/lib/module/utils/bounds/style-composers.js +0 -191
  271. package/lib/module/utils/bounds/style-composers.js.map +0 -1
  272. package/lib/module/utils/gesture/apply-gesture-activation-criteria.js +0 -76
  273. package/lib/module/utils/gesture/apply-gesture-activation-criteria.js.map +0 -1
  274. package/lib/module/utils/gesture/normalize-gesture-translation.js +0 -16
  275. package/lib/module/utils/gesture/normalize-gesture-translation.js.map +0 -1
  276. package/lib/typescript/components/bounds-activator.d.ts +0 -8
  277. package/lib/typescript/components/bounds-activator.d.ts.map +0 -1
  278. package/lib/typescript/hooks/gestures/use-scroll-progress.d.ts.map +0 -1
  279. package/lib/typescript/utils/bounds/build-bound-styles.d.ts +0 -4
  280. package/lib/typescript/utils/bounds/build-bound-styles.d.ts.map +0 -1
  281. package/lib/typescript/utils/bounds/flatten-styles.d.ts.map +0 -1
  282. package/lib/typescript/utils/bounds/geometry.d.ts.map +0 -1
  283. package/lib/typescript/utils/bounds/get-bounds.d.ts +0 -4
  284. package/lib/typescript/utils/bounds/get-bounds.d.ts.map +0 -1
  285. package/lib/typescript/utils/bounds/style-composers.d.ts.map +0 -1
  286. package/lib/typescript/utils/gesture/apply-gesture-activation-criteria.d.ts +0 -17
  287. package/lib/typescript/utils/gesture/apply-gesture-activation-criteria.d.ts.map +0 -1
  288. package/lib/typescript/utils/gesture/normalize-gesture-translation.d.ts +0 -6
  289. package/lib/typescript/utils/gesture/normalize-gesture-translation.d.ts.map +0 -1
  290. package/src/hooks/gestures/use-scroll-progress.tsx +0 -60
  291. package/src/utils/bounds/build-bound-styles.ts +0 -184
  292. package/src/utils/bounds/geometry.ts +0 -113
  293. package/src/utils/bounds/get-bounds.ts +0 -56
  294. package/src/utils/bounds/style-composers.ts +0 -172
  295. package/src/utils/gesture/apply-gesture-activation-criteria.ts +0 -109
  296. package/src/utils/gesture/normalize-gesture-translation.ts +0 -20
  297. /package/lib/commonjs/utils/bounds/{flatten-styles.js → _utils/flatten-styles.js} +0 -0
  298. /package/lib/module/utils/bounds/{flatten-styles.js → _utils/flatten-styles.js} +0 -0
  299. /package/lib/typescript/utils/bounds/{flatten-styles.d.ts → _utils/flatten-styles.d.ts} +0 -0
  300. /package/src/utils/bounds/{flatten-styles.ts → _utils/flatten-styles.ts} +0 -0
@@ -1,50 +1,42 @@
1
1
  import { memo } from "react";
2
- import { StyleSheet } from "react-native";
3
- import Animated, { useAnimatedStyle } from "react-native-reanimated";
4
- import { _useScreenAnimation } from "../hooks/animation/use-screen-animation";
2
+ import { StyleSheet, View } from "react-native";
3
+ import Animated, {
4
+ type StyleProps,
5
+ useAnimatedStyle,
6
+ } from "react-native-reanimated";
7
+ import { useTransitionStyles } from "../providers/transition-styles";
5
8
 
6
- interface RootTransitionAwareProps {
9
+ type Props = {
7
10
  children: React.ReactNode;
8
- }
11
+ };
9
12
 
10
- export const RootTransitionAware = memo(
11
- ({ children }: RootTransitionAwareProps) => {
12
- const { screenInterpolatorProps, screenStyleInterpolator } =
13
- _useScreenAnimation();
13
+ const EMPTY_STYLE = Object.freeze({} as StyleProps);
14
14
 
15
- const animatedContentStyle = useAnimatedStyle(() => {
16
- "worklet";
17
- if (!screenStyleInterpolator) {
18
- return {};
19
- }
20
- const props = screenInterpolatorProps.value;
21
- return screenStyleInterpolator(props).contentStyle || {};
22
- });
15
+ export const RootTransitionAware = memo(({ children }: Props) => {
16
+ const stylesMap = useTransitionStyles();
23
17
 
24
- const animatedOverlayStyle = useAnimatedStyle(() => {
25
- "worklet";
26
- if (!screenStyleInterpolator) {
27
- return {};
28
- }
29
- return (
30
- screenStyleInterpolator(screenInterpolatorProps.value).overlayStyle ||
31
- {}
32
- );
33
- });
18
+ const animatedContentStyle = useAnimatedStyle(() => {
19
+ "worklet";
20
+ return stylesMap.value.contentStyle || EMPTY_STYLE;
21
+ });
34
22
 
35
- return (
36
- <Animated.View style={styles.container}>
37
- <Animated.View
38
- style={[StyleSheet.absoluteFillObject, animatedOverlayStyle]}
39
- pointerEvents="none"
40
- />
41
- <Animated.View style={[styles.content, animatedContentStyle]}>
42
- {children}
43
- </Animated.View>
23
+ const animatedOverlayStyle = useAnimatedStyle(() => {
24
+ "worklet";
25
+ return stylesMap.value.overlayStyle || EMPTY_STYLE;
26
+ });
27
+
28
+ return (
29
+ <View style={styles.container}>
30
+ <Animated.View
31
+ style={[StyleSheet.absoluteFillObject, animatedOverlayStyle]}
32
+ pointerEvents="none"
33
+ />
34
+ <Animated.View style={[styles.content, animatedContentStyle]}>
35
+ {children}
44
36
  </Animated.View>
45
- );
46
- },
47
- );
37
+ </View>
38
+ );
39
+ });
48
40
 
49
41
  const styles = StyleSheet.create({
50
42
  container: {
@@ -1,14 +1,26 @@
1
- import { DraggableCard, ElasticCard, SlideFromBottom, SlideFromTop, ZoomIn } from './presets';
2
- import { DefaultSpec } from './specs';
1
+ import {
2
+ DraggableCard,
3
+ ElasticCard,
4
+ SharedAppleMusic,
5
+ SharedIGImage,
6
+ SharedXImage,
7
+ SlideFromBottom,
8
+ SlideFromTop,
9
+ ZoomIn,
10
+ } from "./presets";
11
+ import { DefaultSpec } from "./specs";
3
12
 
4
13
  export const specs = {
5
- DefaultSpec,
14
+ DefaultSpec,
6
15
  };
7
16
 
8
17
  export const presets = {
9
- SlideFromTop,
10
- ZoomIn,
11
- SlideFromBottom,
12
- DraggableCard,
13
- ElasticCard,
18
+ SlideFromTop,
19
+ ZoomIn,
20
+ SlideFromBottom,
21
+ DraggableCard,
22
+ ElasticCard,
23
+ SharedIGImage,
24
+ SharedAppleMusic,
25
+ SharedXImage,
14
26
  };
@@ -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 };