UNPKG

14 kBPlain TextView Raw
1'use strict';
2import type {
3 IEntryExitAnimationBuilder,
4 EntryExitAnimationFunction,
5} from '../animationBuilder/commonTypes';
6import type { BaseAnimationBuilder } from '../animationBuilder';
7import { ComplexAnimationBuilder } from '../animationBuilder';
8
9/**
10 * Fade in animation. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
11 *
12 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
13 *
14 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#fade
15 */
16export class FadeIn
17 extends ComplexAnimationBuilder
18 implements IEntryExitAnimationBuilder
19{
20 static presetName = 'FadeIn';
21 static createInstance<T extends typeof BaseAnimationBuilder>(
22 this: T
23 ): InstanceType<T> {
24 return new FadeIn() as InstanceType<T>;
25 }
26
27 build = (): EntryExitAnimationFunction => {
28 const delayFunction = this.getDelayFunction();
29 const [animation, config] = this.getAnimationAndConfig();
30 const callback = this.callbackV;
31 const initialValues = this.initialValues;
32 const delay = this.getDelay();
33
34 return () => {
35 'worklet';
36 return {
37 animations: {
38 opacity: delayFunction(delay, animation(1, config)),
39 },
40 initialValues: {
41 opacity: 0,
42 ...initialValues,
43 },
44 callback,
45 };
46 };
47 };
48}
49
50/**
51 * Fade from right animation. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
52 *
53 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
54 *
55 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#fade
56 */
57export class FadeInRight
58 extends ComplexAnimationBuilder
59 implements IEntryExitAnimationBuilder
60{
61 static presetName = 'FadeInRight';
62
63 static createInstance<T extends typeof BaseAnimationBuilder>(
64 this: T
65 ): InstanceType<T> {
66 return new FadeInRight() as InstanceType<T>;
67 }
68
69 build = (): EntryExitAnimationFunction => {
70 const delayFunction = this.getDelayFunction();
71 const [animation, config] = this.getAnimationAndConfig();
72 const callback = this.callbackV;
73 const initialValues = this.initialValues;
74 const delay = this.getDelay();
75
76 return () => {
77 'worklet';
78 return {
79 animations: {
80 opacity: delayFunction(delay, animation(1, config)),
81 transform: [
82 { translateX: delayFunction(delay, animation(0, config)) },
83 ],
84 },
85 initialValues: {
86 opacity: 0,
87 transform: [{ translateX: 25 }],
88 ...initialValues,
89 },
90 callback,
91 };
92 };
93 };
94}
95
96/**
97 * Fade from left animation. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
98 *
99 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
100 *
101 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#fade
102 */
103export class FadeInLeft
104 extends ComplexAnimationBuilder
105 implements IEntryExitAnimationBuilder
106{
107 static presetName = 'FadeInLeft';
108
109 static createInstance<T extends typeof BaseAnimationBuilder>(
110 this: T
111 ): InstanceType<T> {
112 return new FadeInLeft() as InstanceType<T>;
113 }
114
115 build = (): EntryExitAnimationFunction => {
116 const delayFunction = this.getDelayFunction();
117 const [animation, config] = this.getAnimationAndConfig();
118 const callback = this.callbackV;
119 const initialValues = this.initialValues;
120 const delay = this.getDelay();
121
122 return () => {
123 'worklet';
124 return {
125 animations: {
126 opacity: delayFunction(delay, animation(1, config)),
127 transform: [
128 { translateX: delayFunction(delay, animation(0, config)) },
129 ],
130 },
131 initialValues: {
132 opacity: 0,
133 transform: [{ translateX: -25 }],
134 ...initialValues,
135 },
136 callback,
137 };
138 };
139 };
140}
141
142/**
143 * Fade from top animation. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
144 *
145 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
146 *
147 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#fade
148 */
149export class FadeInUp
150 extends ComplexAnimationBuilder
151 implements IEntryExitAnimationBuilder
152{
153 static presetName = 'FadeInUp';
154
155 static createInstance<T extends typeof BaseAnimationBuilder>(
156 this: T
157 ): InstanceType<T> {
158 return new FadeInUp() as InstanceType<T>;
159 }
160
161 build = (): EntryExitAnimationFunction => {
162 const delayFunction = this.getDelayFunction();
163 const [animation, config] = this.getAnimationAndConfig();
164 const callback = this.callbackV;
165 const initialValues = this.initialValues;
166 const delay = this.getDelay();
167
168 return () => {
169 'worklet';
170 return {
171 animations: {
172 opacity: delayFunction(delay, animation(1, config)),
173 transform: [
174 { translateY: delayFunction(delay, animation(0, config)) },
175 ],
176 },
177 initialValues: {
178 opacity: 0,
179 transform: [{ translateY: -25 }],
180 ...initialValues,
181 },
182 callback,
183 };
184 };
185 };
186}
187
188/**
189 * Fade from bottom animation. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
190 *
191 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
192 *
193 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#fade
194 */
195export class FadeInDown
196 extends ComplexAnimationBuilder
197 implements IEntryExitAnimationBuilder
198{
199 static presetName = 'FadeInDown';
200
201 static createInstance<T extends typeof BaseAnimationBuilder>(
202 this: T
203 ): InstanceType<T> {
204 return new FadeInDown() as InstanceType<T>;
205 }
206
207 build = (): EntryExitAnimationFunction => {
208 const delayFunction = this.getDelayFunction();
209 const [animation, config] = this.getAnimationAndConfig();
210 const callback = this.callbackV;
211 const initialValues = this.initialValues;
212 const delay = this.getDelay();
213
214 return () => {
215 'worklet';
216 return {
217 animations: {
218 opacity: delayFunction(delay, animation(1, config)),
219 transform: [
220 { translateY: delayFunction(delay, animation(0, config)) },
221 ],
222 },
223 initialValues: {
224 opacity: 0,
225 transform: [{ translateY: 25 }],
226 ...initialValues,
227 },
228 callback,
229 };
230 };
231 };
232}
233
234/**
235 * Fade out animation. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
236 *
237 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
238 *
239 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#fade
240 */
241export class FadeOut
242 extends ComplexAnimationBuilder
243 implements IEntryExitAnimationBuilder
244{
245 static presetName = 'FadeOut';
246
247 static createInstance<T extends typeof BaseAnimationBuilder>(
248 this: T
249 ): InstanceType<T> {
250 return new FadeOut() as InstanceType<T>;
251 }
252
253 build = (): EntryExitAnimationFunction => {
254 const delayFunction = this.getDelayFunction();
255 const [animation, config] = this.getAnimationAndConfig();
256 const callback = this.callbackV;
257 const initialValues = this.initialValues;
258 const delay = this.getDelay();
259
260 return () => {
261 'worklet';
262 return {
263 animations: {
264 opacity: delayFunction(delay, animation(0, config)),
265 },
266 initialValues: {
267 opacity: 1,
268 ...initialValues,
269 },
270 callback,
271 };
272 };
273 };
274}
275
276/**
277 * Fade to right animation. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
278 *
279 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
280 *
281 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#fade
282 */
283export class FadeOutRight
284 extends ComplexAnimationBuilder
285 implements IEntryExitAnimationBuilder
286{
287 static presetName = 'FadeOutRight';
288
289 static createInstance<T extends typeof BaseAnimationBuilder>(
290 this: T
291 ): InstanceType<T> {
292 return new FadeOutRight() as InstanceType<T>;
293 }
294
295 build = (): EntryExitAnimationFunction => {
296 const delayFunction = this.getDelayFunction();
297 const [animation, config] = this.getAnimationAndConfig();
298 const callback = this.callbackV;
299 const initialValues = this.initialValues;
300 const delay = this.getDelay();
301
302 return () => {
303 'worklet';
304 return {
305 animations: {
306 opacity: delayFunction(delay, animation(0, config)),
307 transform: [
308 { translateX: delayFunction(delay, animation(25, config)) },
309 ],
310 },
311 initialValues: {
312 opacity: 1,
313 transform: [{ translateX: 0 }],
314 ...initialValues,
315 },
316 callback,
317 };
318 };
319 };
320}
321
322/**
323 * Fade to left animation. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
324 *
325 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
326 *
327 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#fade
328 */
329export class FadeOutLeft
330 extends ComplexAnimationBuilder
331 implements IEntryExitAnimationBuilder
332{
333 static presetName = 'FadeOutLeft';
334
335 static createInstance<T extends typeof BaseAnimationBuilder>(
336 this: T
337 ): InstanceType<T> {
338 return new FadeOutLeft() as InstanceType<T>;
339 }
340
341 build = (): EntryExitAnimationFunction => {
342 const delayFunction = this.getDelayFunction();
343 const [animation, config] = this.getAnimationAndConfig();
344 const callback = this.callbackV;
345 const initialValues = this.initialValues;
346 const delay = this.getDelay();
347
348 return () => {
349 'worklet';
350 return {
351 animations: {
352 opacity: delayFunction(delay, animation(0, config)),
353 transform: [
354 { translateX: delayFunction(delay, animation(-25, config)) },
355 ],
356 },
357 initialValues: {
358 opacity: 1,
359 transform: [{ translateX: 0 }],
360 ...initialValues,
361 },
362 callback,
363 };
364 };
365 };
366}
367/**
368 * Fade to top animation. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
369 *
370 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
371 *
372 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#fade
373 */
374export class FadeOutUp
375 extends ComplexAnimationBuilder
376 implements IEntryExitAnimationBuilder
377{
378 static presetName = 'FadeOutUp';
379
380 static createInstance<T extends typeof BaseAnimationBuilder>(
381 this: T
382 ): InstanceType<T> {
383 return new FadeOutUp() as InstanceType<T>;
384 }
385
386 build = (): EntryExitAnimationFunction => {
387 const delayFunction = this.getDelayFunction();
388 const [animation, config] = this.getAnimationAndConfig();
389 const callback = this.callbackV;
390 const initialValues = this.initialValues;
391 const delay = this.getDelay();
392
393 return () => {
394 'worklet';
395 return {
396 animations: {
397 opacity: delayFunction(delay, animation(0, config)),
398 transform: [
399 { translateY: delayFunction(delay, animation(-25, config)) },
400 ],
401 },
402 initialValues: {
403 opacity: 1,
404 transform: [{ translateY: 0 }],
405 ...initialValues,
406 },
407 callback,
408 };
409 };
410 };
411}
412
413/**
414 * Fade to bottom animation. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
415 *
416 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
417 *
418 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#fade
419 */
420export class FadeOutDown
421 extends ComplexAnimationBuilder
422 implements IEntryExitAnimationBuilder
423{
424 static presetName = 'FadeOutDown';
425
426 static createInstance<T extends typeof BaseAnimationBuilder>(
427 this: T
428 ): InstanceType<T> {
429 return new FadeOutDown() as InstanceType<T>;
430 }
431
432 build = (): EntryExitAnimationFunction => {
433 const delayFunction = this.getDelayFunction();
434 const [animation, config] = this.getAnimationAndConfig();
435 const callback = this.callbackV;
436 const initialValues = this.initialValues;
437 const delay = this.getDelay();
438
439 return () => {
440 'worklet';
441 return {
442 animations: {
443 opacity: delayFunction(delay, animation(0, config)),
444 transform: [
445 { translateY: delayFunction(delay, animation(25, config)) },
446 ],
447 },
448 initialValues: {
449 opacity: 1,
450 transform: [{ translateY: 0 }],
451 ...initialValues,
452 },
453 callback,
454 };
455 };
456 };
457}