Skip to content

Commit 5d2cf2d

Browse files
Add v2 mocks (software-mansion#1230)
Co-authored-by: Jakub Gonet <[email protected]>
1 parent 0c2e5ae commit 5d2cf2d

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

mock.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const {
1717
Platform,
1818
processColor,
1919
} = require('react-native');
20+
const ReanimatedV2 = require('./src/reanimated2/mock');
2021

2122
function NOOP() {}
2223

@@ -234,7 +235,10 @@ module.exports = {
234235

235236
...Reanimated,
236237

237-
default: Reanimated,
238+
default: {
239+
...Reanimated,
240+
...ReanimatedV2,
241+
},
238242

239243
Transitioning: {
240244
View: createTransitioningComponent(View),

src/reanimated2/mock.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* eslint-disable standard/no-callback-literal */
2+
const NOOP = () => {};
3+
const ID = (t) => t;
4+
5+
const ReanimatedV2 = {
6+
useSharedValue: (value) => ({ value }),
7+
useDerivedValue: (a) => ({ value: a() }),
8+
useAnimatedScrollHandler: () => NOOP,
9+
useAnimatedGestureHandler: () => NOOP,
10+
useAnimatedStyle: (style) => style,
11+
useAnimatedRef: () => ({ current: null }),
12+
useAnimatedReaction: NOOP,
13+
14+
withTiming: (toValue, _, cb) => {
15+
cb && setTimeout(() => cb(true), 0);
16+
return toValue;
17+
},
18+
withSpring: (toValue, _, cb) => {
19+
cb && setTimeout(() => cb(true), 0);
20+
return toValue;
21+
},
22+
withDecay: (_, cb) => {
23+
cb && setTimeout(() => cb(true), 0);
24+
return 0;
25+
},
26+
cancelAnimation: NOOP,
27+
delay: (_, b) => b,
28+
sequence: () => 0,
29+
repeat: (a) => a,
30+
measure: () => ({
31+
x: 0,
32+
y: 0,
33+
width: 0,
34+
height: 0,
35+
pageX: 0,
36+
pageY: 0,
37+
}),
38+
Easing: {
39+
linear: ID,
40+
ease: ID,
41+
quad: ID,
42+
cubic: ID,
43+
poly: ID,
44+
sin: ID,
45+
circle: ID,
46+
exp: ID,
47+
elastic: ID,
48+
back: ID,
49+
bounce: ID,
50+
bezier: ID,
51+
in: ID,
52+
out: ID,
53+
inOut: ID,
54+
},
55+
};
56+
57+
module.exports = {
58+
...ReanimatedV2,
59+
};

0 commit comments

Comments
 (0)