-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathAnimatedCodeExamples.tsx
111 lines (106 loc) · 3.41 KB
/
AnimatedCodeExamples.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { AbsoluteFill, useCurrentFrame } from 'remotion';
import {
Animated,
Animation,
Fade,
Move,
Scale,
Size,
} from 'remotion-animated';
import CodeLine from './CodeLine';
import HelloWorld from './HelloWorld';
const STATE_DURATION = 50;
const getAnimationState = (frame: number) => {
return Math.min(Math.floor(frame / STATE_DURATION), 3);
};
const AnimatedCodeExamples = () => {
const frame = useCurrentFrame();
const state = getAnimationState(frame);
const AnimationStates: Animation[][] = [
[Scale({ by: 1, initial: 10 })],
[Move({ y: -40 })],
[Move({ y: 0, initialY: -40 })],
[Fade({ to: 0 }), Scale({ by: 0, mass: 75 })],
];
const CurrentAnimations = AnimationStates[state];
return (
<AbsoluteFill className="bg-slate-50">
<AbsoluteFill className="justify-center" style={{ width: '50%' }}>
<Animated
absolute
animations={[
Size({ width: 386, initialWidth: 0 }),
Fade({ to: 1, initial: 0, duration: 10 }),
Move({ y: 40, start: STATE_DURATION }),
Size({ width: 356, initialWidth: 386, start: STATE_DURATION }),
Move({ y: 40, start: STATE_DURATION * 2 }),
Move({ y: 40, start: STATE_DURATION * 3 }),
Size({
height: 84,
initialHeight: 44,
width: 500,
initialWidth: 356,
start: STATE_DURATION * 3,
}),
Fade({ to: 0, start: STATE_DURATION * 4, duration: 10 }),
]}
style={{
height: '44px',
background: '#FCED6A',
borderRadius: '8px',
left: '96px',
top: '26.4%',
}}
/>
<code
className="text-xl pl-14 gap-3 grid"
style={{ position: 'absolute' }}
>
<CodeLine text="<Animated" />
<CodeLine text=" animations={[" />
<CodeLine text=" Scale({ by: 1, initial: 10 })," />
<CodeLine text=" Move({ y: -40, start: 50 })," />
<CodeLine text=" Move({ y: 40, start: 100 })," />
<CodeLine text=" Fade({ to: 0, start: 150 })," />
<CodeLine text=" Scale({ by: 0, start: 150, mass: 75 })," />
<CodeLine text=" ]}" />
<CodeLine text=" >" />
<CodeLine text=" <HelloWorld />" />
<CodeLine text="</Animated>" />
</code>
</AbsoluteFill>
<AbsoluteFill
className="bg-slate-200 rounded-lg items-center justify-center"
style={{
width: 'calc(50% - 4rem)',
height: 'calc(100% - 4rem)',
left: '50%',
margin: '2rem',
overflow: 'hidden',
}}
>
<Animated
key={state}
animations={CurrentAnimations}
delay={STATE_DURATION * state}
>
<HelloWorld />
</Animated>
<Animated
absolute
in={STATE_DURATION}
out={STATE_DURATION * 2 + 10}
animations={[
Fade({ to: 1, start: STATE_DURATION, initial: 0 }),
Fade({ to: 0, start: STATE_DURATION * 2, duration: 10 }),
]}
className="text-2xl mt-24 text-gray-600 font-semibold text-center"
style={{ width: '400px' }}
>
This video was made using Remotion and Remotion Animated.
</Animated>
</AbsoluteFill>
</AbsoluteFill>
);
};
export default AnimatedCodeExamples;