1 |
|
2 | 'use strict';
|
3 |
|
4 | import type {
|
5 | WithSpringConfig,
|
6 | WithTimingConfig,
|
7 | WithDecayConfig,
|
8 | AnimatableValue,
|
9 | AnimationCallback,
|
10 | } from './reanimated2';
|
11 | import {
|
12 | IOSReferenceFrame,
|
13 | InterfaceOrientation,
|
14 | KeyboardState,
|
15 | ReduceMotion,
|
16 | SensorType,
|
17 | ColorSpace,
|
18 | Extrapolation,
|
19 | SharedTransitionType,
|
20 | withReanimatedTimer,
|
21 | advanceAnimationByTime,
|
22 | advanceAnimationByFrame,
|
23 | setUpTests,
|
24 | getAnimatedStyle,
|
25 | } from './reanimated2';
|
26 | import {
|
27 | View as ViewRN,
|
28 | Text as TextRN,
|
29 | Image as ImageRN,
|
30 | Animated as AnimatedRN,
|
31 | processColor as processColorRN,
|
32 | } from 'react-native';
|
33 |
|
34 | const NOOP = () => {};
|
35 | const NOOP_FACTORY = () => NOOP;
|
36 | const ID = <T>(t: T) => t;
|
37 | const IMMEDIATE_CALLBACK_INVOCATION = <T>(callback: () => T) => callback();
|
38 |
|
39 | const hook = {
|
40 | useAnimatedProps: IMMEDIATE_CALLBACK_INVOCATION,
|
41 |
|
42 |
|
43 | useWorkletCallback: ID,
|
44 | useSharedValue: <Value>(init: Value) => ({ value: init }),
|
45 |
|
46 | useAnimatedStyle: IMMEDIATE_CALLBACK_INVOCATION,
|
47 | useAnimatedGestureHandler: NOOP_FACTORY,
|
48 | useAnimatedReaction: NOOP,
|
49 | useAnimatedRef: () => ({ current: null }),
|
50 | useAnimatedScrollHandler: NOOP_FACTORY,
|
51 | useDerivedValue: <Value>(processor: () => Value) => ({ value: processor() }),
|
52 | useAnimatedSensor: () => ({
|
53 | sensor: {
|
54 | value: {
|
55 | x: 0,
|
56 | y: 0,
|
57 | z: 0,
|
58 | interfaceOrientation: 0,
|
59 | qw: 0,
|
60 | qx: 0,
|
61 | qy: 0,
|
62 | qz: 0,
|
63 | yaw: 0,
|
64 | pitch: 0,
|
65 | roll: 0,
|
66 | },
|
67 | },
|
68 | unregister: NOOP,
|
69 | isAvailable: false,
|
70 | config: {
|
71 | interval: 0,
|
72 | adjustToInterfaceOrientation: false,
|
73 | iosReferenceFrame: 0,
|
74 | },
|
75 | }),
|
76 |
|
77 | useAnimatedKeyboard: () => ({ height: 0, state: 0 }),
|
78 |
|
79 | };
|
80 |
|
81 | const animation = {
|
82 | cancelAnimation: NOOP,
|
83 |
|
84 |
|
85 | withDecay: (_userConfig: WithDecayConfig, callback?: AnimationCallback) => {
|
86 | callback?.(true);
|
87 | return 0;
|
88 | },
|
89 | withDelay: <T>(_delayMs: number, nextAnimation: T) => {
|
90 | return nextAnimation;
|
91 | },
|
92 | withRepeat: ID,
|
93 | withSequence: () => 0,
|
94 | withSpring: (
|
95 | toValue: AnimatableValue,
|
96 | _userConfig?: WithSpringConfig,
|
97 | callback?: AnimationCallback
|
98 | ) => {
|
99 | callback?.(true);
|
100 | return toValue;
|
101 | },
|
102 | withTiming: (
|
103 | toValue: AnimatableValue,
|
104 | _userConfig?: WithTimingConfig,
|
105 | callback?: AnimationCallback
|
106 | ) => {
|
107 | callback?.(true);
|
108 | return toValue;
|
109 | },
|
110 | };
|
111 |
|
112 | const interpolation = {
|
113 | Extrapolation,
|
114 | interpolate: NOOP,
|
115 | clamp: NOOP,
|
116 | };
|
117 |
|
118 | const interpolateColor = {
|
119 | Extrapolate: Extrapolation,
|
120 | Extrapolation,
|
121 | ColorSpace,
|
122 | interpolateColor: NOOP,
|
123 |
|
124 | };
|
125 |
|
126 | const Easing = {
|
127 | Easing: {
|
128 | linear: ID,
|
129 | ease: ID,
|
130 | quad: ID,
|
131 | cubic: ID,
|
132 | poly: ID,
|
133 | sin: ID,
|
134 | circle: ID,
|
135 | exp: ID,
|
136 | elastic: ID,
|
137 | back: ID,
|
138 | bounce: ID,
|
139 | bezier: () => ({ factory: ID }),
|
140 | bezierFn: ID,
|
141 | steps: ID,
|
142 | in: ID,
|
143 | out: ID,
|
144 | inOut: ID,
|
145 | },
|
146 | };
|
147 |
|
148 | const platformFunctions = {
|
149 | measure: () => ({
|
150 | x: 0,
|
151 | y: 0,
|
152 | width: 0,
|
153 | height: 0,
|
154 | pageX: 0,
|
155 | pageY: 0,
|
156 | }),
|
157 |
|
158 | scrollTo: NOOP,
|
159 |
|
160 |
|
161 |
|
162 | };
|
163 |
|
164 | const Colors = {
|
165 |
|
166 | processColor: processColorRN,
|
167 |
|
168 | };
|
169 |
|
170 | const PropAdapters = {
|
171 |
|
172 | };
|
173 |
|
174 | class BaseAnimationMock {
|
175 | duration() {
|
176 | return this;
|
177 | }
|
178 |
|
179 | delay() {
|
180 | return this;
|
181 | }
|
182 |
|
183 | springify() {
|
184 | return this;
|
185 | }
|
186 |
|
187 | damping() {
|
188 | return this;
|
189 | }
|
190 |
|
191 | stiffness() {
|
192 | return this;
|
193 | }
|
194 |
|
195 | withCallback() {
|
196 | return this;
|
197 | }
|
198 |
|
199 | randomDelay() {
|
200 | return this;
|
201 | }
|
202 |
|
203 | withInitialValues() {
|
204 | return this;
|
205 | }
|
206 |
|
207 | easing(_: (t: number) => number) {
|
208 | return this;
|
209 | }
|
210 |
|
211 | rotate(_: string) {
|
212 | return this;
|
213 | }
|
214 |
|
215 | mass(_: number) {
|
216 | return this;
|
217 | }
|
218 |
|
219 | restDisplacementThreshold(_: number) {
|
220 | return this;
|
221 | }
|
222 |
|
223 | restSpeedThreshold(_: number) {
|
224 | return this;
|
225 | }
|
226 |
|
227 | overshootClamping(_: number) {
|
228 | return this;
|
229 | }
|
230 |
|
231 | dampingRatio(_: number) {
|
232 | return this;
|
233 | }
|
234 |
|
235 | getDelay() {
|
236 | return 0;
|
237 | }
|
238 |
|
239 | getDelayFunction() {
|
240 | return NOOP;
|
241 | }
|
242 |
|
243 | getDuration() {
|
244 | return 300;
|
245 | }
|
246 |
|
247 | getReduceMotion() {
|
248 | return ReduceMotion.System;
|
249 | }
|
250 |
|
251 | getAnimationAndConfig() {
|
252 | return [NOOP, {}];
|
253 | }
|
254 |
|
255 | build() {
|
256 | return () => ({ initialValues: {}, animations: {} });
|
257 | }
|
258 |
|
259 | reduceMotion() {
|
260 | return this;
|
261 | }
|
262 | }
|
263 |
|
264 | const core = {
|
265 | runOnJS: ID,
|
266 | runOnUI: ID,
|
267 | createWorkletRuntime: NOOP,
|
268 | runOnRuntime: NOOP,
|
269 | makeMutable: ID,
|
270 | makeShareableCloneRecursive: ID,
|
271 | isReanimated3: () => true,
|
272 |
|
273 | enableLayoutAnimations: NOOP,
|
274 |
|
275 | };
|
276 |
|
277 | const layoutReanimation = {
|
278 | BaseAnimationBuilder: new BaseAnimationMock(),
|
279 | ComplexAnimationBuilder: new BaseAnimationMock(),
|
280 | Keyframe: new BaseAnimationMock(),
|
281 |
|
282 | FlipInXUp: new BaseAnimationMock(),
|
283 | FlipInYLeft: new BaseAnimationMock(),
|
284 | FlipInXDown: new BaseAnimationMock(),
|
285 | FlipInYRight: new BaseAnimationMock(),
|
286 | FlipInEasyX: new BaseAnimationMock(),
|
287 | FlipInEasyY: new BaseAnimationMock(),
|
288 | FlipOutXUp: new BaseAnimationMock(),
|
289 | FlipOutYLeft: new BaseAnimationMock(),
|
290 | FlipOutXDown: new BaseAnimationMock(),
|
291 | FlipOutYRight: new BaseAnimationMock(),
|
292 | FlipOutEasyX: new BaseAnimationMock(),
|
293 | FlipOutEasyY: new BaseAnimationMock(),
|
294 |
|
295 | StretchInX: new BaseAnimationMock(),
|
296 | StretchInY: new BaseAnimationMock(),
|
297 | StretchOutX: new BaseAnimationMock(),
|
298 | StretchOutY: new BaseAnimationMock(),
|
299 |
|
300 | FadeIn: new BaseAnimationMock(),
|
301 | FadeInRight: new BaseAnimationMock(),
|
302 | FadeInLeft: new BaseAnimationMock(),
|
303 | FadeInUp: new BaseAnimationMock(),
|
304 | FadeInDown: new BaseAnimationMock(),
|
305 | FadeOut: new BaseAnimationMock(),
|
306 | FadeOutRight: new BaseAnimationMock(),
|
307 | FadeOutLeft: new BaseAnimationMock(),
|
308 | FadeOutUp: new BaseAnimationMock(),
|
309 | FadeOutDown: new BaseAnimationMock(),
|
310 |
|
311 | SlideInRight: new BaseAnimationMock(),
|
312 | SlideInLeft: new BaseAnimationMock(),
|
313 | SlideOutRight: new BaseAnimationMock(),
|
314 | SlideOutLeft: new BaseAnimationMock(),
|
315 | SlideInUp: new BaseAnimationMock(),
|
316 | SlideInDown: new BaseAnimationMock(),
|
317 | SlideOutUp: new BaseAnimationMock(),
|
318 | SlideOutDown: new BaseAnimationMock(),
|
319 |
|
320 | ZoomIn: new BaseAnimationMock(),
|
321 | ZoomInRotate: new BaseAnimationMock(),
|
322 | ZoomInLeft: new BaseAnimationMock(),
|
323 | ZoomInRight: new BaseAnimationMock(),
|
324 | ZoomInUp: new BaseAnimationMock(),
|
325 | ZoomInDown: new BaseAnimationMock(),
|
326 | ZoomInEasyUp: new BaseAnimationMock(),
|
327 | ZoomInEasyDown: new BaseAnimationMock(),
|
328 | ZoomOut: new BaseAnimationMock(),
|
329 | ZoomOutRotate: new BaseAnimationMock(),
|
330 | ZoomOutLeft: new BaseAnimationMock(),
|
331 | ZoomOutRight: new BaseAnimationMock(),
|
332 | ZoomOutUp: new BaseAnimationMock(),
|
333 | ZoomOutDown: new BaseAnimationMock(),
|
334 | ZoomOutEasyUp: new BaseAnimationMock(),
|
335 | ZoomOutEasyDown: new BaseAnimationMock(),
|
336 |
|
337 | BounceIn: new BaseAnimationMock(),
|
338 | BounceInDown: new BaseAnimationMock(),
|
339 | BounceInUp: new BaseAnimationMock(),
|
340 | BounceInLeft: new BaseAnimationMock(),
|
341 | BounceInRight: new BaseAnimationMock(),
|
342 | BounceOut: new BaseAnimationMock(),
|
343 | BounceOutDown: new BaseAnimationMock(),
|
344 | BounceOutUp: new BaseAnimationMock(),
|
345 | BounceOutLeft: new BaseAnimationMock(),
|
346 | BounceOutRight: new BaseAnimationMock(),
|
347 |
|
348 | LightSpeedInRight: new BaseAnimationMock(),
|
349 | LightSpeedInLeft: new BaseAnimationMock(),
|
350 | LightSpeedOutRight: new BaseAnimationMock(),
|
351 | LightSpeedOutLeft: new BaseAnimationMock(),
|
352 |
|
353 | PinwheelIn: new BaseAnimationMock(),
|
354 | PinwheelOut: new BaseAnimationMock(),
|
355 |
|
356 | RotateInDownLeft: new BaseAnimationMock(),
|
357 | RotateInDownRight: new BaseAnimationMock(),
|
358 | RotateInUpLeft: new BaseAnimationMock(),
|
359 | RotateInUpRight: new BaseAnimationMock(),
|
360 | RotateOutDownLeft: new BaseAnimationMock(),
|
361 | RotateOutDownRight: new BaseAnimationMock(),
|
362 | RotateOutUpLeft: new BaseAnimationMock(),
|
363 | RotateOutUpRight: new BaseAnimationMock(),
|
364 |
|
365 | RollInLeft: new BaseAnimationMock(),
|
366 | RollInRight: new BaseAnimationMock(),
|
367 | RollOutLeft: new BaseAnimationMock(),
|
368 | RollOutRight: new BaseAnimationMock(),
|
369 |
|
370 | Layout: new BaseAnimationMock(),
|
371 | LinearTransition: new BaseAnimationMock(),
|
372 | FadingTransition: new BaseAnimationMock(),
|
373 | SequencedTransition: new BaseAnimationMock(),
|
374 | JumpingTransition: new BaseAnimationMock(),
|
375 | CurvedTransition: new BaseAnimationMock(),
|
376 | EntryExitTransition: new BaseAnimationMock(),
|
377 |
|
378 |
|
379 |
|
380 | SharedTransitionType,
|
381 | };
|
382 |
|
383 | const isSharedValue = {
|
384 |
|
385 | };
|
386 |
|
387 | const commonTypes = {
|
388 | SensorType,
|
389 | IOSReferenceFrame,
|
390 | InterfaceOrientation,
|
391 | KeyboardState,
|
392 | ReduceMotion,
|
393 | };
|
394 |
|
395 | const pluginUtils = {
|
396 |
|
397 | };
|
398 |
|
399 | const jestUtils = {
|
400 | withReanimatedTimer,
|
401 | advanceAnimationByTime,
|
402 | advanceAnimationByFrame,
|
403 | setUpTests,
|
404 | getAnimatedStyle,
|
405 | };
|
406 |
|
407 | const LayoutAnimationConfig = {
|
408 |
|
409 | };
|
410 |
|
411 | const mappers = {
|
412 |
|
413 |
|
414 | };
|
415 |
|
416 | const Animated = {
|
417 | View: ViewRN,
|
418 | Text: TextRN,
|
419 | Image: ImageRN,
|
420 | ScrollView: AnimatedRN.ScrollView,
|
421 | FlatList: AnimatedRN.FlatList,
|
422 | Extrapolate: Extrapolation,
|
423 | interpolate: NOOP,
|
424 | interpolateColor: NOOP,
|
425 | clamp: NOOP,
|
426 | createAnimatedComponent: ID,
|
427 | addWhitelistedUIProps: NOOP,
|
428 | addWhitelistedNativeProps: NOOP,
|
429 | };
|
430 |
|
431 | const Reanimated = {
|
432 | ...core,
|
433 | ...hook,
|
434 | ...animation,
|
435 | ...interpolation,
|
436 | ...interpolateColor,
|
437 | ...Easing,
|
438 | ...platformFunctions,
|
439 | ...Colors,
|
440 | ...PropAdapters,
|
441 | ...layoutReanimation,
|
442 | ...isSharedValue,
|
443 | ...commonTypes,
|
444 | ...pluginUtils,
|
445 | ...jestUtils,
|
446 | ...LayoutAnimationConfig,
|
447 | ...mappers,
|
448 | };
|
449 |
|
450 | module.exports = {
|
451 | __esModule: true,
|
452 | ...Reanimated,
|
453 | default: Animated,
|
454 | };
|