UNPKG

6.34 kBPlain TextView Raw
1'use strict';
2import type { BaseAnimationBuilder } from '../animationBuilder';
3import { ComplexAnimationBuilder } from '../animationBuilder';
4import type {
5 EntryExitAnimationsValues,
6 EntryExitAnimationFunction,
7 IEntryExitAnimationBuilder,
8} from '../animationBuilder/commonTypes';
9
10/**
11 * Roll from left animation. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
12 *
13 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
14 *
15 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#roll
16 */
17export class RollInLeft
18 extends ComplexAnimationBuilder
19 implements IEntryExitAnimationBuilder
20{
21 static presetName = 'RollInLeft';
22
23 static createInstance<T extends typeof BaseAnimationBuilder>(
24 this: T
25 ): InstanceType<T> {
26 return new RollInLeft() as InstanceType<T>;
27 }
28
29 build = (): EntryExitAnimationFunction => {
30 const delayFunction = this.getDelayFunction();
31 const [animation, config] = this.getAnimationAndConfig();
32 const delay = this.getDelay();
33 const callback = this.callbackV;
34 const initialValues = this.initialValues;
35
36 return (values: EntryExitAnimationsValues) => {
37 'worklet';
38 return {
39 animations: {
40 transform: [
41 { translateX: delayFunction(delay, animation(0, config)) },
42 { rotate: delayFunction(delay, animation('0deg', config)) },
43 ],
44 },
45 initialValues: {
46 transform: [
47 { translateX: -values.windowWidth },
48 { rotate: '-180deg' },
49 ],
50 ...initialValues,
51 },
52 callback,
53 };
54 };
55 };
56}
57
58/**
59 * Roll from right animation. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
60 *
61 * You pass it to the `entering` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
62 *
63 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#roll
64 */
65export class RollInRight
66 extends ComplexAnimationBuilder
67 implements IEntryExitAnimationBuilder
68{
69 static presetName = 'RollInRight';
70
71 static createInstance<T extends typeof BaseAnimationBuilder>(
72 this: T
73 ): InstanceType<T> {
74 return new RollInRight() as InstanceType<T>;
75 }
76
77 build = (): EntryExitAnimationFunction => {
78 const delayFunction = this.getDelayFunction();
79 const [animation, config] = this.getAnimationAndConfig();
80 const delay = this.getDelay();
81 const callback = this.callbackV;
82 const initialValues = this.initialValues;
83
84 return (values: EntryExitAnimationsValues) => {
85 'worklet';
86 return {
87 animations: {
88 transform: [
89 { translateX: delayFunction(delay, animation(0, config)) },
90 { rotate: delayFunction(delay, animation('0deg', config)) },
91 ],
92 },
93 initialValues: {
94 transform: [{ translateX: values.windowWidth }, { rotate: '180deg' }],
95 ...initialValues,
96 },
97 callback,
98 };
99 };
100 };
101}
102
103/**
104 * Roll to left animation. You can modify the behavior by chaining methods like `.springify()` or `.duration(500)`.
105 *
106 * You pass it to the `exiting` prop on [an Animated component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component).
107 *
108 * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/entering-exiting-animations#roll
109 */
110export class RollOutLeft
111 extends ComplexAnimationBuilder
112 implements IEntryExitAnimationBuilder
113{
114 static presetName = 'RollOutLeft';
115
116 static createInstance<T extends typeof BaseAnimationBuilder>(
117 this: T
118 ): InstanceType<T> {
119 return new RollOutLeft() as InstanceType<T>;
120 }
121
122 build = (): EntryExitAnimationFunction => {
123 const delayFunction = this.getDelayFunction();
124 const [animation, config] = this.getAnimationAndConfig();
125 const delay = this.getDelay();
126 const callback = this.callbackV;
127 const initialValues = this.initialValues;
128
129 return (values: EntryExitAnimationsValues) => {
130 'worklet';
131 return {
132 animations: {
133 transform: [
134 {
135 translateX: delayFunction(
136 delay,
137 animation(-values.windowWidth, config)
138 ),
139 },
140 { rotate: delayFunction(delay, animation('-180deg', config)) },
141 ],
142 },
143 initialValues: {
144 transform: [{ translateX: 0 }, { rotate: '0deg' }],
145 ...initialValues,
146 },
147 callback,
148 };
149 };
150 };
151}
152
153/**
154 * Roll to right 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#roll
159 */
160export class RollOutRight
161 extends ComplexAnimationBuilder
162 implements IEntryExitAnimationBuilder
163{
164 static presetName = 'RollOutRight';
165
166 static createInstance<T extends typeof BaseAnimationBuilder>(
167 this: T
168 ): InstanceType<T> {
169 return new RollOutRight() as InstanceType<T>;
170 }
171
172 build = (): EntryExitAnimationFunction => {
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: EntryExitAnimationsValues) => {
180 'worklet';
181 return {
182 animations: {
183 transform: [
184 {
185 translateX: delayFunction(
186 delay,
187 animation(values.windowWidth, config)
188 ),
189 },
190 { rotate: delayFunction(delay, animation('180deg', config)) },
191 ],
192 },
193 initialValues: {
194 transform: [{ translateX: 0 }, { rotate: '0deg' }],
195 ...initialValues,
196 },
197 callback,
198 };
199 };
200 };
201}