UNPKG

5.45 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 * Stretch animation on the X axis. 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/#stretch
15 */
16export class StretchInX
17 extends ComplexAnimationBuilder
18 implements IEntryExitAnimationBuilder
19{
20 static presetName = 'StretchInX';
21
22 static createInstance<T extends typeof BaseAnimationBuilder>(
23 this: T
24 ): InstanceType<T> {
25 return new StretchInX() as InstanceType<T>;
26 }
27
28 build = (): EntryExitAnimationFunction => {
29 const delayFunction = this.getDelayFunction();
30 const [animation, config] = this.getAnimationAndConfig();
31 const delay = this.getDelay();
32 const callback = this.callbackV;
33 const initialValues = this.initialValues;
34
35 return () => {
36 'worklet';
37 return {
38 animations: {
39 transform: [{ scaleX: delayFunction(delay, animation(1, config)) }],
40 },
41 initialValues: {
42 transform: [{ scaleX: 0 }],
43 ...initialValues,
44 },
45 callback,
46 };
47 };
48 };
49}
50
51/**
52 * Stretch animation on the Y axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
53 *
54 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
55 *
56 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations/#stretch
57 */
58export class StretchInY
59 extends ComplexAnimationBuilder
60 implements IEntryExitAnimationBuilder
61{
62 static presetName = 'StretchInY';
63
64 static createInstance<T extends typeof BaseAnimationBuilder>(
65 this: T
66 ): InstanceType<T> {
67 return new StretchInY() as InstanceType<T>;
68 }
69
70 build = (): EntryExitAnimationFunction => {
71 const delayFunction = this.getDelayFunction();
72 const [animation, config] = this.getAnimationAndConfig();
73 const delay = this.getDelay();
74 const callback = this.callbackV;
75 const initialValues = this.initialValues;
76
77 return () => {
78 'worklet';
79 return {
80 animations: {
81 transform: [{ scaleY: delayFunction(delay, animation(1, config)) }],
82 },
83 initialValues: {
84 transform: [{ scaleY: 0 }],
85 ...initialValues,
86 },
87 callback,
88 };
89 };
90 };
91}
92
93/**
94 * Stretch animation on the X axis. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
95 *
96 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
97 *
98 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations/#stretch
99 */
100export class StretchOutX
101 extends ComplexAnimationBuilder
102 implements IEntryExitAnimationBuilder
103{
104 static presetName = 'StretchOutX';
105
106 static createInstance<T extends typeof BaseAnimationBuilder>(
107 this: T
108 ): InstanceType<T> {
109 return new StretchOutX() as InstanceType<T>;
110 }
111
112 build = (): EntryExitAnimationFunction => {
113 const delayFunction = this.getDelayFunction();
114 const [animation, config] = this.getAnimationAndConfig();
115 const delay = this.getDelay();
116 const callback = this.callbackV;
117 const initialValues = this.initialValues;
118
119 return () => {
120 'worklet';
121 return {
122 animations: {
123 transform: [{ scaleX: delayFunction(delay, animation(0, config)) }],
124 },
125 initialValues: {
126 transform: [{ scaleX: 1 }],
127 ...initialValues,
128 },
129 callback,
130 };
131 };
132 };
133}
134
135/**
136 * Stretch animation on the Y axis. 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/#stretch
141 */
142export class StretchOutY
143 extends ComplexAnimationBuilder
144 implements IEntryExitAnimationBuilder
145{
146 static presetName = 'StretchOutY';
147
148 static createInstance<T extends typeof BaseAnimationBuilder>(
149 this: T
150 ): InstanceType<T> {
151 return new StretchOutY() 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 () => {
162 'worklet';
163 return {
164 animations: {
165 transform: [{ scaleY: delayFunction(delay, animation(0, config)) }],
166 },
167 initialValues: {
168 transform: [{ scaleY: 1 }],
169 ...initialValues,
170 },
171 callback,
172 };
173 };
174 };
175}