UNPKG

19.3 kBPlain TextView Raw
1'use strict';
2import type {
3 IEntryExitAnimationBuilder,
4 EntryExitAnimationFunction,
5 EntryAnimationsValues,
6 ExitAnimationsValues,
7 AnimationConfigFunction,
8 IEntryAnimationBuilder,
9 IExitAnimationBuilder,
10} from '../animationBuilder/commonTypes';
11import type { BaseAnimationBuilder } from '../animationBuilder';
12import { ComplexAnimationBuilder } from '../animationBuilder';
13
14/**
15 * Rotate from top on the X axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
16 *
17 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
18 *
19 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#flip
20 */
21export class FlipInXUp
22 extends ComplexAnimationBuilder
23 implements IEntryAnimationBuilder
24{
25 static presetName = 'FlipInXUp';
26
27 static createInstance<T extends typeof BaseAnimationBuilder>(
28 this: T
29 ): InstanceType<T> {
30 return new FlipInXUp() as InstanceType<T>;
31 }
32
33 build = (): AnimationConfigFunction<EntryAnimationsValues> => {
34 const delayFunction = this.getDelayFunction();
35 const [animation, config] = this.getAnimationAndConfig();
36 const delay = this.getDelay();
37 const callback = this.callbackV;
38 const initialValues = this.initialValues;
39
40 return (targetValues) => {
41 'worklet';
42 return {
43 initialValues: {
44 transform: [
45 { perspective: 500 },
46 { rotateX: '90deg' },
47 { translateY: -targetValues.targetHeight },
48 ],
49 ...initialValues,
50 },
51 animations: {
52 transform: [
53 { perspective: 500 },
54 { rotateX: delayFunction(delay, animation('0deg', config)) },
55 { translateY: delayFunction(delay, animation(0, config)) },
56 ],
57 },
58 callback,
59 };
60 };
61 };
62}
63
64/**
65 * Rotate from left on the Y axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
66 *
67 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
68 *
69 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#flip
70 */
71export class FlipInYLeft
72 extends ComplexAnimationBuilder
73 implements IEntryAnimationBuilder
74{
75 static presetName = 'FlipInYLeft';
76
77 static createInstance<T extends typeof BaseAnimationBuilder>(
78 this: T
79 ): InstanceType<T> {
80 return new FlipInYLeft() as InstanceType<T>;
81 }
82
83 build = (): AnimationConfigFunction<EntryAnimationsValues> => {
84 const delayFunction = this.getDelayFunction();
85 const [animation, config] = this.getAnimationAndConfig();
86 const delay = this.getDelay();
87 const callback = this.callbackV;
88 const initialValues = this.initialValues;
89
90 return (targetValues) => {
91 'worklet';
92 return {
93 initialValues: {
94 transform: [
95 { perspective: 500 },
96 { rotateY: '-90deg' },
97 { translateX: -targetValues.targetWidth },
98 ],
99 ...initialValues,
100 },
101 animations: {
102 transform: [
103 { perspective: delayFunction(delay, animation(500, config)) },
104 { rotateY: delayFunction(delay, animation('0deg', config)) },
105 { translateX: delayFunction(delay, animation(0, config)) },
106 ],
107 },
108 callback,
109 };
110 };
111 };
112}
113
114/**
115 * Rotate from bottom on the X axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
116 *
117 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
118 *
119 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#flip
120 */
121export class FlipInXDown
122 extends ComplexAnimationBuilder
123 implements IEntryAnimationBuilder
124{
125 static presetName = 'FlipInXDown';
126
127 static createInstance<T extends typeof BaseAnimationBuilder>(
128 this: T
129 ): InstanceType<T> {
130 return new FlipInXDown() as InstanceType<T>;
131 }
132
133 build = (): AnimationConfigFunction<EntryAnimationsValues> => {
134 const delayFunction = this.getDelayFunction();
135 const [animation, config] = this.getAnimationAndConfig();
136 const delay = this.getDelay();
137 const callback = this.callbackV;
138 const initialValues = this.initialValues;
139
140 return (targetValues) => {
141 'worklet';
142 return {
143 initialValues: {
144 transform: [
145 { perspective: 500 },
146 { rotateX: '-90deg' },
147 { translateY: targetValues.targetHeight },
148 ],
149 ...initialValues,
150 },
151 animations: {
152 transform: [
153 { perspective: delayFunction(delay, animation(500, config)) },
154 { rotateX: delayFunction(delay, animation('0deg', config)) },
155 { translateY: delayFunction(delay, animation(0, config)) },
156 ],
157 },
158 callback,
159 };
160 };
161 };
162}
163
164/**
165 * Rotate from right on the Y axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
166 *
167 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
168 *
169 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#flip
170 */
171export class FlipInYRight
172 extends ComplexAnimationBuilder
173 implements IEntryAnimationBuilder
174{
175 static presetName = 'FlipInYRight';
176
177 static createInstance<T extends typeof BaseAnimationBuilder>(
178 this: T
179 ): InstanceType<T> {
180 return new FlipInYRight() as InstanceType<T>;
181 }
182
183 build = (): AnimationConfigFunction<EntryAnimationsValues> => {
184 const delayFunction = this.getDelayFunction();
185 const [animation, config] = this.getAnimationAndConfig();
186 const delay = this.getDelay();
187 const callback = this.callbackV;
188 const initialValues = this.initialValues;
189
190 return (targetValues) => {
191 'worklet';
192 return {
193 initialValues: {
194 transform: [
195 { perspective: 500 },
196 { rotateY: '90deg' },
197 { translateX: targetValues.targetWidth },
198 ],
199 ...initialValues,
200 },
201 animations: {
202 transform: [
203 { perspective: delayFunction(delay, animation(500, config)) },
204 { rotateY: delayFunction(delay, animation('0deg', config)) },
205 { translateX: delayFunction(delay, animation(0, config)) },
206 ],
207 },
208 callback,
209 };
210 };
211 };
212}
213
214/**
215 * Eased rotate in on the X axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
216 *
217 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
218 *
219 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#flip
220 */
221export class FlipInEasyX
222 extends ComplexAnimationBuilder
223 implements IEntryExitAnimationBuilder
224{
225 static presetName = 'FlipInEasyX';
226
227 static createInstance<T extends typeof BaseAnimationBuilder>(
228 this: T
229 ): InstanceType<T> {
230 return new FlipInEasyX() as InstanceType<T>;
231 }
232
233 build = (): EntryExitAnimationFunction => {
234 const delayFunction = this.getDelayFunction();
235 const [animation, config] = this.getAnimationAndConfig();
236 const delay = this.getDelay();
237 const callback = this.callbackV;
238 const initialValues = this.initialValues;
239
240 return () => {
241 'worklet';
242 return {
243 initialValues: {
244 transform: [{ perspective: 500 }, { rotateX: '90deg' }],
245 ...initialValues,
246 },
247 animations: {
248 transform: [
249 { perspective: delayFunction(delay, animation(500, config)) },
250 { rotateX: delayFunction(delay, animation('0deg', config)) },
251 ],
252 },
253 callback,
254 };
255 };
256 };
257}
258
259/**
260 * Eased rotate in on the Y axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
261 *
262 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
263 *
264 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#flip
265 */
266export class FlipInEasyY
267 extends ComplexAnimationBuilder
268 implements IEntryExitAnimationBuilder
269{
270 static presetName = 'FlipInEasyY';
271
272 static createInstance<T extends typeof BaseAnimationBuilder>(
273 this: T
274 ): InstanceType<T> {
275 return new FlipInEasyY() as InstanceType<T>;
276 }
277
278 build = (): EntryExitAnimationFunction => {
279 const delayFunction = this.getDelayFunction();
280 const [animation, config] = this.getAnimationAndConfig();
281 const delay = this.getDelay();
282 const callback = this.callbackV;
283 const initialValues = this.initialValues;
284
285 return () => {
286 'worklet';
287 return {
288 initialValues: {
289 transform: [{ perspective: 500 }, { rotateY: '90deg' }],
290 ...initialValues,
291 },
292 animations: {
293 transform: [
294 { perspective: delayFunction(delay, animation(500, config)) },
295 { rotateY: delayFunction(delay, animation('0deg', config)) },
296 ],
297 },
298 callback,
299 };
300 };
301 };
302}
303
304/**
305 * Rotate to top animation on the X axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
306 *
307 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
308 *
309 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#flip
310 */
311export class FlipOutXUp
312 extends ComplexAnimationBuilder
313 implements IExitAnimationBuilder
314{
315 static presetName = 'FlipOutXUp';
316
317 static createInstance<T extends typeof BaseAnimationBuilder>(
318 this: T
319 ): InstanceType<T> {
320 return new FlipOutXUp() as InstanceType<T>;
321 }
322
323 build = (): AnimationConfigFunction<ExitAnimationsValues> => {
324 const delayFunction = this.getDelayFunction();
325 const [animation, config] = this.getAnimationAndConfig();
326 const delay = this.getDelay();
327 const callback = this.callbackV;
328 const initialValues = this.initialValues;
329
330 return (targetValues) => {
331 'worklet';
332 return {
333 initialValues: {
334 transform: [
335 { perspective: 500 },
336 { rotateX: '0deg' },
337 { translateY: 0 },
338 ],
339 ...initialValues,
340 },
341 animations: {
342 transform: [
343 { perspective: delayFunction(delay, animation(500, config)) },
344 { rotateX: delayFunction(delay, animation('90deg', config)) },
345 {
346 translateY: delayFunction(
347 delay,
348 animation(-targetValues.currentHeight, config)
349 ),
350 },
351 ],
352 },
353 callback,
354 };
355 };
356 };
357}
358
359/**
360 * Rotate to left on the Y axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
361 *
362 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
363 *
364 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#flip
365 */
366export class FlipOutYLeft
367 extends ComplexAnimationBuilder
368 implements IExitAnimationBuilder
369{
370 static presetName = 'FlipOutYLeft';
371
372 static createInstance<T extends typeof BaseAnimationBuilder>(
373 this: T
374 ): InstanceType<T> {
375 return new FlipOutYLeft() as InstanceType<T>;
376 }
377
378 build = (): AnimationConfigFunction<ExitAnimationsValues> => {
379 const delayFunction = this.getDelayFunction();
380 const [animation, config] = this.getAnimationAndConfig();
381 const delay = this.getDelay();
382 const callback = this.callbackV;
383 const initialValues = this.initialValues;
384
385 return (targetValues) => {
386 'worklet';
387 return {
388 initialValues: {
389 transform: [
390 { perspective: 500 },
391 { rotateY: '0deg' },
392 { translateX: 0 },
393 ],
394 ...initialValues,
395 },
396 animations: {
397 transform: [
398 { perspective: delayFunction(delay, animation(500, config)) },
399 { rotateY: delayFunction(delay, animation('-90deg', config)) },
400 {
401 translateX: delayFunction(
402 delay,
403 animation(-targetValues.currentWidth, config)
404 ),
405 },
406 ],
407 },
408 callback,
409 };
410 };
411 };
412}
413
414/**
415 * Rotate to bottom on the X axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
416 *
417 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
418 *
419 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#flip
420 */
421export class FlipOutXDown
422 extends ComplexAnimationBuilder
423 implements IExitAnimationBuilder
424{
425 static presetName = 'FlipOutXDown';
426
427 static createInstance<T extends typeof BaseAnimationBuilder>(
428 this: T
429 ): InstanceType<T> {
430 return new FlipOutXDown() as InstanceType<T>;
431 }
432
433 build = (): AnimationConfigFunction<ExitAnimationsValues> => {
434 const delayFunction = this.getDelayFunction();
435 const [animation, config] = this.getAnimationAndConfig();
436 const delay = this.getDelay();
437 const callback = this.callbackV;
438 const initialValues = this.initialValues;
439
440 return (targetValues) => {
441 'worklet';
442 return {
443 initialValues: {
444 transform: [
445 { perspective: 500 },
446 { rotateX: '0deg' },
447 { translateY: 0 },
448 ],
449 ...initialValues,
450 },
451 animations: {
452 transform: [
453 { perspective: delayFunction(delay, animation(500, config)) },
454 { rotateX: delayFunction(delay, animation('-90deg', config)) },
455 {
456 translateY: delayFunction(
457 delay,
458 animation(targetValues.currentHeight, config)
459 ),
460 },
461 ],
462 },
463 callback,
464 };
465 };
466 };
467}
468
469/**
470 * Rotate to right animation on the Y axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
471 *
472 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
473 *
474 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#flip
475 */
476export class FlipOutYRight
477 extends ComplexAnimationBuilder
478 implements IExitAnimationBuilder
479{
480 static presetName = 'FlipOutYRight';
481
482 static createInstance<T extends typeof BaseAnimationBuilder>(
483 this: T
484 ): InstanceType<T> {
485 return new FlipOutYRight() as InstanceType<T>;
486 }
487
488 build = (): AnimationConfigFunction<ExitAnimationsValues> => {
489 const delayFunction = this.getDelayFunction();
490 const [animation, config] = this.getAnimationAndConfig();
491 const delay = this.getDelay();
492 const callback = this.callbackV;
493 const initialValues = this.initialValues;
494
495 return (targetValues) => {
496 'worklet';
497 return {
498 initialValues: {
499 transform: [
500 { perspective: 500 },
501 { rotateY: '0deg' },
502 { translateX: 0 },
503 ],
504 ...initialValues,
505 },
506 animations: {
507 transform: [
508 { perspective: delayFunction(delay, animation(500, config)) },
509 { rotateY: delayFunction(delay, animation('90deg', config)) },
510 {
511 translateX: delayFunction(
512 delay,
513 animation(targetValues.currentWidth, config)
514 ),
515 },
516 ],
517 },
518 callback,
519 };
520 };
521 };
522}
523
524/**
525 * Eased rotate on the X axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
526 *
527 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
528 *
529 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#flip
530 */
531export class FlipOutEasyX
532 extends ComplexAnimationBuilder
533 implements IEntryExitAnimationBuilder
534{
535 static presetName = 'FlipOutEasyX';
536
537 static createInstance<T extends typeof BaseAnimationBuilder>(
538 this: T
539 ): InstanceType<T> {
540 return new FlipOutEasyX() as InstanceType<T>;
541 }
542
543 build = (): EntryExitAnimationFunction => {
544 const delayFunction = this.getDelayFunction();
545 const [animation, config] = this.getAnimationAndConfig();
546 const delay = this.getDelay();
547 const callback = this.callbackV;
548 const initialValues = this.initialValues;
549
550 return () => {
551 'worklet';
552 return {
553 initialValues: {
554 transform: [{ perspective: 500 }, { rotateX: '0deg' }],
555 ...initialValues,
556 },
557 animations: {
558 transform: [
559 { perspective: delayFunction(delay, animation(500, config)) },
560 { rotateX: delayFunction(delay, animation('90deg', config)) },
561 ],
562 },
563 callback,
564 };
565 };
566 };
567}
568
569/**
570 * Eased rotate on the Y axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
571 *
572 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
573 *
574 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#flip
575 */
576export class FlipOutEasyY
577 extends ComplexAnimationBuilder
578 implements IEntryExitAnimationBuilder
579{
580 static presetName = 'FlipOutEasyY';
581
582 static createInstance<T extends typeof BaseAnimationBuilder>(
583 this: T
584 ): InstanceType<T> {
585 return new FlipOutEasyY() as InstanceType<T>;
586 }
587
588 build = (): EntryExitAnimationFunction => {
589 const delayFunction = this.getDelayFunction();
590 const [animation, config] = this.getAnimationAndConfig();
591 const delay = this.getDelay();
592 const callback = this.callbackV;
593 const initialValues = this.initialValues;
594
595 return () => {
596 'worklet';
597 return {
598 initialValues: {
599 transform: [{ perspective: 500 }, { rotateY: '0deg' }],
600 ...initialValues,
601 },
602 animations: {
603 transform: [
604 { perspective: delayFunction(delay, animation(500, config)) },
605 { rotateY: delayFunction(delay, animation('90deg', config)) },
606 ],
607 },
608 callback,
609 };
610 };
611 };
612}