UNPKG

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