UNPKG

7.86 kBPlain TextView Raw
1'use strict';
2import { withSequence, withTiming } from '../../animation';
3import type { BaseAnimationBuilder } from '../animationBuilder';
4import { ComplexAnimationBuilder } from '../animationBuilder';
5import type {
6 EntryExitAnimationsValues,
7 EntryExitAnimationFunction,
8 IEntryExitAnimationBuilder,
9} from '../animationBuilder/commonTypes';
10
11/**
12 * Entry from right animation with change in skew and opacity. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
13 *
14 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
15 *
16 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#lightspeed
17 */
18export class LightSpeedInRight
19 extends ComplexAnimationBuilder
20 implements IEntryExitAnimationBuilder
21{
22 static presetName = 'LightSpeedInRight';
23
24 static createInstance<T extends typeof BaseAnimationBuilder>(
25 this: T
26 ): InstanceType<T> {
27 return new LightSpeedInRight() as InstanceType<T>;
28 }
29
30 build = (): EntryExitAnimationFunction => {
31 const delayFunction = this.getDelayFunction();
32 const [animation, config] = this.getAnimationAndConfig();
33 const delay = this.getDelay();
34 const duration = this.getDuration();
35 const callback = this.callbackV;
36 const initialValues = this.initialValues;
37
38 return (values: EntryExitAnimationsValues) => {
39 'worklet';
40 return {
41 animations: {
42 opacity: delayFunction(delay, withTiming(1, { duration })),
43 transform: [
44 {
45 translateX: delayFunction(
46 delay,
47 animation(0, { ...config, duration: duration * 0.7 })
48 ),
49 },
50 {
51 skewX: delayFunction(
52 delay,
53 withSequence(
54 withTiming('10deg', { duration: duration * 0.7 }),
55 withTiming('-5deg', { duration: duration * 0.15 }),
56 withTiming('0deg', { duration: duration * 0.15 })
57 )
58 ),
59 },
60 ],
61 },
62 initialValues: {
63 opacity: 0,
64 transform: [{ translateX: values.windowWidth }, { skewX: '-45deg' }],
65 ...initialValues,
66 },
67 callback,
68 };
69 };
70 };
71}
72
73/**
74 * Entry from left animation with change in skew and opacity. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
75 *
76 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
77 *
78 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#lightspeed
79 */
80export class LightSpeedInLeft
81 extends ComplexAnimationBuilder
82 implements IEntryExitAnimationBuilder
83{
84 static presetName = 'LightSpeedInLeft';
85
86 static createInstance<T extends typeof BaseAnimationBuilder>(
87 this: T
88 ): InstanceType<T> {
89 return new LightSpeedInLeft() as InstanceType<T>;
90 }
91
92 build = (): EntryExitAnimationFunction => {
93 const delayFunction = this.getDelayFunction();
94 const [animation, config] = this.getAnimationAndConfig();
95 const delay = this.getDelay();
96 const duration = this.getDuration();
97 const callback = this.callbackV;
98 const initialValues = this.initialValues;
99
100 return (values: EntryExitAnimationsValues) => {
101 'worklet';
102 return {
103 animations: {
104 opacity: delayFunction(delay, withTiming(1, { duration })),
105 transform: [
106 {
107 translateX: delayFunction(
108 delay,
109 animation(0, { ...config, duration: duration * 0.7 })
110 ),
111 },
112 {
113 skewX: delayFunction(
114 delay,
115 withSequence(
116 withTiming('-10deg', { duration: duration * 0.7 }),
117 withTiming('5deg', { duration: duration * 0.15 }),
118 withTiming('0deg', { duration: duration * 0.15 })
119 )
120 ),
121 },
122 ],
123 },
124 initialValues: {
125 opacity: 0,
126 transform: [{ translateX: -values.windowWidth }, { skewX: '45deg' }],
127 ...initialValues,
128 },
129 callback,
130 };
131 };
132 };
133}
134
135/**
136 * Exit to right animation with change in skew and opacity. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
137 *
138 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
139 *
140 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#lightspeed
141 */
142export class LightSpeedOutRight
143 extends ComplexAnimationBuilder
144 implements IEntryExitAnimationBuilder
145{
146 static presetName = 'LightSpeedOutRight';
147
148 static createInstance<T extends typeof BaseAnimationBuilder>(
149 this: T
150 ): InstanceType<T> {
151 return new LightSpeedOutRight() as InstanceType<T>;
152 }
153
154 build = (): EntryExitAnimationFunction => {
155 const delayFunction = this.getDelayFunction();
156 const [animation, config] = this.getAnimationAndConfig();
157 const delay = this.getDelay();
158 const callback = this.callbackV;
159 const initialValues = this.initialValues;
160
161 return (values: EntryExitAnimationsValues) => {
162 'worklet';
163 return {
164 animations: {
165 opacity: delayFunction(delay, animation(0, config)),
166 transform: [
167 {
168 translateX: delayFunction(
169 delay,
170 animation(values.windowWidth, config)
171 ),
172 },
173 {
174 skewX: delayFunction(delay, animation('-45deg', config)),
175 },
176 ],
177 },
178 initialValues: {
179 opacity: 1,
180 transform: [{ translateX: 0 }, { skewX: '0deg' }],
181 ...initialValues,
182 },
183 callback,
184 };
185 };
186 };
187}
188
189/**
190 * Exit to left animation with change in skew and opacity. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
191 *
192 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
193 *
194 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations/#lightspeed
195 */
196export class LightSpeedOutLeft
197 extends ComplexAnimationBuilder
198 implements IEntryExitAnimationBuilder
199{
200 static presetName = 'LightSpeedOutLeft';
201
202 static createInstance<T extends typeof BaseAnimationBuilder>(
203 this: T
204 ): InstanceType<T> {
205 return new LightSpeedOutLeft() as InstanceType<T>;
206 }
207
208 build = (): EntryExitAnimationFunction => {
209 const delayFunction = this.getDelayFunction();
210 const [animation, config] = this.getAnimationAndConfig();
211 const delay = this.getDelay();
212 const callback = this.callbackV;
213 const initialValues = this.initialValues;
214
215 return (values: EntryExitAnimationsValues) => {
216 'worklet';
217 return {
218 animations: {
219 opacity: delayFunction(delay, animation(0, config)),
220 transform: [
221 {
222 translateX: delayFunction(
223 delay,
224 animation(-values.windowWidth, config)
225 ),
226 },
227 {
228 skewX: delayFunction(delay, animation('45deg', config)),
229 },
230 ],
231 },
232 initialValues: {
233 opacity: 1,
234 transform: [{ translateX: 0 }, { skewX: '0deg' }],
235 ...initialValues,
236 },
237 callback,
238 };
239 };
240 };
241}