added useGsap hook
Browse files
Remotion-app/src/HelloWorld/Components/GsapAnimation.jsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import { useGsapTimeline } from '
|
2 |
import { AbsoluteFill } from 'remotion';
|
3 |
import gsap from 'gsap';
|
4 |
|
|
|
1 |
+
import { useGsapTimeline } from '../../lib/useGsapTimeline'
|
2 |
import { AbsoluteFill } from 'remotion';
|
3 |
import gsap from 'gsap';
|
4 |
|
Remotion-app/src/lib/useGsapTimeline.js
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gsap from "gsap";
|
2 |
+
import { useEffect, useRef } from "react";
|
3 |
+
import { useCurrentFrame, useVideoConfig } from "remotion";
|
4 |
+
|
5 |
+
export const useGsapTimeline = (gsapTimelineFactory) => {
|
6 |
+
|
7 |
+
const animationScopeRef = useRef(null);
|
8 |
+
const timelineRef = useRef();
|
9 |
+
const frame = useCurrentFrame();
|
10 |
+
const { fps } = useVideoConfig();
|
11 |
+
|
12 |
+
useEffect(() => {
|
13 |
+
if (animationScopeRef.current) // check if the component is mounted
|
14 |
+
{
|
15 |
+
const ctx = gsap.context(() => {
|
16 |
+
timelineRef.current = gsapTimelineFactory();
|
17 |
+
timelineRef.current.pause();
|
18 |
+
}, animationScopeRef);
|
19 |
+
return () => ctx.revert();
|
20 |
+
}
|
21 |
+
|
22 |
+
}, [animationScopeRef.current]);
|
23 |
+
|
24 |
+
useEffect(() => {
|
25 |
+
if (animationScopeRef.current) // check if the component is mounted
|
26 |
+
if (timelineRef.current) {
|
27 |
+
timelineRef.current.seek((frame) / fps);
|
28 |
+
}
|
29 |
+
}, [frame, fps,animationScopeRef.current]);
|
30 |
+
|
31 |
+
return animationScopeRef;
|
32 |
+
};
|